diff --git a/Gemfile b/Gemfile index 6aede02..8c5494a 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,7 @@ gem 'heroku' gem 'omniauth', '~> 1.0' gem 'omniauth-facebook' gem 'omniauth-github' +gem 'omniauth-twitter' gem 'declarative_authorization' gem 'jquery-rails' gem 'rdiscount' diff --git a/Gemfile.lock b/Gemfile.lock index 0fee6f9..7536051 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -110,6 +110,7 @@ GEM net-ssh (>= 1.99.1) netrc (0.7.7) nokogiri (1.4.7) + oauth (0.4.7) oauth2 (0.8.1) faraday (~> 0.8) httpauth (~> 0.1) @@ -124,9 +125,14 @@ GEM omniauth-github (1.1.0) omniauth (~> 1.0) omniauth-oauth2 (~> 1.1) + omniauth-oauth (1.0.1) + oauth + omniauth (~> 1.0) omniauth-oauth2 (1.1.1) oauth2 (~> 0.8.0) omniauth (~> 1.0) + omniauth-twitter (0.0.9) + omniauth-oauth (~> 1.0) pg (0.14.0) polyglot (0.3.2) pry (0.9.12) @@ -218,6 +224,7 @@ DEPENDENCIES omniauth (~> 1.0) omniauth-facebook omniauth-github + omniauth-twitter pg pry rails diff --git a/README.markdown b/README.markdown index 17c9a30..bf8e62e 100644 --- a/README.markdown +++ b/README.markdown @@ -2,6 +2,16 @@ Grupo de Usuários de Ruby do Piauí + +## Twitter Omniaauth +No arquivo config/omniauth.rb adicionei o provider do twitter. + provider :twitter, "{PROVIDER_KEY}", "{PROVIDER_SECRET}" + +Adicionei o arquivo omniauth.rb em spec/support com um método que retorna uma hash de usuário para ser usada no teste + +Adicionei alguns testes em spec/requests/sessions_spec.rb + + ## Primeiros Passos Crie um clone do projeto @@ -50,4 +60,4 @@ Toda vez que você salvar um arquivo importante, o Guard irá executar seus test * Faça as alterações com os respectivos testes (Este projeto utiliza o RSpec) * Para fazer com seus testes executem automaticamente a cada alteração de arquivo, execute o guard na linha de comando * Faça um pull request -* Código sem testes serão mais difíceis de ser aceitos ;) \ No newline at end of file +* Código sem testes serão mais difíceis de ser aceitos ;) diff --git a/app/views/layouts/_profile.html.erb b/app/views/layouts/_profile.html.erb index 6e1d094..4adc9a5 100644 --- a/app/views/layouts/_profile.html.erb +++ b/app/views/layouts/_profile.html.erb @@ -8,6 +8,8 @@ <% else %> <%= link_to "Conectar com Facebook", "/auth/facebook", :class => "login_facebook" %> <%= link_to "Conectar com Github", "/auth/github", :class => "login_github" %> + <%= link_to "Conectar com Twitter", "/auth/twitter", %> + <% end %> diff --git a/config/database.yml.example b/config/database.yml.example deleted file mode 100644 index 90d87cc..0000000 --- a/config/database.yml.example +++ /dev/null @@ -1,22 +0,0 @@ -# SQLite version 3.x -# gem install sqlite3 -development: - adapter: sqlite3 - database: db/development.sqlite3 - pool: 5 - timeout: 5000 - -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. -test: - adapter: sqlite3 - database: db/test.sqlite3 - pool: 5 - timeout: 5000 - -production: - adapter: sqlite3 - database: db/production.sqlite3 - pool: 5 - timeout: 5000 diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 87a71ed..cc9a8f3 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -7,6 +7,7 @@ # GuruPI Teste provider :facebook, '217866758240238', '22c31e695d0fb7f5cf2358e4a00741b3' provider :github, 'ce4651e4408a4ab23d7f', '09bb99877399a43c9fae6714c07ae1469f462cdf' + provider :twitter, "zQeEghPpqkOcnukA3zIPA", "otxvnbVKKjx4gqorVY0u5N3lzZdQdO5U56pJ7hU" end end diff --git a/spec/requests/.sessions_spec.rb.swp b/spec/requests/.sessions_spec.rb.swp new file mode 100644 index 0000000..66d1d29 Binary files /dev/null and b/spec/requests/.sessions_spec.rb.swp differ diff --git a/spec/requests/sessions_spec.rb b/spec/requests/sessions_spec.rb index 7ca24de..69890b9 100644 --- a/spec/requests/sessions_spec.rb +++ b/spec/requests/sessions_spec.rb @@ -4,6 +4,7 @@ describe "Sessions" do button_login_facebook = 'Conectar com Facebook' button_login_github = 'Conectar com Github' + button_login_twitter = 'Conectar com Twitter' describe "GET /" do it "displays '#{button_login_facebook}'" do @@ -15,6 +16,11 @@ visit root_path page.should have_content(button_login_github) end + + it "displays '#{button_login_twitter}'" do + visit root_path + page.should have_content(button_login_twitter) + end it "displays User name and image when sign in via Facebook" do visit root_path @@ -49,5 +55,25 @@ click_on 'Sair' page.should have_content(button_login_github) end + + it "exit and displays '#{button_login_twitter}' again" do + visit root_path + click_on button_login_twitter + click_on "Sair" + page.should have_content(button_login_twitter) + end + + end + + describe "POST /login/auth" do + it "authenticate and displays user when sign in Twitter" do + visit root_path + page.should have_content(button_login_twitter) + set_omniauth_twitter() + user_name = OmniAuth.config.mock_auth[:twitter][:info][:name] + click_link button_login_twitter + page.should have_content 'Sair' + page.should have_content user_name + end end end diff --git a/spec/routing/sessions_routing_spec.rb b/spec/routing/sessions_routing_spec.rb index 9c6c97f..1e7130b 100644 --- a/spec/routing/sessions_routing_spec.rb +++ b/spec/routing/sessions_routing_spec.rb @@ -11,6 +11,10 @@ get("/auth/github/callback").should route_to("sessions#create", :provider => 'github') end + it "routes to #create" do + get("/auth/twitter/callback").should route_to("sessions#create", :provider => 'twitter') + end + it "routes to #destroy" do get("/signout").should route_to("sessions#destroy") end diff --git a/spec/support/omniauth.rb b/spec/support/omniauth.rb new file mode 100644 index 0000000..7e2d11d --- /dev/null +++ b/spec/support/omniauth.rb @@ -0,0 +1,9 @@ +def set_omniauth_twitter(opts={}) + OmniAuth.config.test_mode = true + + OmniAuth.config.mock_auth[:twitter] = OmniAuth::AuthHash.new({ + :provider => 'twitter', + :uid => '12345', + :info => { :email => 'foo@example.com', :name => 'foo' } + }) +end