socialite 0.1.0.pre → 0.1.0.pre.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/app/assets/images/socialite/facebook_64.png +0 -0
  2. data/app/assets/images/socialite/twitter_64.png +0 -0
  3. data/app/controllers/socialite/sessions_controller.rb +69 -0
  4. data/app/controllers/socialite/users_controller.rb +2 -31
  5. data/app/views/layouts/socialite/application.html.haml +1 -1
  6. data/app/views/socialite/identities/new.html.haml +6 -19
  7. data/app/views/socialite/sessions/new.html.haml +30 -0
  8. data/app/views/socialite/users/new.html.haml +10 -0
  9. data/config/routes.rb +6 -7
  10. data/lib/generators/socialite/install_generator.rb +24 -5
  11. data/lib/generators/socialite/migrations_generator.rb +1 -1
  12. data/lib/generators/socialite/templates/socialite.rb +9 -0
  13. data/lib/generators/socialite/templates/users.rb.erb +5 -1
  14. data/lib/generators/socialite/views_generator.rb +22 -0
  15. data/lib/socialite.rb +4 -8
  16. data/lib/socialite/controllers/helpers.rb +5 -115
  17. data/lib/socialite/engine.rb +8 -11
  18. data/lib/socialite/ext/omniauth/identity/model.rb +29 -0
  19. data/lib/socialite/models/identity_concern.rb +24 -5
  20. data/lib/socialite/models/user_concern.rb +39 -0
  21. data/lib/socialite/version.rb +1 -1
  22. data/spec/dummy/app/controllers/pages_controller.rb +7 -0
  23. data/spec/dummy/app/models/user.rb +2 -0
  24. data/spec/dummy/app/views/pages/index.html.haml +5 -0
  25. data/spec/dummy/config/initializers/omniauth-identity.rb +11 -0
  26. data/spec/dummy/config/initializers/socialite.rb +9 -0
  27. data/spec/dummy/config/routes.rb +17 -1
  28. data/spec/dummy/db/migrate/20130207223009_create_socialite_users.rb +16 -0
  29. data/spec/dummy/db/migrate/{20130206224517_create_socialite_identities.rb → 20130207223010_create_socialite_identities.rb} +0 -0
  30. data/spec/dummy/db/schema.rb +7 -3
  31. data/spec/factories/user.rb +11 -1
  32. data/{features/registration/twitter_signup.feature → spec/features/.gitkeep} +0 -0
  33. data/spec/features/facebook_registration_spec.rb +16 -0
  34. data/spec/features/identity_login_spec.rb +26 -0
  35. data/spec/features/identity_registration_spec.rb +31 -0
  36. data/spec/generators/socialite/install_generator_spec.rb +8 -1
  37. data/spec/generators/socialite/views_generator_spec.rb +27 -0
  38. data/spec/models/identity_spec.rb +4 -6
  39. data/spec/models/user_spec.rb +18 -18
  40. data/spec/socialite_spec.rb +31 -7
  41. data/spec/spec_helper.rb +4 -1
  42. data/spec/support/capybara.rb +3 -0
  43. data/spec/support/database_cleaner.rb +18 -0
  44. data/spec/support/identity_shared_example.rb +4 -23
  45. data/spec/support/omniauth.rb +35 -0
  46. metadata +95 -78
  47. data/app/controllers/socialite/identities_controller.rb +0 -41
  48. data/app/controllers/socialite/session_controller.rb +0 -32
  49. data/app/views/socialite/session/new.html.haml +0 -31
  50. data/app/views/socialite/user/_form.html.haml +0 -13
  51. data/app/views/socialite/user/edit.html.haml +0 -1
  52. data/app/views/socialite/user/show.html.haml +0 -16
  53. data/features/authentication/facebook_signin.feature +0 -5
  54. data/features/authentication/twitter_signin.feature +0 -5
  55. data/features/identities/facebook_management.feature +0 -14
  56. data/features/identities/twitter_management.feature +0 -7
  57. data/features/registration/facebook_signup.feature +0 -10
  58. data/features/step_definitions/authentication_steps.rb +0 -31
  59. data/features/step_definitions/common_steps.rb +0 -13
  60. data/features/step_definitions/identity_steps.rb +0 -5
  61. data/features/step_definitions/web_steps.rb +0 -254
  62. data/features/support/env.rb +0 -58
  63. data/features/support/hooks.rb +0 -3
  64. data/features/support/omniauth.rb +0 -31
  65. data/features/support/paths.rb +0 -34
  66. data/features/support/selectors.rb +0 -39
  67. data/lib/socialite/helpers/authentication.rb +0 -17
  68. data/lib/socialite/models/facebook_identity.rb +0 -14
  69. data/spec/dummy/db/migrate/20130206224516_create_socialite_users.rb +0 -12
  70. data/spec/factories/facebook.rb +0 -5
  71. data/spec/factories/twitter.rb +0 -6
  72. data/spec/models/facebook_spec.rb +0 -31
@@ -1,41 +0,0 @@
1
- module Socialite
2
- class IdentitiesController < ApplicationController
3
- unloadable
4
-
5
- before_filter :ensure_user, :only => [:destroy]
6
- respond_to :html, :json
7
-
8
- def new
9
- @identity = env['omniauth.identity'] ||= User.new
10
- end
11
-
12
- def failure
13
- flash_message :error, 'We had trouble signing you in. Did you make sure to grant access? Please select a service below and try again.'
14
- respond_with do |format|
15
- format.html { redirect_back_or_default }
16
- end
17
- end
18
-
19
- def destroy
20
- if identity.destroy
21
- logout! if identities.count == 0
22
- flash_message :notice, 'Identity has been unlinked.'
23
- else
24
- flash_message :error, 'We had trouble unlinking this service.'
25
- end
26
- respond_with(identity) do |format|
27
- format.html { redirect_back_or_default }
28
- end
29
- end
30
-
31
- private
32
-
33
- def identities
34
- @identities = current_user.identities
35
- end
36
-
37
- def identity
38
- @identity ||= current_user.identities.find(params[:id])
39
- end
40
- end
41
- end
@@ -1,32 +0,0 @@
1
- module Socialite
2
- class SessionController < ApplicationController
3
- unloadable
4
-
5
- before_filter :ensure_user, :only => [:destroy]
6
- before_filter :ensure_no_user, :except => [:destroy]
7
-
8
- respond_to :html, :json
9
-
10
- def new; end
11
-
12
- def create
13
- @identity = Identity.find_or_initialize_by_oauth(env['omniauth.auth'])
14
- @identity.build_user if @identity.user.blank?
15
-
16
- if @identity.save
17
- self.current_user = @identity.user
18
- flash_message :notice, 'You have logged in successfully.'
19
- else
20
- flash_message :error, 'An error occurred. Please try again.'
21
- end
22
- respond_with(identity) do |format|
23
- format.html { redirect_back_or_default }
24
- end
25
- end
26
-
27
- def destroy
28
- logout!
29
- redirect_to main_app.root_path, notice: 'Signed out!'
30
- end
31
- end
32
- end
@@ -1,31 +0,0 @@
1
- %h1 Sign In
2
-
3
- %p
4
- %strong Sign in through one of these services:
5
-
6
- .auth_providers
7
- %a.auth_provider{href: "/auth/twitter"}
8
- #{image_tag "twitter_64.png", size: "64x64", alt: "Twitter"}
9
- Twitter
10
- %a.auth_provider{href: "/auth/facebook"}
11
- #{image_tag "facebook_64.png", size: "64x64", alt: "Facebook"}
12
- Facebook
13
- %a.auth_provider{href: "/auth/google_apps"}
14
- #{image_tag "google_apps_64.png", size: "64x64", alt: "Google"}
15
- Google
16
-
17
- %p
18
- %strong Don't use these services?
19
- #{link_to "Create an account", new_identity_path} or login below.
20
-
21
- = form_tag "/auth/identity/callback" do
22
- .field
23
- = label_tag :auth_key, "Email"
24
- %br
25
- = text_field_tag :auth_key
26
- .field
27
- = label_tag :password
28
- %br
29
- = password_field_tag :password
30
- .actions
31
- = submit_tag "Login"
@@ -1,13 +0,0 @@
1
- = simple_form_for(user) do |f|
2
- = f.error_notification
3
-
4
- .inputs
5
- - user.attributes.each do |attribute|
6
- - if attribute.reference?
7
- = f.association attribute.name.to_sym
8
- - else
9
- = f.input attribute.name.to_sym
10
-
11
- .actions
12
- = f.button :submit
13
-
@@ -1 +0,0 @@
1
- = render 'users/form', :locals => {:user => @user}
@@ -1,16 +0,0 @@
1
- %h2 User Settings
2
-
3
- - if @user.facebook_identity
4
- %h3 Facebook Profile
5
- = link_to 'Unlink Facebook', user_identity_path(@user.facebook_identity), :method => :delete
6
- %section.profile.facebook
7
- -# = @user.facebook.info
8
-
9
- - if @user.twitter_identity
10
- %h3 Twitter Profile
11
- = link_to 'Unlink Twitter', user_identity_path(@user.twitter_identity), :method => :delete
12
- %section.profile.twitter
13
- Not Implemented Yet.
14
-
15
- %h2 Listing Identities
16
- = render :partial => 'socialite/identities/identities', :locals => {:identities => @user.identities.all}
@@ -1,5 +0,0 @@
1
- Feature: Facebook Sign In
2
-
3
- Scenario: Successful Sign in with Facebook Account
4
-
5
- Scenario: Failed Sign in with Facebook Account
@@ -1,5 +0,0 @@
1
- Feature: Twitter Sign In
2
-
3
- Scenario: Successful sign in with Twitter
4
-
5
- Scenario: Failed sign in with Twitter
@@ -1,14 +0,0 @@
1
- @omniauth
2
- Feature: Facebook Identity Management
3
-
4
- Background:
5
- Given I am authenticated with facebook
6
-
7
- Scenario: Updating account permissions for Facebook
8
-
9
- Scenario: Unauthorizing Facebook identity from user
10
- When I am on the home page
11
- And I click "User Profile"
12
- And I click "Unlink Facebook"
13
- Then I should not be logged in
14
- And I should see a flash message
@@ -1,7 +0,0 @@
1
- Feature: Twitter Identity Management
2
-
3
- Scenario: Linking user to Twitter
4
-
5
- Scenario: Unlinking user to Twitter
6
-
7
- Scenario: Updating Twitter account permissions
@@ -1,10 +0,0 @@
1
- @omniauth
2
- Feature: Facebook Signup
3
-
4
- Scenario: Registration with Facebook
5
- Given I am not authenticated
6
- When I go to the home page
7
- And I click "Sign in"
8
- And I click "Sign in with Facebook"
9
- Then I should be logged in
10
- And I should see a flash message
@@ -1,31 +0,0 @@
1
- # Steps related to authentication can be found below
2
- #
3
- Given /^I am an authenticated user$/ do
4
- Given %{I am a user}
5
- Given %{I am authenticated}
6
- end
7
-
8
- Given /^I am authenticated with facebook$/ do
9
- Given %{I go to the home page}
10
- And %{I click "Sign in"}
11
- And %{I click "Sign in with Facebook"}
12
-
13
- Then %{I should be authenticated}
14
- And %{I should have a Facebook Identity}
15
- end
16
-
17
- Given /^I am not authenticated$/ do
18
- # do nothing
19
- end
20
-
21
- Then /^I should (not|)\s?be (?:logged in|authenticated)$/ do |negative|
22
- if negative.present?
23
- # page.should_not have_content "Dashboard"
24
- page.should_not have_content "Sign out"
25
- page.should have_content "Sign in"
26
- else
27
- # page.should have_content "Dashboard"
28
- page.should have_content "Sign out"
29
- page.should_not have_content "Sign in"
30
- end
31
- end
@@ -1,13 +0,0 @@
1
- # Don't like the when I follow, so map click
2
- # to the follow web step from capybara.
3
- When /^(?:|I )click "([^"]*)"$/ do |button|
4
- When %{follow "#{button}"}
5
- end
6
-
7
- Then /^I should (not|)\s?see a flash message$/ do |negative|
8
- if negative.present?
9
- page.should_not have_css "div.flash"
10
- else
11
- page.should have_css "div.flash"
12
- end
13
- end
@@ -1,5 +0,0 @@
1
- Then /^I should have a Facebook Identity$/ do
2
- user = Socialite::User.first
3
- user.identities.count.should > 0
4
- user.facebook_identity.should_not be_nil
5
- end
@@ -1,254 +0,0 @@
1
- # TL;DR: YOU SHOULD DELETE THIS FILE
2
- #
3
- # This file was generated by Cucumber-Rails and is only here to get you a head start
4
- # These step definitions are thin wrappers around the Capybara/Webrat API that lets you
5
- # visit pages, interact with widgets and make assertions about page content.
6
- #
7
- # If you use these step definitions as basis for your features you will quickly end up
8
- # with features that are:
9
- #
10
- # * Hard to maintain
11
- # * Verbose to read
12
- #
13
- # A much better approach is to write your own higher level step definitions, following
14
- # the advice in the following blog posts:
15
- #
16
- # * http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html
17
- # * http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
18
- # * http://elabs.se/blog/15-you-re-cuking-it-wrong
19
- #
20
-
21
-
22
- require 'uri'
23
- require 'cgi'
24
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
25
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
26
-
27
- module WithinHelpers
28
- def with_scope(locator)
29
- locator ? within(*selector_for(locator)) { yield } : yield
30
- end
31
- end
32
- World(WithinHelpers)
33
-
34
- # Single-line step scoper
35
- When /^(.*) within (.*[^:])$/ do |step, parent|
36
- with_scope(parent) { When step }
37
- end
38
-
39
- # Multi-line step scoper
40
- When /^(.*) within (.*[^:]):$/ do |step, parent, table_or_string|
41
- with_scope(parent) { When "#{step}:", table_or_string }
42
- end
43
-
44
- Given /^(?:|I )am on (.+)$/ do |page_name|
45
- visit path_to(page_name)
46
- end
47
-
48
- When /^(?:|I )go to (.+)$/ do |page_name|
49
- visit path_to(page_name)
50
- end
51
-
52
- When /^(?:|I )press "([^"]*)"$/ do |button|
53
- click_button(button)
54
- end
55
-
56
- When /^(?:|I )follow "([^"]*)"$/ do |link|
57
- click_link(link)
58
- end
59
-
60
- When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
61
- fill_in(field, :with => value)
62
- end
63
-
64
- When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
65
- fill_in(field, :with => value)
66
- end
67
-
68
- # Use this to fill in an entire form with data from a table. Example:
69
- #
70
- # When I fill in the following:
71
- # | Account Number | 5002 |
72
- # | Expiry date | 2009-11-01 |
73
- # | Note | Nice guy |
74
- # | Wants Email? | |
75
- #
76
- # TODO: Add support for checkbox, select or option
77
- # based on naming conventions.
78
- #
79
- When /^(?:|I )fill in the following:$/ do |fields|
80
- fields.rows_hash.each do |name, value|
81
- When %{I fill in "#{name}" with "#{value}"}
82
- end
83
- end
84
-
85
- When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
86
- select(value, :from => field)
87
- end
88
-
89
- When /^(?:|I )check "([^"]*)"$/ do |field|
90
- check(field)
91
- end
92
-
93
- When /^(?:|I )uncheck "([^"]*)"$/ do |field|
94
- uncheck(field)
95
- end
96
-
97
- When /^(?:|I )choose "([^"]*)"$/ do |field|
98
- choose(field)
99
- end
100
-
101
- When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
102
- attach_file(field, File.expand_path(path))
103
- end
104
-
105
- Then /^(?:|I )should see "([^"]*)"$/ do |text|
106
- if page.respond_to? :should
107
- page.should have_content(text)
108
- else
109
- assert page.has_content?(text)
110
- end
111
- end
112
-
113
- Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
114
- regexp = Regexp.new(regexp)
115
-
116
- if page.respond_to? :should
117
- page.should have_xpath('//*', :text => regexp)
118
- else
119
- assert page.has_xpath?('//*', :text => regexp)
120
- end
121
- end
122
-
123
- Then /^(?:|I )should not see "([^"]*)"$/ do |text|
124
- if page.respond_to? :should
125
- page.should have_no_content(text)
126
- else
127
- assert page.has_no_content?(text)
128
- end
129
- end
130
-
131
- Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
132
- regexp = Regexp.new(regexp)
133
-
134
- if page.respond_to? :should
135
- page.should have_no_xpath('//*', :text => regexp)
136
- else
137
- assert page.has_no_xpath?('//*', :text => regexp)
138
- end
139
- end
140
-
141
- Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
142
- with_scope(parent) do
143
- field = find_field(field)
144
- field_value = (field.tag_name == 'textarea') ? field.text : field.value
145
- if field_value.respond_to? :should
146
- field_value.should =~ /#{value}/
147
- else
148
- assert_match(/#{value}/, field_value)
149
- end
150
- end
151
- end
152
-
153
- Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
154
- with_scope(parent) do
155
- field = find_field(field)
156
- field_value = (field.tag_name == 'textarea') ? field.text : field.value
157
- if field_value.respond_to? :should_not
158
- field_value.should_not =~ /#{value}/
159
- else
160
- assert_no_match(/#{value}/, field_value)
161
- end
162
- end
163
- end
164
-
165
- Then /^the "([^"]*)" field should have the error "([^"]*)"$/ do |field, error_message|
166
- element = find_field(field)
167
- classes = element.find(:xpath, '..')[:class].split(' ')
168
-
169
- form_for_input = element.find(:xpath, 'ancestor::form[1]')
170
- using_formtastic = form_for_input[:class].include?('formtastic')
171
- error_class = using_formtastic ? 'error' : 'field_with_errors'
172
-
173
- if classes.respond_to? :should
174
- classes.should include(error_class)
175
- else
176
- assert classes.include?(error_class)
177
- end
178
-
179
- if page.respond_to?(:should)
180
- if using_formtastic
181
- error_paragraph = element.find(:xpath, '../*[@class="inline-errors"][1]')
182
- error_paragraph.should have_content(error_message)
183
- else
184
- page.should have_content("#{field.titlecase} #{error_message}")
185
- end
186
- else
187
- if using_formtastic
188
- error_paragraph = element.find(:xpath, '../*[@class="inline-errors"][1]')
189
- assert error_paragraph.has_content?(error_message)
190
- else
191
- assert page.has_content?("#{field.titlecase} #{error_message}")
192
- end
193
- end
194
- end
195
-
196
- Then /^the "([^"]*)" field should have no error$/ do |field|
197
- element = find_field(field)
198
- classes = element.find(:xpath, '..')[:class].split(' ')
199
- if classes.respond_to? :should
200
- classes.should_not include('field_with_errors')
201
- classes.should_not include('error')
202
- else
203
- assert !classes.include?('field_with_errors')
204
- assert !classes.include?('error')
205
- end
206
- end
207
-
208
- Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
209
- with_scope(parent) do
210
- field_checked = find_field(label)['checked']
211
- if field_checked.respond_to? :should
212
- field_checked.should be_true
213
- else
214
- assert field_checked
215
- end
216
- end
217
- end
218
-
219
- Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
220
- with_scope(parent) do
221
- field_checked = find_field(label)['checked']
222
- if field_checked.respond_to? :should
223
- field_checked.should be_false
224
- else
225
- assert !field_checked
226
- end
227
- end
228
- end
229
-
230
- Then /^(?:|I )should be on (.+)$/ do |page_name|
231
- current_path = URI.parse(current_url).path
232
- if current_path.respond_to? :should
233
- current_path.should == path_to(page_name)
234
- else
235
- assert_equal path_to(page_name), current_path
236
- end
237
- end
238
-
239
- Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
240
- query = URI.parse(current_url).query
241
- actual_params = query ? CGI.parse(query) : {}
242
- expected_params = {}
243
- expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
244
-
245
- if actual_params.respond_to? :should
246
- actual_params.should == expected_params
247
- else
248
- assert_equal expected_params, actual_params
249
- end
250
- end
251
-
252
- Then /^show me the page$/ do
253
- save_and_open_page
254
- end