active_type 0.4.4 → 0.4.5
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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -1
- data/README.md +4 -4
- data/gemfiles/Gemfile.3.2.mysql2 +1 -1
- data/gemfiles/Gemfile.3.2.mysql2.lock +16 -11
- data/gemfiles/Gemfile.3.2.sqlite3 +1 -1
- data/gemfiles/Gemfile.3.2.sqlite3.lock +16 -11
- data/gemfiles/Gemfile.4.0.sqlite3 +1 -1
- data/gemfiles/Gemfile.4.0.sqlite3.lock +16 -11
- data/gemfiles/Gemfile.4.1.sqlite3 +1 -1
- data/gemfiles/Gemfile.4.1.sqlite3.lock +16 -11
- data/gemfiles/Gemfile.4.2.1.mysql2 +1 -1
- data/gemfiles/Gemfile.4.2.1.mysql2.lock +16 -11
- data/gemfiles/Gemfile.4.2.1.pg +1 -1
- data/gemfiles/Gemfile.4.2.1.pg.lock +16 -11
- data/gemfiles/Gemfile.4.2.1.sqlite3 +1 -1
- data/gemfiles/Gemfile.4.2.1.sqlite3.lock +16 -11
- data/lib/active_type/version.rb +1 -1
- data/lib/active_type/virtual_attributes.rb +1 -1
- data/spec/active_type/extended_record/single_table_inheritance_spec.rb +6 -6
- data/spec/active_type/extended_record_spec.rb +32 -26
- data/spec/active_type/nested_attributes_spec.rb +51 -51
- data/spec/active_type/object_spec.rb +44 -33
- data/spec/active_type/record_spec.rb +15 -11
- data/spec/active_type/util_spec.rb +25 -25
- data/spec/integration/holidays_spec.rb +13 -13
- data/spec/integration/shape_spec.rb +12 -14
- data/spec/integration/sign_in_spec.rb +12 -12
- data/spec/integration/sign_up_spec.rb +9 -9
- data/spec/shared_examples/accessors.rb +3 -3
- data/spec/shared_examples/belongs_to.rb +2 -2
- data/spec/shared_examples/coercible_columns.rb +27 -27
- data/spec/shared_examples/constructor.rb +2 -2
- data/spec/shared_examples/defaults.rb +10 -10
- data/spec/shared_examples/dirty_tracking.rb +4 -4
- data/spec/shared_examples/dupable.rb +4 -4
- data/spec/shared_examples/mass_assignment.rb +1 -1
- metadata +2 -2
@@ -13,6 +13,9 @@ module ObjectSpec
|
|
13
13
|
|
14
14
|
end
|
15
15
|
|
16
|
+
class PlainObject < ActiveType::Object
|
17
|
+
end
|
18
|
+
|
16
19
|
|
17
20
|
class ObjectWithValidations < Object
|
18
21
|
|
@@ -124,7 +127,7 @@ describe ActiveType::Object do
|
|
124
127
|
it 'is possible to override attributes with super' do
|
125
128
|
subject.overridable_test = "test"
|
126
129
|
|
127
|
-
subject.overridable_test.
|
130
|
+
expect(subject.overridable_test).to eq("testtest")
|
128
131
|
end
|
129
132
|
end
|
130
133
|
|
@@ -170,31 +173,31 @@ describe ActiveType::Object do
|
|
170
173
|
it 'returns true for true' do
|
171
174
|
subject.virtual_attribute = true
|
172
175
|
|
173
|
-
subject.virtual_attribute
|
176
|
+
expect(subject.virtual_attribute?).to eq(true)
|
174
177
|
end
|
175
178
|
|
176
179
|
it 'returns false for false' do
|
177
180
|
subject.virtual_attribute = false
|
178
181
|
|
179
|
-
subject.virtual_attribute
|
182
|
+
expect(subject.virtual_attribute?).to eq(false)
|
180
183
|
end
|
181
184
|
|
182
185
|
it 'returns false for nil' do
|
183
186
|
subject.virtual_attribute = nil
|
184
187
|
|
185
|
-
subject.virtual_attribute
|
188
|
+
expect(subject.virtual_attribute?).to eq(false)
|
186
189
|
end
|
187
190
|
|
188
191
|
it 'returns true for 1' do
|
189
192
|
subject.virtual_attribute = 1
|
190
193
|
|
191
|
-
subject.virtual_attribute
|
194
|
+
expect(subject.virtual_attribute?).to eq(true)
|
192
195
|
end
|
193
196
|
|
194
197
|
it 'returns true for an object' do
|
195
198
|
subject.virtual_attribute = Object.new
|
196
199
|
|
197
|
-
subject.virtual_attribute
|
200
|
+
expect(subject.virtual_attribute?).to eq(true)
|
198
201
|
end
|
199
202
|
|
200
203
|
end
|
@@ -205,14 +208,14 @@ describe ActiveType::Object do
|
|
205
208
|
subject.virtual_string = "string"
|
206
209
|
subject.virtual_integer = "17"
|
207
210
|
|
208
|
-
subject.attributes.
|
211
|
+
expect(subject.attributes).to eq({
|
209
212
|
"virtual_string" => "string",
|
210
213
|
"virtual_integer" => 17,
|
211
214
|
"virtual_time" => nil,
|
212
215
|
"virtual_date" => nil,
|
213
216
|
"virtual_boolean" => nil,
|
214
217
|
"virtual_attribute" => nil,
|
215
|
-
}
|
218
|
+
})
|
216
219
|
end
|
217
220
|
|
218
221
|
it 'also includes inherited attributes' do
|
@@ -220,7 +223,7 @@ describe ActiveType::Object do
|
|
220
223
|
object.virtual_string = "string"
|
221
224
|
object.virtual_integer = "17"
|
222
225
|
|
223
|
-
object.attributes.
|
226
|
+
expect(object.attributes).to eq({
|
224
227
|
"virtual_string" => "string",
|
225
228
|
"virtual_integer" => 17,
|
226
229
|
"virtual_time" => nil,
|
@@ -228,7 +231,7 @@ describe ActiveType::Object do
|
|
228
231
|
"virtual_boolean" => nil,
|
229
232
|
"virtual_attribute" => nil,
|
230
233
|
"another_virtual_string" => nil,
|
231
|
-
}
|
234
|
+
})
|
232
235
|
end
|
233
236
|
|
234
237
|
it 'also includes included attributes' do
|
@@ -236,7 +239,7 @@ describe ActiveType::Object do
|
|
236
239
|
object.virtual_string = "string"
|
237
240
|
object.virtual_integer = "17"
|
238
241
|
|
239
|
-
object.attributes.
|
242
|
+
expect(object.attributes).to eq({
|
240
243
|
"virtual_string" => "string",
|
241
244
|
"virtual_integer" => 17,
|
242
245
|
"virtual_time" => nil,
|
@@ -244,7 +247,7 @@ describe ActiveType::Object do
|
|
244
247
|
"virtual_boolean" => nil,
|
245
248
|
"virtual_attribute" => nil,
|
246
249
|
"another_virtual_string" => nil,
|
247
|
-
}
|
250
|
+
})
|
248
251
|
end
|
249
252
|
|
250
253
|
end
|
@@ -256,13 +259,13 @@ describe ActiveType::Object do
|
|
256
259
|
object.virtual_string = "string"
|
257
260
|
object.another_virtual_string = "another string"
|
258
261
|
|
259
|
-
object.virtual_string.
|
260
|
-
object.another_virtual_string.
|
262
|
+
expect(object.virtual_string).to eq("string")
|
263
|
+
expect(object.another_virtual_string).to eq("another string")
|
261
264
|
end
|
262
265
|
|
263
266
|
it 'does not define the attribute on the parent class' do
|
264
267
|
object = ObjectSpec::Object.new
|
265
|
-
object.
|
268
|
+
expect(object).not_to respond_to(:another_virtual_string)
|
266
269
|
end
|
267
270
|
|
268
271
|
end
|
@@ -273,41 +276,43 @@ describe ActiveType::Object do
|
|
273
276
|
object.virtual_string = "string"
|
274
277
|
object.another_virtual_string = "another string"
|
275
278
|
|
276
|
-
object.virtual_string.
|
277
|
-
object.another_virtual_string.
|
279
|
+
expect(object.virtual_string).to eq("string")
|
280
|
+
expect(object.another_virtual_string).to eq("another string")
|
278
281
|
end
|
279
282
|
|
280
283
|
it 'does not define the attribute on the parent class' do
|
281
284
|
object = ObjectSpec::Object.new
|
282
|
-
object.
|
285
|
+
expect(object).not_to respond_to(:another_virtual_string)
|
283
286
|
end
|
284
287
|
end
|
285
288
|
|
286
289
|
describe 'validations' do
|
287
290
|
subject { ObjectSpec::ObjectWithValidations.new }
|
288
291
|
|
289
|
-
it
|
292
|
+
it 'has 1 error_on' do
|
293
|
+
expect(subject.error_on(:virtual_string).size).to eq(1)
|
294
|
+
end
|
290
295
|
|
291
296
|
it 'validates the presence of boolean values' do
|
292
297
|
subject.virtual_boolean = false
|
293
|
-
subject.
|
298
|
+
expect(subject.error_on(:virtual_boolean).size).to eq(1)
|
294
299
|
subject.virtual_boolean = '0'
|
295
|
-
subject.
|
300
|
+
expect(subject.error_on(:virtual_boolean).size).to eq(1)
|
296
301
|
subject.virtual_boolean = 0
|
297
|
-
subject.
|
302
|
+
expect(subject.error_on(:virtual_boolean).size).to eq(1)
|
298
303
|
subject.virtual_boolean = true
|
299
|
-
subject.
|
304
|
+
expect(subject.errors_on(:virtual_boolean).size).to eq(0)
|
300
305
|
end
|
301
306
|
|
302
307
|
it 'has no errors if validations pass' do
|
303
308
|
subject.virtual_string = "foo"
|
304
309
|
subject.virtual_boolean = true
|
305
|
-
subject.
|
306
|
-
subject.
|
310
|
+
expect(subject).to be_valid
|
311
|
+
expect(subject.errors_on(:virtual_string).size).to eq(0)
|
307
312
|
end
|
308
313
|
|
309
314
|
it 'causes #save to return false' do
|
310
|
-
subject.save.
|
315
|
+
expect(subject.save).to be_falsey
|
311
316
|
end
|
312
317
|
end
|
313
318
|
|
@@ -317,6 +322,12 @@ describe ActiveType::Object do
|
|
317
322
|
|
318
323
|
describe 'duping' do
|
319
324
|
it_should_behave_like "a class supporting dup for attributes", ActiveType::Object
|
325
|
+
|
326
|
+
it 'can dup without attributes' do
|
327
|
+
expect {
|
328
|
+
ObjectSpec::PlainObject.new.dup
|
329
|
+
}.not_to raise_error
|
330
|
+
end
|
320
331
|
end
|
321
332
|
|
322
333
|
describe 'dirty tracking' do
|
@@ -339,9 +350,9 @@ describe ActiveType::Object do
|
|
339
350
|
%w[before_validation before_save after_save after_commit].each do |callback|
|
340
351
|
|
341
352
|
it "calls #{callback}", :rollback => false do
|
342
|
-
subject.
|
353
|
+
expect(subject).to receive("#{callback}_callback")
|
343
354
|
|
344
|
-
subject.save.
|
355
|
+
expect(subject.save).to eq(true)
|
345
356
|
end
|
346
357
|
|
347
358
|
end
|
@@ -349,9 +360,9 @@ describe ActiveType::Object do
|
|
349
360
|
%w[before_validation before_save].each do |callback|
|
350
361
|
|
351
362
|
it "aborts the chain when #{callback} returns false" do
|
352
|
-
subject.
|
363
|
+
allow(subject).to receive_messages("#{callback}_callback" => false)
|
353
364
|
|
354
|
-
subject.save.
|
365
|
+
expect(subject.save).to be_falsey
|
355
366
|
end
|
356
367
|
|
357
368
|
end
|
@@ -373,7 +384,7 @@ describe ActiveType::Object do
|
|
373
384
|
|
374
385
|
describe '.all' do
|
375
386
|
it 'returns []' do
|
376
|
-
ObjectSpec::Object.all.
|
387
|
+
expect(ObjectSpec::Object.all).to eq([])
|
377
388
|
end
|
378
389
|
end
|
379
390
|
|
@@ -381,8 +392,8 @@ describe ActiveType::Object do
|
|
381
392
|
it 'returns an object' do
|
382
393
|
object = ObjectSpec::Object.create(:virtual_string => "string")
|
383
394
|
|
384
|
-
object.
|
385
|
-
object.virtual_string.
|
395
|
+
expect(object).to be_a(ObjectSpec::Object)
|
396
|
+
expect(object.virtual_string).to eq("string")
|
386
397
|
end
|
387
398
|
end
|
388
399
|
|
@@ -59,11 +59,11 @@ describe ActiveType::Record do
|
|
59
59
|
subject { RecordSpec::Record.new }
|
60
60
|
|
61
61
|
it 'is a ActiveRecord::Base' do
|
62
|
-
subject.
|
62
|
+
expect(subject).to be_a(ActiveRecord::Base)
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'is an abstract class' do
|
66
|
-
ActiveType::Record.
|
66
|
+
expect(ActiveType::Record).to be_abstract_class
|
67
67
|
end
|
68
68
|
|
69
69
|
describe 'constructors' do
|
@@ -94,7 +94,7 @@ describe ActiveType::Record do
|
|
94
94
|
it 'is possible to override attributes with super' do
|
95
95
|
subject.overridable_test = "test"
|
96
96
|
|
97
|
-
subject.overridable_test.
|
97
|
+
expect(subject.overridable_test).to eq("testtest")
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -158,7 +158,7 @@ describe ActiveType::Record do
|
|
158
158
|
subject.virtual_string = "string"
|
159
159
|
subject.virtual_integer = "17"
|
160
160
|
|
161
|
-
subject.attributes.
|
161
|
+
expect(subject.attributes).to eq({
|
162
162
|
"virtual_string" => "string",
|
163
163
|
"virtual_integer" => 17,
|
164
164
|
"virtual_time" => nil,
|
@@ -171,7 +171,7 @@ describe ActiveType::Record do
|
|
171
171
|
"persisted_time" => nil,
|
172
172
|
"persisted_date" => nil,
|
173
173
|
"persisted_boolean" => nil
|
174
|
-
}
|
174
|
+
})
|
175
175
|
end
|
176
176
|
|
177
177
|
end
|
@@ -179,8 +179,12 @@ describe ActiveType::Record do
|
|
179
179
|
describe 'validations' do
|
180
180
|
subject { RecordSpec::RecordWithValidations.new }
|
181
181
|
|
182
|
-
it
|
183
|
-
|
182
|
+
it 'has 1 error_on' do
|
183
|
+
expect(subject.error_on(:persisted_string).size).to eq(1)
|
184
|
+
end
|
185
|
+
it 'has 1 error_on' do
|
186
|
+
expect(subject.error_on(:virtual_string).size).to eq(1)
|
187
|
+
end
|
184
188
|
end
|
185
189
|
|
186
190
|
describe 'undefined columns' do
|
@@ -207,9 +211,9 @@ describe ActiveType::Record do
|
|
207
211
|
|
208
212
|
it 'persists to the database' do
|
209
213
|
subject.persisted_string = "persisted string"
|
210
|
-
subject.save.
|
214
|
+
expect(subject.save).to eq(true)
|
211
215
|
|
212
|
-
subject.class.find(subject.id).persisted_string.
|
216
|
+
expect(subject.class.find(subject.id).persisted_string).to eq("persisted string")
|
213
217
|
end
|
214
218
|
end
|
215
219
|
|
@@ -218,8 +222,8 @@ describe ActiveType::Record do
|
|
218
222
|
record = RecordSpec::Record.new
|
219
223
|
other_record = RecordSpec::OtherRecord.new
|
220
224
|
|
221
|
-
record.
|
222
|
-
other_record.
|
225
|
+
expect(record).not_to respond_to(:other_string)
|
226
|
+
expect(other_record).not_to respond_to(:persisted_string)
|
223
227
|
end
|
224
228
|
end
|
225
229
|
|
@@ -42,10 +42,10 @@ describe ActiveType::Util do
|
|
42
42
|
record = UtilSpec::BaseRecord.create!(:persisted_string => 'foo')
|
43
43
|
base_scope = UtilSpec::BaseRecord.where(:persisted_string => 'foo')
|
44
44
|
casted_scope = ActiveType::Util.cast(base_scope, UtilSpec::ExtendedRecord)
|
45
|
-
casted_scope.build.
|
45
|
+
expect(casted_scope.build).to be_a(UtilSpec::ExtendedRecord)
|
46
46
|
found_record = casted_scope.find(record.id)
|
47
|
-
found_record.persisted_string.
|
48
|
-
found_record.
|
47
|
+
expect(found_record.persisted_string).to eq('foo')
|
48
|
+
expect(found_record).to be_a(UtilSpec::ExtendedRecord)
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'preserves existing scope conditions' do
|
@@ -54,7 +54,7 @@ describe ActiveType::Util do
|
|
54
54
|
base_scope = UtilSpec::BaseRecord.where(:persisted_string => 'foo')
|
55
55
|
casted_scope = ActiveType::Util.cast(base_scope, UtilSpec::ExtendedRecord)
|
56
56
|
casted_match = UtilSpec::ExtendedRecord.find(match.id)
|
57
|
-
casted_scope.to_a.
|
57
|
+
expect(casted_scope.to_a).to eq([casted_match])
|
58
58
|
end
|
59
59
|
|
60
60
|
end
|
@@ -64,57 +64,57 @@ describe ActiveType::Util do
|
|
64
64
|
it 'casts a base record to an extended record' do
|
65
65
|
base_record = UtilSpec::BaseRecord.create!(:persisted_string => 'foo')
|
66
66
|
extended_record = ActiveType::Util.cast(base_record, UtilSpec::ExtendedRecord)
|
67
|
-
extended_record.
|
68
|
-
extended_record.
|
69
|
-
extended_record.id.
|
70
|
-
extended_record.id.
|
71
|
-
extended_record.persisted_string.
|
67
|
+
expect(extended_record).to be_a(UtilSpec::ExtendedRecord)
|
68
|
+
expect(extended_record).to be_persisted
|
69
|
+
expect(extended_record.id).to be_present
|
70
|
+
expect(extended_record.id).to eq(base_record.id)
|
71
|
+
expect(extended_record.persisted_string).to eq('foo')
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'casts an extended record to a base record' do
|
75
75
|
extended_record = UtilSpec::ExtendedRecord.create!(:persisted_string => 'foo')
|
76
76
|
base_record = ActiveType::Util.cast(extended_record, UtilSpec::BaseRecord)
|
77
|
-
base_record.
|
78
|
-
base_record.
|
79
|
-
base_record.id.
|
80
|
-
base_record.id.
|
81
|
-
base_record.persisted_string.
|
77
|
+
expect(base_record).to be_a(UtilSpec::BaseRecord)
|
78
|
+
expect(base_record).to be_persisted
|
79
|
+
expect(base_record.id).to be_present
|
80
|
+
expect(base_record.id).to eq(extended_record.id)
|
81
|
+
expect(base_record.persisted_string).to eq('foo')
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'calls after_initialize callbacks of the cast target' do
|
85
85
|
base_record = UtilSpec::BaseRecord.create!(:persisted_string => 'foo')
|
86
86
|
extended_record = ActiveType::Util.cast(base_record, UtilSpec::ExtendedRecord)
|
87
|
-
extended_record.virtual_string.
|
87
|
+
expect(extended_record.virtual_string).to be_present
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'lets after_initialize callbacks access attributes (bug in ActiveRecord#becomes)' do
|
91
91
|
base_record = UtilSpec::BaseRecord.create!(:persisted_string => 'foo')
|
92
92
|
extended_record = ActiveType::Util.cast(base_record, UtilSpec::ExtendedRecord)
|
93
|
-
extended_record.virtual_string.
|
93
|
+
expect(extended_record.virtual_string).to eq('persisted_string is foo')
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'preserves the #type of an STI record that is casted to an ExtendedRecord' do
|
97
97
|
child_record = UtilSpec::Child.create!(:persisted_string => 'foo')
|
98
98
|
extended_child_record = ActiveType::Util.cast(child_record, UtilSpec::ExtendedChild)
|
99
|
-
extended_child_record.
|
100
|
-
extended_child_record.type.
|
99
|
+
expect(extended_child_record).to be_a(UtilSpec::ExtendedChild)
|
100
|
+
expect(extended_child_record.type).to eq('UtilSpec::Child')
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'changes the #type of an STI record when casted to another type in the hierarchy' do
|
104
104
|
child_record = UtilSpec::Child.create!(:persisted_string => 'foo')
|
105
105
|
child_sibling_record = ActiveType::Util.cast(child_record, UtilSpec::ChildSibling)
|
106
|
-
child_sibling_record.
|
107
|
-
child_sibling_record.type.
|
106
|
+
expect(child_sibling_record).to be_a(UtilSpec::ChildSibling)
|
107
|
+
expect(child_sibling_record.type).to eq('UtilSpec::Child')
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'preserves dirty tracking flags' do
|
111
111
|
base_record = UtilSpec::BaseRecord.create!(:persisted_string => 'foo')
|
112
|
-
base_record.changes.
|
112
|
+
expect(base_record.changes).to eq({})
|
113
113
|
base_record.persisted_string = 'bar'
|
114
|
-
base_record.changes.
|
114
|
+
expect(base_record.changes).to eq({ 'persisted_string' => ['foo', 'bar'] })
|
115
115
|
extended_record = ActiveType::Util.cast(base_record, UtilSpec::ExtendedRecord)
|
116
|
-
extended_record.
|
117
|
-
extended_record.changes.
|
116
|
+
expect(extended_record).to be_a(UtilSpec::ExtendedRecord)
|
117
|
+
expect(extended_record.changes).to eq({ 'persisted_string' => ['foo', 'bar'] })
|
118
118
|
end
|
119
119
|
|
120
120
|
end
|
@@ -122,7 +122,7 @@ describe ActiveType::Util do
|
|
122
122
|
end
|
123
123
|
|
124
124
|
it "exposes all methods through ActiveType's root namespace" do
|
125
|
-
ActiveType.
|
125
|
+
expect(ActiveType).to respond_to(:cast)
|
126
126
|
end
|
127
127
|
|
128
128
|
end
|
@@ -51,15 +51,15 @@ describe HolidaySpec::HolidayForm do
|
|
51
51
|
it 'will return holidays including updated ones' do
|
52
52
|
HolidaySpec::Holiday.create!(:name => 'New Year', :date => '2014-01-01')
|
53
53
|
form = HolidaySpec::HolidayForm.new(:holidays_attributes => params.slice('2'))
|
54
|
-
form.holidays.collect(&:name).
|
54
|
+
expect(form.holidays.collect(&:name)).to eq(["New Year", "Epiphany"])
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'can create a list of holidays' do
|
58
|
-
update(params).
|
58
|
+
expect(update(params)).to eq(true)
|
59
59
|
|
60
60
|
holidays = HolidaySpec::Holiday.order(:date)
|
61
|
-
holidays.collect(&:name).
|
62
|
-
holidays.collect(&:date).
|
61
|
+
expect(holidays.collect(&:name)).to eq(["New Year", "Epiphany"])
|
62
|
+
expect(holidays.collect(&:date)).to eq([Date.civil(2014, 1, 1), Date.civil(2014, 1, 6)])
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'can update holidays' do
|
@@ -67,22 +67,22 @@ describe HolidaySpec::HolidayForm do
|
|
67
67
|
|
68
68
|
params['1']['name'] += ' 2014'
|
69
69
|
params['2']['name'] += ' 2014'
|
70
|
-
update(params).
|
70
|
+
expect(update(params)).to eq(true)
|
71
71
|
|
72
72
|
holidays = HolidaySpec::Holiday.order(:date)
|
73
|
-
holidays.collect(&:name).
|
74
|
-
holidays.collect(&:date).
|
73
|
+
expect(holidays.collect(&:name)).to eq(["New Year 2014", "Epiphany 2014"])
|
74
|
+
expect(holidays.collect(&:date)).to eq([Date.civil(2014, 1, 1), Date.civil(2014, 1, 6)])
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'can destroy holidays' do
|
78
78
|
update(params)
|
79
79
|
|
80
80
|
params['1']['_destroy'] = '1'
|
81
|
-
update(params).
|
81
|
+
expect(update(params)).to eq(true)
|
82
82
|
|
83
83
|
holidays = HolidaySpec::Holiday.order(:date)
|
84
|
-
holidays.collect(&:name).
|
85
|
-
holidays.collect(&:date).
|
84
|
+
expect(holidays.collect(&:name)).to eq(["Epiphany"])
|
85
|
+
expect(holidays.collect(&:date)).to eq([Date.civil(2014, 1, 6)])
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'will not save if some fields are invalid' do
|
@@ -91,11 +91,11 @@ describe HolidaySpec::HolidayForm do
|
|
91
91
|
params['1']['name'] = '-'
|
92
92
|
params['1']['_destroy'] = '1'
|
93
93
|
params['2']['name'] = '' # invalid
|
94
|
-
update(params).
|
94
|
+
expect(update(params)).to be_falsey
|
95
95
|
|
96
96
|
holidays = HolidaySpec::Holiday.order(:date)
|
97
|
-
holidays.collect(&:name).
|
98
|
-
holidays.collect(&:date).
|
97
|
+
expect(holidays.collect(&:name)).to eq(["New Year", "Epiphany"])
|
98
|
+
expect(holidays.collect(&:date)).to eq([Date.civil(2014, 1, 1), Date.civil(2014, 1, 6)])
|
99
99
|
end
|
100
100
|
|
101
101
|
|
@@ -55,9 +55,7 @@ describe ShapeSpec::ShapeForm do
|
|
55
55
|
def update(params)
|
56
56
|
form.child_type = params[:type]
|
57
57
|
form.child_attributes = params.except(:type)
|
58
|
-
|
59
|
-
params['id'] = form.child.id
|
60
|
-
end
|
58
|
+
form.save
|
61
59
|
end
|
62
60
|
|
63
61
|
it 'can create a circle' do
|
@@ -66,10 +64,10 @@ describe ShapeSpec::ShapeForm do
|
|
66
64
|
'radius' => '20'
|
67
65
|
}.with_indifferent_access
|
68
66
|
|
69
|
-
update(params).
|
67
|
+
expect(update(params)).to eq(true)
|
70
68
|
|
71
|
-
ShapeSpec::Circle.all.collect(&:radius).
|
72
|
-
ShapeSpec::Rectangle.count.
|
69
|
+
expect(ShapeSpec::Circle.all.collect(&:radius)).to eq([20])
|
70
|
+
expect(ShapeSpec::Rectangle.count).to eq(0)
|
73
71
|
end
|
74
72
|
|
75
73
|
it 'can create a rectangle' do
|
@@ -79,11 +77,11 @@ describe ShapeSpec::ShapeForm do
|
|
79
77
|
'width' => '30'
|
80
78
|
}.with_indifferent_access
|
81
79
|
|
82
|
-
update(params).
|
80
|
+
expect(update(params)).to eq(true)
|
83
81
|
|
84
|
-
ShapeSpec::Circle.count.
|
85
|
-
ShapeSpec::Rectangle.all.collect(&:length).
|
86
|
-
ShapeSpec::Rectangle.all.collect(&:width).
|
82
|
+
expect(ShapeSpec::Circle.count).to eq(0)
|
83
|
+
expect(ShapeSpec::Rectangle.all.collect(&:length)).to eq([100])
|
84
|
+
expect(ShapeSpec::Rectangle.all.collect(&:width)).to eq([30])
|
87
85
|
end
|
88
86
|
|
89
87
|
it 'can update' do
|
@@ -94,9 +92,9 @@ describe ShapeSpec::ShapeForm do
|
|
94
92
|
update(params)
|
95
93
|
|
96
94
|
params['radius'] = '30'
|
97
|
-
update(params).
|
95
|
+
expect(update(params)).to eq(true)
|
98
96
|
|
99
|
-
ShapeSpec::Circle.all.collect(&:radius).
|
97
|
+
expect(ShapeSpec::Circle.all.collect(&:radius)).to eq([30])
|
100
98
|
end
|
101
99
|
|
102
100
|
it 'has validations' do
|
@@ -104,9 +102,9 @@ describe ShapeSpec::ShapeForm do
|
|
104
102
|
'type' => 'circle'
|
105
103
|
}.with_indifferent_access
|
106
104
|
|
107
|
-
update(params).
|
105
|
+
expect(update(params)).to be_falsey
|
108
106
|
|
109
|
-
form.child.errors['radius'].
|
107
|
+
expect(form.child.errors['radius']).to eq(["can't be blank"])
|
110
108
|
end
|
111
109
|
|
112
110
|
end
|
@@ -29,21 +29,21 @@ describe SignInSpec::SignIn do
|
|
29
29
|
describe 'with missing credentials' do
|
30
30
|
|
31
31
|
it 'is invalid' do
|
32
|
-
subject.
|
32
|
+
expect(subject).not_to be_valid
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'has errors' do
|
36
36
|
subject.valid?
|
37
|
-
subject.errors[:email].
|
38
|
-
subject.errors[:password].
|
37
|
+
expect(subject.errors[:email]).to eq(["can't be blank"])
|
38
|
+
expect(subject.errors[:password]).to eq(["can't be blank"])
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'does not save' do
|
42
|
-
subject.save.
|
42
|
+
expect(subject.save).to be_falsey
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'does not set the session' do
|
46
|
-
subject.
|
46
|
+
expect(subject).not_to receive :set_session
|
47
47
|
subject.save
|
48
48
|
end
|
49
49
|
|
@@ -57,20 +57,20 @@ describe SignInSpec::SignIn do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'is invalid' do
|
60
|
-
subject.
|
60
|
+
expect(subject).not_to be_valid
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'has errors' do
|
64
64
|
subject.valid?
|
65
|
-
subject.errors[:password].
|
65
|
+
expect(subject.errors[:password]).to eq(["is not correct"])
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'does not save' do
|
69
|
-
subject.save.
|
69
|
+
expect(subject.save).to be_falsey
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'does not set the session' do
|
73
|
-
subject.
|
73
|
+
expect(subject).not_to receive :set_session
|
74
74
|
subject.save
|
75
75
|
end
|
76
76
|
|
@@ -84,15 +84,15 @@ describe SignInSpec::SignIn do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'is invalid' do
|
87
|
-
subject.
|
87
|
+
expect(subject).to be_valid
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'does save' do
|
91
|
-
subject.save.
|
91
|
+
expect(subject.save).to eq(true)
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'sets the session' do
|
95
|
-
subject.
|
95
|
+
expect(subject).to receive :set_session
|
96
96
|
subject.save
|
97
97
|
end
|
98
98
|
|