hello-rails 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -4
- data/app/controllers/hello/concerns/management/forgot_password.rb +1 -1
- data/app/controllers/hello/concerns/registration/sign_up.rb +7 -3
- data/app/controllers/hello/registration/sign_up_controller.rb +9 -1
- data/app/models/access.rb +2 -1
- data/app/models/credential.rb +2 -1
- data/app/models/email_credential.rb +2 -1
- data/app/models/password_credential.rb +2 -1
- data/app/models/user.rb +2 -1
- data/app/views/hello/shared/_nav_pills.html.erb +0 -2
- data/config/locales/hello.fr.yml +2 -4
- data/db/migrate/3_create_users.rb +10 -15
- data/lib/data/locales.yml +228 -0
- data/lib/generators/hello/install/install_generator.rb +8 -29
- data/lib/generators/hello/install/templates/initializer.rb +1 -1
- data/lib/generators/hello/install/templates/models/concerns/user/authorization.rb +8 -13
- data/lib/generators/hello/install/templates/models/user.rb +2 -1
- data/lib/generators/hello/users/USAGE +10 -0
- data/lib/generators/hello/{install/templates/users → users/templates/app}/controllers/users_controller.rb +2 -4
- data/lib/generators/hello/{install/templates/users → users/templates/app}/views/users/index.html.erb +1 -1
- data/lib/generators/hello/{install/templates/users → users/templates/app}/views/users/list.html.erb +3 -1
- data/lib/generators/hello/{install/templates/users → users/templates/app}/views/users/new.html.erb +2 -2
- data/lib/generators/hello/{install/templates/users → users/templates/app}/views/users/show.html.erb +0 -0
- data/lib/generators/hello/users/users_generator.rb +21 -0
- data/lib/hello/business/registration/sign_up.rb +30 -122
- data/lib/hello/locales.rb +1 -232
- data/lib/hello/rails_active_record/access.rb +12 -10
- data/lib/hello/rails_active_record/credential.rb +22 -18
- data/lib/hello/rails_active_record/email_credential.rb +12 -20
- data/lib/hello/rails_active_record/password_credential.rb +11 -32
- data/lib/hello/rails_active_record/user.rb +75 -54
- data/lib/hello/rails_controller.rb +1 -3
- data/lib/hello/rails_controller/restrict_by_role.rb +2 -2
- data/lib/hello/version.rb +1 -1
- data/spec/bdd/hello/authentication/classic_sign_in_spec.rb +2 -2
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_locale/change_locale_on_the_sign_in_form_spec.rb +1 -1
- data/spec/bdd/hello/management/manage_email_credentials/manage_email_credentials_emails_page_spec.rb +7 -7
- data/spec/bdd/hello/management/manage_password_credentials/manage_password_forgot_password_spec.rb +1 -1
- data/spec/bdd/hello/management/manage_password_credentials/manage_password_reset_password_spec.rb +1 -1
- data/spec/bdd/hello/management/manage_profile/manage_profile_page_spec.rb +0 -2
- data/spec/bdd/hello/other/create_user_spec.rb +1 -3
- data/spec/bdd/hello/other/impersonate_user_spec.rb +1 -2
- data/spec/bdd/hello/other/list_users_spec.rb +2 -4
- data/spec/bdd/hello/registration/classic_sign_up_spec.rb +3 -4
- data/spec/bdd/hello/support.rb +0 -4
- data/spec/business/hello/registration/sign_up_spec.rb +10 -2
- data/spec/controllers/authentication_spec.rb +3 -3
- data/spec/models/create_and_destroy/email_credential_create_and_destroy_spec.rb +81 -0
- data/spec/models/create_and_destroy/password_credential_create_and_destroy_spec.rb +60 -0
- data/spec/models/create_and_destroy/user_create_and_destroy_spec.rb +124 -0
- data/spec/models/credential_spec.rb +12 -3
- data/spec/models/email_credential_spec.rb +1 -2
- data/spec/models/password_credential_spec.rb +1 -2
- data/spec/models/user_spec.rb +87 -27
- data/spec/requests/forgot_password_spec.rb +1 -1
- data/spec/support/factories.rb +10 -14
- data/spec/support/helpers/given.rb +8 -16
- data/spec/support/helpers/when.rb +0 -1
- metadata +42 -38
- data/lib/generators/hello/from_devise/USAGE +0 -8
- data/lib/generators/hello/from_devise/from_devise_generator.rb +0 -13
- data/lib/generators/hello/from_devise/templates/from_devise.migration.rb +0 -39
- data/spec/models/hello/sign_up_model_spec.rb +0 -64
data/spec/bdd/hello/management/manage_email_credentials/manage_email_credentials_emails_page_spec.rb
CHANGED
@@ -89,11 +89,11 @@ RSpec.bdd.uic "Emails Page" do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
When "I attempt to remove that email" do
|
92
|
-
|
92
|
+
click_nth_button("Remove", 0)
|
93
93
|
end
|
94
94
|
|
95
95
|
Then "I should see an alert message" do
|
96
|
-
expect_flash_alert "
|
96
|
+
expect_flash_alert "Email credentials is too short (minimum is 1 character)"
|
97
97
|
end
|
98
98
|
|
99
99
|
Then "and I should still see that email on the list" do
|
@@ -114,21 +114,21 @@ RSpec.bdd.uic "Emails Page" do
|
|
114
114
|
end
|
115
115
|
|
116
116
|
When "I attempt to remove that email" do
|
117
|
-
click_nth_button("Remove",
|
117
|
+
click_nth_button("Remove", 0)
|
118
118
|
end
|
119
119
|
|
120
120
|
Then "I should see a confirmation message" do
|
121
|
-
expect_flash_notice "
|
121
|
+
expect_flash_notice "foo@bar.com was successfully removed"
|
122
122
|
end
|
123
123
|
|
124
|
-
Then "and I should no longer see
|
124
|
+
Then "and I should no longer see the old email on the list" do
|
125
125
|
within all("table tr")[1] do
|
126
126
|
expect_not_to_see @new_email
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
130
|
Then "nor in the database" do
|
131
|
-
expect(EmailCredential.pluck(:email)).not_to include @
|
131
|
+
expect(EmailCredential.pluck(:email)).not_to include 'foo@bar.com'
|
132
132
|
end
|
133
133
|
end
|
134
134
|
end
|
@@ -221,7 +221,7 @@ RSpec.bdd.uic "Emails Page" do
|
|
221
221
|
|
222
222
|
def _when_visit_valid
|
223
223
|
When "I visit a valid token URL" do
|
224
|
-
@credential = create(:
|
224
|
+
@credential = create(:user).email_credentials.first
|
225
225
|
token = @credential.reset_verifying_token!
|
226
226
|
visit the_url(@credential.id, token)
|
227
227
|
end
|
data/spec/bdd/hello/management/manage_password_credentials/manage_password_reset_password_spec.rb
CHANGED
@@ -12,7 +12,7 @@ RSpec.bdd.uic "Reset Password" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def _I_visit_with_a_valid_token
|
15
|
-
@reset_token ||=
|
15
|
+
@reset_token ||= given_I_have_a_user_and_forgot_my_password
|
16
16
|
p = PasswordCredential.last
|
17
17
|
visit hello.reset_password_path(p.id, p.user_id, @reset_token)
|
18
18
|
end
|
@@ -24,7 +24,6 @@ RSpec.bdd.uic "Profile Page" do
|
|
24
24
|
scenario "Valid" do
|
25
25
|
When "I submit new valid values in the form" do
|
26
26
|
fill_in 'user_name', with: (@new_name = 'James Pinto')
|
27
|
-
fill_in 'user_city', with: (@new_city = 'Brasilia')
|
28
27
|
fill_in 'user_username', with: (@new_username = 'new_username')
|
29
28
|
click_button 'Update'
|
30
29
|
end
|
@@ -40,7 +39,6 @@ RSpec.bdd.uic "Profile Page" do
|
|
40
39
|
Then "and the new values should reflect on the database" do
|
41
40
|
user = User.last
|
42
41
|
expect(user.name).to eq(@new_name)
|
43
|
-
expect(user.city).to eq(@new_city)
|
44
42
|
expect(user.username).to eq(@new_username)
|
45
43
|
end
|
46
44
|
end
|
@@ -17,8 +17,7 @@ RSpec.bdd.capability "I can Create Users" do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
Given 'I visit New User Webmaster Page with Sudo Mode' do
|
20
|
-
visit '/'
|
21
|
-
click_link 'User List'
|
20
|
+
visit '/users'
|
22
21
|
click_link "View User List as a Webmaster"
|
23
22
|
fill_in 'user_password', with: '1234'
|
24
23
|
click_button 'Confirm'
|
@@ -28,7 +27,6 @@ RSpec.bdd.capability "I can Create Users" do
|
|
28
27
|
scenario "Success" do
|
29
28
|
|
30
29
|
When 'I submit a new user John' do
|
31
|
-
fill_in 'user_city', with: 'Brasilia'
|
32
30
|
fill_in 'user_name', with: 'john'
|
33
31
|
fill_in 'user_username', with: 'john'
|
34
32
|
fill_in 'user_email', with: 'john@test.com'
|
@@ -15,8 +15,7 @@ RSpec.bdd.capability "I can List Users" do
|
|
15
15
|
scenario 'I have access to the page' do
|
16
16
|
|
17
17
|
When 'I visit the users page' do
|
18
|
-
visit '/'
|
19
|
-
click_link 'User List'
|
18
|
+
visit '/users'
|
20
19
|
end
|
21
20
|
|
22
21
|
Then 'I should be on the users page' do
|
@@ -37,8 +36,7 @@ RSpec.bdd.capability "I can List Users" do
|
|
37
36
|
|
38
37
|
scenario "Via User List Page" do
|
39
38
|
When 'I visit james profile from the User List page' do
|
40
|
-
visit '/'
|
41
|
-
click_link 'User List'
|
39
|
+
visit '/users'
|
42
40
|
click_link 'james'
|
43
41
|
end
|
44
42
|
end # scenario
|
@@ -46,7 +46,7 @@ RSpec.bdd.capability "I can Sign Up With Email" do
|
|
46
46
|
api "API", type: :request do
|
47
47
|
scenario "Valid Parameters" do
|
48
48
|
When "I sign up with valid parameters" do
|
49
|
-
post "/hello/sign_up.json", sign_up: {email: "foo@bar.com", password: "foobar", name: "Foo Bar",
|
49
|
+
post "/hello/sign_up.json", sign_up: {email: "foo@bar.com", password: "foobar", name: "Foo Bar", username: "foobar"}
|
50
50
|
end
|
51
51
|
end # scenario
|
52
52
|
|
@@ -168,12 +168,12 @@ RSpec.bdd.capability "I can Sign Up With Email" do
|
|
168
168
|
api "API", type: :request do
|
169
169
|
scenario "Valid Parameters" do
|
170
170
|
When "I sign up with valid parameters" do
|
171
|
-
post "/hello/sign_up.json", sign_up: {email: "foo@bar.com", password: "foobar", name: "Foo Bar",
|
171
|
+
post "/hello/sign_up.json", sign_up: {email: "foo@bar.com", password: "foobar", name: "Foo Bar", username: "foobar"}
|
172
172
|
end
|
173
173
|
|
174
174
|
Then "I should see the access object" do
|
175
175
|
expect(json_response.keys).to match_array ["expires_at", "token", "user", "user_id"]
|
176
|
-
expect(json_response["user"].keys).to match_array ["id", "accesses_count", "
|
176
|
+
expect(json_response["user"].keys).to match_array ["id", "accesses_count", "created_at", "credentials_count", "locale", "name", "role", "time_zone", "updated_at", "username"]
|
177
177
|
end
|
178
178
|
|
179
179
|
Then "I should get a 201 response" do
|
@@ -204,7 +204,6 @@ RSpec.bdd.capability "I can Sign Up With Email" do
|
|
204
204
|
"email"=>["can't be blank"],
|
205
205
|
"password"=>["can't be blank"],
|
206
206
|
"name"=>["can't be blank"],
|
207
|
-
"city"=>["can't be blank"]
|
208
207
|
})
|
209
208
|
end
|
210
209
|
|
data/spec/bdd/hello/support.rb
CHANGED
@@ -5,7 +5,6 @@ def fill_in_registration_form
|
|
5
5
|
fill_in 'sign_up_email', with: 'foo@bar.com'
|
6
6
|
fill_in 'sign_up_username', with: 'foobar'
|
7
7
|
fill_in 'sign_up_password', with: '1234'
|
8
|
-
fill_in 'sign_up_city', with: 'OMG! I can customize Hello!'
|
9
8
|
end
|
10
9
|
end
|
11
10
|
|
@@ -26,21 +25,18 @@ end
|
|
26
25
|
|
27
26
|
def sign_in_as_an_onboarding
|
28
27
|
u = create(:user_onboarding)
|
29
|
-
create(:email_credential, user: u, email: "#{u.username}@example.com")
|
30
28
|
sign_in_with(u.username)
|
31
29
|
expect(current_user.role).to eq('onboarding')
|
32
30
|
end
|
33
31
|
|
34
32
|
def sign_in_as_a_user
|
35
33
|
u = create(:user_user)
|
36
|
-
create(:email_credential, user: u, email: "#{u.username}@example.com")
|
37
34
|
sign_in_with(u.username)
|
38
35
|
expect(current_user.role).to eq('user')
|
39
36
|
end
|
40
37
|
|
41
38
|
def sign_in_as_a_webmaster
|
42
39
|
u = create(:user_webmaster)
|
43
|
-
create(:email_credential, user: u, email: "#{u.username}@example.com")
|
44
40
|
sign_in_with(u.username)
|
45
41
|
expect(current_user.role).to eq('webmaster')
|
46
42
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
module Hello
|
4
4
|
describe Business::Registration::SignUp do
|
5
5
|
describe '.register(email:string, username:string, password:string)' do
|
6
|
-
let(:valid_attrs) { {
|
6
|
+
let(:valid_attrs) { { name: 'James Pinto', email: 'foo@bar.com', username: 'foobar', password: 'foobar' } }
|
7
7
|
|
8
8
|
describe 'original state' do
|
9
9
|
it('no errors') { expect(subject.errors.messages).to eq({}) }
|
@@ -13,7 +13,14 @@ module Hello
|
|
13
13
|
before do
|
14
14
|
subject.register({})
|
15
15
|
end
|
16
|
-
it('a lot of errors')
|
16
|
+
it('has a lot of errors') do
|
17
|
+
expect(subject.errors.messages).to eq({
|
18
|
+
email: ["can't be blank"],
|
19
|
+
name: ["can't be blank"],
|
20
|
+
password: ["can't be blank"],
|
21
|
+
username: ["can't be blank"]
|
22
|
+
})
|
23
|
+
end
|
17
24
|
end # describe
|
18
25
|
|
19
26
|
describe 'by field' do
|
@@ -252,6 +259,7 @@ module Hello
|
|
252
259
|
end # describe
|
253
260
|
end # describe config
|
254
261
|
end # describe password
|
262
|
+
|
255
263
|
end # describe by field
|
256
264
|
end # describe .register
|
257
265
|
end # describe Business::SignUp
|
@@ -46,7 +46,7 @@ module Hello::Management
|
|
46
46
|
json_body = JSON(response.body)
|
47
47
|
expect(response.status).to eq(200)
|
48
48
|
expect(response.status_message).to eq('OK')
|
49
|
-
expect(json_body.keys).to match_array(%w(id created_at updated_at name role username locale time_zone credentials_count accesses_count
|
49
|
+
expect(json_body.keys).to match_array(%w(id created_at updated_at name role username locale time_zone credentials_count accesses_count))
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'SESSION' do
|
@@ -56,7 +56,7 @@ module Hello::Management
|
|
56
56
|
json_body = JSON(response.body)
|
57
57
|
expect(response.status).to eq(200)
|
58
58
|
expect(response.status_message).to eq('OK')
|
59
|
-
expect(json_body.keys).to match_array(%w(id created_at updated_at name role username locale time_zone credentials_count accesses_count
|
59
|
+
expect(json_body.keys).to match_array(%w(id created_at updated_at name role username locale time_zone credentials_count accesses_count))
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'HEADER' do
|
@@ -66,7 +66,7 @@ module Hello::Management
|
|
66
66
|
json_body = JSON(response.body)
|
67
67
|
expect(response.status).to eq(200)
|
68
68
|
expect(response.status_message).to eq('OK')
|
69
|
-
expect(json_body.keys).to match_array(%w(id created_at updated_at name role username locale time_zone credentials_count accesses_count
|
69
|
+
expect(json_body.keys).to match_array(%w(id created_at updated_at name role username locale time_zone credentials_count accesses_count))
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EmailCredential do
|
4
|
+
|
5
|
+
describe 'ClassMethods' do
|
6
|
+
describe '#new' do
|
7
|
+
it "is not valid" do
|
8
|
+
expect(subject).to be_invalid
|
9
|
+
expect(subject.errors.messages).to eq({:email => ["can't be blank"]})
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".create" do
|
14
|
+
subject { EmailCredential.new(email: 'foo@example.com') }
|
15
|
+
|
16
|
+
describe "invalid examples" do
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "valid examples" do
|
21
|
+
describe "does save without a user" do
|
22
|
+
it "does save without a user" do
|
23
|
+
expect(subject.user).to eq(nil)
|
24
|
+
expect(subject.save).to eq(true)
|
25
|
+
expect(Credential.count).to eq(1)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "does save with an invalid user" do
|
29
|
+
subject.user = User.new
|
30
|
+
expect(subject.save).to eq(true)
|
31
|
+
expect(subject.errors.messages).to eq({})
|
32
|
+
expect(Credential.count).to eq(1)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "saves with a valid user" do
|
37
|
+
user = create(:user)
|
38
|
+
expect(Credential.count).to eq(2)
|
39
|
+
subject.user = user
|
40
|
+
expect(subject.save).to eq(true)
|
41
|
+
expect(Credential.count).to eq(3)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ".destroy!" do
|
48
|
+
describe "valid examples" do
|
49
|
+
describe "with 1 email and 1 password" do
|
50
|
+
subject { create(:user) }
|
51
|
+
|
52
|
+
it "works" do
|
53
|
+
subject # touch
|
54
|
+
expect(User.count).to eq(1)
|
55
|
+
expect(Credential.count).to eq(2)
|
56
|
+
subject.destroy!
|
57
|
+
expect(User.count).to eq(0)
|
58
|
+
expect(Credential.count).to eq(0)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "with 2 emails and 1 password" do
|
63
|
+
subject do
|
64
|
+
u = create(:user)
|
65
|
+
u.email_credentials.create!(email: 'bar@example.com')
|
66
|
+
u
|
67
|
+
end
|
68
|
+
|
69
|
+
it "works" do
|
70
|
+
subject # touch
|
71
|
+
expect(User.count).to eq(1)
|
72
|
+
expect(Credential.count).to eq(3)
|
73
|
+
subject.destroy!
|
74
|
+
expect(User.count).to eq(0)
|
75
|
+
expect(Credential.count).to eq(0)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PasswordCredential do
|
4
|
+
|
5
|
+
describe 'ClassMethods' do
|
6
|
+
describe '#new' do
|
7
|
+
it "is not valid" do
|
8
|
+
expect(subject).to be_invalid
|
9
|
+
expect(subject.errors.messages).to eq({:password => ["can't be blank"]})
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".create" do
|
14
|
+
subject { PasswordCredential.new(password: '1234') }
|
15
|
+
|
16
|
+
describe "valid examples" do
|
17
|
+
describe "does save without a user" do
|
18
|
+
it "does save without a user" do
|
19
|
+
expect(subject.user).to eq(nil)
|
20
|
+
expect(subject.save).to eq(true)
|
21
|
+
expect(Credential.count).to eq(1)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "does save with an invalid user" do
|
25
|
+
subject.user = User.new
|
26
|
+
expect(subject.save).to eq(true)
|
27
|
+
expect(subject.errors.messages).to eq({})
|
28
|
+
expect(Credential.count).to eq(1)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "saves with a valid user" do
|
33
|
+
user = create(:user)
|
34
|
+
expect(Credential.count).to eq(2)
|
35
|
+
subject.user = user
|
36
|
+
expect(subject.save).to eq(true)
|
37
|
+
expect(Credential.count).to eq(3)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe ".destroy!" do
|
44
|
+
describe "valid examples" do
|
45
|
+
describe "with 1 email and 1 password" do
|
46
|
+
subject { create(:user) }
|
47
|
+
|
48
|
+
it "works" do
|
49
|
+
subject # touch
|
50
|
+
expect(User.count).to eq(1)
|
51
|
+
expect(Credential.count).to eq(2)
|
52
|
+
subject.destroy!
|
53
|
+
expect(User.count).to eq(0)
|
54
|
+
expect(Credential.count).to eq(0)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe User do
|
4
|
+
|
5
|
+
describe 'ClassMethods' do
|
6
|
+
describe '#new' do
|
7
|
+
it "is not valid" do
|
8
|
+
expect(subject).to be_invalid
|
9
|
+
expect(subject.errors.messages).to eq({
|
10
|
+
:locale=>["can't be blank", "is not included in the list"],
|
11
|
+
:time_zone=>["can't be blank", "is not included in the list"],
|
12
|
+
:name=>["can't be blank"],
|
13
|
+
:email_credentials=>["is too short (minimum is 1 character)"],
|
14
|
+
:username => ["can't be blank"],
|
15
|
+
:email => ["can't be blank"],
|
16
|
+
:password => ["can't be blank"],
|
17
|
+
})
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe ".create" do
|
22
|
+
subject do
|
23
|
+
build(:user, :without_credentials)
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "invalid examples" do
|
27
|
+
describe "number of emails" do
|
28
|
+
it "does not save with 0 emails and 0 passwords" do
|
29
|
+
expect(subject.save).to eq(false)
|
30
|
+
expect(User.count).to eq(0)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "does not save with 0 email and 1 password" do
|
34
|
+
subject.password_credentials.build(password: '1234')
|
35
|
+
subject.save
|
36
|
+
expect(subject.errors.messages).to eq({:email => ["can't be blank"], :email_credentials=>["is too short (minimum is 1 character)"]})
|
37
|
+
expect(User.count).to eq(0)
|
38
|
+
expect(Credential.count).to eq(0)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "number of passwords" do
|
43
|
+
it "does not save with 1 email and 0 passwords" do
|
44
|
+
subject.email_credentials.build(email: 'foo@example.com')
|
45
|
+
subject.save
|
46
|
+
expect(subject.errors.messages).to eq(:password => ["can't be blank"])
|
47
|
+
expect(User.count).to eq(0)
|
48
|
+
expect(Credential.count).to eq(0)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "does not save with 1 email and 2 passwords" do
|
52
|
+
subject.email_credentials.build(email: 'foo@example.com')
|
53
|
+
subject.password_credentials.build(password: '1234')
|
54
|
+
subject.password_credentials.build(password: '5678')
|
55
|
+
subject.save
|
56
|
+
expect(subject.errors.messages).to eq(:password_credentials => ["is the wrong length (should be 1 character)"])
|
57
|
+
expect(User.count).to eq(0)
|
58
|
+
expect(Credential.count).to eq(0)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "valid examples" do
|
64
|
+
it "save with 1 email and 1 passwords" do
|
65
|
+
subject.email_credentials.build(email: 'foo@example.com')
|
66
|
+
subject.password_credentials.build(password: '1234')
|
67
|
+
subject.save
|
68
|
+
expect(subject.errors.messages).to eq({})
|
69
|
+
expect(User.count).to eq(1)
|
70
|
+
expect(Credential.count).to eq(2)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "save with 2 email and 1 passwords" do
|
74
|
+
subject.email_credentials.build(email: 'foo@example.com')
|
75
|
+
subject.email_credentials.build(email: 'bar@example.com')
|
76
|
+
subject.password_credentials.build(password: '1234')
|
77
|
+
subject.save
|
78
|
+
expect(subject.errors.messages).to eq({})
|
79
|
+
expect(User.count).to eq(1)
|
80
|
+
expect(Credential.count).to eq(3)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe ".destroy!" do
|
86
|
+
describe "valid examples" do
|
87
|
+
describe "with 1 email and 1 password" do
|
88
|
+
subject do
|
89
|
+
u = build(:user)
|
90
|
+
u.save!
|
91
|
+
u
|
92
|
+
end
|
93
|
+
|
94
|
+
it "works" do
|
95
|
+
subject # touch
|
96
|
+
expect(User.count).to eq(1)
|
97
|
+
expect(Credential.count).to eq(2)
|
98
|
+
subject.destroy!
|
99
|
+
expect(User.count).to eq(0)
|
100
|
+
expect(Credential.count).to eq(0)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
describe "with 2 emails and 1 password" do
|
104
|
+
subject do
|
105
|
+
u = build(:user)
|
106
|
+
u.email_credentials.build(email: 'bar@example.com')
|
107
|
+
u.save!
|
108
|
+
u
|
109
|
+
end
|
110
|
+
|
111
|
+
it "works" do
|
112
|
+
subject # touch
|
113
|
+
expect(User.count).to eq(1)
|
114
|
+
expect(Credential.count).to eq(3)
|
115
|
+
subject.destroy!
|
116
|
+
expect(User.count).to eq(0)
|
117
|
+
expect(Credential.count).to eq(0)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|