ateam-merb-auth-old 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +44 -0
- data/README +212 -0
- data/Rakefile +50 -0
- data/TODO +14 -0
- data/activerecord_generators/ma_migration/ma_migration_generator.rb +41 -0
- data/activerecord_generators/ma_migration/templates/schema/migrations/%time_stamp%_add_ma_user.rb +21 -0
- data/app/controllers/application.rb +7 -0
- data/app/controllers/sessions.rb +3 -0
- data/app/controllers/users.rb +3 -0
- data/app/helpers/application_helper.rb +64 -0
- data/app/mailers/user_mailer.rb +24 -0
- data/app/mailers/views/user_mailer/activation.text.erb +1 -0
- data/app/mailers/views/user_mailer/forgot_password.text.erb +5 -0
- data/app/mailers/views/user_mailer/signup.text.erb +7 -0
- data/app/views/layout/merb_auth.html.erb +16 -0
- data/app/views/sessions/new.html.erb +13 -0
- data/app/views/users/new.html.erb +21 -0
- data/datamapper_generators/ma_migration/ma_migration_generator.rb +38 -0
- data/datamapper_generators/ma_migration/templates/schema/migrations/add_ma_user.rb +21 -0
- data/lib/ateam-merb-auth-old.rb +1 -0
- data/lib/merb-auth.rb +184 -0
- data/lib/merb-auth/adapters/activerecord/init.rb +26 -0
- data/lib/merb-auth/adapters/activerecord/map.rb +44 -0
- data/lib/merb-auth/adapters/activerecord/model.rb +81 -0
- data/lib/merb-auth/adapters/common.rb +161 -0
- data/lib/merb-auth/adapters/datamapper/init.rb +28 -0
- data/lib/merb-auth/adapters/datamapper/map.rb +35 -0
- data/lib/merb-auth/adapters/datamapper/model.rb +72 -0
- data/lib/merb-auth/adapters/map.rb +0 -0
- data/lib/merb-auth/adapters/sequel/init.rb +26 -0
- data/lib/merb-auth/adapters/sequel/map.rb +36 -0
- data/lib/merb-auth/adapters/sequel/model.rb +86 -0
- data/lib/merb-auth/controller/controller.rb +113 -0
- data/lib/merb-auth/controller/sessions_base.rb +41 -0
- data/lib/merb-auth/controller/users_base.rb +58 -0
- data/lib/merb-auth/initializer.rb +47 -0
- data/lib/merb-auth/merbtasks.rb +168 -0
- data/lib/merb-auth/slicetasks.rb +102 -0
- data/plugins/forgotten_password/app/controllers/passwords.rb +90 -0
- data/plugins/forgotten_password/app/models/user.rb +52 -0
- data/plugins/forgotten_password/app/views/passwords/edit.html.erb +9 -0
- data/plugins/forgotten_password/app/views/passwords/new.html.erb +4 -0
- data/plugins/forgotten_password/forgotten_password.rb +6 -0
- data/plugins/forgotten_password/init.rb +8 -0
- data/plugins/forgotten_password/spec/controller_spec.rb +236 -0
- data/plugins/forgotten_password/spec/model_spec.rb +52 -0
- data/plugins/forgotten_password/spec/spec_helper.rb +36 -0
- data/public/javascripts/master.js +0 -0
- data/public/stylesheets/master.css +2 -0
- data/spec/controllers/plugins/test_plugin.rb +17 -0
- data/spec/controllers/sessions_spec.rb +118 -0
- data/spec/controllers/users_spec.rb +119 -0
- data/spec/mailers/user_mailer_spec.rb +75 -0
- data/spec/merb_auth_spec.rb +231 -0
- data/spec/models/ar_model_spec.rb +50 -0
- data/spec/models/common_spec.rb +0 -0
- data/spec/models/model_spec.rb +23 -0
- data/spec/models/sq_model_spec.rb +50 -0
- data/spec/shared_specs/shared_model_spec.rb +445 -0
- data/spec/spec_helper.rb +114 -0
- data/spec/spec_helpers/helpers.rb +18 -0
- data/spec/spec_helpers/valid_model_hashes.rb +10 -0
- data/stubs/app/controllers/application.rb +2 -0
- data/stubs/app/controllers/main.rb +2 -0
- data/stubs/app/mailers/views/activation.text.erb +1 -0
- data/stubs/app/mailers/views/signup.text.erb +7 -0
- data/stubs/app/views/sessions/new.html.erb +14 -0
- data/stubs/app/views/users/new.html.erb +18 -0
- metadata +120 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), "..", "spec_helper" )
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
describe "MA ActiveRecord User Model" do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
|
8
|
+
Merb.stub!(:orm_generator_scope).and_return("activerecord")
|
9
|
+
|
10
|
+
adapter_path = File.join( File.dirname(__FILE__), "..", "..", "lib", "merb-auth", "adapters")
|
11
|
+
MA.register_adapter :datamapper, "#{adapter_path}/datamapper"
|
12
|
+
MA.register_adapter :activerecord, "#{adapter_path}/activerecord"
|
13
|
+
MA.loaded
|
14
|
+
|
15
|
+
ActiveRecord::Migration.verbose = false
|
16
|
+
ActiveRecord::Base.establish_connection(
|
17
|
+
:adapter => 'sqlite3',
|
18
|
+
:database => ':memory:')
|
19
|
+
|
20
|
+
class UserMigration < ActiveRecord::Migration
|
21
|
+
def self.up
|
22
|
+
create_table "users", :force => true do |t|
|
23
|
+
t.column :login, :string
|
24
|
+
t.column :email, :string
|
25
|
+
t.column :crypted_password, :string, :limit => 40
|
26
|
+
t.column :salt, :string, :limit => 40
|
27
|
+
t.column :created_at, :datetime
|
28
|
+
t.column :updated_at, :datetime
|
29
|
+
t.column :remember_token, :string
|
30
|
+
t.column :remember_token_expires_at, :datetime
|
31
|
+
t.column :activation_code, :string, :limit => 40
|
32
|
+
t.column :activated_at, :datetime
|
33
|
+
t.column :password_reset_key, :string
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
UserMigration.up
|
39
|
+
|
40
|
+
class User < ActiveRecord::Base
|
41
|
+
include MerbAuth::Adapter::ActiveRecord
|
42
|
+
include MerbAuth::Adapter::ActiveRecord::DefaultModelSetup
|
43
|
+
end
|
44
|
+
|
45
|
+
MA.activate
|
46
|
+
end
|
47
|
+
|
48
|
+
it_should_behave_like "A MerbAuth User Model"
|
49
|
+
|
50
|
+
end
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), "..", "spec_helper" )
|
2
|
+
require 'dm-core'
|
3
|
+
|
4
|
+
describe "MA User Model" do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
DataMapper.setup(:default, 'sqlite3::memory:')
|
8
|
+
Merb.stub!(:orm_generator_scope).and_return("datamapper")
|
9
|
+
|
10
|
+
adapter_path = File.join( File.dirname(__FILE__), "..", "..", "lib", "merb-auth", "adapters")
|
11
|
+
MA.register_adapter :datamapper, "#{adapter_path}/datamapper"
|
12
|
+
MA.register_adapter :activerecord, "#{adapter_path}/activerecord"
|
13
|
+
MA.loaded
|
14
|
+
|
15
|
+
class User
|
16
|
+
include MA::Adapter::DataMapper
|
17
|
+
include MA::Adapter::DataMapper::DefaultModelSetup
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it_should_behave_like "A MerbAuth User Model"
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), "..", "spec_helper" )
|
2
|
+
require 'sequel'
|
3
|
+
|
4
|
+
describe "MA Sequel User Model" do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
|
8
|
+
Merb.stub!(:orm_generator_scope).and_return("sequel")
|
9
|
+
|
10
|
+
adapter_path = File.join( File.dirname(__FILE__), "..", "..", "lib", "merb-auth", "adapters")
|
11
|
+
MA.register_adapter :datamapper, "#{adapter_path}/datamapper"
|
12
|
+
MA.register_adapter :activerecord, "#{adapter_path}/activerecord"
|
13
|
+
MA.register_adapter :sequel, "#{adapter_path}/sequel"
|
14
|
+
MA.loaded
|
15
|
+
|
16
|
+
sqdb = Sequel.sqlite
|
17
|
+
|
18
|
+
sqdb.create_table! :users do
|
19
|
+
primary_key :id
|
20
|
+
column :login, :text
|
21
|
+
column :email, :text
|
22
|
+
column :crypted_password, :varchar, :size => 40
|
23
|
+
column :salt, :varchar, :size => 40
|
24
|
+
column :created_at, :datetime
|
25
|
+
column :updated_at, :datetime
|
26
|
+
column :remember_token, :text
|
27
|
+
column :remember_token_expires_at, :datetime
|
28
|
+
column :activation_code, :varchar, :size => 40
|
29
|
+
column :activated_at, :datetime
|
30
|
+
column :password_reset_key, :text
|
31
|
+
end
|
32
|
+
|
33
|
+
class User < Sequel::Model
|
34
|
+
include MerbAuth::Adapter::Sequel
|
35
|
+
include MerbAuth::Adapter::Sequel::DefaultModelSetup
|
36
|
+
|
37
|
+
def attributes
|
38
|
+
values
|
39
|
+
end
|
40
|
+
end
|
41
|
+
User.raise_on_save_failure = false
|
42
|
+
|
43
|
+
Sequel.datetime_class = DateTime
|
44
|
+
|
45
|
+
MA.activate
|
46
|
+
end
|
47
|
+
|
48
|
+
it_should_behave_like "A MerbAuth User Model"
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,445 @@
|
|
1
|
+
describe "A MerbAuth User Model", :shared => true do
|
2
|
+
|
3
|
+
before(:all) do
|
4
|
+
raise "You need to set the MerbAuth[:user] class to use this spec" unless MA[:user].is_a?(Class)
|
5
|
+
end
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
MA[:user].clear_database_table
|
9
|
+
@hash = valid_user_hash
|
10
|
+
@user = MA[:user].new(@hash)
|
11
|
+
MA[:from_email] = "example@email.com"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should include MerbAuth::Adapter::Common mixin" do
|
15
|
+
MA[:user].should include(MA::Adapter::Common)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should setup the name of the resource" do
|
19
|
+
MA[:single_resource].should == :user
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should set the name of the collection" do
|
23
|
+
MA[:plural_resource].should == :users
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "Fields" do
|
27
|
+
|
28
|
+
before(:each) do
|
29
|
+
MA[:use_activation] = true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should make a valid user" do
|
33
|
+
user = MA[:user].new(valid_user_hash)
|
34
|
+
user.save
|
35
|
+
user.errors.should be_empty
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should have a login field" do
|
39
|
+
user = MA[:user].new
|
40
|
+
user.should respond_to(:login)
|
41
|
+
user.valid?
|
42
|
+
user.errors.on(:login).should_not be_blank
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should have an email field" do
|
46
|
+
user = MA[:user].new
|
47
|
+
user.should respond_to(:email)
|
48
|
+
user.valid?
|
49
|
+
user.errors.on(:email).should_not be_blank
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should add on some random numbers on the end if the username is already taken" do
|
53
|
+
hash = valid_user_hash.except(:login)
|
54
|
+
hash[:email] = "homer@simpsons.com"
|
55
|
+
u1 = MA[:user].new(hash)
|
56
|
+
u1.save
|
57
|
+
u1.should_not be_new_record
|
58
|
+
u1.login.should == "homer"
|
59
|
+
|
60
|
+
h2 = valid_user_hash.except(:login)
|
61
|
+
h2[:email] = "homer@shelbyvile.com"
|
62
|
+
u2 = MA[:user].new(h2)
|
63
|
+
u2.save
|
64
|
+
u2.should_not be_new_record
|
65
|
+
u2.login.should match(/homer\d{3}/)
|
66
|
+
u2.login.should == "homer000"
|
67
|
+
|
68
|
+
h3 = valid_user_hash.except(:login)
|
69
|
+
h3[:email] = "homer@hotmail.com"
|
70
|
+
u3 = MA[:user].new(h3)
|
71
|
+
u3.save
|
72
|
+
u3.should_not be_new_record
|
73
|
+
u3.login.should match(/homer\d{3}/)
|
74
|
+
u3.login.should == "homer001"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should fail login if there are less than 3 chars" do
|
78
|
+
user = MA[:user].new
|
79
|
+
user.login = "AB"
|
80
|
+
user.valid?
|
81
|
+
user.errors.on(:login).should_not be_blank
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should not fail login with between 3 and 40 chars" do
|
85
|
+
user = MA[:user].new
|
86
|
+
[3,40].each do |num|
|
87
|
+
user.login = "a" * num
|
88
|
+
user.valid?
|
89
|
+
user.errors.on(:login).should be_blank
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should fail login with over 90 chars" do
|
94
|
+
user = MA[:user].new
|
95
|
+
user.login = "A" * 41
|
96
|
+
user.valid?
|
97
|
+
user.errors.on(:login).should_not be_blank
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should make sure login is unique regardless of case" do
|
101
|
+
MA[:user].find_with_conditions(:login => "Daniel").should be_nil
|
102
|
+
user = MA[:user].new( valid_user_hash.with(:login => "Daniel") )
|
103
|
+
user2 = MA[:user].new( valid_user_hash.with(:login => "daniel"))
|
104
|
+
user.save
|
105
|
+
user.should_not be_a_new_record
|
106
|
+
user2.save
|
107
|
+
user2.should be_a_new_record
|
108
|
+
user2.errors.on(:login).should_not be_blank
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should downcase logins" do
|
112
|
+
user = MA[:user].new( valid_user_hash.with(:login => "DaNieL"))
|
113
|
+
user.login.should == "daniel"
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should authenticate a user using a class method" do
|
117
|
+
hash = valid_user_hash
|
118
|
+
user = MA[:user].new(hash)
|
119
|
+
user.save
|
120
|
+
user.should_not be_new_record
|
121
|
+
user.activate
|
122
|
+
MA[:user].authenticate(hash[:email], hash[:password]).should_not be_nil
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should not authenticate a user using the wrong password" do
|
126
|
+
user = MA[:user].new(valid_user_hash)
|
127
|
+
user.save
|
128
|
+
|
129
|
+
user.activate
|
130
|
+
MA[:user].authenticate(valid_user_hash[:email], "not_the_password").should be_nil
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should not authenticate a user using the wrong login" do
|
134
|
+
user = MA[:user].create(valid_user_hash)
|
135
|
+
|
136
|
+
user.activate
|
137
|
+
MA[:user].authenticate("not_the_login@blah.com", valid_user_hash[:password]).should be_nil
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should not authenticate a user that does not exist" do
|
141
|
+
MA[:user].authenticate("i_dont_exist", "password").should be_nil
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "the password fields" do
|
147
|
+
|
148
|
+
it "should respond to password" do
|
149
|
+
@user.should respond_to(:password)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should respond to password_confirmation" do
|
153
|
+
@user.should respond_to(:password_confirmation)
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should respond to crypted_password" do
|
157
|
+
@user.should respond_to(:crypted_password)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should require password if password is required" do
|
161
|
+
user = MA[:user].new( valid_user_hash.without(:password))
|
162
|
+
user.stub!(:password_required?).and_return(true)
|
163
|
+
user.valid?
|
164
|
+
user.errors.on(:password).should_not be_nil
|
165
|
+
user.errors.on(:password).should_not be_empty
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should set the salt" do
|
169
|
+
user = MA[:user].new(valid_user_hash)
|
170
|
+
user.salt.should be_nil
|
171
|
+
user.send(:encrypt_password)
|
172
|
+
user.salt.should_not be_nil
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should require the password on create" do
|
176
|
+
user = MA[:user].new(valid_user_hash.without(:password))
|
177
|
+
user.save
|
178
|
+
user.errors.on(:password).should_not be_nil
|
179
|
+
user.errors.on(:password).should_not be_empty
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should require password_confirmation if the password_required?" do
|
183
|
+
user = MA[:user].new(valid_user_hash.without(:password_confirmation))
|
184
|
+
user.save
|
185
|
+
(user.errors.on(:password) || user.errors.on(:password_confirmation)).should_not be_nil
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should fail when password is outside 4 and 40 chars" do
|
189
|
+
[3,41].each do |num|
|
190
|
+
user = MA[:user].new(valid_user_hash.with(:password => ("a" * num)))
|
191
|
+
user.valid?
|
192
|
+
user.errors.on(:password).should_not be_blank
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should pass when password is within 4 and 40 chars" do
|
197
|
+
[4,30,40].each do |num|
|
198
|
+
user = MA[:user].new(valid_user_hash.with(:password => ("a" * num), :password_confirmation => ("a" * num)))
|
199
|
+
user.valid?
|
200
|
+
user.errors.on(:password).should be_blank
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should autenticate against a password" do
|
205
|
+
user = MA[:user].new(valid_user_hash)
|
206
|
+
user.save
|
207
|
+
user.should be_authenticated(valid_user_hash[:password])
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should not require a password when saving an existing user" do
|
211
|
+
hash = valid_user_hash
|
212
|
+
user = MA[:user].new(hash)
|
213
|
+
user.save
|
214
|
+
user.should_not be_a_new_record
|
215
|
+
user.login.should == hash[:login].downcase
|
216
|
+
user = MA[:user].find_with_conditions(:login => hash[:login].downcase)
|
217
|
+
user.password.should be_nil
|
218
|
+
user.password_confirmation.should be_nil
|
219
|
+
user.login = "some_different_login_to_allow_saving"
|
220
|
+
(user.save).should if user
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
describe "activation setup" do
|
226
|
+
|
227
|
+
before(:each) do
|
228
|
+
MA[:use_activation] = true
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should have an activation_code as an attribute" do
|
232
|
+
@user.attributes.keys.any?{|a| a.to_s == "activation_code"}.should_not be_nil
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should create an activation code on create" do
|
236
|
+
@user.activation_code.should be_nil
|
237
|
+
@user.save
|
238
|
+
@user.activation_code.should_not be_nil
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should not be active when created" do
|
242
|
+
@user.should_not be_activated
|
243
|
+
@user.save
|
244
|
+
@user.should_not be_activated
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should respond to activate" do
|
248
|
+
@user.should respond_to(:activate)
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should respond to activated? & active?" do
|
252
|
+
@user.save
|
253
|
+
@user.should_not be_active
|
254
|
+
@user.should_not be_activated
|
255
|
+
@user.activate
|
256
|
+
@user.reload
|
257
|
+
@user.should be_active
|
258
|
+
@user.should be_activated
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should activate a user when activate is called" do
|
262
|
+
@user.should_not be_activated
|
263
|
+
@user.save
|
264
|
+
@user.activate
|
265
|
+
@user.should be_activated
|
266
|
+
MA[:user].find_with_conditions(:email => @hash[:email]).should be_activated
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should should show recently activated when the instance is activated" do
|
270
|
+
@user.should_not be_recently_activated
|
271
|
+
@user.activate
|
272
|
+
@user.should be_recently_activated
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should not show recently activated when the instance is fresh" do
|
276
|
+
@user.activate
|
277
|
+
@user = nil
|
278
|
+
MA[:user].find_with_conditions(:email => @hash[:email]).should_not be_recently_activated
|
279
|
+
end
|
280
|
+
|
281
|
+
it "should send an email to ask for activation" do
|
282
|
+
MA[:use_activation] = true
|
283
|
+
MA::UserMailer.should_receive(:dispatch_and_deliver) do |action, mail_args, mailer_params|
|
284
|
+
action.should == :signup
|
285
|
+
mail_args.keys.should include(:from)
|
286
|
+
mail_args.keys.should include(:to)
|
287
|
+
mail_args.keys.should include(:subject)
|
288
|
+
mail_args[:subject].should_not be_blank
|
289
|
+
mail_args[:to].should == @user.email
|
290
|
+
mailer_params[:user].should == @user
|
291
|
+
end
|
292
|
+
@user.save
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should not send an email to ask for activation when use_activation is not set" do
|
296
|
+
MA[:use_activation] = false
|
297
|
+
MA::UserMailer.should_not_receive(:dispatch_and_deliver)
|
298
|
+
@user.save
|
299
|
+
end
|
300
|
+
|
301
|
+
it "should send out a welcome email to confirm that the account is activated" do
|
302
|
+
@user.save
|
303
|
+
MA::UserMailer.should_receive(:dispatch_and_deliver) do |action, mail_args, mailer_params|
|
304
|
+
action.should == :activation
|
305
|
+
mail_args.keys.should include(:from)
|
306
|
+
mail_args.keys.should include(:to)
|
307
|
+
mail_args.keys.should include(:subject)
|
308
|
+
mail_args[:to].should == @user.email
|
309
|
+
mailer_params[:user].should == @user
|
310
|
+
end
|
311
|
+
@user.activate
|
312
|
+
end
|
313
|
+
|
314
|
+
it "should send a please activate email" do
|
315
|
+
user = MA[:user].new(valid_user_hash)
|
316
|
+
MA::UserMailer.should_receive(:dispatch_and_deliver) do |action, mail_args, mailer_params|
|
317
|
+
action.should == :signup
|
318
|
+
[:from, :to, :subject].each{ |f| mail_args.keys.should include(f)}
|
319
|
+
mail_args[:to].should == user.email
|
320
|
+
mailer_params[:user].should == user
|
321
|
+
end
|
322
|
+
user.save
|
323
|
+
user.should_not be_a_new_record
|
324
|
+
end
|
325
|
+
|
326
|
+
it "should not send a please activate email when updating" do
|
327
|
+
user = MA[:user].new(valid_user_hash)
|
328
|
+
user.save
|
329
|
+
MA[:user].should_not_receive(:signup_notification)
|
330
|
+
user.login = "not in the valid hash for login"
|
331
|
+
user.save
|
332
|
+
end
|
333
|
+
|
334
|
+
it "should check that a user is active if the configuration calls for activation" do
|
335
|
+
MA[:use_activation] = true
|
336
|
+
hash = valid_user_hash
|
337
|
+
hash2 = valid_user_hash
|
338
|
+
user = MA[:user].new(hash)
|
339
|
+
user.save
|
340
|
+
user.reload
|
341
|
+
MA[:user].authenticate(user.email, hash[:password]).should be_nil
|
342
|
+
MA[:use_activation] = false
|
343
|
+
u2 = MA[:user].new(hash2)
|
344
|
+
u2.save
|
345
|
+
u2.reload
|
346
|
+
MA[:user].authenticate(u2.email, hash2[:password]).should == u2
|
347
|
+
MA[:user].authenticate(user.email, hash[:passowrd]).should be_nil
|
348
|
+
MA[:use_activateion] = true
|
349
|
+
user.activate
|
350
|
+
user.reload
|
351
|
+
MA[:user].authenticate(user.email, hash[:password]).should == user
|
352
|
+
MA[:user].authenticate(u2.email, hash2[:password]).should == u2
|
353
|
+
end
|
354
|
+
|
355
|
+
it "should not activate the user when use_activation is true" do
|
356
|
+
MA[:use_activation] = true
|
357
|
+
u = MA[:user].new(valid_user_hash)
|
358
|
+
u.save
|
359
|
+
u.should_not be_activated
|
360
|
+
end
|
361
|
+
|
362
|
+
it "should set the use to active if there is no activation required" do
|
363
|
+
MA[:use_activation] = false
|
364
|
+
u = MA[:user].new(valid_user_hash)
|
365
|
+
u.save
|
366
|
+
u.should be_activated
|
367
|
+
end
|
368
|
+
|
369
|
+
end
|
370
|
+
|
371
|
+
describe "remember me" do
|
372
|
+
predicate_matchers[:remember_token] = :remember_token?
|
373
|
+
|
374
|
+
before do
|
375
|
+
MA[:user].clear_database_table
|
376
|
+
@user = MA[:user].new(valid_user_hash)
|
377
|
+
end
|
378
|
+
|
379
|
+
it "should have a remember_token_expires_at attribute" do
|
380
|
+
@user.attributes.keys.any?{|a| a.to_s == "remember_token_expires_at"}.should_not be_nil
|
381
|
+
end
|
382
|
+
|
383
|
+
it "should respond to remember_token?" do
|
384
|
+
@user.should respond_to(:remember_token?)
|
385
|
+
end
|
386
|
+
|
387
|
+
it "should return true if remember_token_expires_at is set and is in the future" do
|
388
|
+
@user.remember_token_expires_at = DateTime.now + 3600
|
389
|
+
@user.should remember_token
|
390
|
+
end
|
391
|
+
|
392
|
+
it "should set remember_token_expires_at to a specific date" do
|
393
|
+
time = DateTime.civil(2009,12,25)
|
394
|
+
@user.remember_me_until(time)
|
395
|
+
@user.remember_token_expires_at.should == time
|
396
|
+
end
|
397
|
+
|
398
|
+
it "should set the remember_me token when remembering" do
|
399
|
+
time = DateTime.civil(2009,12,25)
|
400
|
+
@user.remember_me_until(time)
|
401
|
+
@user.remember_token.should_not be_nil
|
402
|
+
@user.save
|
403
|
+
MA[:user].find_with_conditions(:login => @user.login).remember_token.should_not be_nil
|
404
|
+
end
|
405
|
+
|
406
|
+
it "should remember me for" do
|
407
|
+
t = DateTime.now
|
408
|
+
DateTime.stub!(:now).and_return(t)
|
409
|
+
today = DateTime.now
|
410
|
+
remember_until = today + (2* Merb::Const::WEEK) / Merb::Const::DAY
|
411
|
+
@user.remember_me_for( Merb::Const::WEEK * 2)
|
412
|
+
@user.remember_token_expires_at.should be_close(remember_until, 0.0001)
|
413
|
+
end
|
414
|
+
|
415
|
+
it "should remember_me for two weeks" do
|
416
|
+
t = DateTime.now
|
417
|
+
DateTime.stub!(:now).and_return(t)
|
418
|
+
@user.remember_me
|
419
|
+
@user.remember_token_expires_at.should be_close(DateTime.now + (2 * Merb::Const::WEEK ) / Merb::Const::DAY, 0.0001)
|
420
|
+
end
|
421
|
+
|
422
|
+
it "should forget me" do
|
423
|
+
@user.remember_me
|
424
|
+
@user.save
|
425
|
+
@user.forget_me
|
426
|
+
@user.remember_token.should be_nil
|
427
|
+
@user.remember_token_expires_at.should be_nil
|
428
|
+
end
|
429
|
+
|
430
|
+
it "should persist the forget me to the database" do
|
431
|
+
@user.remember_me
|
432
|
+
@user.save
|
433
|
+
|
434
|
+
@user = MA[:user].find_with_conditions(:email => @user.email)
|
435
|
+
@user.remember_token.should_not be_nil
|
436
|
+
|
437
|
+
@user.forget_me
|
438
|
+
|
439
|
+
@user = MA[:user].find_with_conditions(:email => @user.email)
|
440
|
+
@user.remember_token.should be_nil
|
441
|
+
@user.remember_token_expires_at.should be_nil
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
end
|