authlogic_facebook_shim 0.3.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/Gemfile +4 -0
  2. data/Gemfile.lock +113 -0
  3. data/README.rdoc +8 -1
  4. data/Rakefile +39 -20
  5. data/authlogic_facebook_shim.gemspec +22 -19
  6. data/lib/authlogic_facebook_shim/adapters/koala_adapter.rb +12 -9
  7. data/lib/authlogic_facebook_shim/railtie.rb +19 -0
  8. data/lib/authlogic_facebook_shim/session/adapter.rb +23 -0
  9. data/lib/authlogic_facebook_shim/session/config.rb +1 -1
  10. data/lib/authlogic_facebook_shim/session/facebook.rb +3 -4
  11. data/lib/authlogic_facebook_shim/session.rb +4 -0
  12. data/lib/authlogic_facebook_shim/version.rb +3 -0
  13. data/lib/authlogic_facebook_shim.rb +6 -9
  14. data/test/dummy/app/controllers/application_controller.rb +3 -0
  15. data/test/dummy/app/helpers/application_helper.rb +2 -0
  16. data/test/{rails_root → dummy}/app/models/user.rb +1 -0
  17. data/test/{rails_root → dummy}/app/models/user_session.rb +0 -0
  18. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  19. data/test/dummy/config/application.rb +49 -0
  20. data/test/dummy/config/boot.rb +10 -0
  21. data/test/dummy/config/database.yml +6 -0
  22. data/test/dummy/config/environment.rb +5 -0
  23. data/test/dummy/config/environments/development.rb +27 -0
  24. data/test/dummy/config/environments/test.rb +37 -0
  25. data/test/{rails_root → dummy}/config/facebook.yml +0 -0
  26. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  27. data/test/dummy/config/initializers/inflections.rb +10 -0
  28. data/test/dummy/config/initializers/mime_types.rb +5 -0
  29. data/test/dummy/config/initializers/secret_token.rb +7 -0
  30. data/test/dummy/config/initializers/session_store.rb +8 -0
  31. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  32. data/test/dummy/config/locales/en.yml +5 -0
  33. data/test/dummy/config/routes.rb +2 -0
  34. data/test/dummy/config.ru +4 -0
  35. data/test/{rails_root → dummy}/db/migrate/20101217000008_create_users.rb +0 -0
  36. data/test/{rails_root → dummy}/db/seeds.rb +0 -0
  37. data/test/dummy/log/test.log +1386 -0
  38. data/test/test_helper.rb +20 -20
  39. data/test/units/adapters/koala_adapter_test.rb +202 -146
  40. data/test/units/session/config_test.rb +110 -108
  41. data/test/units/session/facebook_test.rb +175 -156
  42. metadata +123 -155
  43. data/VERSION +0 -1
  44. data/test/rails_root/app/controllers/application_controller.rb +0 -10
  45. data/test/rails_root/app/helpers/application_helper.rb +0 -3
  46. data/test/rails_root/config/boot.rb +0 -110
  47. data/test/rails_root/config/database.yml +0 -10
  48. data/test/rails_root/config/environment.rb +0 -31
  49. data/test/rails_root/config/environments/development.rb +0 -0
  50. data/test/rails_root/config/environments/test.rb +0 -0
  51. data/test/rails_root/config/initializers/authlogic_facebook_koala.rb +0 -5
  52. data/test/rails_root/config/initializers/new_rails_defaults.rb +0 -21
  53. data/test/rails_root/config/initializers/session_store.rb +0 -15
  54. data/test/rails_root/config/locales/en.yml +0 -5
  55. data/test/rails_root/config/routes.rb +0 -43
  56. data/test/rails_root/log/test.log +0 -1137
  57. data/test/rails_root/script/console +0 -3
  58. data/test/rails_root/script/dbconsole +0 -3
  59. data/test/rails_root/script/generate +0 -3
@@ -1,145 +1,147 @@
1
1
  require File.expand_path( '../../test_helper.rb', File.dirname(__FILE__) )
2
2
 
3
- class AuthlogicFacebookShim::Session::ConfigTest < ActiveSupport::TestCase
4
-
5
- context "Session::Config" do
3
+ describe AuthlogicFacebookShim::Session::Config do
6
4
 
7
- setup do
8
- @session_class = Class.new(Authlogic::Session::Base)
9
- end
5
+ before do
6
+ @session_class = Class.new(Authlogic::Session::Base)
7
+ end
10
8
 
11
- context "facebook_config_file" do
9
+ describe "facebook_config_file" do
12
10
 
13
- should "have a default 'facebook.yml'" do
14
- assert_equal 'facebook.yml', @session_class.facebook_config_file
15
- end
16
-
17
- should "have a setter method" do
18
- fb_config = 'fbconf.yml'
19
- @session_class.facebook_config_file = fb_config
20
- assert_equal fb_config, @session_class.facebook_config_file
21
- end
22
-
11
+ it "should have a default 'facebook.yml'" do
12
+ @session_class.facebook_config_file.must_equal 'facebook.yml'
13
+ end
14
+
15
+ it "should have a setter method" do
16
+ fb_config = 'fbconf.yml'
17
+ @session_class.facebook_config_file = fb_config
18
+ @session_class.facebook_config_file.must_equal fb_config
23
19
  end
24
20
 
25
- context "facebook_app_id" do
21
+ end
22
+
23
+ describe "facebook_app_id" do
26
24
 
27
- should "default to default_config.app_id" do
28
- default_from_config = 'defaultappid'
29
- flexmock(@session_class).should_receive('default_config.app_id').and_return(default_from_config).once
30
- assert_equal default_from_config, @session_class.facebook_app_id
31
- end
25
+ it "should default to default_config.app_id" do
26
+ default_from_config = 'defaultappid'
32
27
 
33
- should "have a setter method" do
34
- fb_app_id = '234234234'
35
- @session_class.facebook_app_id = fb_app_id
36
- assert_equal fb_app_id, @session_class.facebook_app_id
37
- end
28
+ expect @session_class.default_config, 'app_id', :with => [], :return => default_from_config
38
29
 
30
+ @session_class.facebook_app_id.must_equal default_from_config
31
+ end
32
+
33
+ it "should have a setter method" do
34
+ fb_app_id = '234234234'
35
+ @session_class.facebook_app_id = fb_app_id
36
+ @session_class.facebook_app_id.must_equal fb_app_id
39
37
  end
38
+
39
+ end
40
40
 
41
- context "facebook_secret_key" do
41
+ describe "facebook_secret_key" do
42
42
 
43
- should "default to default_config.secret_key" do
44
- default_from_config = 'defaultsecretkey'
45
- flexmock(@session_class).should_receive('default_config.secret_key').and_return(default_from_config).once
46
- assert_equal default_from_config, @session_class.facebook_secret_key
47
- end
43
+ it "should default to default_config.secret_key" do
44
+ default_from_config = 'defaultsecretkey'
48
45
 
49
- should "have a setter method" do
50
- fb_secret = '553246736447566b583138525a716e693950736'
51
- @session_class.facebook_secret_key = fb_secret
52
- assert_equal fb_secret, @session_class.facebook_secret_key
53
- end
46
+ expect @session_class.default_config, 'secret_key', :with => [], :return => default_from_config
54
47
 
48
+ @session_class.facebook_secret_key.must_equal default_from_config
55
49
  end
56
50
 
57
- context "facebook_api_key" do
58
-
59
- should "default to default_config.api_key" do
60
- default_from_config = 'defaultapikey'
61
- flexmock(@session_class).should_receive('default_config.api_key').and_return(default_from_config).once
62
- assert_equal default_from_config, @session_class.facebook_api_key
63
- end
64
-
65
- should "have a setter method" do
66
- fb_api_key = '25a366a46366451636933676978776a45585734'
67
- @session_class.facebook_api_key = fb_api_key
68
- assert_equal fb_api_key, @session_class.facebook_api_key
69
- end
70
-
51
+ it "should have a setter method" do
52
+ fb_secret = '553246736447566b583138525a716e693950736'
53
+ @session_class.facebook_secret_key = fb_secret
54
+ @session_class.facebook_secret_key.must_equal fb_secret
71
55
  end
72
56
 
73
- context "facebook_uid_field" do
57
+ end
58
+
59
+ describe "facebook_api_key" do
74
60
 
75
- should "have a default of :facebook_uid" do
76
- assert_equal :facebook_uid, @session_class.facebook_uid_field
77
- end
61
+ it "should default to default_config.api_key" do
62
+ default_from_config = 'defaultapikey'
78
63
 
79
- should "have a setter method" do
80
- fb_uid_field = 'fb_uid'
81
- @session_class.facebook_uid_field = fb_uid_field
82
- assert_equal fb_uid_field, @session_class.facebook_uid_field
83
- end
64
+ expect @session_class.default_config, 'api_key', :with => [], :return => default_from_config
84
65
 
66
+ @session_class.facebook_api_key.must_equal default_from_config
85
67
  end
86
68
 
87
- context "facebook_finder" do
69
+ it "should have a setter method" do
70
+ fb_api_key = '25a366a46366451636933676978776a45585734'
71
+ @session_class.facebook_api_key = fb_api_key
72
+ @session_class.facebook_api_key.must_equal fb_api_key
73
+ end
74
+
75
+ end
76
+
77
+ describe "facebook_uid_field" do
88
78
 
89
- should 'have a default nil' do
90
- assert_nil @session_class.facebook_finder
91
- end
92
-
93
- should "have a setter method" do
94
- fb_finder = 'find_by_fb_uid'
95
- @session_class.facebook_finder = fb_finder
96
- assert_equal fb_finder, @session_class.facebook_finder
97
- end
98
-
79
+ it "should have a default of :facebook_uid" do
80
+ @session_class.facebook_uid_field.must_equal :facebook_uid
99
81
  end
100
82
 
101
- context "facebook_auto_register" do
83
+ it "should have a setter method" do
84
+ fb_uid_field = 'fb_uid'
85
+ @session_class.facebook_uid_field = fb_uid_field
86
+ @session_class.facebook_uid_field.must_equal fb_uid_field
87
+ end
88
+
89
+ end
90
+
91
+ describe "facebook_finder" do
102
92
 
103
- should 'have a default false' do
104
- assert_false @session_class.facebook_auto_register
105
- end
106
-
107
- should "have a setter method" do
108
- fb_auto_reg = true
109
- @session_class.facebook_auto_register = fb_auto_reg
110
- assert_equal fb_auto_reg, @session_class.facebook_auto_register
111
- end
112
-
93
+ it 'should default to false' do
94
+ @session_class.facebook_finder.must_equal false
113
95
  end
96
+
97
+ it "should have a setter method" do
98
+ fb_finder = 'find_by_fb_uid'
99
+ @session_class.facebook_finder = fb_finder
100
+ @session_class.facebook_finder.must_equal fb_finder
101
+ end
102
+
103
+ end
104
+
105
+ describe "facebook_auto_register" do
114
106
 
115
- context "default_config" do
107
+ it 'should have a default false' do
108
+ @session_class.facebook_auto_register.must_equal false
109
+ end
110
+
111
+ it "should have a setter method" do
112
+ fb_auto_reg = true
113
+ @session_class.facebook_auto_register = fb_auto_reg
114
+ @session_class.facebook_auto_register.must_equal fb_auto_reg
115
+ end
116
+
117
+ end
116
118
 
117
- should "be a class method" do
118
- assert @session_class.respond_to?(:default_config)
119
- end
120
-
121
- should "return an OpenStruct" do
122
- assert @session_class.default_config.is_a?(OpenStruct)
123
- end
124
-
125
- should "return the app_id from the default config file" do
126
- assert_equal 'appidfromfile', @session_class.default_config.app_id
127
- end
128
-
129
- should "return the api_key from the default config file" do
130
- assert_equal 'apikeyfromfile', @session_class.default_config.api_key
131
- end
132
-
133
- should "return the secret_key from the default config file" do
134
- assert_equal 'secretkeyfromfile', @session_class.default_config.secret_key
135
- end
119
+ describe "default_config" do
136
120
 
137
- should "return an empty OpenStruct if the file isn't found" do
138
- flexmock(@session_class).should_receive(:facebook_config_file).and_return('notthere.yml').once
139
- assert_equal OpenStruct.new({}), @session_class.default_config
140
- end
121
+ it "should be a class method" do
122
+ @session_class.must_respond_to :default_config
141
123
  end
142
124
 
125
+ it "should return an OpenStruct" do
126
+ @session_class.default_config.must_be_instance_of OpenStruct
127
+ end
128
+
129
+ it "should return the app_id from the default config file" do
130
+ @session_class.default_config.app_id.must_equal 'appidfromfile'
131
+ end
132
+
133
+ it "should return the api_key from the default config file" do
134
+ @session_class.default_config.api_key.must_equal 'apikeyfromfile'
135
+ end
136
+
137
+ it "should return the secret_key from the default config file" do
138
+ @session_class.default_config.secret_key.must_equal 'secretkeyfromfile'
139
+ end
140
+
141
+ it "should return an empty OpenStruct if the file isn't found" do
142
+ expect @session_class, :facebook_config_file, :with => [], :return => 'notthere.yml'
143
+ @session_class.default_config.must_equal OpenStruct.new({})
144
+ end
143
145
  end
144
146
 
145
147
  end
@@ -1,218 +1,237 @@
1
1
  require File.expand_path( '../../test_helper.rb', File.dirname(__FILE__) )
2
+ require 'koala'
2
3
 
3
- class AuthlogicFacebookShim::Session::FacebookTest < ActiveSupport::TestCase
4
-
5
- setup :activate_authlogic
4
+ describe AuthlogicFacebookShim::Session::Facebook do
5
+
6
+ before do
7
+ activate_authlogic
8
+ end
6
9
 
7
- context "Session::Facebook" do
10
+ describe "setup - for my own sanity" do
8
11
 
9
- setup do
10
- @mock_cookies = MockCookieJar.new
11
- @mock_cookies['fbs_mockappid'] = {:value => 'access_token=mockaccesstoken&expires=0&secret=mocksecret&session_key=mocksessionkey&sig=cbd80b97f124bf392f76e2ee61168990&uid=mockuid'}
12
+ before do
13
+ @session = UserSession.new
14
+ override @session, :controller => controller
15
+ end
12
16
 
13
- flexmock(controller).should_receive(:cookies).and_return(@mock_cookies).by_default
14
-
15
- @session = flexmock(UserSession.new)
16
- @session.should_receive(:controller).and_return(controller).by_default
17
+ it "should set the controller" do
18
+ @session.controller.must_equal controller
17
19
  end
18
-
19
- context "setup - for my own sanity" do
20
+
21
+ end
22
+
23
+ describe "config accessors" do
24
+
25
+ before do
26
+ @session = UserSession.new
27
+ override @session, :controller => controller
28
+ end
29
+
30
+ after do
31
+ Object.instance_eval do
32
+ remove_const :User
33
+ remove_const :UserSession
34
+ GC.start
20
35
 
21
- should "set the controller" do
22
- assert_equal controller, @session.controller
36
+ load(File.join(Rails.root, 'app', 'models', 'user.rb'))
37
+ load(File.join(Rails.root, 'app', 'models', 'user_session.rb'))
23
38
  end
39
+ end
40
+
41
+ it "should return facebook_app_id" do
42
+ mockappid = 'mockappid'
43
+ override UserSession, :facebook_app_id => mockappid
44
+ @session.send(:facebook_app_id).must_equal mockappid
45
+ end
46
+
47
+ it "should return facebook_api_key" do
48
+ mockapikey = 'mockapikey'
49
+ override UserSession, :facebook_api_key => mockapikey
24
50
 
25
- should "set the cookies" do
26
- assert_equal @mock_cookies, @session.controller.cookies
27
- end
28
-
51
+ @session.send(:facebook_api_key).must_equal mockapikey
29
52
  end
30
-
31
- context "config accessors" do
32
53
 
33
- should "return facebook_app_id" do
34
- mockappid = 'mockappid'
35
- flexmock(UserSession).should_receive(:facebook_app_id).and_return(mockappid).once
36
- assert_equal mockappid, @session.send(:facebook_app_id)
37
- end
54
+ it "should return facebook_secret_key" do
55
+ mocksecret = 'mocksecret'
56
+ override UserSession, :facebook_secret_key => mocksecret
57
+
58
+ @session.send(:facebook_secret_key).must_equal mocksecret
59
+ end
38
60
 
39
- should "return facebook_api_key" do
40
- mockapikey = 'mockapikey'
41
- flexmock(UserSession).should_receive(:facebook_api_key).and_return(mockapikey).once
42
- assert_equal mockapikey, @session.send(:facebook_api_key)
43
- end
61
+ it "should return facebook_uid_field" do
62
+ mockuidfield = 'mock_uidfield'
63
+ override UserSession, :facebook_uid_field => mockuidfield
64
+
65
+ @session.send(:facebook_uid_field).must_equal mockuidfield
66
+ end
67
+
68
+ describe "facebook_finder" do
44
69
 
45
- should "return facebook_secret_key" do
46
- mocksecret = 'mocksecret'
47
- flexmock(UserSession).should_receive(:facebook_secret_key).and_return(mocksecret).once
48
- assert_equal mocksecret, @session.send(:facebook_secret_key)
70
+ it "should delegate to the class" do
71
+ mockfinder = 'mockfinder'
72
+ override UserSession, :facebook_finder => mockfinder
73
+
74
+ @session.send(:facebook_finder).must_equal mockfinder
49
75
  end
50
76
 
51
- should "return facebook_uid_field" do
52
- mockuidfield = 'mockuidfield'
53
- flexmock(UserSession).should_receive(:facebook_uid_field).and_return(mockuidfield).once
54
- assert_equal mockuidfield, @session.send(:facebook_uid_field)
77
+ it "should default if the class returns nil" do
78
+ override UserSession, :facebook_finder => false
79
+ override @session, :facebook_uid_field => 'mock_uidfield'
80
+
81
+ @session.send(:facebook_finder).must_equal "find_by_mock_uidfield"
55
82
  end
56
-
57
- context "facebook_finder" do
58
83
 
59
- should "delegate to the class" do
60
- mockfinder = 'mockfinder'
61
- flexmock(UserSession).should_receive(:facebook_finder).and_return(mockfinder).once
62
- assert_equal mockfinder, @session.send(:facebook_finder)
63
- end
84
+ end
64
85
 
65
- should "default if the class returns nil" do
66
- flexmock(UserSession).should_receive(:facebook_finder).and_return(nil).once
67
- @session.should_receive(:facebook_uid_field).and_return('mockuidfield').once
68
- assert_equal "find_by_mockuidfield", @session.send(:facebook_finder)
69
- end
86
+ it "should return facebook_auto_register?" do
87
+ override UserSession, :facebook_auto_register => true
88
+
89
+ @session.send(:facebook_auto_register?).must_equal true
90
+ end
70
91
 
71
- end
92
+ end
93
+
94
+ describe "validating with facebook" do
95
+
96
+ before do
97
+ @session = UserSession.new
98
+ override @session, :controller => controller
99
+ end
100
+
101
+ describe "with a valid facebook session" do
102
+
103
+ before do
104
+ @facebook_session = OpenStruct.new(:uid => 'mockuid')
72
105
 
73
- should "return facebook_auto_register?" do
74
- flexmock(UserSession).should_receive(:facebook_auto_register).and_return(true).once
75
- assert @session.send(:facebook_auto_register?)
106
+ override @session, :facebook_session? => true
107
+ override @session, :facebook_session => @facebook_session
76
108
  end
77
109
 
78
- end
79
-
80
- context "validating with facebook" do
110
+ describe "with an existing facebook uid" do
81
111
 
82
- context "with a valid facebook session" do
112
+ before do
113
+ override @session, :facebook_finder => 'finder_method'
114
+
115
+ @user = User.create
116
+ override User, :finder_method => @user
83
117
 
84
- setup do
85
- @facebook_session = flexmock('facebook session', :uid => 'mockuid')
86
- @session.should_receive(:facebook_session).and_return(@facebook_session).by_default
118
+ @session.save
119
+ end
120
+
121
+ it "should return true for logged_in_with_facebook?" do
122
+ @session.logged_in_with_facebook?.must_equal true
87
123
  end
124
+
125
+ it "should set attempted_record" do
126
+ @session.attempted_record.must_equal @user
127
+ end
128
+
129
+ end
88
130
 
89
- context "with an existing facebook uid" do
131
+ describe "without an existing facebook uid" do
90
132
 
91
- setup do
92
- @session.should_receive(:facebook_finder).and_return('finder_method').by_default
133
+ before do
134
+ override @session, :facebook_finder => 'finder_method'
135
+ override User, :finder_method => nil
93
136
 
94
- @user = User.create
95
- flexmock(User).should_receive('finder_method').with('mockuid').and_return(@user).by_default
137
+ @user = User.new
138
+ override User, :new => @user
139
+ end
140
+
141
+ describe "and facebook_auto_register? true" do
96
142
 
143
+ before do
144
+ override @session, :facebook_auto_register? => true
145
+ end
146
+
147
+ it "should build a new user on attempted_record" do
148
+ override User, :new => @user
149
+
97
150
  @session.save
151
+ @session.attempted_record.must_equal @user
98
152
  end
99
153
 
100
- should "return true for logged_in_with_facebook?" do
101
- assert @session.logged_in_with_facebook?
154
+ it "should attempt to call before_connect on the new user" do
155
+ expect @user, :before_connect, :with => [@facebook_session], :return => true
156
+ assert @session.save
102
157
  end
103
158
 
104
- should "set attempted_record" do
105
- assert_equal @user, @session.attempted_record
159
+ it "should save the new user" do
160
+ expect @user, :save, :with => [:validate => false], :return => true
161
+ assert @session.save
106
162
  end
107
163
 
108
164
  end
165
+
166
+ describe "and facebook_auto_register? false" do
109
167
 
110
- context "without an existing facebook uid" do
111
-
112
- setup do
113
- @session.should_receive(:facebook_finder).and_return('finder_method').by_default
114
- flexmock(User).should_receive('finder_method').with('mockuid').and_return(nil).by_default
168
+ it "should return false for logged_in_with_facebook?" do
169
+ override @session, :facebook_auto_register? => false
170
+ @session.save
115
171
 
116
- @user = flexmock(User.new)
117
- flexmock(User).should_receive(:new).and_return(@user).by_default
172
+ @session.logged_in_with_facebook?.must_equal false
118
173
  end
119
174
 
120
- context "and facebook_auto_register? true" do
175
+ it "should not set attempted record" do
176
+ override @session, :facebook_auto_register? => false
121
177
 
122
- setup do
123
- @session.should_receive(:facebook_auto_register?).and_return(true).by_default
124
- end
125
-
126
- should "build a new user on attempted_record" do
127
- flexmock(User).should_receive(:new).and_return(@user).once
128
- @session.save
129
- assert_equal @user, @session.attempted_record
130
- end
131
-
132
- should "attempt to call before_connect on the new user" do
133
- # TODO this is a bit flakey because I can't get flexmock to mock with(@facebook_session)
134
- @user.should_receive(:before_connect).with(any).and_return(true).once
135
- assert @session.save
136
- end
137
-
138
- should "save the new user" do
139
- @user.should_receive(:save).with(false).and_return(true).at_least.once
140
- assert @session.save
141
- end
142
-
143
- end
144
-
145
- context "and facebook_auto_register? false" do
146
-
147
- should "return false for logged_in_with_facebook?" do
148
- @session.should_receive(:facebook_auto_register?).and_return(false).once
149
- @session.save
150
-
151
- assert_equal false, @session.logged_in_with_facebook?
152
- end
153
-
154
- should "not set attempted record" do
155
- @session.should_receive(:facebook_auto_register?).and_return(false).once
156
- @session.save
178
+ @session.save
157
179
 
158
- assert_nil @session.attempted_record
159
- end
160
-
180
+ @session.attempted_record.must_be_nil
161
181
  end
162
182
 
163
183
  end
164
-
184
+
165
185
  end
166
186
 
167
- context "when skip_facebook_authentication is true" do
187
+ end
168
188
 
169
- should "not attempt to validate with facebook" do
170
- @session.should_receive(:skip_facebook_authentication).and_return(true).once
171
- @session.should_receive(:validate_by_facebook).never
172
-
173
- assert_equal false, @session.save
174
- end
189
+ describe "when skip_facebook_authentication is true" do
190
+
191
+ it "should not attempt to validate with facebook" do
192
+ override @session, :skip_facebook_authentication => true
193
+ override @session, :validate_by_facebook => lambda { raise Override::ExpectationError.new('to not be called', 'called') }
175
194
 
176
- should "return false for logged_in_with_facebook?" do
177
- @session.should_receive(:skip_facebook_authentication).and_return(true).once
178
-
179
- assert_equal false, @session.save
180
- assert_nil @session.logged_in_with_facebook?
181
- end
195
+ @session.save.must_equal false
196
+ end
197
+
198
+ it "should return false for logged_in_with_facebook?" do
199
+ override @session, :skip_facebook_authentication => true
182
200
 
183
- should "not set attempted record" do
184
- @session.should_receive(:skip_facebook_authentication).and_return(true).once
185
-
186
- assert_equal false, @session.save
187
- assert_nil @session.attempted_record
188
- end
201
+ @session.save.must_equal false
202
+ @session.logged_in_with_facebook?.must_be_nil
189
203
  end
190
204
 
191
- context "when authenticating_with_unauthorized_record? is false" do
205
+ it "should not set attempted record" do
206
+ override @session, :skip_facebook_authentication => true
192
207
 
193
- should "not attempt to validate with facebook" do
194
- @session.should_receive(:authenticating_with_unauthorized_record?).and_return(false).at_least.once
195
- @session.should_receive(:validate_by_facebook).never
196
-
197
- assert_equal false, @session.save
198
- end
208
+ @session.save.must_equal false
209
+ @session.attempted_record.must_be_nil
210
+ end
211
+ end
212
+
213
+ describe "when authenticating_with_unauthorized_record? is true" do
214
+
215
+ before do
216
+ override @session, :facebook_session? => true
217
+ override @session, :authenticating_with_unauthorized_record? => true
218
+ end
199
219
 
200
- should "return false for logged_in_with_facebook?" do
201
- @session.should_receive(:authenticating_with_unauthorized_record?).and_return(true).at_least.once
202
-
203
- assert_equal false, @session.save
204
- assert_nil @session.logged_in_with_facebook?
205
- end
220
+ it "should not attempt to validate with facebook" do
221
+ override @session, :validate_by_facebook => lambda { raise Override::ExpectationError.new('to not be called', 'called') }
206
222
 
207
- should "not set attempted record" do
208
- @session.should_receive(:authenticating_with_unauthorized_record?).and_return(true).at_least.once
223
+ @session.save.must_equal false
224
+ end
209
225
 
210
- assert_equal false, @session.save
211
- assert_nil @session.attempted_record
212
- end
213
-
226
+ it "should return false for logged_in_with_facebook?" do
227
+ @session.save.must_equal false
228
+ @session.logged_in_with_facebook?.must_be_nil
214
229
  end
215
230
 
231
+ it "should not set attempted record" do
232
+ @session.save.must_equal false
233
+ @session.attempted_record.must_be_nil
234
+ end
216
235
 
217
236
  end
218
237