mori 0.0.1 → 0.1.0
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.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +51 -1
- data/Rakefile +1 -0
- data/app/controllers/mori/base_controller.rb +3 -0
- data/app/controllers/mori/invites_controller.rb +37 -0
- data/app/controllers/mori/passwords_controller.rb +59 -0
- data/app/controllers/mori/registrations_controller.rb +32 -7
- data/app/controllers/mori/sessions_controller.rb +10 -6
- data/app/helpers/mori_helper.rb +1 -1
- data/app/mailers/mori_mailer.rb +18 -0
- data/app/views/invites/new.html.erb +1 -0
- data/app/views/invites/show.html.erb +1 -0
- data/app/views/layouts/mori/application.html.erb +7 -1
- data/app/views/layouts/mori/form.html.erb +15 -0
- data/app/views/mori_forms/_accept_invite.html.erb +16 -0
- data/app/views/mori_forms/_change_password.html.erb +22 -0
- data/app/views/mori_forms/_forgot_password.html.erb +14 -0
- data/app/views/mori_forms/_invite_new_user_form.html.erb +14 -0
- data/app/views/mori_forms/_password_reset.html.erb +20 -0
- data/app/views/mori_forms/_registration.html.erb +22 -0
- data/app/views/mori_forms/_sessions.html.erb +18 -0
- data/app/views/mori_mailer/confirm_email.html.erb +4 -0
- data/app/views/mori_mailer/forgot_password.html.erb +7 -0
- data/app/views/mori_mailer/invite_user.html.erb +5 -0
- data/app/views/passwords/change.html.erb +1 -0
- data/app/views/passwords/forgot.html.erb +2 -0
- data/app/views/passwords/reset.html.erb +1 -0
- data/app/views/passwords/send_reset.html.erb +1 -0
- data/app/views/registrations/new.html.erb +2 -0
- data/app/views/sessions/new.html.erb +2 -0
- data/app/views/shared/_links.html.erb +11 -0
- data/config/database.travis.yml +3 -25
- data/config/initializers/warden.rb +5 -5
- data/config/locales/mori.en.yml +20 -16
- data/config/routes.rb +22 -2
- data/db/migrate/20140128055658_create_users.rb +29 -0
- data/lib/assets/javascripts/bootstrap.min.js +6 -0
- data/lib/assets/stylesheets/bootstrap.min.css +7 -0
- data/lib/generators/mori/install/install_generator.rb +130 -0
- data/lib/generators/mori/install/templates/db/migrate/add_mori_to_users.rb +23 -0
- data/{db/migrate/20140128055658_create_mori_users.rb → lib/generators/mori/install/templates/db/migrate/create_users.rb} +6 -9
- data/lib/generators/mori/install/templates/mori.rb +32 -0
- data/lib/generators/mori/install/templates/user.rb +3 -0
- data/lib/generators/mori/views/USAGE +12 -0
- data/lib/generators/mori/views/views_generator.rb +39 -0
- data/lib/mori/configuration.rb +17 -10
- data/lib/mori/controller.rb +25 -0
- data/lib/mori/engine.rb +2 -6
- data/lib/mori/password.rb +21 -0
- data/lib/mori/token.rb +3 -12
- data/lib/mori/user.rb +124 -0
- data/lib/mori/version.rb +1 -1
- data/lib/mori.rb +3 -3
- data/spec/dummy/app/assets/javascripts/application.js +2 -0
- data/spec/dummy/app/controllers/application_controller.rb +1 -0
- data/spec/dummy/app/models/user.rb +4 -0
- data/spec/dummy/app/views/application/index.html.erb +13 -0
- data/spec/dummy/app/views/application/test_login.html.erb +1 -0
- data/spec/dummy/app/views/layouts/application.html.erb +2 -2
- data/spec/dummy/config/application.rb +9 -7
- data/spec/dummy/config/database.yml +6 -24
- data/spec/dummy/config/environments/production.rb +2 -2
- data/spec/dummy/config/environments/test.rb +3 -3
- data/spec/dummy/config/initializers/mime_types.rb +2 -2
- data/spec/dummy/config/initializers/mori.rb +12 -1
- data/spec/dummy/config/initializers/secret_token.rb +6 -1
- data/spec/dummy/config/locales/en.yml +1 -1
- data/spec/dummy/config/routes.rb +2 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/{20140209071716_create_users.mori_engine.rb → 20140421045106_create_users.mori_engine.rb} +2 -6
- data/spec/dummy/db/schema.rb +14 -21
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +14442 -21478
- data/spec/dummy/log/test.log +128933 -76950
- data/spec/dummy/public/404.html +1 -1
- data/spec/dummy/public/422.html +1 -1
- data/spec/dummy/public/500.html +1 -1
- data/spec/dummy/tmp/cache/assets/development/sprockets/07db4022ed50ebf1535599a3e2344037 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/09f817f5fe8888d5c59a3b285c3ef605 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/19f899de0e04ccfd931a7a11e36aca13 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1b98ef3337306536c2890a74951d225c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2000a2ad47f8e201455b785beb7b1384 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/22de1150643c428d3f508171d74347a3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3453364cd811fec54cae0a92adc719e4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4462cfec451130aa58d88b3da13913c3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/45753608d28d02693f8f6277074589a1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/56b349da612a4be9d5e6733778ce17e4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5b3ef4ce70e1da7b1afd392754613726 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/770ff8b64985dd08cab8c32a1fa76438 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8e4cef792c949716da8fe3e9ee0cda70 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a6374c002de146da5c25b8cfd375ce6c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b085c718dd9381a5d4036f00b47d1b91 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c207a30f2b33f7df2c5336aed05485a2 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cf4d7483cd5aff334d69dd3173f9b953 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e2b0bfc208732a6cf47d67c1be32e54f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/07db4022ed50ebf1535599a3e2344037 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/09f817f5fe8888d5c59a3b285c3ef605 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/1143c7a241c19613744d1a2be3ad7cd1 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/19f899de0e04ccfd931a7a11e36aca13 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/1b98ef3337306536c2890a74951d225c +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/39cd89cab4906d24583c876a477cf098 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/4462cfec451130aa58d88b3da13913c3 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/45753608d28d02693f8f6277074589a1 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/56b349da612a4be9d5e6733778ce17e4 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/5b3ef4ce70e1da7b1afd392754613726 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/770ff8b64985dd08cab8c32a1fa76438 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/8e4cef792c949716da8fe3e9ee0cda70 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/9d5b4060cdb29606bd153ef2ca742a22 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/a6374c002de146da5c25b8cfd375ce6c +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/b085c718dd9381a5d4036f00b47d1b91 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/c1fb58de0c271425746c77af9e101750 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/c207a30f2b33f7df2c5336aed05485a2 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/e2b0bfc208732a6cf47d67c1be32e54f +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/factories/mori_users.rb +8 -8
- data/spec/features/invites_spec.rb +64 -0
- data/spec/features/passwords_spec.rb +101 -0
- data/spec/features/registrations_spec.rb +37 -10
- data/spec/features/sessions_spec.rb +24 -28
- data/spec/helpers/mori_helper_spec.rb +3 -12
- data/spec/helpers.rb +10 -0
- data/spec/mailers/mori/mailer_spec.rb +24 -4
- data/spec/models/mori/user_spec.rb +187 -167
- data/spec/spec_helper.rb +17 -6
- metadata +108 -53
- data/app/assets/javascripts/mori/application.js +0 -13
- data/app/assets/stylesheets/mori/application.css +0 -13
- data/app/controllers/mori_controller.rb +0 -8
- data/app/mailers/mori/mailer.rb +0 -17
- data/app/models/mori/user.rb +0 -85
- data/app/views/mori/mailer/confirm_email.html.erb +0 -1
- data/app/views/mori/mailer/invite_user.html.erb +0 -1
- data/app/views/mori/mailer/password_reset_notification.html.erb +0 -1
- data/app/views/mori/registrations/new.slim +0 -9
- data/app/views/mori/sessions/new.slim +0 -8
- data/db/migrate/20140126052000_enable_hstore.rb +0 -9
- data/lib/mori/string.rb +0 -20
- data/spec/dummy/app/views/application/index.slim +0 -2
- data/spec/dummy/db/migrate/20140128055553_enable_hstore.mori.rb +0 -10
- data/spec/dummy/log/user.log +0 -43
- data/spec/dummy/tmp/pids/server.pid +0 -1
- data/spec/mailer_matcher.rb +0 -33
- data/spec/views/mori/registrations/create.html.erb_spec.rb +0 -5
- data/spec/views/mori/registrations/new.html.erb_spec.rb +0 -5
- data/spec/views/mori/sessions/create.html.erb_spec.rb +0 -5
- data/spec/views/mori/sessions/destroy.html.erb_spec.rb +0 -5
- data/spec/views/mori/sessions/new.html.erb_spec.rb +0 -5
|
@@ -1,195 +1,215 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
describe User do
|
|
5
|
-
|
|
6
|
-
let(:password){"imapassword"}
|
|
7
|
-
let(:password2){"imtheotherpassword"}
|
|
8
|
-
let(:email){"theemail@theexample.com"}
|
|
9
|
-
|
|
10
|
-
#########################################
|
|
11
|
-
# User Validation
|
|
12
|
-
#########################################
|
|
13
|
-
|
|
14
|
-
describe "is Valid: it" do
|
|
15
|
-
it {should validate_presence_of(:email)}
|
|
16
|
-
it {should validate_uniqueness_of(:email)}
|
|
17
|
-
it {should validate_presence_of(:password)}
|
|
18
|
-
it { should allow_value('foo@example.co.uk').for(:email) }
|
|
19
|
-
it { should allow_value('foo@example.com').for(:email) }
|
|
20
|
-
it { should allow_value('foo+bar@example.com').for(:email) }
|
|
21
|
-
it { should_not allow_value('foo@').for(:email) }
|
|
22
|
-
it { should_not allow_value('foo@example..com').for(:email) }
|
|
23
|
-
it { should_not allow_value('foo@.example.com').for(:email) }
|
|
24
|
-
it { should_not allow_value('foo').for(:email) }
|
|
25
|
-
it { should_not allow_value('example.com').for(:email) }
|
|
26
|
-
it { should_not allow_value('foo;@example.com').for(:email) }
|
|
27
|
-
|
|
28
|
-
it "should require basic information" do
|
|
29
|
-
build(:mori_minimal_user).valid?.should be true
|
|
30
|
-
build(:mori_invited_user).valid?.should be true
|
|
31
|
-
end
|
|
32
|
-
end
|
|
3
|
+
describe User do
|
|
33
4
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
5
|
+
let(:password) { 'imapassword' }
|
|
6
|
+
let(:password2) { 'imtheotherpassword' }
|
|
7
|
+
let(:email) { 'theemail@theexample.com' }
|
|
8
|
+
|
|
9
|
+
#########################################
|
|
10
|
+
# User Validation
|
|
11
|
+
#########################################
|
|
12
|
+
|
|
13
|
+
describe 'is Valid: it' do
|
|
14
|
+
it { should validate_presence_of(:email) }
|
|
15
|
+
it { should validate_uniqueness_of(:email) }
|
|
16
|
+
it { should validate_presence_of(:password) }
|
|
17
|
+
it { should allow_value('foo@example.co.uk').for(:email) }
|
|
18
|
+
it { should allow_value('foo@example.com').for(:email) }
|
|
19
|
+
it { should allow_value('foo+bar@example.com').for(:email) }
|
|
20
|
+
it { should_not allow_value('foo@').for(:email) }
|
|
21
|
+
it { should_not allow_value('foo@example..com').for(:email) }
|
|
22
|
+
it { should_not allow_value('foo@.example.com').for(:email) }
|
|
23
|
+
it { should_not allow_value('foo').for(:email) }
|
|
24
|
+
it { should_not allow_value('example.com').for(:email) }
|
|
25
|
+
it { should_not allow_value('foo;@example.com').for(:email) }
|
|
26
|
+
|
|
27
|
+
it 'should require basic information' do
|
|
28
|
+
build(:mori_minimal_user).valid?.should be true
|
|
29
|
+
build(:mori_invited_user).valid?.should be true
|
|
51
30
|
end
|
|
31
|
+
end
|
|
52
32
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
33
|
+
#########################################
|
|
34
|
+
# Post Creation/Save methods
|
|
35
|
+
#########################################
|
|
36
|
+
describe 'after creation it' do
|
|
37
|
+
it 'should encrypt the password' do
|
|
38
|
+
user = build(:mori_minimal_user)
|
|
39
|
+
password_before = user.password
|
|
40
|
+
user.save
|
|
41
|
+
user.password.should eq password_before
|
|
42
|
+
user.password.to_s.should_not eq password_before
|
|
43
|
+
end
|
|
44
|
+
it 'should normalize the email on save' do
|
|
45
|
+
user = build(:mori_minimal_user, :email => 'E MAIL@exa MpLE.com')
|
|
46
|
+
user.save
|
|
47
|
+
user.email.should eq 'email@example.com'
|
|
48
|
+
user.email.should_not eq 'E MAIL@exa MpLE.com'
|
|
59
49
|
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
#########################################
|
|
53
|
+
# Helper methods for the User model
|
|
54
|
+
#########################################
|
|
55
|
+
it '#find_by_normalized_email' do
|
|
56
|
+
create(:mori_minimal_user)
|
|
57
|
+
user = User.find_by_normalized_email('e maIl@eXam ple.com')
|
|
58
|
+
user.email.should eq 'email@example.com'
|
|
59
|
+
end
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
#########################################
|
|
62
|
+
# Inviting a User to the System
|
|
63
|
+
#########################################
|
|
64
|
+
describe 'Inviting a User' do
|
|
65
|
+
before :each do
|
|
66
|
+
User.invite(email)
|
|
67
|
+
@user = User.find_by_email(email)
|
|
68
|
+
end
|
|
69
|
+
it 'should be invitable' do
|
|
70
|
+
@user.should_not be nil
|
|
71
|
+
@user.invitation_sent.should eq Date.today
|
|
72
|
+
end
|
|
73
|
+
it 'should not be able to invite a user that exists' do
|
|
74
|
+
valid, message = User.invite(email)
|
|
75
|
+
valid.should be false
|
|
76
|
+
message.should eq I18n.t('flashes.could_not_invite_user')
|
|
77
|
+
end
|
|
78
|
+
describe 'accepting the invitation' do
|
|
65
79
|
before :each do
|
|
66
80
|
User.invite(email)
|
|
67
81
|
@user = User.find_by_email(email)
|
|
68
82
|
end
|
|
69
|
-
it
|
|
70
|
-
@user.
|
|
71
|
-
@user.
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
User.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
user.password.should eq password
|
|
82
|
-
end
|
|
83
|
-
it "should not be able to use a stale token" do
|
|
84
|
-
Timecop.freeze(Date.today + 3.weeks) do
|
|
85
|
-
expect{@user.accept_invitation(@user.invitation_token,password)}.to raise_error
|
|
86
|
-
end
|
|
83
|
+
it 'should set their password' do
|
|
84
|
+
User.accept_invitation(@user.invitation_token, password, password)
|
|
85
|
+
@user.reload.password.should_not eq password
|
|
86
|
+
end
|
|
87
|
+
it 'should not be able to use a stale token' do
|
|
88
|
+
Timecop.freeze(Date.today + 3.weeks) do
|
|
89
|
+
valid, message = User.accept_invitation(
|
|
90
|
+
@user.invitation_token,
|
|
91
|
+
password,
|
|
92
|
+
password)
|
|
93
|
+
valid.should eq false
|
|
94
|
+
message.should eq 'Expired Invitation Token'
|
|
87
95
|
end
|
|
88
96
|
end
|
|
89
97
|
end
|
|
98
|
+
end
|
|
90
99
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
100
|
+
#########################################
|
|
101
|
+
# Resetting the password
|
|
102
|
+
#########################################
|
|
103
|
+
describe 'Resetting their password' do
|
|
104
|
+
before(:each) do
|
|
105
|
+
@user = create(:mori_minimal_user)
|
|
106
|
+
User.forgot_password(@user.email)
|
|
107
|
+
@user = User.find_by_email('email@example.com')
|
|
108
|
+
end
|
|
109
|
+
it 'should be able to reset password' do
|
|
110
|
+
@user.password_reset_token.should_not be nil
|
|
111
|
+
@user.password_reset_sent.should eq Date.today
|
|
112
|
+
end
|
|
113
|
+
it 'should require a valid reset token' do
|
|
114
|
+
expect { User.reset_password('token123', password) }.to raise_error
|
|
115
|
+
token = @user.password_reset_token
|
|
116
|
+
User.reset_password(token, password, password)
|
|
117
|
+
::BCrypt::Password.new(@user.reload.password).should eq password
|
|
118
|
+
end
|
|
119
|
+
it 'should not be able to use an old token' do
|
|
120
|
+
token = @user.password_reset_token
|
|
121
|
+
::Timecop.freeze(Date.today + 3.weeks) do
|
|
122
|
+
valid, message = User.reset_password(token, password, password)
|
|
123
|
+
valid.should eq false
|
|
124
|
+
message.should eq 'Expired Reset Token'
|
|
114
125
|
end
|
|
115
126
|
end
|
|
127
|
+
end
|
|
116
128
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
#########################################
|
|
130
|
+
# Actions a User can Take
|
|
131
|
+
#########################################
|
|
132
|
+
|
|
133
|
+
describe 'changing their password' do
|
|
134
|
+
before :each do
|
|
135
|
+
@user = create(:mori_minimal_user)
|
|
136
|
+
end
|
|
137
|
+
it 'should be able to change their password' do
|
|
138
|
+
@user.change_password('123456789sdf', password2, password2)
|
|
139
|
+
::BCrypt::Password.new(@user.reload.password).should eq password2
|
|
140
|
+
end
|
|
141
|
+
it 'should return false if both new passwords don\'t match' do
|
|
142
|
+
valid, message = @user.change_password('123456789sdf', password2, 'potato')
|
|
143
|
+
valid.should eq false
|
|
144
|
+
message.should eq I18n.t('flashes.passwords_did_not_match')
|
|
132
145
|
end
|
|
146
|
+
it 'should raise an error if the incorrect password is provided' do
|
|
147
|
+
valid, message = @user.change_password(password2, password, password)
|
|
148
|
+
valid.should eq false
|
|
149
|
+
message.should eq I18n.t('flashes.password_change_failed')
|
|
150
|
+
end
|
|
151
|
+
end
|
|
133
152
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
end
|
|
142
|
-
it "should require a valid token" do
|
|
143
|
-
expect{User.confirm_email(@user.email, "tokentoken123")}.to raise_error
|
|
144
|
-
end
|
|
145
|
-
it "should require the token to be recent" do
|
|
146
|
-
token = @user.confirmation_token
|
|
147
|
-
::Timecop.freeze(Date.today + 3.weeks) do
|
|
148
|
-
expect {User.confirm_email(@user.email, token)}.to raise_error
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
it "should set confirmed to true" do
|
|
152
|
-
user = User.confirm_email(@user.email, @user.confirmation_token)
|
|
153
|
-
user.confirmed.should eq true
|
|
154
|
-
end
|
|
153
|
+
#########################################
|
|
154
|
+
# Confirming Their Email
|
|
155
|
+
#########################################
|
|
156
|
+
|
|
157
|
+
describe 'confirming their email' do
|
|
158
|
+
before :each do
|
|
159
|
+
@user = create(:mori_minimal_user)
|
|
155
160
|
end
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
User.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
user = create(:mori_minimal_user)
|
|
168
|
-
Mailer.stub(:password_reset_notification)
|
|
169
|
-
Mailer.should_receive(:password_reset_notification)
|
|
170
|
-
User.forgot_password(user.email)
|
|
171
|
-
end
|
|
172
|
-
it "confirming their email" do
|
|
173
|
-
Mailer.stub(:confirm_email)
|
|
174
|
-
Mailer.should_receive(:confirm_email)
|
|
175
|
-
user = create(:mori_minimal_user)
|
|
161
|
+
it 'should require a valid token' do
|
|
162
|
+
valid, message = User.confirm_email('tokentoken123')
|
|
163
|
+
valid.should eq false
|
|
164
|
+
message.should eq 'Invalid Confirmation Token'
|
|
165
|
+
end
|
|
166
|
+
it 'should require the token to be recent' do
|
|
167
|
+
token = @user.confirmation_token
|
|
168
|
+
::Timecop.freeze(Date.today + 3.weeks) do
|
|
169
|
+
valid, message = User.confirm_email(token)
|
|
170
|
+
valid.should eq false
|
|
171
|
+
message.should eq 'Expired Confirmation Token'
|
|
176
172
|
end
|
|
177
173
|
end
|
|
174
|
+
it 'should set confirmed to true' do
|
|
175
|
+
valid, message = User.confirm_email(@user.confirmation_token)
|
|
176
|
+
valid.should eq true
|
|
177
|
+
message.should eq 'Email Confirmed'
|
|
178
|
+
end
|
|
179
|
+
end
|
|
178
180
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
181
|
+
#########################################
|
|
182
|
+
# Emails sent from the model
|
|
183
|
+
#########################################
|
|
184
|
+
describe 'should recieve an email for' do
|
|
185
|
+
it 'getting invited' do
|
|
186
|
+
MoriMailer.should_receive(:invite_user).and_call_original
|
|
187
|
+
User.invite(email)
|
|
188
|
+
end
|
|
189
|
+
it 'resetting their password' do
|
|
190
|
+
user = create(:mori_minimal_user)
|
|
191
|
+
MoriMailer.should_receive(:forgot_password).and_call_original
|
|
192
|
+
User.forgot_password(user.email)
|
|
193
|
+
end
|
|
194
|
+
it 'confirming their email' do
|
|
195
|
+
MoriMailer.should_receive(:confirm_email).and_call_original
|
|
196
|
+
create(:mori_minimal_user)
|
|
197
|
+
end
|
|
198
|
+
end
|
|
182
199
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
200
|
+
#########################################
|
|
201
|
+
# Authentication
|
|
202
|
+
#########################################
|
|
203
|
+
|
|
204
|
+
describe 'logging in' do
|
|
205
|
+
before :each do
|
|
206
|
+
@user = create(:mori_minimal_user, :password => password)
|
|
207
|
+
end
|
|
208
|
+
it 'should be able to authenticate with their credentials' do
|
|
209
|
+
@user.authenticate(password).should eq true
|
|
210
|
+
end
|
|
211
|
+
it 'should raise an error if password is incorrect' do
|
|
212
|
+
@user.authenticate(password2).should eq false
|
|
193
213
|
end
|
|
194
214
|
end
|
|
195
215
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -3,19 +3,19 @@ ENV['RAILS_ENV'] ||= 'test'
|
|
|
3
3
|
PROJECT_ROOT = File.expand_path('../..', __FILE__)
|
|
4
4
|
$LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
|
|
5
5
|
|
|
6
|
-
require File.expand_path(
|
|
6
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
|
7
7
|
|
|
8
8
|
Bundler.require
|
|
9
9
|
|
|
10
10
|
require 'rspec/rails'
|
|
11
11
|
require 'rspec/autorun'
|
|
12
|
-
require 'mailer_matcher'
|
|
13
12
|
require 'factory_girl_rails'
|
|
14
13
|
require 'shoulda-matchers'
|
|
15
14
|
require 'timecop'
|
|
16
15
|
require 'bcrypt'
|
|
17
16
|
require 'capybara/rspec'
|
|
18
|
-
|
|
17
|
+
require 'database_cleaner'
|
|
18
|
+
require 'helpers'
|
|
19
19
|
|
|
20
20
|
# Coveralls!
|
|
21
21
|
require 'coveralls'
|
|
@@ -24,15 +24,26 @@ Coveralls.wear!
|
|
|
24
24
|
Rails.backtrace_cleaner.remove_silencers!
|
|
25
25
|
|
|
26
26
|
# Load support files
|
|
27
|
-
Dir[
|
|
27
|
+
Dir['#{File.dirname(__FILE__)}/support/**/*.rb'].each { |f| require f }
|
|
28
28
|
|
|
29
29
|
RSpec.configure do |config|
|
|
30
30
|
config.include FactoryGirl::Syntax::Methods
|
|
31
|
+
config.include Helpers
|
|
31
32
|
|
|
32
33
|
config.mock_with :rspec
|
|
33
|
-
config.use_transactional_fixtures =
|
|
34
|
+
config.use_transactional_fixtures = false
|
|
34
35
|
config.infer_base_class_for_anonymous_controllers = false
|
|
35
|
-
config.order =
|
|
36
|
+
config.order = 'random'
|
|
37
|
+
config.formatter = 'documentation'
|
|
36
38
|
|
|
37
39
|
Timecop.safe_mode = true
|
|
40
|
+
|
|
41
|
+
DatabaseCleaner.strategy = :transaction
|
|
42
|
+
config.before(:each) do
|
|
43
|
+
DatabaseCleaner.start
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
config.after(:each) do
|
|
47
|
+
DatabaseCleaner.clean
|
|
48
|
+
end
|
|
38
49
|
end
|