summer_residents 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/app/assets/javascripts/summer_residents/families.js.coffee +4 -3
- data/app/assets/stylesheets/summer_residents/index.css.scss +0 -1
- data/app/assets/stylesheets/{scaffold.css.scss → summer_residents/scaffold.css.scss} +0 -0
- data/app/controllers/summer_residents/families_controller.rb +62 -11
- data/app/controllers/summer_residents/residents_controller.rb +61 -15
- data/app/helpers/summer_residents/families_helper.rb +5 -2
- data/app/models/summer_residents/family.rb +6 -6
- data/app/models/summer_residents/resident.rb +5 -4
- data/app/views/summer_residents/families/_form.html.erb +3 -1
- data/app/views/summer_residents/families/_show.html.erb +2 -1
- data/app/views/summer_residents/residents/show.js.erb +2 -0
- data/config/routes.rb +4 -1
- data/lib/summer_residents/version.rb +1 -1
- data/test/dummy/app/assets/stylesheets/application.css +1 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +15331 -609
- data/test/dummy/log/test.log +92122 -102930
- data/test/dummy/tmp/cache/assets/C0C/340/sprockets%2F3e10b26701406087f43a575c352670a2 +0 -0
- data/test/dummy/tmp/cache/assets/C17/E40/sprockets%2F118a412056292d7411d8193503fb49a9 +0 -0
- data/test/dummy/tmp/cache/assets/C48/A90/sprockets%2F44f28067e46c1394d651c1e008d21444 +0 -0
- data/test/dummy/tmp/cache/assets/C4D/E30/sprockets%2Fde7042330d91b983460cb3660515c696 +0 -0
- data/test/dummy/tmp/cache/assets/C74/3C0/sprockets%2Fe0ef69401362609001ec8c701f19424d +0 -0
- data/test/dummy/tmp/cache/assets/CB6/820/sprockets%2Fd61769c2ee29a86730bc3363b4177e44 +0 -0
- data/test/dummy/tmp/cache/assets/CBC/C50/sprockets%2Fec81d55f497370b307d6134e078c6e67 +0 -0
- data/test/dummy/tmp/cache/assets/CC9/4F0/sprockets%2F14fe707820d56ba2b50031e146ec453b +0 -0
- data/test/dummy/tmp/cache/assets/CCD/D10/sprockets%2F7271e2d6e6c01212bbb52a44f156634f +0 -0
- data/test/dummy/tmp/cache/assets/CCE/5B0/sprockets%2F84ce8cb866785417ed6d445387b68d16 +0 -0
- data/test/dummy/tmp/cache/assets/CD6/C50/sprockets%2Fd30f21629ea47cf66530fa0e347272b4 +0 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/CDB/6C0/sprockets%2F40030d8625f95c8a0596f6c60a6bfa06 +0 -0
- data/test/dummy/tmp/cache/assets/CDD/CE0/sprockets%2F7c8a52da3818bb4518674c6b42e33e06 +0 -0
- data/test/dummy/tmp/cache/assets/CDF/150/sprockets%2Fc0a58c8ae34b270594349b0293af7c57 +0 -0
- data/test/dummy/tmp/cache/assets/CE3/830/sprockets%2Fec587d17374b217777d1eb62bf3b6333 +0 -0
- data/test/dummy/tmp/cache/assets/CE5/360/sprockets%2Fb39bd00a34edf45b61c779a743262889 +0 -0
- data/test/dummy/tmp/cache/assets/CF0/AB0/sprockets%2Fa465902921141ac00053ded0ad6c93ac +0 -0
- data/test/dummy/tmp/cache/assets/CFD/E20/sprockets%2F436e8f8981b54d9d20467249d7a7fdf6 +0 -0
- data/test/dummy/tmp/cache/assets/D03/B50/sprockets%2F3a2ae11c363a7701239a2c67ea95f6c6 +0 -0
- data/test/dummy/tmp/cache/assets/{D6C/F70/sprockets%2F46c2084fcf2657dbdd233ee2c9e4b225 → D0F/890/sprockets%2Fee4fd02927226891c4d3acc680781b5a} +0 -0
- data/test/dummy/tmp/cache/assets/D12/B70/sprockets%2F9759811171683daeb16c1fb7eb0e35f4 +0 -0
- data/test/dummy/tmp/cache/assets/D15/770/sprockets%2Fa5c394e67a188bffc608ed34a4051576 +0 -0
- data/test/dummy/tmp/cache/assets/D19/0A0/sprockets%2F1e35fcc2baf7216d7b9c9984c6533625 +0 -0
- data/test/dummy/tmp/cache/assets/D1E/580/sprockets%2F5f965913df7a03e307dfd9326f9b06b7 +0 -0
- data/test/dummy/tmp/cache/assets/D20/A20/sprockets%2Ff436736e76a3ca772d2b5fddb8892870 +0 -0
- data/test/dummy/tmp/cache/assets/D24/DF0/sprockets%2F205e10fc11b2c5ed047b48e7d13ca262 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D36/370/sprockets%2F7178352dd338e132ca059a481fe2bace +0 -0
- data/test/dummy/tmp/cache/assets/D37/B70/sprockets%2Ff0048dadb571a867f23a5dfb3c326094 +0 -0
- data/test/dummy/tmp/cache/assets/D3D/D00/sprockets%2F7027f25337293c380e48d2bdbedacc93 +0 -0
- data/test/dummy/tmp/cache/assets/D3D/D70/sprockets%2F45943af2b094ee90fce73291ba95bc30 +0 -0
- data/test/dummy/tmp/cache/assets/D43/910/sprockets%2Fc9afda605b36879345b790d22cdf07b5 +0 -0
- data/test/dummy/tmp/cache/assets/D48/0A0/sprockets%2F9c2b47f6cf5a76ea751fc43e8205534f +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D4F/4A0/sprockets%2F4fcb3c5126d2489feb99578dfa0c8507 +0 -0
- data/test/dummy/tmp/cache/assets/D54/A00/sprockets%2F8e83a77287c6ca6edbb1b48d769e3276 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/850/sprockets%2F4015515d4be88de02aa43ff1b0abb594 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/B40/sprockets%2F3aa0d717f2a3eb20c0a583c8c6db6355 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/D69/960/sprockets%2F3faea27f81a699241e2d2c3184ceab19 +0 -0
- data/test/dummy/tmp/cache/assets/D6F/780/sprockets%2F6e2cc1c3eae74a65125d63f6f34a28e9 +0 -0
- data/test/dummy/tmp/cache/assets/{D76/9D0/sprockets%2F8d86f62b904d9184acace3e5a9be4181 → D8C/A90/sprockets%2F8fca9a9d923b82d7d768beb3588428ee} +0 -0
- data/test/dummy/tmp/cache/assets/D90/520/sprockets%2Fda676dd9c68be1ffb5e836b487384f96 +0 -0
- data/test/dummy/tmp/cache/assets/D95/100/sprockets%2F3ee88a516d94a42c0c21beea2c1c3e97 +0 -0
- data/test/dummy/tmp/cache/assets/D96/4B0/sprockets%2Fb64ec923e1e43a43b8fa9064cc80cdb3 +0 -0
- data/test/dummy/tmp/cache/assets/D97/CB0/sprockets%2Ff95b6eaa26f994a010ed654a0f51fcc1 +0 -0
- data/test/dummy/tmp/cache/assets/D9E/C90/sprockets%2F8a1c5d9244d5839eaacd39ac9a64e13a +0 -0
- data/test/dummy/tmp/cache/assets/D9F/570/sprockets%2Feb341e70cde39cf6ea39db55533b8a45 +0 -0
- data/test/dummy/tmp/cache/assets/DA3/BD0/sprockets%2Ff2d6642531ee641d87cdd438fdbea8d0 +0 -0
- data/test/dummy/tmp/cache/assets/DA3/E10/sprockets%2F8d5bba0fc4cb582381e2ef2ee753678b +0 -0
- data/test/dummy/tmp/cache/assets/DA5/520/sprockets%2F10b128ecc49960bb1c887ccdaf99ec91 +0 -0
- data/test/dummy/tmp/cache/assets/DAF/3B0/sprockets%2F3ce75fe60cc183f9f27fc86cb6944bf0 +0 -0
- data/test/dummy/tmp/cache/assets/DAF/790/sprockets%2F7ffb357c2a7edeff87e544e239e24f03 +0 -0
- data/test/dummy/tmp/cache/assets/DB0/160/sprockets%2Fc4b981f6cd852a8e73b3a48e576ed6eb +0 -0
- data/test/dummy/tmp/cache/assets/DBC/260/sprockets%2Fcb31a6c2d0a1f9f6ab00a66587c35bcf +0 -0
- data/test/dummy/tmp/cache/assets/DBD/EF0/sprockets%2Fa2db4bbebe3c68a1b5123b305e4979da +0 -0
- data/test/dummy/tmp/cache/assets/DBF/300/sprockets%2F170ac57c3fd70b4711fd602fcbe19aec +0 -0
- data/test/dummy/tmp/cache/assets/DD0/2F0/sprockets%2F2cb2d409afda49a014f5bfef65f75c67 +0 -0
- data/test/dummy/tmp/cache/assets/DD1/3F0/sprockets%2F42293a1a5f441d9c2bedfcbf787cab79 +0 -0
- data/test/dummy/tmp/cache/assets/DD2/320/sprockets%2F2cf889cdaa93cb54f873b751e3aed1e0 +0 -0
- data/test/dummy/tmp/cache/assets/DD9/500/sprockets%2F847459f486a4caae1b66d4f4a6dbfc4f +0 -0
- data/test/dummy/tmp/cache/assets/DDB/050/sprockets%2Fc88e4d0ba2ecc58ff1f67f67f21d79a1 +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/DDC/630/sprockets%2Fd23e663fbbe6dfdb81e7a5d86d87b507 +0 -0
- data/test/dummy/tmp/cache/assets/DEF/A00/sprockets%2F9f7f8ceff43fe6de4364055deae3f995 +0 -0
- data/test/dummy/tmp/cache/assets/DF6/A90/sprockets%2Fac2c35cc5c863628183bee0dd1ee5ceb +0 -0
- data/test/dummy/tmp/cache/assets/DF6/DE0/sprockets%2Fd4eb25c8857c4c413cacaf6e7a0ccd26 +0 -0
- data/test/dummy/tmp/cache/assets/DFE/900/sprockets%2Fc2179e85f80bf4aa7ed6fcb7f0a04f0e +0 -0
- data/test/dummy/tmp/cache/assets/{D99/740/sprockets%2F4ad8f22ee13aa24cfe3ea674d87041f6 → E00/030/sprockets%2F0acb71cf6e4786fbb0ad9c568c3e59aa} +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/E16/2A0/sprockets%2F4a328bf0e2d5dc70bdbaa60d575b0dfa +0 -0
- data/test/dummy/tmp/cache/assets/E1A/230/sprockets%2Fcbcc10a256ea10ededbb2e49ef08455b +0 -0
- data/test/dummy/tmp/cache/assets/E37/D90/sprockets%2Fedfb5d28b5ae57d74522cc7dd9d7dbd3 +0 -0
- data/test/dummy/tmp/cache/assets/E5A/620/sprockets%2Fc5bcf8acda5da24fd6af1082f46a9de5 +0 -0
- data/test/functional/summer_residents/authentication_test.rb +1 -1
- data/test/functional/summer_residents/families_controller_test.rb +174 -16
- data/test/functional/summer_residents/residents_controller_test.rb +67 -6
- data/test/unit/summer_residents/family_test.rb +8 -4
- metadata +14 -30
- data/test/dummy/tmp/pids/server.pid +0 -1
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -18,6 +18,24 @@ module SummerResidents
|
|
18
18
|
assert_response :success
|
19
19
|
end
|
20
20
|
|
21
|
+
test "should get add_user_info" do
|
22
|
+
@family.destroy
|
23
|
+
get :add_user_info
|
24
|
+
assert_response :success
|
25
|
+
family = assigns(:family)
|
26
|
+
assert_template :new
|
27
|
+
assert_nil family.mother
|
28
|
+
assert family.father
|
29
|
+
assert_nil family.father.id
|
30
|
+
assert_equal users(:joe_user), family.father.user
|
31
|
+
assert_select 'input#adding_user_info[value="1"]', 1
|
32
|
+
end
|
33
|
+
|
34
|
+
test "add_user_info should redirect to show if family already exists" do
|
35
|
+
get :add_user_info
|
36
|
+
assert_redirected_to family_path(@family.id)
|
37
|
+
end
|
38
|
+
|
21
39
|
test "should show family" do
|
22
40
|
get :show, id: @family
|
23
41
|
assert_response :success
|
@@ -46,6 +64,97 @@ module SummerResidents
|
|
46
64
|
@mother_hash = { first_name: @mother.first_name, last_name: @mother.last_name, email: @mother.email }
|
47
65
|
end
|
48
66
|
|
67
|
+
EMAIL_LINE_INTRO = "Before you can log into your account, you must set your password by following this link: http://#{Rails.application.config.action_mailer.default_url_options[:host]}/reset_password\\?uuid="
|
68
|
+
|
69
|
+
def verify_expected_email parent, email
|
70
|
+
assert_equal [parent.email], email.to
|
71
|
+
assert_email_contains /^#{EMAIL_LINE_INTRO}#{User.find_by_email(parent.email).password_recovery.reset_link}\.$/, email
|
72
|
+
end
|
73
|
+
|
74
|
+
def given_a_user_with_no_family_info
|
75
|
+
@user = users(:jose_user)
|
76
|
+
@controller.log_in_as @user
|
77
|
+
end
|
78
|
+
|
79
|
+
def when_creating_family_from_user adding_user_info=true
|
80
|
+
args = { mother: @mother_hash, father: { first_name: @father.first_name, last_name: @father.last_name, email: @user.email } }
|
81
|
+
args[:adding_user_info] = "1" if adding_user_info
|
82
|
+
post :create, args
|
83
|
+
end
|
84
|
+
|
85
|
+
def when_adding_family_info
|
86
|
+
assert_difference('Family.count') do
|
87
|
+
assert_difference('User.count') do
|
88
|
+
when_creating_family_from_user
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def expect_the_correct_family
|
94
|
+
@fam = assigns(:family)
|
95
|
+
assert_equal 0, @fam.errors.count, @fam.errors.messages.inspect
|
96
|
+
father = @fam.father
|
97
|
+
assert father
|
98
|
+
assert father.user
|
99
|
+
mother = @fam.mother
|
100
|
+
assert mother
|
101
|
+
assert mother.user
|
102
|
+
[:first_name, :last_name].each { |attr|
|
103
|
+
assert_equal @father.__send__(attr), father.__send__(attr)
|
104
|
+
assert_equal @mother.__send__(attr), mother.__send__(attr)
|
105
|
+
}
|
106
|
+
assert_equal @mother.email, mother.email
|
107
|
+
assert_equal @user.email, father.email
|
108
|
+
end
|
109
|
+
|
110
|
+
def should_fail_to_create_family_from_user adding_user_info=true
|
111
|
+
assert_no_difference('Family.count') do
|
112
|
+
assert_no_difference('Resident.count') do
|
113
|
+
assert_no_difference('User.count') do
|
114
|
+
when_creating_family_from_user adding_user_info
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
assert_redirected_to @controller.login_path
|
120
|
+
end
|
121
|
+
|
122
|
+
test "should create family from existing user when family info was added and resident info already exists" do
|
123
|
+
given_a_user_with_no_family_info
|
124
|
+
assert_difference('Resident.count') do
|
125
|
+
expect_each_new_user_to_receive_email 1 do
|
126
|
+
when_adding_family_info
|
127
|
+
end
|
128
|
+
end
|
129
|
+
expect_the_correct_family
|
130
|
+
assert_redirected_to family_path(@fam.id)
|
131
|
+
verify_expected_email @mother, @email
|
132
|
+
end
|
133
|
+
|
134
|
+
test "should create family from existing user when family info was added and only login info exists" do
|
135
|
+
given_a_user_with_no_family_info
|
136
|
+
@user.resident.destroy
|
137
|
+
assert_difference('Resident.count', 2) do
|
138
|
+
expect_each_new_user_to_receive_email 1 do
|
139
|
+
when_adding_family_info
|
140
|
+
end
|
141
|
+
end
|
142
|
+
expect_the_correct_family
|
143
|
+
assert_redirected_to family_path(@fam.id)
|
144
|
+
verify_expected_email @mother, @email
|
145
|
+
end
|
146
|
+
|
147
|
+
test "should not allow creating family from existing user unless family info was added" do
|
148
|
+
given_a_user_with_no_family_info
|
149
|
+
should_fail_to_create_family_from_user false
|
150
|
+
end
|
151
|
+
|
152
|
+
test "should not allow creating family from existing user if not current_user" do
|
153
|
+
given_a_user_with_no_family_info
|
154
|
+
@controller.log_in_as users(:dad_user)
|
155
|
+
should_fail_to_create_family_from_user
|
156
|
+
end
|
157
|
+
|
49
158
|
test "should create family" do
|
50
159
|
assert_difference('Family.count') do
|
51
160
|
assert_difference('Resident.count', 2) do
|
@@ -58,6 +167,32 @@ module SummerResidents
|
|
58
167
|
assert_redirected_to families_path
|
59
168
|
end
|
60
169
|
|
170
|
+
def expect_each_new_user_to_receive_email count, &block
|
171
|
+
assert_difference('ActionMailer::Base.deliveries.size', count) do
|
172
|
+
yield
|
173
|
+
end
|
174
|
+
if 2 == count
|
175
|
+
@mother_email, @father_email = ActionMailer::Base.deliveries.pop(2)
|
176
|
+
@father_email, @mother_email = [@mother_email, @father_email] if ([@father.email] == @mother_email.to)
|
177
|
+
elsif 1 == count
|
178
|
+
@email = ActionMailer::Base.deliveries.pop
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def assert_email_contains regex, email
|
183
|
+
assert email.body =~ regex, "Mail body expected to match: #{regex}\nActual: <<<<<\n#{email.body}\n>>>>>"
|
184
|
+
end
|
185
|
+
|
186
|
+
test "when creating family, each parent shuld receive a password initializatin email" do
|
187
|
+
assert_difference('PasswordRecovery.count', 2) do
|
188
|
+
expect_each_new_user_to_receive_email 2 do
|
189
|
+
post :create, father: @father_hash, mother: @mother_hash
|
190
|
+
end
|
191
|
+
end
|
192
|
+
verify_expected_email @father, @father_email
|
193
|
+
verify_expected_email @mother, @mother_email
|
194
|
+
end
|
195
|
+
|
61
196
|
def should_fail_to_create_family_from parents
|
62
197
|
@family.destroy
|
63
198
|
assert_no_difference('Family.count') do
|
@@ -92,10 +227,7 @@ module SummerResidents
|
|
92
227
|
|
93
228
|
test "father's email is required" do
|
94
229
|
should_fail_to_create_family_from mother: @mother_hash, father: { first_name: @father.first_name, last_name: @father.last_name }
|
95
|
-
|
96
|
-
there_should_be_errors_on_column :"father-email", 2
|
97
|
-
should_fail_validation_because :"father-email", "can't be blank"
|
98
|
-
should_fail_validation_because :"father-email", "does not appear to be valid"
|
230
|
+
should_fail_validation_for_one_reason :"father-email", "can't be blank"
|
99
231
|
end
|
100
232
|
|
101
233
|
test "father's first name cannot be blank" do
|
@@ -110,10 +242,7 @@ module SummerResidents
|
|
110
242
|
|
111
243
|
test "father's email cannot be blank" do
|
112
244
|
should_fail_to_create_family_from mother: @mother_hash, father: { first_name: @father.first_name, last_name: @father.last_name, email: "" }
|
113
|
-
|
114
|
-
there_should_be_errors_on_column :"father-email", 2
|
115
|
-
should_fail_validation_because :"father-email", "can't be blank"
|
116
|
-
should_fail_validation_because :"father-email", "does not appear to be valid"
|
245
|
+
should_fail_validation_for_one_reason :"father-email", "can't be blank"
|
117
246
|
end
|
118
247
|
|
119
248
|
test "father's email must be valid" do
|
@@ -133,10 +262,7 @@ module SummerResidents
|
|
133
262
|
|
134
263
|
test "mother's email is required" do
|
135
264
|
should_fail_to_create_family_from father: @father_hash, mother: { first_name: @mother.first_name, last_name: @mother.last_name }
|
136
|
-
|
137
|
-
there_should_be_errors_on_column :"mother-email", 2
|
138
|
-
should_fail_validation_because :"mother-email", "can't be blank"
|
139
|
-
should_fail_validation_because :"mother-email", "does not appear to be valid"
|
265
|
+
should_fail_validation_for_one_reason :"mother-email", "can't be blank"
|
140
266
|
end
|
141
267
|
|
142
268
|
test "mother's first name cannot be blank" do
|
@@ -151,15 +277,47 @@ module SummerResidents
|
|
151
277
|
|
152
278
|
test "mother's email cannot be blank" do
|
153
279
|
should_fail_to_create_family_from father: @father_hash, mother: { first_name: @mother.first_name, last_name: @mother.last_name, email: "" }
|
154
|
-
|
155
|
-
there_should_be_errors_on_column :"mother-email", 2
|
156
|
-
should_fail_validation_because :"mother-email", "can't be blank"
|
157
|
-
should_fail_validation_because :"mother-email", "does not appear to be valid"
|
280
|
+
should_fail_validation_for_one_reason :"mother-email", "can't be blank"
|
158
281
|
end
|
159
282
|
|
160
283
|
test "mother's email must be valid" do
|
161
284
|
should_fail_to_create_family_from father: @father_hash, mother: { first_name: @mother.first_name, last_name: @mother.last_name, email: "123" }
|
162
285
|
should_fail_validation_for_one_reason :"mother-email", "does not appear to be valid"
|
163
286
|
end
|
287
|
+
|
288
|
+
def expect_only_one_resident_was_created
|
289
|
+
@fam = assigns(:family)
|
290
|
+
assert_equal 0, @fam.errors.count, @fam.errors.messages.inspect
|
291
|
+
assert @fam.id
|
292
|
+
father = @fam.father
|
293
|
+
assert father
|
294
|
+
assert father.id
|
295
|
+
assert father.user
|
296
|
+
mother = @fam.mother
|
297
|
+
assert_nil mother
|
298
|
+
[:first_name, :last_name].each { |attr|
|
299
|
+
assert_equal @father.__send__(attr), father.__send__(attr)
|
300
|
+
}
|
301
|
+
assert_equal @user.email, father.email
|
302
|
+
end
|
303
|
+
|
304
|
+
test "should create resident if user already exists and only one resident specified" do
|
305
|
+
given_a_user_with_no_family_info
|
306
|
+
@user.resident.destroy
|
307
|
+
@mother_hash.each { |k,v|
|
308
|
+
@mother_hash[k] = ""
|
309
|
+
}
|
310
|
+
assert_difference('Family.count') do
|
311
|
+
assert_difference('Resident.count') do
|
312
|
+
assert_no_difference('User.count') do
|
313
|
+
assert_no_difference('ActionMailer::Base.deliveries.size') do
|
314
|
+
when_creating_family_from_user
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
expect_only_one_resident_was_created
|
320
|
+
assert_redirected_to family_path(@fam.id)
|
321
|
+
end
|
164
322
|
end
|
165
323
|
end
|
@@ -25,7 +25,70 @@ module SummerResidents
|
|
25
25
|
assert_response :success
|
26
26
|
assert_template :edit
|
27
27
|
end
|
28
|
+
|
29
|
+
test "edit should render show template when cancelling" do
|
30
|
+
get :edit, :id => @new_resident, format: :js, cancel: "1"
|
31
|
+
assert_response :success
|
32
|
+
assert_template :show
|
33
|
+
end
|
34
|
+
|
35
|
+
def log_in_as_single_parent
|
36
|
+
users(:joe_user).destroy
|
37
|
+
@user = users(:hadassah_user)
|
38
|
+
@user.admin = false
|
39
|
+
@user.save!
|
40
|
+
@controller.log_in_as @user
|
41
|
+
end
|
42
|
+
|
43
|
+
def when_creating_resident options
|
44
|
+
post :create, options.merge({format: :js })
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_resident options
|
48
|
+
assert_difference('Resident.count') do
|
49
|
+
assert_difference('User.count') do
|
50
|
+
assert_difference('ActionMailer::Base.deliveries.size') do
|
51
|
+
when_creating_resident options
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
test "should get new" do
|
58
|
+
log_in_as_single_parent
|
59
|
+
get :new, format: :js, type: :Mother
|
60
|
+
assert_response :success
|
61
|
+
assert_template :edit
|
62
|
+
end
|
63
|
+
|
64
|
+
test "new should render show template when cancelling" do
|
65
|
+
log_in_as_single_parent
|
66
|
+
get :new, format: :js, cancel: "2", type: :Mother
|
67
|
+
assert_response :success
|
68
|
+
assert_template :show
|
69
|
+
end
|
28
70
|
|
71
|
+
test "should create resident as spouse of current_user" do
|
72
|
+
log_in_as_single_parent
|
73
|
+
create_resident :cell => @resident.cell, :first_name => @resident.first_name, :last_name => @resident.last_name, :email => @resident.email, :type => :Father
|
74
|
+
assert_response :success
|
75
|
+
assert_template :show
|
76
|
+
resident = assigns(:resident)
|
77
|
+
[:first_name, :last_name, :cell, :email].each { |e|
|
78
|
+
assert_equal @resident.__send__(e), resident.__send__(e)
|
79
|
+
}
|
80
|
+
assert resident.family.mother == @user.resident
|
81
|
+
end
|
82
|
+
|
83
|
+
test "create should fail and render errors if missing first_name" do
|
84
|
+
log_in_as_single_parent
|
85
|
+
when_creating_resident :cell => @resident.cell, :first_name => "", :last_name => @resident.last_name, :email => @resident.email, :type => :Father
|
86
|
+
expect_resident_was_not_updated
|
87
|
+
there_should_be_errors 1
|
88
|
+
there_should_be_errors_on_column :"first_name", 1
|
89
|
+
should_fail_validation_because :"first_name", "can't be blank"
|
90
|
+
end
|
91
|
+
|
29
92
|
test "should update resident" do
|
30
93
|
update_resident :cell => @resident.cell, :first_name => @resident.first_name, :last_name => @resident.last_name, :email => @resident.email, :type => :Father
|
31
94
|
assert_response :success
|
@@ -56,9 +119,8 @@ module SummerResidents
|
|
56
119
|
test "should not update resident if missing email" do
|
57
120
|
update_resident :cell => @resident.cell, :first_name => @resident.first_name, :last_name => @resident.last_name, :type => :Father
|
58
121
|
expect_resident_was_not_updated
|
59
|
-
there_should_be_errors
|
60
|
-
there_should_be_errors_on_column :email,
|
61
|
-
should_fail_validation_because :email, "does not appear to be valid"
|
122
|
+
there_should_be_errors 1
|
123
|
+
there_should_be_errors_on_column :email, 1
|
62
124
|
should_fail_validation_because :email, "can't be blank"
|
63
125
|
end
|
64
126
|
|
@@ -81,9 +143,8 @@ module SummerResidents
|
|
81
143
|
test "should not update resident if email is blank" do
|
82
144
|
update_resident :cell => @resident.cell, :first_name => @resident.first_name, :last_name => @resident.last_name, :email => "", :type => :Father
|
83
145
|
expect_resident_was_not_updated
|
84
|
-
there_should_be_errors
|
85
|
-
there_should_be_errors_on_column :email,
|
86
|
-
should_fail_validation_because :email, "does not appear to be valid"
|
146
|
+
there_should_be_errors 1
|
147
|
+
there_should_be_errors_on_column :email, 1
|
87
148
|
should_fail_validation_because :email, "can't be blank"
|
88
149
|
end
|
89
150
|
|