Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login com twitter #44

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -218,6 +224,7 @@ DEPENDENCIES
omniauth (~> 1.0)
omniauth-facebook
omniauth-github
omniauth-twitter
pg
pry
rails
Expand Down
12 changes: 11 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ;)
* Código sem testes serão mais difíceis de ser aceitos ;)
2 changes: 2 additions & 0 deletions app/views/layouts/_profile.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
</div>
</div>
22 changes: 0 additions & 22 deletions config/database.yml.example

This file was deleted.

1 change: 1 addition & 0 deletions config/initializers/omniauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# GuruPI Teste
provider :facebook, '217866758240238', '22c31e695d0fb7f5cf2358e4a00741b3'
provider :github, 'ce4651e4408a4ab23d7f', '09bb99877399a43c9fae6714c07ae1469f462cdf'
provider :twitter, "zQeEghPpqkOcnukA3zIPA", "otxvnbVKKjx4gqorVY0u5N3lzZdQdO5U56pJ7hU"
end
end

Expand Down
Binary file added spec/requests/.sessions_spec.rb.swp
Binary file not shown.
26 changes: 26 additions & 0 deletions spec/requests/sessions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions spec/routing/sessions_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions spec/support/omniauth.rb
Original file line number Diff line number Diff line change
@@ -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 => '[email protected]', :name => 'foo' }
})
end