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
@@ -49,7 +49,7 @@
49
49
 
50
50
  <body>
51
51
  <!-- This file lives in public/404.html -->
52
- <div class="dialog">
52
+ <div class='dialog'>
53
53
  <h1>The page you were looking for doesn't exist.</h1>
54
54
  <p>You may have mistyped the address or the page may have moved.</p>
55
55
  </div>
@@ -49,7 +49,7 @@
49
49
 
50
50
  <body>
51
51
  <!-- This file lives in public/422.html -->
52
- <div class="dialog">
52
+ <div class='dialog'>
53
53
  <h1>The change you wanted was rejected.</h1>
54
54
  <p>Maybe you tried to change something you didn't have access to.</p>
55
55
  </div>
@@ -49,7 +49,7 @@
49
49
 
50
50
  <body>
51
51
  <!-- This file lives in public/500.html -->
52
- <div class="dialog">
52
+ <div class='dialog'>
53
53
  <h1>We're sorry, but something went wrong.</h1>
54
54
  </div>
55
55
  <p>If you are the application owner check the logs for more information.</p>
@@ -1,16 +1,16 @@
1
1
  # Read about factories at https://github.com/thoughtbot/factory_girl
2
2
 
3
3
  FactoryGirl.define do
4
- factory :mori_minimal_user, :class => 'Mori::User' do
5
- email "email@example.com"
6
- password "123456789sdf"
4
+ factory :mori_minimal_user, :class => 'User' do
5
+ email 'email@example.com'
6
+ password '123456789sdf'
7
7
  end
8
- factory :mori_invited_user, :class => 'Mori::User' do
9
- email "email@example.com"
10
- invitation_token "sdflkjadfsd24rec2"
8
+ factory :mori_invited_user, :class => 'User' do
9
+ email 'email@example.com'
10
+ invitation_token 'sdflkjadfsd24rec2'
11
11
  end
12
- factory :mori_random_user, :class => 'Mori::User' do
12
+ factory :mori_random_user, :class => 'User' do
13
13
  email Faker::Internet.email
14
- password "password"
14
+ password 'password'
15
15
  end
16
16
  end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Inviting Users', :type => :feature do
4
+ before(:each) do
5
+ @user = create(:mori_minimal_user, :password => 'password123')
6
+ end
7
+ describe 'Sending an invite' do
8
+ it 'should require you to be logged in' do
9
+ visit '/invites/new'
10
+ page.has_content?('Log In').should eq true
11
+ end
12
+ it 'should not invite a user that already exists' do
13
+ log_in(@user.email, 'password123')
14
+ visit '/invites/new'
15
+ within(:css, '#invite_new_user_form') do
16
+ fill_in 'E-mail', :with => @user.email
17
+ click_button 'Invite User'
18
+ end
19
+ page.has_content?(I18n.t('flashes.could_not_invite_user')).should eq true
20
+ end
21
+ it 'should send an invite' do
22
+ log_in(@user.email, 'password123')
23
+ visit '/invites/new'
24
+ MoriMailer.should_receive(:invite_user).exactly(1).times
25
+ within(:css, '#invite_new_user_form') do
26
+ fill_in 'E-mail', :with => 'imanewemail@email.com'
27
+ click_button 'Invite User'
28
+ end
29
+ page.current_path.should eq Mori.configuration.dashboard_path
30
+ end
31
+ end
32
+ describe 'Accepting an invite' do
33
+ before(:each) do
34
+ _valid, message = Mori.configuration.user_model.invite('new_email@email.com')
35
+ @user = User.find_by_email('new_email@email.com')
36
+ end
37
+ it 'should redirect to the homepage if the invite token is not found' do
38
+ visit '/invites/asd234fdsasd234'
39
+ page.current_path.should eq root_path
40
+ end
41
+ it 'should redirect to the invites path if validation fails' do
42
+ visit "/invites/#{@user.invitation_token}"
43
+ User.should_receive(:accept_invitation).exactly(1).times.and_call_original
44
+ within(:css, '.edit_user') do
45
+ fill_in 'Password', :with => 'passwoasdfasdfasdasdf'
46
+ fill_in 'Password confirmation', :with => 'password123'
47
+ end
48
+ click_button 'Accept'
49
+ page.current_path.should eq "/invites/#{@user.invitation_token}"
50
+ page.has_content?(I18n.t('flashes.passwords_dont_match')).should eq true
51
+ end
52
+ it 'should accept the invite and log the new user in' do
53
+ visit "/invites/#{@user.invitation_token}"
54
+ User.should_receive(:accept_invitation).exactly(1).times.and_call_original
55
+ within(:css, '.edit_user') do
56
+ fill_in 'Password', :with => 'password123'
57
+ fill_in 'Password confirmation', :with => 'password123'
58
+ end
59
+ click_button 'Accept'
60
+ page.current_path.should eq Mori.configuration.dashboard_path
61
+ page.has_content?(I18n.t('flashes.logged_in')).should be true
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Password Management', :type => :feature do
4
+ before(:each) do
5
+ @user = create(:mori_minimal_user, :password => 'password123')
6
+ end
7
+ describe 'Resetting/Forgetting your Password' do
8
+ it 'when you submit a forgotten password' do
9
+ MoriMailer.should_receive(:forgot_password).exactly(1).times.and_call_original
10
+ visit '/passwords/forgot'
11
+ within '#forgot_password_form' do
12
+ fill_in 'email', :with => @user.email
13
+ end
14
+ click_button 'Reset Password'
15
+ current_url.should eq send_reset_passwords_url
16
+ page.has_content?('Password Reset Sent').should be true
17
+ end
18
+ it 'shouldn\'t send a forgotten password for a user that doesn\'t exist' do
19
+ visit '/passwords/forgot'
20
+ within '#forgot_password_form' do
21
+ fill_in 'email', :with => 'imaemail@email.com'
22
+ end
23
+ click_button 'Reset Password'
24
+ page.has_content?('Reset My Password').should be true
25
+ end
26
+ it 'should change a users password when they go to the link from the email' do
27
+ Mori.configuration.user_model.forgot_password(@user.email)
28
+ user = Mori.configuration.user_model.find_by_email(@user.email)
29
+ visit "/passwords/reset?token=#{user.password_reset_token}"
30
+ within '.edit_user' do
31
+ fill_in 'user_password', :with => 'password123'
32
+ fill_in 'user_password_confirmation', :with => 'password123'
33
+ end
34
+ click_button 'Update Password'
35
+ page.current_path.should eq Mori.configuration.dashboard_path
36
+ end
37
+ it 'should render the reset form again if the change failed' do
38
+ Timecop.freeze(Date.today - 3.weeks) do
39
+ Mori.configuration.user_model.forgot_password(@user.email)
40
+ end
41
+ user = Mori.configuration.user_model.find_by_email(@user.email)
42
+ visit "/passwords/reset?token=#{user.password_reset_token}"
43
+ within '.edit_user' do
44
+ fill_in 'user_password', :with => 'password123'
45
+ fill_in 'user_password_confirmation', :with => 'password123'
46
+ end
47
+ click_button 'Update Password'
48
+ page.has_content?('Expired Reset Token').should be true
49
+ end
50
+ it 'should redirect if no user is found' do
51
+ visit '/passwords/reset?token=123asdf123'
52
+ page.current_path.should eq root_path
53
+ end
54
+ it 'should redirect if I\'m already logged in' do
55
+ log_in(@user.email, 'password123')
56
+ visit '/passwords/forgot'
57
+ page.current_path.should eq Mori.configuration.dashboard_path
58
+ end
59
+ end
60
+ describe 'Changing your Password' do
61
+ it 'should require you to be logged in' do
62
+ visit '/passwords/change'
63
+ page.has_content?('Log In').should be true
64
+ end
65
+ it 'should change a users password' do
66
+ new_pass = 'potato'
67
+ log_in(@user.email, 'password123')
68
+ visit '/passwords/change'
69
+ within '#password_change_form' do
70
+ fill_in 'password', :with => 'password123'
71
+ fill_in 'new_password', :with => new_pass
72
+ fill_in 'new_password_confirmation', :with => new_pass
73
+ end
74
+ click_button 'Change Password'
75
+ ::BCrypt::Password.new(Mori.configuration.user_model.find(@user.id).password).should eq new_pass
76
+ current_path.should eq Mori.configuration.dashboard_path
77
+ end
78
+ it 'should fail if the current password is not correct' do
79
+ log_in(@user.email, 'password123')
80
+ visit '/passwords/change'
81
+ within '#password_change_form' do
82
+ fill_in 'password', :with => 'passw123'
83
+ fill_in 'new_password', :with => 'pass'
84
+ fill_in 'new_password_confirmation', :with => 'pass'
85
+ end
86
+ click_button 'Change Password'
87
+ page.has_content?(I18n.t('flashes.password_change_failed')).should be true
88
+ end
89
+ it 'should fail when the password confirmations don\'t match' do
90
+ log_in(@user.email, 'password123')
91
+ visit '/passwords/change'
92
+ within '#password_change_form' do
93
+ fill_in 'password', :with => 'password123'
94
+ fill_in 'new_password', :with => 'potato'
95
+ fill_in 'new_password_confirmation', :with => 'potatwo'
96
+ end
97
+ click_button 'Change Password'
98
+ page.has_content?(I18n.t('flashes.passwords_did_not_match')).should be true
99
+ end
100
+ end
101
+ end
@@ -1,23 +1,50 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "The registration process", :type => :feature do
4
- it "should be able to register" do
3
+ describe 'The registration process', :type => :feature do
4
+ it 'should be able to register' do
5
5
  visit '/sign_up'
6
- within('#new_mori_user') do
6
+ within('#new_user') do
7
7
  fill_in 'Email', :with => Faker::Internet.email
8
- fill_in 'Password', :with => "imapassword123"
8
+ fill_in 'Password', :with => 'imapassword123'
9
9
  end
10
- click_button 'Create User'
11
- current_path.should eq Mori.configuration.after_signup_url
10
+ click_button 'Sign Up'
11
+ current_path.should eq Mori.configuration.after_sign_up_path
12
12
  end
13
- it "should redirect them if already signed up" do
13
+ it 'should redirect them if already signed up' do
14
14
  visit '/sign_up'
15
- within '#new_mori_user' do
15
+ within '#new_user' do
16
16
  fill_in 'Email', :with => Faker::Internet.email
17
17
  fill_in 'Password', :with => 'password123'
18
18
  end
19
- click_button 'Create User'
19
+ click_button 'Sign Up'
20
20
  visit '/sign_up'
21
- current_path.should eq Mori.configuration.after_signup_url
21
+ current_path.should eq Mori.configuration.after_sign_up_path
22
+ end
23
+ it 'should not allow invalid credentials' do
24
+ visit '/sign_up'
25
+ within('#new_user') do
26
+ fill_in 'Email', :with => 'namenamename'
27
+ fill_in 'Password', :with => 'imapassword123'
28
+ end
29
+ click_button 'Sign Up'
30
+ current_path.should eq '/registrations'
31
+ end
32
+ describe 'confirming your email' do
33
+ before :each do
34
+ @user = create(:mori_minimal_user)
35
+ end
36
+ it 'should confirm their email' do
37
+ visit "/registrations/confirmation?token=#{@user.confirmation_token}"
38
+ @user.reload.confirmed.should eq true
39
+ current_path.should eq Mori.configuration.dashboard_path
40
+ end
41
+ it 'should redirect if confirmation is not found' do
42
+ visit '/registrations/confirmation?token=123123'
43
+ current_path.should eq root_path
44
+ end
45
+ it 'should redirect if no confirmation token' do
46
+ visit '/registrations/confirmation'
47
+ current_path.should eq root_path
48
+ end
22
49
  end
23
50
  end
@@ -1,31 +1,27 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Sessions controller", :type => :feature do
4
- let(:password){"password123"}
5
- before(:each) do
6
- @user = create(:mori_random_user, :password => "password123")
7
- end
8
- def log_in
9
- visit '/login'
10
- within '#new_session' do
11
- fill_in "Email", :with => @user.email
12
- fill_in "Password", :with => password
13
- end
14
- page.find('#submit_button').click
15
- end
16
- it "should be able to log in" do
17
- log_in
18
- current_path.should eq Mori.configuration.after_login_url
19
- end
20
- it "should redirect to the after login url if already logged in" do
21
- log_in
22
- visit '/login'
23
- current_path.should eq Mori.configuration.after_login_url
24
- end
25
- it "should be able to log out" do
26
- log_in
27
- click_link 'Log Out'
28
- visit '/login'
29
- current_path.should eq '/login'
30
- end
3
+ describe 'Sessions controller', :type => :feature do
4
+ let(:password) { 'password123' }
5
+ before :each do
6
+ @user = create(:mori_random_user, :password => 'password123')
7
+ end
8
+ it 'should be able to log in' do
9
+ log_in(@user.email, password)
10
+ current_path.should eq Mori.configuration.dashboard_path
11
+ end
12
+ it 'should redirect to the after login url if already logged in' do
13
+ log_in(@user.email, password)
14
+ visit '/login'
15
+ current_path.should eq Mori.configuration.dashboard_path
16
+ end
17
+ it 'should not log in with invalid credentials' do
18
+ log_in(@user.email, 'imapassword!')
19
+ current_path.should eq '/sessions'
20
+ end
21
+ it 'should be able to log out' do
22
+ log_in(@user.email, password)
23
+ click_link 'Log Out'
24
+ visit '/login'
25
+ current_path.should eq '/login'
26
+ end
31
27
  end
@@ -1,15 +1,6 @@
1
1
  require 'spec_helper'
2
-
3
- # Specs in this file have access to a helper object that includes
4
- # the MoriHelper. For example:
5
- #
6
- # describe MoriHelper do
7
- # describe "string concat" do
8
- # it "concats two strings with spaces" do
9
- # expect(helper.concat_strings("this","that")).to eq("this that")
10
- # end
11
- # end
12
- # end
13
2
  describe MoriHelper do
14
- pending "add some examples to (or delete) #{__FILE__}"
3
+ it 'should return the logout link' do
4
+ logout_link.should eq link_to('Log Out', '/logout', :method => :delete)
5
+ end
15
6
  end
data/spec/helpers.rb ADDED
@@ -0,0 +1,10 @@
1
+ module Helpers
2
+ def log_in(email, pass)
3
+ visit '/login'
4
+ within '#new_session' do
5
+ fill_in 'Email', :with => email
6
+ fill_in 'Password', :with => pass
7
+ click_button 'Log In'
8
+ end
9
+ end
10
+ end
@@ -1,7 +1,27 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- module Mori
4
- describe Mailer do
5
- pending "add some examples to (or delete) #{__FILE__}"
3
+ describe MoriMailer do
4
+ before :each do
5
+ @user = create(:mori_minimal_user, :invitation_token => "67ssdf67a67sdf76", :password_reset_token => "s7df8s7sd8d")
6
+ @host = ::ActionMailer::Base.default_url_options[:host]
7
+ end
8
+ it "is from configuration email" do
9
+ email = MoriMailer.forgot_password(@user)
10
+ Mori.configuration.from_email.should eq email.from[0]
11
+ end
12
+ it "should contain an invite url in invite email" do
13
+ email = MoriMailer.invite_user(@user)
14
+ regexp = %r{http://#{@host}/invites/#{@user.invitation_token}}
15
+ email.body.to_s.should =~ regexp
16
+ end
17
+ it "should contain password reset URL in forgot password email" do
18
+ email = MoriMailer.forgot_password(@user)
19
+ regexp = %r{http://#{@host}/passwords/forgot\?token=#{@user.password_reset_token}}
20
+ email.body.to_s.should =~ regexp
21
+ end
22
+ it "should contain confirmation URL in confirmation email" do
23
+ email = MoriMailer.confirm_email(@user)
24
+ regexp = %r{http://#{@host}/registrations/confirmation\?token=#{@user.confirmation_token}}
25
+ email.body.to_s.should =~ regexp
6
26
  end
7
27
  end