blue_light_special 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. data/README.rdoc +28 -0
  2. data/VERSION +1 -1
  3. data/app/controllers/blue_light_special/impersonations_controller.rb +6 -3
  4. data/test/rails_root/app/controllers/admin/admin_controller.rb +14 -0
  5. data/test/rails_root/app/controllers/admin/users_controller.rb +52 -0
  6. data/test/rails_root/config/initializers/blue_light_special.rb +20 -3
  7. data/test/rails_root/db/migrate/{20100305173127_blue_light_special_create_users.rb → 20100727214301_blue_light_special_create_users.rb} +4 -1
  8. data/test/rails_root/db/migrate/{20100305173129_create_delayed_jobs.rb → 20100727214302_create_delayed_jobs.rb} +0 -0
  9. data/test/rails_root/test/factories/user.rb +10 -0
  10. data/test/rails_root/test/integration/admin/users_test.rb +201 -0
  11. data/test/rails_root/test/integration/edit_profile_test.rb +35 -0
  12. data/test/rails_root/test/integration/facebook_test.rb +48 -36
  13. data/test/rails_root/test/integration/impersonation_test.rb +5 -4
  14. data/test/rails_root/test/integration/password_reset_test.rb +5 -4
  15. data/test/rails_root/test/integration/sign_in_test.rb +0 -6
  16. data/test/rails_root/test/integration/sign_up_test.rb +3 -40
  17. data/test/rails_root/vendor/gems/delayed_job-1.8.4/generators/delayed_job/delayed_job_generator.rb +22 -0
  18. data/test/rails_root/vendor/gems/delayed_job-1.8.4/generators/delayed_job/templates/migration.rb +20 -0
  19. data/test/rails_root/vendor/gems/delayed_job-1.8.4/init.rb +1 -0
  20. data/test/rails_root/vendor/gems/delayed_job-1.8.4/lib/delayed/command.rb +76 -0
  21. data/test/rails_root/vendor/gems/delayed_job-1.8.4/lib/delayed/job.rb +270 -0
  22. data/test/rails_root/vendor/gems/delayed_job-1.8.4/lib/delayed/message_sending.rb +22 -0
  23. data/test/rails_root/vendor/gems/delayed_job-1.8.4/lib/delayed/performable_method.rb +55 -0
  24. data/test/rails_root/vendor/gems/delayed_job-1.8.4/lib/delayed/recipes.rb +27 -0
  25. data/test/rails_root/vendor/gems/delayed_job-1.8.4/lib/delayed/tasks.rb +15 -0
  26. data/test/rails_root/vendor/gems/delayed_job-1.8.4/lib/delayed/worker.rb +54 -0
  27. data/test/rails_root/vendor/gems/delayed_job-1.8.4/lib/delayed_job.rb +13 -0
  28. data/test/rails_root/vendor/gems/delayed_job-1.8.4/recipes/delayed_job.rb +1 -0
  29. data/test/rails_root/vendor/gems/delayed_job-1.8.4/spec/database.rb +42 -0
  30. data/test/rails_root/vendor/gems/delayed_job-1.8.4/spec/delayed_method_spec.rb +150 -0
  31. data/test/rails_root/vendor/gems/delayed_job-1.8.4/spec/job_spec.rb +406 -0
  32. data/test/rails_root/vendor/gems/delayed_job-1.8.4/spec/story_spec.rb +17 -0
  33. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.4/generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb +21 -0
  34. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.4/lib/formtastic.rb +1312 -0
  35. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.4/lib/justin_french/formtastic.rb +10 -0
  36. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.4/rails/init.rb +3 -0
  37. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.4/spec/formtastic_spec.rb +3079 -0
  38. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.4/spec/test_helper.rb +14 -0
  39. data/test/rails_root/vendor/gems/mini_fb-0.2.2/lib/mini_fb.rb +284 -0
  40. data/test/rails_root/vendor/gems/mini_fb-0.2.2/test/test_mini_fb.rb +29 -0
  41. metadata +111 -6
@@ -62,6 +62,34 @@ interface. If you'd like to generate the admin interface, run:
62
62
 
63
63
  This will generate your user admin controller and its integration test.
64
64
 
65
+ == Mad Mimi
66
+
67
+ If you'd like an overview of Mad Mimi, check out the third part of
68
+ {this screencast}[http://railslab.newrelic.com/2009/10/23/episode-21-on-the-edge-part-3].
69
+ In order to get Blue Light Special working with Mad Mimi, you'll need to sign
70
+ up for an account at {madmimi.com}[http://madmimi.com/r/b8599b9343f82e3bc30984ca4f3fea3f].
71
+
72
+ Your Mad Mimi account needs API access, so be sure to enable that during the signup
73
+ process. The support people at Mad Mimi will manually authorize your account for
74
+ API access. This usually happens within a few hours after you've signed up. Until
75
+ your account is authorized, you'll see HTTP errors when your Rails app attempts to
76
+ send email.
77
+
78
+ After you've signed up and your API access has been approved, all you'll need to do is
79
+ put your Mad Mimi username and API key in config/blue_light_special.yml.
80
+
81
+ == Facebook Connect
82
+
83
+ To set up Facebook Connect, go to the {Facebook developer page}[http://facebook.com/developers]
84
+ and create a new Facebook app. Since you're only using this app for Facebook Connect,
85
+ you can leave most of the fields blank. Be sure to give your app a name, and then
86
+ head over to the Connect settings and set the Connect URL to point at your Rails app.
87
+ In the Advanced section, you'll need to set Email Domain to the domain from which you'll
88
+ be sending email messages.
89
+
90
+ After you've finished setting up your Facebook app, grab its API key and secret key
91
+ and put them in config/blue_light_special.yml.
92
+
65
93
  == Copyright
66
94
 
67
95
  Copyright (c) 2010 Envy Labs LLC. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -14,8 +14,11 @@ class BlueLightSpecial::ImpersonationsController < ApplicationController
14
14
  flash[:failure] = "Cannot impersonate yourself"
15
15
  redirect_to root_url
16
16
  else
17
- session[:admin_user_id] = current_user.id
18
- session[:impersonation_hash] = Impersonation.hash_for(current_user.id)
17
+ unless session[:admin_user_id]
18
+ session[:admin_user_id] = current_user.id
19
+ session[:impersonation_hash] = Impersonation.hash_for(current_user.id)
20
+ end
21
+ session[:impersonation_back_url] = request.env["HTTP_REFERER"]
19
22
  sign_in(user)
20
23
  redirect_to root_url
21
24
  end
@@ -28,7 +31,7 @@ class BlueLightSpecial::ImpersonationsController < ApplicationController
28
31
  session[:admin_user_id] = nil
29
32
  session[:impersonation_hash] = nil
30
33
  sign_in(admin_user)
31
- redirect_to impersonations_url
34
+ redirect_to session[:impersonation_back_url]
32
35
  else
33
36
  deny_access
34
37
  end
@@ -0,0 +1,14 @@
1
+ class Admin::AdminController < ApplicationController
2
+
3
+ before_filter :authenticate
4
+ before_filter :check_role
5
+
6
+
7
+ private
8
+
9
+
10
+ def check_role
11
+ redirect_to root_url unless current_user.admin?
12
+ end
13
+
14
+ end
@@ -0,0 +1,52 @@
1
+ class Admin::UsersController < Admin::AdminController
2
+
3
+ def index
4
+ @users = User.all
5
+ end
6
+
7
+ def show
8
+ @user = User.find(params[:id])
9
+ end
10
+
11
+ def new
12
+ @user = User.new
13
+ end
14
+
15
+ def create
16
+ @user = User.new(params[:user])
17
+ @user.role = params[:user][:role]
18
+ if @user.save
19
+ flash[:notice] = "Created #{@user.name}"
20
+ redirect_to admin_user_url(@user)
21
+ else
22
+ render :action => 'new'
23
+ end
24
+ end
25
+
26
+ def edit
27
+ @user = User.find(params[:id])
28
+ end
29
+
30
+ def update
31
+ @user = User.find(params[:id])
32
+ @user.role = params[:user][:role]
33
+ if @user.update_attributes(params[:user])
34
+ flash[:notice] = "Updated #{@user.name}"
35
+ redirect_to admin_user_url(@user)
36
+ else
37
+ render :action => 'edit'
38
+ end
39
+ end
40
+
41
+ def destroy
42
+ @user = User.find(params[:id])
43
+ if @user != current_user
44
+ @user.destroy
45
+ flash[:notice] = "Deleted #{@user.name}"
46
+ else
47
+ flash[:error] = "Cannot delete yourself"
48
+ end
49
+ redirect_to admin_users_url
50
+ end
51
+
52
+ end
@@ -1,4 +1,21 @@
1
- BlueLightSpecial.configure do |config|
2
- config.mailer_sender = 'donotreply@example.com'
3
- config.impersonation_hash = 'REPLACE WITH A LONG HASH HERE'
1
+ require 'yaml'
2
+
3
+ begin
4
+ configuration = YAML.load_file("#{Rails.root}/config/blue_light_special.yml")[Rails.env]
5
+ configuration = HashWithIndifferentAccess.new(configuration)
6
+
7
+ BlueLightSpecial.configure do |config|
8
+ config.mailer_sender = configuration[:mailer_sender]
9
+ config.impersonation_hash = configuration[:impersonation_hash]
10
+ config.use_facebook_connect = configuration[:use_facebook_connect]
11
+ config.facebook_api_key = configuration[:facebook_api_key]
12
+ config.facebook_secret_key = configuration[:facebook_secret_key]
13
+ end
14
+
15
+ MadMimiMailer.api_settings = {
16
+ :username => configuration[:madmimi_username],
17
+ :api_key => configuration[:madmimi_api_key]
18
+ }
19
+ rescue LoadError
20
+ puts "The /config/blue_light_special.yml file is missing or broken."
4
21
  end
@@ -1,7 +1,9 @@
1
1
  class BlueLightSpecialCreateUsers < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table(:users) do |t|
4
- t.string :email
4
+ t.string :email, :limit => 100
5
+ t.string :first_name, :limit => 50
6
+ t.string :last_name, :limit => 50
5
7
  t.string :role, :limit => 50
6
8
  t.string :encrypted_password, :limit => 128
7
9
  t.string :salt, :limit => 128
@@ -13,6 +15,7 @@ class BlueLightSpecialCreateUsers < ActiveRecord::Migration
13
15
 
14
16
  add_index :users, :email
15
17
  add_index :users, :remember_token
18
+ add_index :users, :facebook_uid
16
19
  end
17
20
 
18
21
  def self.down
@@ -2,8 +2,14 @@ Factory.sequence :email do |n|
2
2
  "user#{n}@example.com"
3
3
  end
4
4
 
5
+ Factory.sequence :facebook_id do |n|
6
+ n
7
+ end
8
+
5
9
  Factory.define :user do |user|
6
10
  user.email { Factory.next :email }
11
+ user.first_name { "Factory" }
12
+ user.last_name { "User" }
7
13
  user.password { "password" }
8
14
  user.password_confirmation { "password" }
9
15
  end
@@ -11,3 +17,7 @@ end
11
17
  Factory.define :admin_user, :parent => :user do |admin|
12
18
  admin.role 'admin'
13
19
  end
20
+
21
+ Factory.define :facebook_user, :parent => :user do |user|
22
+ user.facebook_uid { Factory.next :facebook_id }
23
+ end
@@ -0,0 +1,201 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ class Admin::UsersTest < ActionController::IntegrationTest
4
+
5
+ setup do
6
+ ActionMailer::Base.deliveries.clear
7
+ end
8
+
9
+ teardown do
10
+ ActionMailer::Base.deliveries.clear
11
+ end
12
+
13
+ context 'Signed in as an admin' do
14
+
15
+ setup do
16
+ @bob = Factory(:user, :email => 'bob@bob.bob', :first_name => 'Bob')
17
+ @joe = Factory(:user, :email => 'joe@joe.joe', :first_name => 'Joe')
18
+ @ted = Factory(:user, :email => 'ted@ted.ted', :first_name => 'Ted')
19
+ @admin_user = Factory(:admin_user, :email => 'admin@example.com')
20
+ sign_in_as(@admin_user.email, @admin_user.password)
21
+ end
22
+
23
+ context 'when listing users' do
24
+
25
+ should 'show the list of users' do
26
+ visit admin_users_url
27
+ assert_contain(/bob@bob.bob/)
28
+ assert_contain(/joe@joe.joe/)
29
+ assert_contain(/ted@ted.ted/)
30
+ end
31
+
32
+ end
33
+
34
+ context 'when creating a new user' do
35
+
36
+ context 'with valid data' do
37
+
38
+ should 'display "Created [name]"' do
39
+ create_user(:first_name => 'Tom', :last_name => 'Tom')
40
+ assert_contain(/Created Tom Tom/)
41
+ end
42
+
43
+ should 'redirect to the user show page' do
44
+ create_user(:email => 'tom@tom.tom')
45
+ user = User.find_by_email('tom@tom.tom')
46
+ assert_equal current_url, admin_user_url(user)
47
+ end
48
+
49
+ should 'be able to set the role' do
50
+ create_user(:email => 'tom@tom.tom', :role => 'admin')
51
+ user = User.find_by_email('tom@tom.tom')
52
+ assert user.admin?
53
+ end
54
+
55
+ end
56
+
57
+ context 'with invalid data' do
58
+
59
+ should 'display error messages' do
60
+ create_user(
61
+ :first_name => '',
62
+ :last_name => '',
63
+ :email => 'invalidemail',
64
+ :password_confirmation => 'bad')
65
+ assert_contain(/First name can't be blank/)
66
+ assert_contain(/Last name can't be blank/)
67
+ assert_contain(/Email is invalid/)
68
+ assert_contain(/Password doesn't match confirmation/)
69
+ end
70
+
71
+ should 'redisplay the new user form' do
72
+ create_user(:first_name => '')
73
+ assert_have_selector 'form.new_user'
74
+ end
75
+
76
+ end
77
+
78
+ end
79
+
80
+ context 'when editing a user' do
81
+
82
+ context 'with valid data' do
83
+
84
+ should 'display "Updated [name]"' do
85
+ edit_user(@ted, :first_name => 'Tom', :last_name => 'Tom' )
86
+ assert_contain(/Updated Tom Tom/)
87
+ end
88
+
89
+ should 'redirect to the user show page' do
90
+ edit_user(@ted, :email => 'tom@tom.tom')
91
+ user = User.find_by_email('tom@tom.tom')
92
+ assert_equal current_url, admin_user_url(user)
93
+ end
94
+
95
+ should 'be able to change the role' do
96
+ edit_user(@ted, :role => 'admin')
97
+ @ted.reload
98
+ assert @ted.admin?
99
+ end
100
+
101
+ end
102
+
103
+ context 'with invalid data' do
104
+
105
+ should 'display error messages' do
106
+ edit_user(@ted,
107
+ :first_name => '',
108
+ :last_name => '',
109
+ :email => 'invalidemail',
110
+ :password => 'good',
111
+ :password_confirmation => 'bad')
112
+ assert_contain(/First name can't be blank/)
113
+ assert_contain(/Last name can't be blank/)
114
+ assert_contain(/Email is invalid/)
115
+ assert_contain(/Password doesn't match confirmation/)
116
+ end
117
+
118
+ should 'redisplay the edit form' do
119
+ edit_user(@ted, :first_name => '')
120
+ assert_have_selector 'form.edit_user'
121
+ end
122
+
123
+ end
124
+
125
+ end
126
+
127
+ context 'when deleting a user' do
128
+
129
+ should 'display "Deleted [name]"' do
130
+ delete_user(@bob)
131
+ assert_contain(/Deleted Bob/)
132
+ end
133
+
134
+ should 'redirect to the user list' do
135
+ delete_user(@bob)
136
+ assert_equal current_url, admin_users_url
137
+ end
138
+
139
+ should 'not display the deleted user in the list' do
140
+ delete_user(@bob)
141
+ assert_not_contain(/bob@bob.bob/)
142
+ end
143
+
144
+ should 'not allow deleting currently logged in user' do
145
+ visit admin_user_url(@admin_user), :delete
146
+ assert_contain(/Cannot delete yourself/)
147
+ assert_contain(/admin@example.com/)
148
+ end
149
+
150
+ end
151
+
152
+ end
153
+
154
+ context 'Signed in as a non-admin user' do
155
+
156
+ setup do
157
+ @user = Factory(:user)
158
+ sign_in_as(@user.email, @user.password)
159
+ end
160
+
161
+ should 'not give access' do
162
+ visit admin_users_url
163
+ assert_not_equal current_url, admin_users_url
164
+ end
165
+
166
+ end
167
+
168
+
169
+ private
170
+
171
+
172
+ def create_user(options = {})
173
+ visit admin_users_url
174
+ click_link 'New User'
175
+ fill_in 'Email', :with => options[:email] || 'tom@tom.tom'
176
+ fill_in 'Password', :with => options[:password] || 'password'
177
+ fill_in 'Confirm Password', :with => options[:password_confirmation] || options[:password] || 'password'
178
+ fill_in 'First Name', :with => options[:first_name] || 'Tom'
179
+ fill_in 'Last Name', :with => options[:last_name] || 'Tom'
180
+ select options[:role] || '', :from => 'Role'
181
+ click_button 'Save'
182
+ end
183
+
184
+ def edit_user(user, options = {})
185
+ visit admin_user_url(user)
186
+ click_link 'Edit'
187
+ fill_in 'Email', :with => options[:email] || 'tom@tom.tom'
188
+ fill_in 'Password', :with => options[:password] || ''
189
+ fill_in 'Confirm Password', :with => options[:password_confirmation] || options[:password] || ''
190
+ fill_in 'First Name', :with => options[:first_name] || 'Tom'
191
+ fill_in 'Last Name', :with => options[:last_name] || 'Tom'
192
+ select options[:role] || '', :from => 'Role'
193
+ click_button 'Save'
194
+ end
195
+
196
+ def delete_user(user)
197
+ visit admin_user_url(user)
198
+ click_link 'Delete'
199
+ end
200
+
201
+ end
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ class EditProfileTest < ActionController::IntegrationTest
4
+
5
+ context 'Editing a user profile' do
6
+
7
+ setup do
8
+ @user = Factory(:user, :password => 'password')
9
+ sign_in_as(@user.email, 'password')
10
+ visit edit_user_path(@user)
11
+ end
12
+
13
+ should_respond_with :success
14
+
15
+ should "see the form with his info" do
16
+ assert_select "input#user_first_name[value='#{@user.first_name}']"
17
+ assert_select "input#user_last_name[value='#{@user.last_name}']"
18
+ assert_select "input#user_email[value='#{@user.email}']"
19
+ end
20
+
21
+ should "update valid information and see the SHOW page" do
22
+ fill_in "user_first_name", :with => 'OtherName'
23
+ click_button 'Save'
24
+ assert_contain /othername/i
25
+ end
26
+
27
+ should "update invalid information and see errors" do
28
+ fill_in "user_first_name", :with => ''
29
+ click_button 'Save'
30
+ assert_contain /First name .* blank/i
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -1,49 +1,61 @@
1
1
  require 'test_helper'
2
- require 'facebooker/mock/service'
3
- require 'facebooker/mock/session'
4
2
 
5
3
  class FacebookTest < ActionController::IntegrationTest
4
+
5
+ if BlueLightSpecial.configuration.use_facebook_connect
6
6
 
7
- context 'Signing in with Facebook' do
7
+ context 'Signing in with Facebook' do
8
8
 
9
- setup do
10
- Facebooker::MockService.fixture_path = File.dirname(__FILE__) + '/../facebooker_fixtures'
11
- fb_session = Facebooker::MockSession.create
12
- fb_session.secure!
13
- CitiesController.any_instance.stubs(:facebook_session).returns(fb_session)
14
- end
9
+ setup do
10
+ cookies[BlueLightSpecial.configuration.facebook_api_key + "_user"] = "8055"
11
+ cookies[BlueLightSpecial.configuration.facebook_api_key + "_session_key"] = "123456789"
12
+ FakeWeb.register_uri(:post,
13
+ %r|http://api.facebook.com/restserver.php|,
14
+ :body => '[{"about_me":"","activities":"","affiliations":{},"birthday":"July 18","books":"","current_location":{"city":"Orlando","state":"Florida","country":"United States","zip":""},"education_history":[{"name":"Florida Institute of Technology","year":1995,"concentrations":{},"degree":"","school_type":"Unknown"}],"first_name":"Bob","hometown_location":null,"hs_info":{"hs1_name":"Cheyenne Mountain High School","hs2_name":"","grad_year":1992,"hs1_id":3202,"hs2_id":0},"interests":"","is_app_user":true,"last_name":"Jones","meeting_for":{},"meeting_sex":{},"movies":"","music":"","name":"Bob Jones","notes_count":null,"pic":"http:\/\/profile.ak.fbcdn.net\/hprofile-ak-sf2p\/hs272.snc3\/23197_1334019372_5345_s.jpg","pic_big":"http:\/\/profile.ak.fbcdn.net\/v228\/245\/118\/n1334019372_6158.jpg","pic_small":"http:\/\/profile.ak.fbcdn.net\/hprofile-ak-sf2p\/hs272.snc3\/23197_1334019372_5345_t.jpg","political":"","profile_update_time":1267034911,"quotes":"","relationship_status":"","religion":"","sex":"male","significant_other_id":null,"status":{"message":"","time":0,"status_id":0},"timezone":-5,"tv":"","uid":8055,"wall_count":34,"work_history":{},"pic_square":"http:\/\/profile.ak.fbcdn.net\/hprofile-ak-sf2p\/hs272.snc3\/23197_1334019372_5345_q.jpg","has_added_app":true,"email_hashes":{},"locale":"en_US","profile_url":"http:\/\/www.facebook.com\/profile.php?id=1334019372","proxied_email":"apps+339309032618.1334019372.a320f4a38471f7b537079f5c13bb33f1@proxymail.facebook.com","pic_big_with_logo":"http:\/\/external.ak.fbcdn.net\/safe_image.php?logo&d=20fef10357c21b2e1acc8dac7d4bed49&url=http%3A%2F%2Fprofile.ak.fbcdn.net%2Fv228%2F245%2F118%2Fn1334019372_6158.jpg&v=5","pic_small_with_logo":"http:\/\/external.ak.fbcdn.net\/safe_image.php?logo&d=ad4b560e363f5b40ccbe81e1d985c91e&url=http%3A%2F%2Fprofile.ak.fbcdn.net%2Fhprofile-ak-sf2p%2Fhs272.snc3%2F23197_1334019372_5345_t.jpg&v=5","pic_square_with_logo":"http:\/\/external.ak.fbcdn.net\/safe_image.php?logo&d=a0118842ed70fce04e7883f5ab52023f&url=http%3A%2F%2Fprofile.ak.fbcdn.net%2Fhprofile-ak-sf2p%2Fhs272.snc3%2F23197_1334019372_5345_q.jpg&v=5","pic_with_logo":"http:\/\/external.ak.fbcdn.net\/safe_image.php?logo&d=eb90cc8c5f332436f5d56009aab6b467&url=http%3A%2F%2Fprofile.ak.fbcdn.net%2Fhprofile-ak-sf2p%2Fhs272.snc3%2F23197_1334019372_5345_s.jpg&v=5","birthday_date":"07\/18","email":"bob@example.com","allowed_restrictions":"alcohol"}]'
15
+ )
16
+ end
15
17
 
16
- should 'find an existing user with the facebook uid' do
17
- user = Factory( :facebook_user,
18
- :facebook_uid => 8055,
19
- :email => 'bob@facebook.com',
20
- :first_name => 'Bob',
21
- :last_name => 'Jones',
22
- :display_name => 'Bob Jones',
23
- :zip_code => '11111')
24
-
25
- visit city_url(City.default)
26
- assert controller.signed_in?
27
- assert_equal controller.current_user, user
28
- end
18
+ teardown do
19
+ cookies[BlueLightSpecial.configuration.facebook_api_key + "_user"] = nil
20
+ cookies[BlueLightSpecial.configuration.facebook_api_key + "_session_key"] = nil
21
+ end
29
22
 
30
- should 'create a new user when the facebook uid is not found' do
31
- assert_nil User.find_by_facebook_uid(8055)
23
+ should 'find an existing user with the facebook uid' do
24
+ user = Factory( :facebook_user,
25
+ :facebook_uid => 8055,
26
+ :email => 'bob@facebook.com')
27
+
28
+ visit fb_connect_url
29
+ assert controller.signed_in?
30
+ assert_equal controller.current_user, user
31
+ end
32
+
33
+ should 'find an existing user with the facebook email address' do
34
+ user = Factory( :user,
35
+ :facebook_uid => nil,
36
+ :email => 'bob@example.com')
37
+
38
+ visit fb_connect_url
39
+ assert controller.signed_in?
40
+ assert_equal controller.current_user, user
41
+ end
42
+
43
+ should 'create a new user when the facebook uid is not found' do
44
+ assert_nil User.find_by_facebook_uid(8055)
32
45
 
33
- visit city_url(City.default)
34
- assert controller.signed_in?
35
- assert_equal controller.current_user.facebook_uid, 8055
36
- end
46
+ visit fb_connect_url
47
+ assert controller.signed_in?
48
+ assert_equal '8055', controller.current_user.facebook_uid
49
+ end
37
50
 
38
- should 'copy the facebook user details' do
39
- visit city_url(City.default)
40
- assert controller.signed_in?
41
- assert_equal controller.current_user.first_name, 'Dave'
42
- assert_equal controller.current_user.last_name, 'Fetterman'
43
- assert_equal controller.current_user.display_name, 'Dave Fetterman'
44
- assert_equal controller.current_user.email, 'bob@facebook.com'
45
- end
51
+ should 'copy the facebook user details' do
52
+ visit fb_connect_url
53
+ assert controller.signed_in?
54
+ assert_equal 'bob@example.com', controller.current_user.email
55
+ end
46
56
 
57
+ end
58
+
47
59
  end
48
60
 
49
61
  end