From b5c7c4a2116264e8cce21c29882d3bac2a2a0b88 Mon Sep 17 00:00:00 2001 From: renato Date: Mon, 29 Apr 2013 10:52:55 -0300 Subject: [PATCH 1/3] login com twitter --- Gemfile | 1 + Gemfile.lock | 7 +++++++ app/views/layouts/_profile.html.erb | 2 ++ config/database.yml.example | 22 ---------------------- config/initializers/omniauth.rb | 1 + spec/requests/.sessions_spec.rb.swp | Bin 0 -> 12288 bytes spec/requests/sessions_spec.rb | 13 +++++++++++++ spec/routing/sessions_routing_spec.rb | 4 ++++ spec/support/omniauth.rb | 9 +++++++++ 9 files changed, 37 insertions(+), 22 deletions(-) delete mode 100644 config/database.yml.example create mode 100644 spec/requests/.sessions_spec.rb.swp create mode 100644 spec/support/omniauth.rb 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/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 0000000000000000000000000000000000000000..66d1d296ed91d908ab3a06bc36c78a33dec08a96 GIT binary patch literal 12288 zcmeI2L2D#M6vrzbbXQ#!R}Tv!<>b&&$@C;yc85R^6*nsAMv|;T3~fzMO;2rRs(P!c zC!3Yz6Q~#6i{eL6_a=x3VLyO^h=L$qJS@UqJ$TT6_jFBmc4p#k6c3>qei_pJs`|bE zd#?&+s!_Y}%4_s&b)MjQgpg}j_TIQmYUJw&3DI0Kt6J^+(LopA=GrPbE7RsdW@OJz z81`7AnY59yOxrAtQmroX*oH}_vs6@-PC}FNIMn=7#*HChO_blR>c)ZZ@ejQM zUV+;b$ZTu2eu6B_&()?YPtlW)uHRnY?@Bw%S)IbPMfg2AI@;&$zTm>J27FYpKfXBc|@ZAYQz5-Xl74Rzf z1!oJs1Ydy9K^MFUPJ>h6#sh@xf(zhv@G@8i&w$_WC*%ik4SWom;BBx0o&?9hZ^sGw z7JLFe1n-0Qz!rEGJPv+6M#y!r2i^kn;5e89e?p5wk0X*}ABI=JE8rFI3LJF>_<@(a z<*95EN_p{j|C7>`CA@0dD(f_9oAr1UD`~m3G&5XBl65(T<<~^RV3i3Skiv+@9T9Iu z9U-@9BeOUo7n~dq}o-Of#Jr+VmWGaV^PSK z!bk4UW;u!BHc}Xyo4WaDo-Q9w@^)sNS8h;G7-6Ya%0?-(?P4n2sN`>eBqC;(Qzo0V zDNNd7JEjncZsQ>}B9T-`y4DZ0LYoTXo7}`&G&rrSoL^m|VIfAC&sP}0;?6TN?0O<> zJ8L-4`?4!Z$0P%Hhl1{pEOnX`GQW(#he8de-yJi}Za`VWgmmHT2Q;~2h68D_m^YN# zI!q{T?7t4iO*9nFt?65S3E9hYtTO9jy^GXU@*b(U5J!sB@D2{cDm_yX-DJb)cqwRG zn=Xc7s*LRkzFpN>W2c2sVE2-o-_66=4kbPfswqT-3Ic z`Ho8J&;sLFa@wxC{9_I3hI6(2nmaRBKU-f|sE4VDZKnBib|>Xa=2FHq|33wGzWt{X zpDVlWu0$S_cURJr){#NtCoLa`cfjd#XcycByFuZ^NV_}NhQcnlB '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 From da859589b6479a0ee68779461897c9a30d26bb85 Mon Sep 17 00:00:00 2001 From: renato Date: Mon, 29 Apr 2013 11:13:05 -0300 Subject: [PATCH 2/3] testes --- spec/requests/sessions_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/requests/sessions_spec.rb b/spec/requests/sessions_spec.rb index 1577fe8..69890b9 100644 --- a/spec/requests/sessions_spec.rb +++ b/spec/requests/sessions_spec.rb @@ -16,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 @@ -50,6 +55,14 @@ 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 From bf687c6429b6d52f63dafdb311ea6b6dc3c73f51 Mon Sep 17 00:00:00 2001 From: Renato Filho Date: Mon, 29 Apr 2013 11:19:57 -0300 Subject: [PATCH 3/3] Update README.markdown --- README.markdown | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 ;)