mori 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +51 -1
  4. data/Rakefile +1 -0
  5. data/app/controllers/mori/base_controller.rb +3 -0
  6. data/app/controllers/mori/invites_controller.rb +37 -0
  7. data/app/controllers/mori/passwords_controller.rb +59 -0
  8. data/app/controllers/mori/registrations_controller.rb +32 -7
  9. data/app/controllers/mori/sessions_controller.rb +10 -6
  10. data/app/helpers/mori_helper.rb +1 -1
  11. data/app/mailers/mori_mailer.rb +18 -0
  12. data/app/views/invites/new.html.erb +1 -0
  13. data/app/views/invites/show.html.erb +1 -0
  14. data/app/views/layouts/mori/application.html.erb +7 -1
  15. data/app/views/layouts/mori/form.html.erb +15 -0
  16. data/app/views/mori_forms/_accept_invite.html.erb +16 -0
  17. data/app/views/mori_forms/_change_password.html.erb +22 -0
  18. data/app/views/mori_forms/_forgot_password.html.erb +14 -0
  19. data/app/views/mori_forms/_invite_new_user_form.html.erb +14 -0
  20. data/app/views/mori_forms/_password_reset.html.erb +20 -0
  21. data/app/views/mori_forms/_registration.html.erb +22 -0
  22. data/app/views/mori_forms/_sessions.html.erb +18 -0
  23. data/app/views/mori_mailer/confirm_email.html.erb +4 -0
  24. data/app/views/mori_mailer/forgot_password.html.erb +7 -0
  25. data/app/views/mori_mailer/invite_user.html.erb +5 -0
  26. data/app/views/passwords/change.html.erb +1 -0
  27. data/app/views/passwords/forgot.html.erb +2 -0
  28. data/app/views/passwords/reset.html.erb +1 -0
  29. data/app/views/passwords/send_reset.html.erb +1 -0
  30. data/app/views/registrations/new.html.erb +2 -0
  31. data/app/views/sessions/new.html.erb +2 -0
  32. data/app/views/shared/_links.html.erb +11 -0
  33. data/config/database.travis.yml +3 -25
  34. data/config/initializers/warden.rb +5 -5
  35. data/config/locales/mori.en.yml +20 -16
  36. data/config/routes.rb +22 -2
  37. data/db/migrate/20140128055658_create_users.rb +29 -0
  38. data/lib/assets/javascripts/bootstrap.min.js +6 -0
  39. data/lib/assets/stylesheets/bootstrap.min.css +7 -0
  40. data/lib/generators/mori/install/install_generator.rb +130 -0
  41. data/lib/generators/mori/install/templates/db/migrate/add_mori_to_users.rb +23 -0
  42. data/{db/migrate/20140128055658_create_mori_users.rb → lib/generators/mori/install/templates/db/migrate/create_users.rb} +6 -9
  43. data/lib/generators/mori/install/templates/mori.rb +32 -0
  44. data/lib/generators/mori/install/templates/user.rb +3 -0
  45. data/lib/generators/mori/views/USAGE +12 -0
  46. data/lib/generators/mori/views/views_generator.rb +39 -0
  47. data/lib/mori/configuration.rb +17 -10
  48. data/lib/mori/controller.rb +25 -0
  49. data/lib/mori/engine.rb +2 -6
  50. data/lib/mori/password.rb +21 -0
  51. data/lib/mori/token.rb +3 -12
  52. data/lib/mori/user.rb +124 -0
  53. data/lib/mori/version.rb +1 -1
  54. data/lib/mori.rb +3 -3
  55. data/spec/dummy/app/assets/javascripts/application.js +2 -0
  56. data/spec/dummy/app/controllers/application_controller.rb +1 -0
  57. data/spec/dummy/app/models/user.rb +4 -0
  58. data/spec/dummy/app/views/application/index.html.erb +13 -0
  59. data/spec/dummy/app/views/application/test_login.html.erb +1 -0
  60. data/spec/dummy/app/views/layouts/application.html.erb +2 -2
  61. data/spec/dummy/config/application.rb +9 -7
  62. data/spec/dummy/config/database.yml +6 -24
  63. data/spec/dummy/config/environments/production.rb +2 -2
  64. data/spec/dummy/config/environments/test.rb +3 -3
  65. data/spec/dummy/config/initializers/mime_types.rb +2 -2
  66. data/spec/dummy/config/initializers/mori.rb +12 -1
  67. data/spec/dummy/config/initializers/secret_token.rb +6 -1
  68. data/spec/dummy/config/locales/en.yml +1 -1
  69. data/spec/dummy/config/routes.rb +2 -1
  70. data/spec/dummy/db/development.sqlite3 +0 -0
  71. data/spec/dummy/db/migrate/{20140209071716_create_users.mori_engine.rb → 20140421045106_create_users.mori_engine.rb} +2 -6
  72. data/spec/dummy/db/schema.rb +14 -21
  73. data/spec/dummy/db/test.sqlite3 +0 -0
  74. data/spec/dummy/log/development.log +14442 -21478
  75. data/spec/dummy/log/test.log +128933 -76950
  76. data/spec/dummy/public/404.html +1 -1
  77. data/spec/dummy/public/422.html +1 -1
  78. data/spec/dummy/public/500.html +1 -1
  79. data/spec/dummy/tmp/cache/assets/development/sprockets/07db4022ed50ebf1535599a3e2344037 +0 -0
  80. data/spec/dummy/tmp/cache/assets/development/sprockets/09f817f5fe8888d5c59a3b285c3ef605 +0 -0
  81. data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  82. data/spec/dummy/tmp/cache/assets/development/sprockets/19f899de0e04ccfd931a7a11e36aca13 +0 -0
  83. data/spec/dummy/tmp/cache/assets/development/sprockets/1b98ef3337306536c2890a74951d225c +0 -0
  84. data/spec/dummy/tmp/cache/assets/development/sprockets/2000a2ad47f8e201455b785beb7b1384 +0 -0
  85. data/spec/dummy/tmp/cache/assets/development/sprockets/22de1150643c428d3f508171d74347a3 +0 -0
  86. data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  87. data/spec/dummy/tmp/cache/assets/development/sprockets/3453364cd811fec54cae0a92adc719e4 +0 -0
  88. data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  89. data/spec/dummy/tmp/cache/assets/development/sprockets/4462cfec451130aa58d88b3da13913c3 +0 -0
  90. data/spec/dummy/tmp/cache/assets/development/sprockets/45753608d28d02693f8f6277074589a1 +0 -0
  91. data/spec/dummy/tmp/cache/assets/development/sprockets/56b349da612a4be9d5e6733778ce17e4 +0 -0
  92. data/spec/dummy/tmp/cache/assets/development/sprockets/5b3ef4ce70e1da7b1afd392754613726 +0 -0
  93. data/spec/dummy/tmp/cache/assets/development/sprockets/770ff8b64985dd08cab8c32a1fa76438 +0 -0
  94. data/spec/dummy/tmp/cache/assets/development/sprockets/8e4cef792c949716da8fe3e9ee0cda70 +0 -0
  95. data/spec/dummy/tmp/cache/assets/development/sprockets/a6374c002de146da5c25b8cfd375ce6c +0 -0
  96. data/spec/dummy/tmp/cache/assets/development/sprockets/b085c718dd9381a5d4036f00b47d1b91 +0 -0
  97. data/spec/dummy/tmp/cache/assets/development/sprockets/c207a30f2b33f7df2c5336aed05485a2 +0 -0
  98. data/spec/dummy/tmp/cache/assets/development/sprockets/cf4d7483cd5aff334d69dd3173f9b953 +0 -0
  99. data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  100. data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  101. data/spec/dummy/tmp/cache/assets/development/sprockets/e2b0bfc208732a6cf47d67c1be32e54f +0 -0
  102. data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  103. data/spec/dummy/tmp/cache/assets/test/sprockets/07db4022ed50ebf1535599a3e2344037 +0 -0
  104. data/spec/dummy/tmp/cache/assets/test/sprockets/09f817f5fe8888d5c59a3b285c3ef605 +0 -0
  105. data/spec/dummy/tmp/cache/assets/test/sprockets/1143c7a241c19613744d1a2be3ad7cd1 +0 -0
  106. data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  107. data/spec/dummy/tmp/cache/assets/test/sprockets/19f899de0e04ccfd931a7a11e36aca13 +0 -0
  108. data/spec/dummy/tmp/cache/assets/test/sprockets/1b98ef3337306536c2890a74951d225c +0 -0
  109. data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  110. data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  111. data/spec/dummy/tmp/cache/assets/test/sprockets/39cd89cab4906d24583c876a477cf098 +0 -0
  112. data/spec/dummy/tmp/cache/assets/test/sprockets/4462cfec451130aa58d88b3da13913c3 +0 -0
  113. data/spec/dummy/tmp/cache/assets/test/sprockets/45753608d28d02693f8f6277074589a1 +0 -0
  114. data/spec/dummy/tmp/cache/assets/test/sprockets/56b349da612a4be9d5e6733778ce17e4 +0 -0
  115. data/spec/dummy/tmp/cache/assets/test/sprockets/5b3ef4ce70e1da7b1afd392754613726 +0 -0
  116. data/spec/dummy/tmp/cache/assets/test/sprockets/770ff8b64985dd08cab8c32a1fa76438 +0 -0
  117. data/spec/dummy/tmp/cache/assets/test/sprockets/8e4cef792c949716da8fe3e9ee0cda70 +0 -0
  118. data/spec/dummy/tmp/cache/assets/test/sprockets/9d5b4060cdb29606bd153ef2ca742a22 +0 -0
  119. data/spec/dummy/tmp/cache/assets/test/sprockets/a6374c002de146da5c25b8cfd375ce6c +0 -0
  120. data/spec/dummy/tmp/cache/assets/test/sprockets/b085c718dd9381a5d4036f00b47d1b91 +0 -0
  121. data/spec/dummy/tmp/cache/assets/test/sprockets/c1fb58de0c271425746c77af9e101750 +0 -0
  122. data/spec/dummy/tmp/cache/assets/test/sprockets/c207a30f2b33f7df2c5336aed05485a2 +0 -0
  123. data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  124. data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  125. data/spec/dummy/tmp/cache/assets/test/sprockets/e2b0bfc208732a6cf47d67c1be32e54f +0 -0
  126. data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  127. data/spec/factories/mori_users.rb +8 -8
  128. data/spec/features/invites_spec.rb +64 -0
  129. data/spec/features/passwords_spec.rb +101 -0
  130. data/spec/features/registrations_spec.rb +37 -10
  131. data/spec/features/sessions_spec.rb +24 -28
  132. data/spec/helpers/mori_helper_spec.rb +3 -12
  133. data/spec/helpers.rb +10 -0
  134. data/spec/mailers/mori/mailer_spec.rb +24 -4
  135. data/spec/models/mori/user_spec.rb +187 -167
  136. data/spec/spec_helper.rb +17 -6
  137. metadata +108 -53
  138. data/app/assets/javascripts/mori/application.js +0 -13
  139. data/app/assets/stylesheets/mori/application.css +0 -13
  140. data/app/controllers/mori_controller.rb +0 -8
  141. data/app/mailers/mori/mailer.rb +0 -17
  142. data/app/models/mori/user.rb +0 -85
  143. data/app/views/mori/mailer/confirm_email.html.erb +0 -1
  144. data/app/views/mori/mailer/invite_user.html.erb +0 -1
  145. data/app/views/mori/mailer/password_reset_notification.html.erb +0 -1
  146. data/app/views/mori/registrations/new.slim +0 -9
  147. data/app/views/mori/sessions/new.slim +0 -8
  148. data/db/migrate/20140126052000_enable_hstore.rb +0 -9
  149. data/lib/mori/string.rb +0 -20
  150. data/spec/dummy/app/views/application/index.slim +0 -2
  151. data/spec/dummy/db/migrate/20140128055553_enable_hstore.mori.rb +0 -10
  152. data/spec/dummy/log/user.log +0 -43
  153. data/spec/dummy/tmp/pids/server.pid +0 -1
  154. data/spec/mailer_matcher.rb +0 -33
  155. data/spec/views/mori/registrations/create.html.erb_spec.rb +0 -5
  156. data/spec/views/mori/registrations/new.html.erb_spec.rb +0 -5
  157. data/spec/views/mori/sessions/create.html.erb_spec.rb +0 -5
  158. data/spec/views/mori/sessions/destroy.html.erb_spec.rb +0 -5
  159. data/spec/views/mori/sessions/new.html.erb_spec.rb +0 -5
@@ -1,195 +1,215 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Mori
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
- # Post Creation/Save methods
36
- #########################################
37
- describe "after creation it" do
38
- it "should encrypt the password" do
39
- user = build(:mori_minimal_user)
40
- password_before = user.password
41
- user.save
42
- user.password.should eq password_before
43
- user.password.to_s.should_not eq password_before
44
- end
45
- it "should normalize the email on save" do
46
- user = build(:mori_minimal_user, email: "E MAIL@exa MpLE.com")
47
- user.save
48
- user.email.should eq "email@example.com"
49
- user.email.should_not eq "E MAIL@exa MpLE.com"
50
- end
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
- # Helper methods for the User model
55
- #########################################
56
- it "#find_by_normalized_email" do
57
- create(:mori_minimal_user)
58
- User.find_by_normalized_email('e maIl@eXam ple.com').email.should eq 'email@example.com'
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
- # Inviting a User to the System
63
- #########################################
64
- describe "Inviting a User" do
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 "should be invitable" do
70
- @user.should_not be nil
71
- @user.invitation_sent.should eq Date.today
72
- end
73
- describe "accepting the invitation" do
74
- before :each do
75
- User.invite(email)
76
- @user = User.find_by_email(email)
77
- end
78
- it "should set their password" do
79
- user = @user.accept_invitation(@user.invitation_token,password)
80
- user.password.to_s.should_not eq password
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
- # Resetting the password
93
- #########################################
94
- describe "Resetting their password" do
95
- before(:each) do
96
- @user = create(:mori_minimal_user)
97
- User.forgot_password(@user.email)
98
- @user = User.find_by_email('email@example.com')
99
- end
100
- it "should be able to reset password" do
101
- @user.password_reset_token.should_not be nil
102
- @user.password_reset_sent.should eq Date.today
103
- end
104
- it "should require a valid reset token" do
105
- expect {@user.reset_password('token123',password)}.to raise_error
106
- token = @user.password_reset_token
107
- @user.reset_password(token, password).password.should eq password
108
- end
109
- it "should not be able to use an old token" do
110
- token = @user.password_reset_token
111
- ::Timecop.freeze(Date.today + 3.weeks) do
112
- expect {@user.reset_password(token, password)}.to raise_error
113
- end
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
- # Actions a User can Take
119
- #########################################
120
-
121
- describe "changing their password" do
122
- before :each do
123
- @user = create(:mori_minimal_user)
124
- end
125
- it "should be able to change their password" do
126
- User.change_password(@user.email,"123456789sdf",password2)
127
- ::BCrypt::Password.new(User.find_by_email(@user.email).password).should eq password2
128
- end
129
- it "should raise an error if the incorrect password is provided" do
130
- expect{ User.change_password(@user.email,password2,password)}.to raise_error
131
- end
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
- # Confirming Their Email
136
- #########################################
137
-
138
- describe "confirming their email" do
139
- before :each do
140
- @user = create(:mori_minimal_user)
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
- # Emails sent from the model
158
- #########################################
159
-
160
- describe "should recieve an email for" do
161
- it "getting invited" do
162
- Mailer.stub(:invite_user)
163
- Mailer.should_receive(:invite_user)
164
- User.invite(email)
165
- end
166
- it "resetting their password" do
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
- # Authentication
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
- describe "logging in" do
184
- before :each do
185
- @user = create(:mori_minimal_user, :password => password)
186
- end
187
- it "should be able to authenticate with their credentials" do
188
- @user.authenticate(password).should be true
189
- end
190
- it "should raise an error if password is incorrect" do
191
- expect{@user.authenticate(password2) }.to raise_error
192
- end
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("../dummy/config/environment.rb", __FILE__)
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["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
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 = true
34
+ config.use_transactional_fixtures = false
34
35
  config.infer_base_class_for_anonymous_controllers = false
35
- config.order = "random"
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