nyauth 0.0.1

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.
Files changed (110) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +1 -0
  4. data/Rakefile +26 -0
  5. data/app/assets/javascripts/nyauth/application.js +13 -0
  6. data/app/assets/stylesheets/nyauth/application.css +15 -0
  7. data/app/controllers/concerns/nyauth/session_concern.rb +71 -0
  8. data/app/controllers/nyauth/confirmation_requests_controller.rb +28 -0
  9. data/app/controllers/nyauth/confirmations_controller.rb +19 -0
  10. data/app/controllers/nyauth/new_password_requests_controller.rb +28 -0
  11. data/app/controllers/nyauth/new_passwords_controller.rb +26 -0
  12. data/app/controllers/nyauth/passwords_controller.rb +26 -0
  13. data/app/controllers/nyauth/registrations_controller.rb +26 -0
  14. data/app/controllers/nyauth/sessions_controller.rb +31 -0
  15. data/app/helpers/nyauth/application_helper.rb +4 -0
  16. data/app/mailers/nyauth/user_mailer.rb +15 -0
  17. data/app/models/concerns/nyauth/authenticatable.rb +18 -0
  18. data/app/models/concerns/nyauth/confirmable.rb +34 -0
  19. data/app/models/concerns/nyauth/new_password_ability.rb +35 -0
  20. data/app/models/concerns/nyauth/password_digest_ability.rb +40 -0
  21. data/app/responders/nyauth/app_responder.rb +6 -0
  22. data/app/responders/nyauth/confirmation_responder.rb +14 -0
  23. data/app/services/nyauth/confirmation_request_service.rb +15 -0
  24. data/app/services/nyauth/session_service.rb +21 -0
  25. data/app/views/layouts/nyauth/mailer.html.erb +1 -0
  26. data/app/views/layouts/nyauth/mailer.text.erb +1 -0
  27. data/app/views/nyauth/confirmation_requests/new.html.slim +5 -0
  28. data/app/views/nyauth/confirmations/edit.html.slim +5 -0
  29. data/app/views/nyauth/group_requests/edit.html.slim +0 -0
  30. data/app/views/nyauth/group_requests/new.html.slim +14 -0
  31. data/app/views/nyauth/groups/show.html.slim +0 -0
  32. data/app/views/nyauth/layouts/application.html.slim +15 -0
  33. data/app/views/nyauth/layouts/mailer.html.slim +1 -0
  34. data/app/views/nyauth/layouts/mailer.text.slim +1 -0
  35. data/app/views/nyauth/new_password_requests/new.html.slim +5 -0
  36. data/app/views/nyauth/new_passwords/edit.html.slim +11 -0
  37. data/app/views/nyauth/passwords/edit.html.slim +11 -0
  38. data/app/views/nyauth/registrations/new.html.slim +12 -0
  39. data/app/views/nyauth/sessions/new.html.slim +15 -0
  40. data/app/views/nyauth/user_mailer/request_confirmation.html.slim +2 -0
  41. data/app/views/nyauth/user_mailer/request_confirmation.text.erb +3 -0
  42. data/app/views/nyauth/user_mailer/request_new_password.html.slim +2 -0
  43. data/app/views/nyauth/user_mailer/request_new_password.text.erb +3 -0
  44. data/config/application.yml +1 -0
  45. data/config/locales/en.yml +46 -0
  46. data/config/routes.rb +10 -0
  47. data/lib/nyauth/encryptor.rb +26 -0
  48. data/lib/nyauth/engine.rb +21 -0
  49. data/lib/nyauth/version.rb +3 -0
  50. data/lib/nyauth.rb +5 -0
  51. data/lib/tasks/nyauth_tasks.rake +4 -0
  52. data/spec/controllers/application_controller_spec.rb +5 -0
  53. data/spec/dummy/README.rdoc +28 -0
  54. data/spec/dummy/Rakefile +6 -0
  55. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  56. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  57. data/spec/dummy/app/controllers/application_controller.rb +7 -0
  58. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  59. data/spec/dummy/app/models/user.rb +5 -0
  60. data/spec/dummy/app/views/layouts/application.html.erb +20 -0
  61. data/spec/dummy/bin/bundle +3 -0
  62. data/spec/dummy/bin/rails +4 -0
  63. data/spec/dummy/bin/rake +4 -0
  64. data/spec/dummy/bin/setup +29 -0
  65. data/spec/dummy/config/application.rb +32 -0
  66. data/spec/dummy/config/boot.rb +5 -0
  67. data/spec/dummy/config/database.yml +25 -0
  68. data/spec/dummy/config/environment.rb +5 -0
  69. data/spec/dummy/config/environments/development.rb +42 -0
  70. data/spec/dummy/config/environments/production.rb +79 -0
  71. data/spec/dummy/config/environments/test.rb +46 -0
  72. data/spec/dummy/config/initializers/assets.rb +11 -0
  73. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  74. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  75. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  76. data/spec/dummy/config/initializers/inflections.rb +16 -0
  77. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  78. data/spec/dummy/config/initializers/session_store.rb +3 -0
  79. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  80. data/spec/dummy/config/locales/en.yml +23 -0
  81. data/spec/dummy/config/routes.rb +3 -0
  82. data/spec/dummy/config/secrets.yml +22 -0
  83. data/spec/dummy/config.ru +4 -0
  84. data/spec/dummy/db/development.sqlite3 +0 -0
  85. data/spec/dummy/db/migrate/20150303135922_create_users.rb +18 -0
  86. data/spec/dummy/db/schema.rb +32 -0
  87. data/spec/dummy/db/test.sqlite3 +0 -0
  88. data/spec/dummy/log/development.log +1906 -0
  89. data/spec/dummy/log/test.log +6719 -0
  90. data/spec/dummy/public/404.html +67 -0
  91. data/spec/dummy/public/422.html +67 -0
  92. data/spec/dummy/public/500.html +66 -0
  93. data/spec/dummy/public/favicon.ico +0 -0
  94. data/spec/factories/users.rb +21 -0
  95. data/spec/featrues/nyauth/confirmation_requests_spec.rb +35 -0
  96. data/spec/featrues/nyauth/new_password_requests_spec.rb +43 -0
  97. data/spec/featrues/nyauth/passwords_spec.rb +27 -0
  98. data/spec/featrues/nyauth/registrations_spec.rb +24 -0
  99. data/spec/featrues/nyauth/sessions_spec.rb +36 -0
  100. data/spec/models/user_spec.rb +9 -0
  101. data/spec/rails_helper.rb +41 -0
  102. data/spec/spec_helper.rb +9 -0
  103. data/spec/support/controllers/nyauth/session_concern.rb +39 -0
  104. data/spec/support/macros/controller_macros.rb +3 -0
  105. data/spec/support/macros/feature_macros.rb +8 -0
  106. data/spec/support/models/nyauth/authenticatable.rb +36 -0
  107. data/spec/support/models/nyauth/confirmable.rb +27 -0
  108. data/spec/support/models/nyauth/new_password_ability.rb +13 -0
  109. data/spec/support/models/nyauth/password_digest_ability.rb +18 -0
  110. metadata +280 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,21 @@
1
+ FactoryGirl.define do
2
+ factory :user, class: 'User' do
3
+ sequence(:email) { |n| "user#{n}@example.com" }
4
+ password { 'password' }
5
+ nickname { Faker::Name.name }
6
+
7
+ trait :without_nickname do
8
+ nickname nil
9
+ end
10
+
11
+ trait :requested_confirmation do
12
+ confirmation_key 'key'
13
+ confirmation_key_expired_at { Time.current + 1.hour }
14
+ end
15
+
16
+ trait :requested_new_password do
17
+ new_password_key 'key'
18
+ new_password_key_expired_at { Time.current + 1.hour }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,35 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe 'Nyauth::ConfirmationRequests' do
4
+ let!(:user) { create(:user) }
5
+
6
+ feature 'confirmation' do
7
+ background do
8
+ visit nyauth.new_confirmation_request_path
9
+ end
10
+
11
+ scenario 'request & confirm' do
12
+ fill_in('user_email', with: user.email)
13
+ click_button('request confirmation')
14
+
15
+ open_email(user.email)
16
+ current_email.click_link('confirm')
17
+
18
+ expect(page).to have_content('confirmed')
19
+ user.reload
20
+ expect(user).to be_confirmed
21
+ end
22
+
23
+ scenario 'request expired' do
24
+ fill_in('user_email', with: user.email)
25
+ click_button('request confirmation')
26
+
27
+ Timecop.freeze(Time.current + 3.hours) do
28
+ open_email(user.email)
29
+ current_email.click_link('confirm')
30
+
31
+ expect(page).to have_content('expired')
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,43 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe 'Nyauth::NewPasswordRequests' do
4
+ let!(:user) { create(:user) }
5
+
6
+ feature 'confirmation' do
7
+ let(:new_password) { 'cool_password' }
8
+ background do
9
+ visit nyauth.new_new_password_request_path
10
+ end
11
+
12
+ scenario 'request & set new password' do
13
+ fill_in('user_email', with: user.email)
14
+ click_button('request new password')
15
+
16
+ open_email(user.email)
17
+ current_email.click_link('set new password')
18
+
19
+ fill_in('user_password', with: new_password)
20
+ fill_in('user_password_confirmation', with: new_password)
21
+ click_button('Update')
22
+
23
+ expect(page).to have_content('updated')
24
+ expect(current_path).to eq nyauth.new_session_path
25
+ end
26
+
27
+ scenario 'request expired' do
28
+ fill_in('user_email', with: user.email)
29
+ click_button('request new password')
30
+
31
+ Timecop.freeze(Time.current + 3.hours) do
32
+ open_email(user.email)
33
+ current_email.click_link('set new password')
34
+
35
+ fill_in('user_password', with: new_password)
36
+ fill_in('user_password_confirmation', with: new_password)
37
+ click_button('Update')
38
+
39
+ expect(page).to have_content('expired')
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,27 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe 'Nyauth::Passwords' do
4
+ let(:user) { create(:user) }
5
+
6
+ feature 'password' do
7
+ let(:new_password) { 'cool_password' }
8
+ background do
9
+ sign_in(user)
10
+ visit nyauth.edit_password_path
11
+ end
12
+
13
+ scenario 'update password' do
14
+ fill_in('user_password', with: new_password)
15
+ fill_in('user_password_confirmation', with: new_password)
16
+ click_button('Update')
17
+
18
+ expect(page).to have_content('updated')
19
+ end
20
+
21
+ scenario "can't udpate password" do
22
+ click_button('Update')
23
+
24
+ expect(page).to have_content('errors')
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe 'Nyauth::Registrations' do
4
+ let(:user) { build(:user) }
5
+
6
+ feature 'register' do
7
+ background { visit nyauth.new_registration_path }
8
+
9
+ scenario 'create user' do
10
+ fill_in('user_email', with: user.email)
11
+ fill_in('user_password', with: user.password)
12
+ fill_in('user_password_confirmation', with: user.password)
13
+ click_button('Sign up')
14
+
15
+ expect(page).to have_content('registration success')
16
+ end
17
+
18
+ scenario "can't create user" do
19
+ click_button('Sign up')
20
+
21
+ expect(page).to have_content('errors')
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe 'Nyauth::Sessions' do
4
+ let(:user) { create(:user) }
5
+
6
+ feature 'sign in' do
7
+ background { visit nyauth.new_session_path }
8
+
9
+ scenario 'sign in user' do
10
+ fill_in('session_service_email', with: user.email)
11
+ fill_in('session_service_password', with: user.password)
12
+ click_button('Sign in')
13
+
14
+ expect(page).to have_content('sign in success')
15
+ end
16
+
17
+ scenario "can't sign in user" do
18
+ click_button('Sign in')
19
+
20
+ expect(page).to have_content('invalid')
21
+ end
22
+
23
+ end
24
+
25
+ feature 'sign out' do
26
+ background do
27
+ sign_in(user)
28
+ end
29
+
30
+ scenario 'sign out user' do
31
+ visit nyauth.root_path
32
+ click_link('Sign out')
33
+ expect(page).to have_content('sign out')
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe User do
4
+ let(:user) { create(:user) }
5
+ it { expect(user).to be_persisted }
6
+ it_behaves_like 'Nyauth::Authenticatable', User
7
+ it_behaves_like 'Nyauth::Confirmable', User
8
+ it_behaves_like 'Nyauth::NewPasswordAvility', User
9
+ end
@@ -0,0 +1,41 @@
1
+ ENV["RAILS_ENV"] ||= 'test'
2
+ require 'spec_helper'
3
+ require File.expand_path("../dummy/config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'capybara/email/rspec'
6
+ require 'rack_session_access/capybara'
7
+
8
+ Rails.application.config do
9
+ config.middleware.use RackSessionAccess::Middleware
10
+ end
11
+
12
+ ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
13
+ Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f }
14
+ FactoryGirl.definition_file_paths << File.join(ENGINE_RAILS_ROOT, "spec/factories")
15
+
16
+ ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
17
+
18
+ RSpec.configure do |config|
19
+ config.use_transactional_fixtures = false
20
+ config.infer_spec_type_from_file_location!
21
+
22
+ config.include FactoryGirl::Syntax::Methods
23
+ config.include ControllerMacros, type: :controller
24
+ config.include FeatureMacros, type: :feature
25
+
26
+ config.before(:suite) do
27
+ DatabaseRewinder.clean
28
+ Rails.cache.clear
29
+ end
30
+
31
+ config.before(:all) do
32
+ FactoryGirl.reload
33
+ end
34
+
35
+ config.after :each do
36
+ DatabaseRewinder.clean
37
+ Rails.cache.clear
38
+ end
39
+
40
+ Faker::Config.locale = :en
41
+ end
@@ -0,0 +1,9 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |expectations|
3
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
4
+ end
5
+
6
+ config.mock_with :rspec do |mocks|
7
+ mocks.verify_partial_doubles = true
8
+ end
9
+ end
@@ -0,0 +1,39 @@
1
+ RSpec.shared_examples 'Nyauth::SessionConcern' do
2
+ describe '#sign_in' do
3
+ subject { controller.sign_in(user) }
4
+
5
+ context 'as user' do
6
+ let(:options) { { as: :user } }
7
+
8
+ context 'given user' do
9
+ let(:user) { create(:user) }
10
+ it '#signed_in? should change result from false to true 'do
11
+ expect {
12
+ subject
13
+ }.to change { controller.signed_in?(options) }.from(false).to(true)
14
+ end
15
+
16
+ it '#current_authenticated should change from result nil to user 'do
17
+ expect {
18
+ subject
19
+ }.to change { controller.current_authenticated }.from(nil).to(user)
20
+ end
21
+ end
22
+
23
+ context 'given nil' do
24
+ let(:user) { nil }
25
+ it '#signed_in? should not change result from false'do
26
+ expect {
27
+ subject
28
+ }.not_to change { controller.signed_in?(options) }.from(false)
29
+ end
30
+
31
+ it '#current_authenticated should not change result from nil'do
32
+ expect {
33
+ subject
34
+ }.not_to change { controller.current_authenticated }.from(nil)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module ControllerMacros
2
+ include Nyauth::SessionConcern
3
+ end
@@ -0,0 +1,8 @@
1
+ module FeatureMacros
2
+ include Nyauth::SessionConcern
3
+
4
+ def sign_in(client)
5
+ session_value = signed_in_session_object(client)
6
+ page.set_rack_session(signed_in_session_key => session_value)
7
+ end
8
+ end
@@ -0,0 +1,36 @@
1
+ RSpec.shared_examples 'Nyauth::Authenticatable' do |klass|
2
+ it_behaves_like 'Nyauth::PasswordDigestAbility', klass
3
+ let!(:instance) { create(klass.name.downcase.to_sym, email: email, password: password) }
4
+
5
+ describe '.authenticate' do
6
+ let(:email) { 'correct@example.com' }
7
+ let(:password) { 'password' }
8
+ subject { klass.authenticate(given_email, given_password) }
9
+
10
+ context 'when correct email' do
11
+ let(:given_email) { email }
12
+ context 'and correct password' do
13
+ let(:given_password) { password }
14
+ it { is_expected.to eq instance }
15
+ end
16
+
17
+ context 'and wrong password' do
18
+ let(:given_password) { 'invalid' }
19
+ it { is_expected.to be_nil }
20
+ end
21
+ end
22
+
23
+ context 'when wrong email' do
24
+ let(:given_email) { 'wrong@example.com' }
25
+ context 'and correct password' do
26
+ let(:given_password) { password }
27
+ it { is_expected.to be_nil }
28
+ end
29
+
30
+ context 'and wrong password' do
31
+ let(:given_password) { 'invalid' }
32
+ it { is_expected.to be_nil }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,27 @@
1
+ RSpec.shared_examples 'Nyauth::Confirmable' do |klass|
2
+ let!(:instance) { create(klass.name.downcase.to_sym, :requested_confirmation) }
3
+
4
+ describe '#confirm' do
5
+ subject { instance.confirm }
6
+ before { Timecop.freeze }
7
+ after { Timecop.return }
8
+
9
+ it do
10
+ expect {
11
+ subject
12
+ }.to change(instance, :confirmed?).from(false).to(true)
13
+ end
14
+
15
+ it do
16
+ expect {
17
+ subject
18
+ }.to change(instance, :confirmed_at).from(nil).to(Time.current)
19
+ end
20
+
21
+ it do
22
+ expect {
23
+ subject
24
+ }.to change(instance, :confirmation_key).to(nil)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ RSpec.shared_examples 'Nyauth::NewPasswordAvility' do |klass|
2
+ let!(:instance) { create(klass.name.downcase.to_sym) }
3
+
4
+ describe '#request_new_password' do
5
+ subject { instance.request_new_password }
6
+
7
+ it do
8
+ expect {
9
+ subject
10
+ }.to change(instance, :new_password_key).from(nil)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ RSpec.shared_examples 'Nyauth::PasswordDigestAbility' do |klass|
2
+ let(:instance) { create(klass.name.downcase.to_sym, password: password) }
3
+
4
+ describe '#verify_password?' do
5
+ let(:password) { 'password' }
6
+ subject { instance.verify_password?(given_password) }
7
+
8
+ context 'when correct password' do
9
+ let(:given_password) { password }
10
+ it { is_expected.to be true }
11
+ end
12
+
13
+ context 'when wrong password' do
14
+ let(:given_password) { 'invalid' }
15
+ it { is_expected.to be false }
16
+ end
17
+ end
18
+ end