nyauth 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -20
  3. data/app/controllers/nyauth/{new_password_requests_controller.rb → reset_password_requests_controller.rb} +5 -5
  4. data/app/controllers/nyauth/{new_passwords_controller.rb → reset_passwords_controller.rb} +4 -4
  5. data/app/mailers/nyauth/request_mailer.rb +1 -1
  6. data/app/models/concerns/nyauth/password_digest_ability.rb +1 -2
  7. data/app/models/concerns/nyauth/reset_password_ability.rb +35 -0
  8. data/app/views/nyauth/request_mailer/request_reset_password.html.slim +2 -0
  9. data/app/views/nyauth/request_mailer/request_reset_password.text.erb +3 -0
  10. data/app/views/nyauth/reset_password_requests/new.html.slim +5 -0
  11. data/app/views/nyauth/{new_passwords → reset_passwords}/edit.html.slim +1 -1
  12. data/config/locales/en.yml +3 -3
  13. data/config/routes.rb +2 -2
  14. data/lib/nyauth/configuration.rb +9 -5
  15. data/lib/nyauth/version.rb +1 -1
  16. data/spec/dummy/app/models/user.rb +1 -1
  17. data/spec/dummy/db/development.sqlite3 +0 -0
  18. data/spec/dummy/db/migrate/20150303135922_create_users.rb +2 -2
  19. data/spec/dummy/db/production.sqlite3 +0 -0
  20. data/spec/dummy/db/schema.rb +7 -7
  21. data/spec/dummy/db/test.sqlite3 +0 -0
  22. data/spec/dummy/log/development.log +51 -0
  23. data/spec/dummy/log/test.log +5193 -0
  24. data/spec/factories/users.rb +3 -3
  25. data/spec/featrues/nyauth/{new_password_requests_spec.rb → reset_password_requests_spec.rb} +9 -9
  26. data/spec/helpers/nyauth/application_helper_spec.rb +10 -10
  27. data/spec/mailers/nyauth/request_mailer_spec.rb +3 -3
  28. data/spec/models/user_spec.rb +1 -1
  29. data/spec/support/models/nyauth/reset_password_ability.rb +13 -0
  30. metadata +15 -13
  31. data/app/models/concerns/nyauth/new_password_ability.rb +0 -35
  32. data/app/views/nyauth/new_password_requests/new.html.slim +0 -5
  33. data/app/views/nyauth/request_mailer/request_new_password.html.slim +0 -2
  34. data/app/views/nyauth/request_mailer/request_new_password.text.erb +0 -3
  35. data/spec/support/models/nyauth/new_password_ability.rb +0 -13
@@ -13,9 +13,9 @@ FactoryGirl.define do
13
13
  confirmation_key_expired_at { Time.current + 1.hour }
14
14
  end
15
15
 
16
- trait :requested_new_password do
17
- new_password_key 'key'
18
- new_password_key_expired_at { Time.current + 1.hour }
16
+ trait :requested_reset_password do
17
+ reset_password_key 'key'
18
+ reset_password_key_expired_at { Time.current + 1.hour }
19
19
  end
20
20
  end
21
21
  end
@@ -4,20 +4,20 @@ RSpec.describe 'Nyauth::NewPasswordRequests' do
4
4
  let!(:user) { create(:user) }
5
5
 
6
6
  feature 'confirmation' do
7
- let(:new_password) { 'cool_password' }
7
+ let(:reset_password) { 'cool_password' }
8
8
  background do
9
- visit nyauth.new_new_password_request_path
9
+ visit nyauth.new_reset_password_request_path
10
10
  end
11
11
 
12
- scenario 'request & set new password' do
12
+ scenario 'request & set reset password' do
13
13
  fill_in('user_email', with: user.email)
14
- click_button('request new password')
14
+ click_button('reset password')
15
15
 
16
16
  open_email(user.email)
17
17
  current_email.click_link('set new password')
18
18
 
19
- fill_in('user_password', with: new_password)
20
- fill_in('user_password_confirmation', with: new_password)
19
+ fill_in('user_password', with: reset_password)
20
+ fill_in('user_password_confirmation', with: reset_password)
21
21
  click_button('Update')
22
22
 
23
23
  expect(page).to have_content('updated')
@@ -26,14 +26,14 @@ RSpec.describe 'Nyauth::NewPasswordRequests' do
26
26
 
27
27
  scenario 'request expired' do
28
28
  fill_in('user_email', with: user.email)
29
- click_button('request new password')
29
+ click_button('reset password')
30
30
 
31
31
  Timecop.freeze(Time.current + 3.hours) do
32
32
  open_email(user.email)
33
33
  current_email.click_link('set new password')
34
34
 
35
- fill_in('user_password', with: new_password)
36
- fill_in('user_password_confirmation', with: new_password)
35
+ fill_in('user_password', with: reset_password)
36
+ fill_in('user_password_confirmation', with: reset_password)
37
37
  click_button('Update')
38
38
 
39
39
  expect(page).to have_content('expired')
@@ -100,8 +100,8 @@ RSpec.describe Nyauth::ApplicationHelper do
100
100
  end
101
101
  end
102
102
 
103
- describe '#new_password_requests_path_for' do
104
- subject { helper.new_password_requests_path_for(client_name) }
103
+ describe '#reset_password_requests_path_for' do
104
+ subject { helper.reset_password_requests_path_for(client_name) }
105
105
 
106
106
  context 'when client_name is admin' do
107
107
  let(:client_name) { :admin }
@@ -110,12 +110,12 @@ RSpec.describe Nyauth::ApplicationHelper do
110
110
 
111
111
  context 'when client_name is user' do
112
112
  let(:client_name) { :user }
113
- it { is_expected.to eq "/new_password_requests" }
113
+ it { is_expected.to eq "/reset_password_requests" }
114
114
  end
115
115
  end
116
116
 
117
- describe '#new_new_password_request_path_for' do
118
- subject { helper.new_new_password_request_path_for(client_name) }
117
+ describe '#new_reset_password_request_path_for' do
118
+ subject { helper.new_reset_password_request_path_for(client_name) }
119
119
 
120
120
  context 'when client_name is admin' do
121
121
  let(:client_name) { :admin }
@@ -124,13 +124,13 @@ RSpec.describe Nyauth::ApplicationHelper do
124
124
 
125
125
  context 'when client_name is user' do
126
126
  let(:client_name) { :user }
127
- it { is_expected.to eq "/new_password_requests/new" }
127
+ it { is_expected.to eq "/reset_password_requests/new" }
128
128
  end
129
129
  end
130
130
 
131
- describe '#new_password_path_for(:new_password_key)' do
132
- subject { helper.new_password_path_for(client_name, new_password_key) }
133
- let(:new_password_key) { 'hogehoge' }
131
+ describe '#reset_password_path_for(:reset_password_key)' do
132
+ subject { helper.reset_password_path_for(client_name, reset_password_key) }
133
+ let(:reset_password_key) { 'hogehoge' }
134
134
 
135
135
  context 'when client_name is admin' do
136
136
  let(:client_name) { :admin }
@@ -139,7 +139,7 @@ RSpec.describe Nyauth::ApplicationHelper do
139
139
 
140
140
  context 'when client_name is user' do
141
141
  let(:client_name) { :user }
142
- it { is_expected.to eq "/new_passwords/#{new_password_key}" }
142
+ it { is_expected.to eq "/reset_passwords/#{reset_password_key}" }
143
143
  end
144
144
  end
145
145
  end
@@ -7,9 +7,9 @@ RSpec.describe Nyauth::RequestMailer do
7
7
  it { expect(mail).to have_body_text 'Plese confirm your email' }
8
8
  end
9
9
 
10
- describe '#request_new_password' do
11
- let(:user) { create(:user, :requested_new_password) }
12
- subject(:mail) { Nyauth::RequestMailer.request_new_password(user) }
10
+ describe '#request_reset_password' do
11
+ let(:user) { create(:user, :requested_reset_password) }
12
+ subject(:mail) { Nyauth::RequestMailer.request_reset_password(user) }
13
13
  it { expect(mail).to have_body_text 'Plese set your new password' }
14
14
  end
15
15
  end
@@ -5,5 +5,5 @@ RSpec.describe User do
5
5
  it { expect(user).to be_persisted }
6
6
  it_behaves_like 'Nyauth::Authenticatable', User
7
7
  it_behaves_like 'Nyauth::Confirmable', User
8
- it_behaves_like 'Nyauth::NewPasswordAvility', User
8
+ it_behaves_like 'Nyauth::ResetPasswordAvility', User
9
9
  end
@@ -0,0 +1,13 @@
1
+ RSpec.shared_examples 'Nyauth::ResetPasswordAvility' do |klass|
2
+ let!(:instance) { create(klass.name.downcase.to_sym) }
3
+
4
+ describe '#request_reset_password' do
5
+ subject { instance.request_reset_password }
6
+
7
+ it do
8
+ expect {
9
+ subject
10
+ }.to change(instance, :reset_password_key).from(nil)
11
+ end
12
+ end
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nyauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ppworks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-24 00:00:00.000000000 Z
11
+ date: 2015-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -97,17 +97,17 @@ files:
97
97
  - app/controllers/concerns/nyauth/session_concern.rb
98
98
  - app/controllers/nyauth/confirmation_requests_controller.rb
99
99
  - app/controllers/nyauth/confirmations_controller.rb
100
- - app/controllers/nyauth/new_password_requests_controller.rb
101
- - app/controllers/nyauth/new_passwords_controller.rb
102
100
  - app/controllers/nyauth/passwords_controller.rb
103
101
  - app/controllers/nyauth/registrations_controller.rb
102
+ - app/controllers/nyauth/reset_password_requests_controller.rb
103
+ - app/controllers/nyauth/reset_passwords_controller.rb
104
104
  - app/controllers/nyauth/sessions_controller.rb
105
105
  - app/helpers/nyauth/application_helper.rb
106
106
  - app/mailers/nyauth/request_mailer.rb
107
107
  - app/models/concerns/nyauth/authenticatable.rb
108
108
  - app/models/concerns/nyauth/confirmable.rb
109
- - app/models/concerns/nyauth/new_password_ability.rb
110
109
  - app/models/concerns/nyauth/password_digest_ability.rb
110
+ - app/models/concerns/nyauth/reset_password_ability.rb
111
111
  - app/responders/nyauth/app_responder.rb
112
112
  - app/responders/nyauth/confirmation_responder.rb
113
113
  - app/services/nyauth/confirmation_request_service.rb
@@ -119,14 +119,14 @@ files:
119
119
  - app/views/nyauth/layouts/application.html.slim
120
120
  - app/views/nyauth/layouts/mailer.html.slim
121
121
  - app/views/nyauth/layouts/mailer.text.slim
122
- - app/views/nyauth/new_password_requests/new.html.slim
123
- - app/views/nyauth/new_passwords/edit.html.slim
124
122
  - app/views/nyauth/passwords/edit.html.slim
125
123
  - app/views/nyauth/registrations/new.html.slim
126
124
  - app/views/nyauth/request_mailer/request_confirmation.html.slim
127
125
  - app/views/nyauth/request_mailer/request_confirmation.text.erb
128
- - app/views/nyauth/request_mailer/request_new_password.html.slim
129
- - app/views/nyauth/request_mailer/request_new_password.text.erb
126
+ - app/views/nyauth/request_mailer/request_reset_password.html.slim
127
+ - app/views/nyauth/request_mailer/request_reset_password.text.erb
128
+ - app/views/nyauth/reset_password_requests/new.html.slim
129
+ - app/views/nyauth/reset_passwords/edit.html.slim
130
130
  - app/views/nyauth/sessions/new.html.slim
131
131
  - config/application.yml
132
132
  - config/locales/en.yml
@@ -178,6 +178,7 @@ files:
178
178
  - spec/dummy/db/development.sqlite3
179
179
  - spec/dummy/db/migrate/20150303135922_create_users.rb
180
180
  - spec/dummy/db/migrate/20150317141956_create_admins.rb
181
+ - spec/dummy/db/production.sqlite3
181
182
  - spec/dummy/db/schema.rb
182
183
  - spec/dummy/db/test.sqlite3
183
184
  - spec/dummy/log/development.log
@@ -207,9 +208,9 @@ files:
207
208
  - spec/factories/admins.rb
208
209
  - spec/factories/users.rb
209
210
  - spec/featrues/nyauth/confirmation_requests_spec.rb
210
- - spec/featrues/nyauth/new_password_requests_spec.rb
211
211
  - spec/featrues/nyauth/passwords_spec.rb
212
212
  - spec/featrues/nyauth/registrations_spec.rb
213
+ - spec/featrues/nyauth/reset_password_requests_spec.rb
213
214
  - spec/featrues/nyauth/sessions_spec.rb
214
215
  - spec/featrues/url_helper_on_application_spec.rb
215
216
  - spec/helpers/nyauth/application_helper_spec.rb
@@ -225,8 +226,8 @@ files:
225
226
  - spec/support/macros/feature_macros.rb
226
227
  - spec/support/models/nyauth/authenticatable.rb
227
228
  - spec/support/models/nyauth/confirmable.rb
228
- - spec/support/models/nyauth/new_password_ability.rb
229
229
  - spec/support/models/nyauth/password_digest_ability.rb
230
+ - spec/support/models/nyauth/reset_password_ability.rb
230
231
  homepage: https://github.com/ppworks/nyauth
231
232
  licenses:
232
233
  - MIT
@@ -289,6 +290,7 @@ test_files:
289
290
  - spec/dummy/db/development.sqlite3
290
291
  - spec/dummy/db/migrate/20150303135922_create_users.rb
291
292
  - spec/dummy/db/migrate/20150317141956_create_admins.rb
293
+ - spec/dummy/db/production.sqlite3
292
294
  - spec/dummy/db/schema.rb
293
295
  - spec/dummy/db/test.sqlite3
294
296
  - spec/dummy/log/development.log
@@ -320,9 +322,9 @@ test_files:
320
322
  - spec/factories/admins.rb
321
323
  - spec/factories/users.rb
322
324
  - spec/featrues/nyauth/confirmation_requests_spec.rb
323
- - spec/featrues/nyauth/new_password_requests_spec.rb
324
325
  - spec/featrues/nyauth/passwords_spec.rb
325
326
  - spec/featrues/nyauth/registrations_spec.rb
327
+ - spec/featrues/nyauth/reset_password_requests_spec.rb
326
328
  - spec/featrues/nyauth/sessions_spec.rb
327
329
  - spec/featrues/url_helper_on_application_spec.rb
328
330
  - spec/helpers/nyauth/application_helper_spec.rb
@@ -338,5 +340,5 @@ test_files:
338
340
  - spec/support/macros/feature_macros.rb
339
341
  - spec/support/models/nyauth/authenticatable.rb
340
342
  - spec/support/models/nyauth/confirmable.rb
341
- - spec/support/models/nyauth/new_password_ability.rb
342
343
  - spec/support/models/nyauth/password_digest_ability.rb
344
+ - spec/support/models/nyauth/reset_password_ability.rb
@@ -1,35 +0,0 @@
1
- module Nyauth
2
- module NewPasswordAbility
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- before_validation :check_new_password_key, on: :new_password
7
- validates :email, email: { strict_mode: false }
8
- validates :password, presence: true,
9
- length: { minimum: 8 },
10
- on: [:create, :update_password, :new_password]
11
- validates :password, confirmation: true
12
- end
13
-
14
- def update_new_password(params)
15
- self.attributes = params
16
- self.save(context: :new_password)
17
- end
18
-
19
- def request_new_password
20
- self.new_password_key = SecureRandom.hex(32)
21
- self.new_password_key_expired_at = Time.current + 1.hour
22
- save
23
- end
24
-
25
- private
26
-
27
- def check_new_password_key
28
- if new_password_key_expired_at.past?
29
- errors.add(:new_password_key, :expired)
30
- else
31
- self.new_password_key = nil
32
- end
33
- end
34
- end
35
- end
@@ -1,5 +0,0 @@
1
- = form_for(client_class.new, url: new_password_requests_path_for(client_name), mehotd: :post, html: { class: 'pure-form' }) do |f|
2
- fieldset
3
- legend= t 'nav.new_password_requests.new'
4
- = f.text_field(:email, placeholder: :email)
5
- = f.submit 'request new password', data: { disable_with: '...' }, class: 'pure-button pure-button-primary'
@@ -1,2 +0,0 @@
1
- p Plese set your new password
2
- p = link_to 'set new password', edit_new_password_url(@client.new_password_key)
@@ -1,3 +0,0 @@
1
- Plese set your new password
2
-
3
- <%= edit_new_password_url(@client.new_password_key) %>
@@ -1,13 +0,0 @@
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