smart_properties 1.3.0 → 1.4.0
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/lib/smart_properties.rb +5 -16
- data/smart_properties.gemspec +1 -1
- data/spec/smart_properties_spec.rb +103 -218
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2348523c881e2d305ed3c9491cdc5ff5ab4c211c
|
4
|
+
data.tar.gz: 5fb7e1a4a6498b7d98d70786c53df1ed81337646
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9314f5a0c3de2c5deb2555c16d3a98073bceffd1cddf04ed0dee81bc22cf2e463f62f39c591fee1af5f6d84c2b26281f3bd191e449614ea7703698fb115a79b7
|
7
|
+
data.tar.gz: 1a7e4cbc840468d4dcea882eefd1ad46bcd1ce37c703a0bb6742c5417cee477c69235edb1d32acb8c401cb02e2e5a2553ec93f6a418ed7eace24da723f928d71
|
data/lib/smart_properties.rb
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
#
|
23
23
|
module SmartProperties
|
24
24
|
|
25
|
-
VERSION = "1.
|
25
|
+
VERSION = "1.4.0"
|
26
26
|
|
27
27
|
class Property
|
28
28
|
|
@@ -50,16 +50,7 @@ module SmartProperties
|
|
50
50
|
|
51
51
|
def convert(value, scope)
|
52
52
|
return value unless converter
|
53
|
-
|
54
|
-
if converter.respond_to?(:call)
|
55
|
-
scope.instance_exec(value, &converter)
|
56
|
-
else
|
57
|
-
begin
|
58
|
-
value.send(:"#{converter}")
|
59
|
-
rescue NoMethodError
|
60
|
-
raise ArgumentError, "#{value.class.name} does not respond to ##{converter}"
|
61
|
-
end
|
62
|
-
end
|
53
|
+
scope.instance_exec(value, &converter)
|
63
54
|
end
|
64
55
|
|
65
56
|
def default(scope)
|
@@ -70,12 +61,10 @@ module SmartProperties
|
|
70
61
|
return true unless value
|
71
62
|
return true unless accepter
|
72
63
|
|
73
|
-
if accepter.
|
74
|
-
accepter.include?(value)
|
75
|
-
elsif !accepter.kind_of?(Proc)
|
76
|
-
accepter === value
|
77
|
-
else
|
64
|
+
if accepter.respond_to?(:to_proc)
|
78
65
|
!!scope.instance_exec(value, &accepter)
|
66
|
+
else
|
67
|
+
Array(accepter).any? { |accepter| accepter === value }
|
79
68
|
end
|
80
69
|
end
|
81
70
|
|
data/smart_properties.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
gem.version = SmartProperties::VERSION
|
21
21
|
|
22
|
-
gem.add_development_dependency "rspec", "~> 2.
|
22
|
+
gem.add_development_dependency "rspec", "~> 2.14"
|
23
23
|
gem.add_development_dependency "rake", "~> 0.8"
|
24
24
|
gem.add_development_dependency "guard-rspec", "~> 0.7"
|
25
25
|
end
|
@@ -3,22 +3,20 @@ require 'spec_helper'
|
|
3
3
|
describe SmartProperties do
|
4
4
|
|
5
5
|
context "when extending an other class" do
|
6
|
-
|
7
|
-
subject do
|
6
|
+
subject(:klass) do
|
8
7
|
Class.new.tap do |c|
|
9
8
|
c.send(:include, described_class)
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
13
12
|
it "should add a .property method" do
|
14
|
-
|
13
|
+
klass.respond_to?(:property, true).should be_true
|
15
14
|
end
|
16
15
|
|
17
16
|
context "and defining a property with invalid configuration options" do
|
18
|
-
|
19
17
|
it "should raise an error reporting one invalid option when one invalid option was given" do
|
20
18
|
expect {
|
21
|
-
|
19
|
+
klass.tap do |c|
|
22
20
|
c.instance_eval do
|
23
21
|
property :title, :invalid_option => 'boom'
|
24
22
|
end
|
@@ -28,21 +26,18 @@ describe SmartProperties do
|
|
28
26
|
|
29
27
|
it "should raise an error reporting three invalid options when three invalid options were given" do
|
30
28
|
expect {
|
31
|
-
|
29
|
+
klass.tap do |c|
|
32
30
|
c.instance_eval do
|
33
31
|
property :title, :invalid_option_1 => 'boom', :invalid_option_2 => 'boom', :invalid_option_3 => 'boom'
|
34
32
|
end
|
35
33
|
end
|
36
34
|
}.to raise_error(ArgumentError, "SmartProperties do not support the following configuration options: invalid_option_1, invalid_option_2, invalid_option_3.")
|
37
35
|
end
|
38
|
-
|
39
36
|
end
|
40
|
-
|
41
37
|
end
|
42
38
|
|
43
39
|
context "when used to build a class that has a property called :title" do
|
44
|
-
|
45
|
-
subject do
|
40
|
+
subject(:klass) do
|
46
41
|
title = Object.new.tap do |o|
|
47
42
|
def o.to_title; 'chunky'; end
|
48
43
|
end
|
@@ -62,103 +57,76 @@ describe SmartProperties do
|
|
62
57
|
klass
|
63
58
|
end
|
64
59
|
|
60
|
+
let(:superklass) { klass }
|
61
|
+
|
65
62
|
it { should have_smart_property(:title) }
|
66
63
|
|
67
64
|
context "instances of this class" do
|
68
|
-
|
69
|
-
klass = subject.call
|
70
|
-
|
71
|
-
subject do
|
72
|
-
klass.new
|
73
|
-
end
|
65
|
+
subject(:instance) { klass.new }
|
74
66
|
|
75
67
|
it { should respond_to(:title) }
|
76
68
|
it { should respond_to(:title=) }
|
77
69
|
|
78
70
|
it "should have 'chucky' as default value for title" do
|
79
|
-
|
71
|
+
instance.title.should be == 'chunky'
|
80
72
|
end
|
81
73
|
|
82
74
|
it "should convert all values that are assigned to title into strings" do
|
83
|
-
|
84
|
-
|
75
|
+
instance.title = double(:to_title => 'bacon')
|
76
|
+
instance.title.should be == 'bacon'
|
85
77
|
end
|
86
78
|
|
87
79
|
it "should not allow to set nil as title" do
|
88
|
-
expect {
|
80
|
+
expect { instance.title = nil }.to raise_error(ArgumentError, "TestDummy requires the property title to be set")
|
89
81
|
end
|
90
82
|
|
91
83
|
it "should not allow to set objects as title that do not respond to #to_title" do
|
92
|
-
expect {
|
84
|
+
expect { instance.title = Object.new }.to raise_error(NoMethodError, /undefined method `to_title'/)
|
93
85
|
end
|
94
86
|
|
95
87
|
it "should not influence other instances that have been initialized with different attributes" do
|
96
|
-
|
88
|
+
other_instance = klass.new :title => double(:to_title => 'Lorem ipsum')
|
97
89
|
|
98
|
-
|
99
|
-
|
90
|
+
instance.title.should be == 'chunky'
|
91
|
+
other_instance.title.should be == 'Lorem ipsum'
|
100
92
|
end
|
101
93
|
|
102
94
|
context "when initialized with a block" do
|
103
|
-
|
104
|
-
subject do
|
95
|
+
subject(:instance) do
|
105
96
|
klass.new do |c|
|
106
97
|
c.title = double(:to_title => 'bacon')
|
107
98
|
end
|
108
99
|
end
|
109
100
|
|
110
101
|
it "should have the title specified in the block" do
|
111
|
-
|
102
|
+
instance.title.should be == 'bacon'
|
112
103
|
end
|
113
|
-
|
114
104
|
end
|
115
|
-
|
116
105
|
end
|
117
106
|
|
118
107
|
context "when subclassed" do
|
119
|
-
|
120
|
-
superklass = subject.call
|
121
|
-
|
122
|
-
subject do
|
123
|
-
Class.new(superklass)
|
124
|
-
end
|
108
|
+
subject(:subklass) { Class.new(superklass) }
|
125
109
|
|
126
110
|
it { should have_smart_property(:title) }
|
127
111
|
|
128
112
|
context "instances of this subclass" do
|
129
|
-
|
130
|
-
klass = subject.call
|
131
|
-
|
132
|
-
subject do
|
133
|
-
klass.new
|
134
|
-
end
|
113
|
+
subject(:instance) { subklass.new }
|
135
114
|
|
136
115
|
it { should respond_to(:title) }
|
137
116
|
it { should respond_to(:title=) }
|
138
|
-
|
139
117
|
end
|
140
118
|
|
141
119
|
context "instances of this subclass that have been intialized from a set of attributes" do
|
142
|
-
|
143
|
-
klass = subject.call
|
144
|
-
|
145
|
-
subject do
|
146
|
-
klass.new :title => stub(:to_title => 'Message')
|
147
|
-
end
|
120
|
+
subject(:instance) { subklass.new :title => double(:to_title => 'Message') }
|
148
121
|
|
149
122
|
it "should have the correct title" do
|
150
|
-
|
123
|
+
instance.title.should be == 'Message'
|
151
124
|
end
|
152
|
-
|
153
125
|
end
|
154
|
-
|
155
126
|
end
|
156
127
|
|
157
128
|
context "when subclassed and extended with a property called text" do
|
158
|
-
|
159
|
-
superklass = subject.call
|
160
|
-
|
161
|
-
subject do
|
129
|
+
subject(:subklass) do
|
162
130
|
Class.new(superklass).tap do |c|
|
163
131
|
c.instance_eval do
|
164
132
|
property :text
|
@@ -170,80 +138,46 @@ describe SmartProperties do
|
|
170
138
|
it { should have_smart_property(:text) }
|
171
139
|
|
172
140
|
context "instances of this subclass" do
|
173
|
-
|
174
|
-
klass = subject.call
|
175
|
-
|
176
|
-
subject do
|
177
|
-
klass.new
|
178
|
-
end
|
141
|
+
subject(:instance) { subklass.new }
|
179
142
|
|
180
143
|
it { should respond_to(:title) }
|
181
144
|
it { should respond_to(:title=) }
|
182
145
|
it { should respond_to(:text) }
|
183
146
|
it { should respond_to(:text=) }
|
184
|
-
|
185
147
|
end
|
186
148
|
|
187
149
|
context "instances of the super class" do
|
188
|
-
|
189
|
-
subject do
|
190
|
-
superklass.new
|
191
|
-
end
|
150
|
+
subject(:instance) { superklass.new }
|
192
151
|
|
193
152
|
it { should_not respond_to(:text) }
|
194
153
|
it { should_not respond_to(:text=) }
|
195
|
-
|
196
154
|
end
|
197
155
|
|
198
156
|
context "instances of this subclass" do
|
199
|
-
|
200
|
-
klass = subject.call
|
201
|
-
|
202
157
|
context "when initialized with a set of attributes" do
|
158
|
+
subject(:instance) { subklass.new :title => double(:to_title => 'Message'), :text => "Hello" }
|
203
159
|
|
204
|
-
|
205
|
-
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should have the correct title" do
|
209
|
-
subject.title.should be == 'Message'
|
210
|
-
end
|
211
|
-
|
212
|
-
it "should have the correct text" do
|
213
|
-
subject.text.should be == 'Hello'
|
214
|
-
end
|
215
|
-
|
160
|
+
it("should have the correct title") { instance.title.should be == 'Message' }
|
161
|
+
it("should have the correct text") { instance.text.should be == 'Hello' }
|
216
162
|
end
|
217
163
|
|
218
164
|
context "when initialized with a block" do
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
c.title = stub(:to_title => 'Message')
|
165
|
+
subject(:instance) do
|
166
|
+
subklass.new do |c|
|
167
|
+
c.title = double(:to_title => 'Message')
|
223
168
|
c.text = "Hello"
|
224
169
|
end
|
225
170
|
end
|
226
171
|
|
227
|
-
it
|
228
|
-
|
229
|
-
end
|
230
|
-
|
231
|
-
it "should have the text specified in the block" do
|
232
|
-
subject.text.should be == 'Hello'
|
233
|
-
end
|
234
|
-
|
172
|
+
it("should have the correct title") { instance.title.should be == 'Message' }
|
173
|
+
it("should have the correct text") { instance.text.should be == 'Hello' }
|
235
174
|
end
|
236
|
-
|
237
175
|
end
|
238
|
-
|
239
176
|
end
|
240
177
|
|
241
178
|
context "when extended with a :type property at runtime" do
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
subject do
|
246
|
-
klass.tap do |c|
|
179
|
+
before do
|
180
|
+
superklass.tap do |c|
|
247
181
|
c.instance_eval do
|
248
182
|
property :type, :converts => :to_sym
|
249
183
|
end
|
@@ -254,51 +188,29 @@ describe SmartProperties do
|
|
254
188
|
it { should have_smart_property(:type) }
|
255
189
|
|
256
190
|
context "instances of this class" do
|
257
|
-
|
258
|
-
klass = subject.call
|
259
|
-
|
260
|
-
subject do
|
261
|
-
klass.new :title => double(:to_title => 'Lorem ipsum')
|
262
|
-
end
|
191
|
+
subject(:instance) { superklass.new :title => double(:to_title => 'Lorem ipsum') }
|
263
192
|
|
264
193
|
it { should respond_to(:type) }
|
265
194
|
it { should respond_to(:type=) }
|
266
|
-
|
267
195
|
end
|
268
196
|
|
269
197
|
context "when subclassing this class" do
|
270
|
-
|
271
|
-
superklass = subject.call
|
272
|
-
|
273
|
-
subject do
|
274
|
-
Class.new(superklass)
|
275
|
-
end
|
198
|
+
subject(:subclass) { Class.new(superklass) }
|
276
199
|
|
277
200
|
context "instances of this class" do
|
278
|
-
|
279
|
-
klass = subject.call
|
280
|
-
|
281
|
-
subject do
|
282
|
-
klass.new :title => double(:to_title => 'Lorem ipsum')
|
283
|
-
end
|
201
|
+
subject(:instance) { subclass.new :title => double(:to_title => 'Lorem ipsum') }
|
284
202
|
|
285
203
|
it { should respond_to :title }
|
286
204
|
it { should respond_to :title= }
|
287
|
-
|
288
205
|
it { should respond_to :type }
|
289
206
|
it { should respond_to :type= }
|
290
|
-
|
291
207
|
end
|
292
|
-
|
293
208
|
end
|
294
|
-
|
295
209
|
end
|
296
|
-
|
297
210
|
end
|
298
211
|
|
299
|
-
context "when used to build a class that has a property called :title
|
300
|
-
|
301
|
-
subject do
|
212
|
+
context "when used to build a class that has a property called :title that uses a lambda statement for conversion" do
|
213
|
+
subject(:klass) do
|
302
214
|
Class.new.tap do |c|
|
303
215
|
c.send(:include, described_class)
|
304
216
|
c.instance_eval do
|
@@ -308,25 +220,43 @@ describe SmartProperties do
|
|
308
220
|
end
|
309
221
|
|
310
222
|
context "instances of this class" do
|
223
|
+
subject(:instance) { klass.new }
|
311
224
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
klass.new
|
225
|
+
it "should convert the property title as specified the lambda statement" do
|
226
|
+
instance.title = "Lorem ipsum"
|
227
|
+
instance.title.should be == "<title>Lorem ipsum</title>"
|
316
228
|
end
|
229
|
+
end
|
230
|
+
end
|
317
231
|
|
318
|
-
|
319
|
-
|
320
|
-
|
232
|
+
context "when used to build a class that has a property called :title that uses an object that responds to #to_proc for conversion" do
|
233
|
+
subject(:klass) do
|
234
|
+
converter = Object.new.tap do |o|
|
235
|
+
def o.to_proc
|
236
|
+
lambda { |t| "<title>#{t.to_s}</title>"}
|
237
|
+
end
|
321
238
|
end
|
322
239
|
|
240
|
+
Class.new.tap do |c|
|
241
|
+
c.send(:include, described_class)
|
242
|
+
c.instance_eval do
|
243
|
+
property :title, :converts => converter
|
244
|
+
end
|
245
|
+
end
|
323
246
|
end
|
324
247
|
|
248
|
+
context "instances of this class" do
|
249
|
+
subject(:instance) { klass.new }
|
250
|
+
|
251
|
+
it "should convert the property title as specified the lambda statement" do
|
252
|
+
instance.title = "Lorem ipsum"
|
253
|
+
instance.title.should be == "<title>Lorem ipsum</title>"
|
254
|
+
end
|
255
|
+
end
|
325
256
|
end
|
326
257
|
|
327
258
|
context "when used to build a class that has a property called :visible which uses an array of valid values for acceptance checking" do
|
328
|
-
|
329
|
-
subject do
|
259
|
+
subject(:klass) do
|
330
260
|
Class.new.tap do |c|
|
331
261
|
def c.name; "TestDummy"; end
|
332
262
|
|
@@ -339,32 +269,47 @@ describe SmartProperties do
|
|
339
269
|
end
|
340
270
|
|
341
271
|
context "instances of this class" do
|
342
|
-
|
343
|
-
klass = subject.call
|
344
|
-
|
345
|
-
subject do
|
346
|
-
klass.new
|
347
|
-
end
|
272
|
+
subject(:instance) { klass.new }
|
348
273
|
|
349
274
|
it "should allow to set true as value for visible" do
|
350
|
-
expect {
|
275
|
+
expect { instance.visible = true }.to_not raise_error
|
351
276
|
end
|
352
277
|
|
353
278
|
it "should allow to set false as value for visible" do
|
354
|
-
expect {
|
279
|
+
expect { instance.visible = false }.to_not raise_error
|
355
280
|
end
|
356
281
|
|
357
282
|
it "should not allow to set :maybe as value for visible" do
|
358
|
-
expect {
|
283
|
+
expect { instance.visible = :maybe }.to raise_error(ArgumentError, "TestDummy does not accept :maybe as value for the property visible")
|
359
284
|
end
|
285
|
+
end
|
286
|
+
end
|
360
287
|
|
288
|
+
context "when used to build a class that has a property called :title that can either be a String or a Symbol" do
|
289
|
+
subject(:klass) do
|
290
|
+
Class.new.tap do |c|
|
291
|
+
c.send(:include, described_class)
|
292
|
+
c.instance_eval do
|
293
|
+
property :title, accepts: [String, Symbol]
|
294
|
+
end
|
295
|
+
end
|
361
296
|
end
|
362
297
|
|
298
|
+
context "intance of this class" do
|
299
|
+
subject(:instance) { klass.new }
|
300
|
+
|
301
|
+
it "should accept a String as title" do
|
302
|
+
expect { subject.title = "Test" }.to_not raise_error
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should accept a Symbol as title" do
|
306
|
+
expect { subject.title = :test }.to_not raise_error
|
307
|
+
end
|
308
|
+
end
|
363
309
|
end
|
364
310
|
|
365
311
|
context 'when used to build a class that has a property called :license_plate which uses a lambda statement for accpetance checking' do
|
366
|
-
|
367
|
-
subject do
|
312
|
+
subject(:klass) do
|
368
313
|
Class.new.tap do |c|
|
369
314
|
def c.name; 'TestDummy'; end
|
370
315
|
|
@@ -377,28 +322,20 @@ describe SmartProperties do
|
|
377
322
|
end
|
378
323
|
|
379
324
|
context 'instances of this class' do
|
380
|
-
|
381
|
-
klass = subject.call
|
382
|
-
|
383
|
-
subject do
|
384
|
-
klass.new
|
385
|
-
end
|
325
|
+
subject(:instance) { klass.new }
|
386
326
|
|
387
327
|
it 'should not a accept "invalid" as value for license_plate' do
|
388
|
-
expect {
|
328
|
+
expect { instance.license_plate = "invalid" }.to raise_error(ArgumentError, 'TestDummy does not accept "invalid" as value for the property license_plate')
|
389
329
|
end
|
390
330
|
|
391
331
|
it 'should accept "NE RD 1337" as license plate' do
|
392
|
-
expect {
|
332
|
+
expect { instance.license_plate = "NE RD 1337" }.to_not raise_error
|
393
333
|
end
|
394
|
-
|
395
334
|
end
|
396
|
-
|
397
335
|
end
|
398
336
|
|
399
337
|
context 'when used to build a class that has a property called :text whose getter is overriden' do
|
400
|
-
|
401
|
-
subject do
|
338
|
+
subject(:klass) do
|
402
339
|
Class.new.tap do |c|
|
403
340
|
c.send(:include, described_class)
|
404
341
|
|
@@ -415,24 +352,16 @@ describe SmartProperties do
|
|
415
352
|
end
|
416
353
|
|
417
354
|
context "instances of this class" do
|
418
|
-
|
419
|
-
klass = subject.call
|
420
|
-
|
421
|
-
subject do
|
422
|
-
klass.new
|
423
|
-
end
|
355
|
+
subject(:instance) { klass.new }
|
424
356
|
|
425
357
|
it "should return the accepted value for the property called :text" do
|
426
|
-
|
358
|
+
instance.text.should be == '<em>Hello</em>'
|
427
359
|
end
|
428
|
-
|
429
360
|
end
|
430
|
-
|
431
361
|
end
|
432
362
|
|
433
363
|
context 'when used to build a class that has a property called :id whose default value is a lambda statement' do
|
434
|
-
|
435
|
-
subject do
|
364
|
+
subject(:klass) do
|
436
365
|
counter = Class.new.tap do |c|
|
437
366
|
|
438
367
|
c.class_eval do
|
@@ -454,22 +383,16 @@ describe SmartProperties do
|
|
454
383
|
end
|
455
384
|
|
456
385
|
context "instances of this class" do
|
457
|
-
|
458
|
-
klass = subject.call
|
459
|
-
|
460
386
|
it "should have auto-incrementing ids" do
|
461
387
|
first_instance = klass.new
|
462
388
|
second_instance = klass.new
|
463
389
|
|
464
390
|
(second_instance.id - first_instance.id).should be == 1
|
465
391
|
end
|
466
|
-
|
467
392
|
end
|
468
|
-
|
469
393
|
end
|
470
394
|
|
471
395
|
context 'when used to build a class that is then subclassed and later extended at runtime' do
|
472
|
-
|
473
396
|
let!(:klass) do
|
474
397
|
Class.new.tap do |c|
|
475
398
|
c.send(:include, described_class)
|
@@ -490,16 +413,13 @@ describe SmartProperties do
|
|
490
413
|
end
|
491
414
|
|
492
415
|
context "the class" do
|
493
|
-
|
494
416
|
subject { klass }
|
495
417
|
|
496
418
|
it { should have_smart_property(:title) }
|
497
419
|
it { should have_smart_property(:priority) }
|
498
|
-
|
499
420
|
end
|
500
421
|
|
501
422
|
context 'the subclass' do
|
502
|
-
|
503
423
|
subject { subklass }
|
504
424
|
|
505
425
|
it { should have_smart_property(:title) }
|
@@ -513,7 +433,7 @@ describe SmartProperties do
|
|
513
433
|
s.body = "Lorem ipsum dolor sit amet."
|
514
434
|
end
|
515
435
|
|
516
|
-
expect {
|
436
|
+
expect { subklass.new(&configuration_instructions) }.to_not raise_error
|
517
437
|
end
|
518
438
|
|
519
439
|
it "should be initializable using a hash of attributes" do
|
@@ -523,15 +443,12 @@ describe SmartProperties do
|
|
523
443
|
:body => "Lorem ipsum dolor sit amet."
|
524
444
|
}
|
525
445
|
|
526
|
-
expect {
|
446
|
+
expect { subklass.new(attributes) }.to_not raise_error
|
527
447
|
end
|
528
|
-
|
529
448
|
end
|
530
|
-
|
531
449
|
end
|
532
450
|
|
533
451
|
context "when building a class that has a property which is not required and has a default" do
|
534
|
-
|
535
452
|
subject(:klass) do
|
536
453
|
Class.new.tap do |c|
|
537
454
|
c.send(:include, described_class)
|
@@ -540,43 +457,33 @@ describe SmartProperties do
|
|
540
457
|
end
|
541
458
|
|
542
459
|
context 'instances of that class' do
|
543
|
-
|
544
460
|
context 'when created with a set of attributes that explicitly contains nil for the title' do
|
545
|
-
|
546
461
|
subject(:instance) { klass.new :title => nil }
|
547
462
|
|
548
463
|
it "should have no title" do
|
549
464
|
instance.title.should be_nil
|
550
465
|
end
|
551
|
-
|
552
466
|
end
|
553
467
|
|
554
468
|
context 'when created without any arguments' do
|
555
|
-
|
556
469
|
subject(:instance) { klass.new }
|
557
470
|
|
558
471
|
it "should have the default title" do
|
559
472
|
instance.title.should be == 'Lorem Ipsum'
|
560
473
|
end
|
561
|
-
|
562
474
|
end
|
563
475
|
|
564
476
|
context 'when created with an empty block' do
|
565
|
-
|
566
477
|
subject(:instance) { klass.new {} }
|
567
478
|
|
568
479
|
it "should have the default title" do
|
569
480
|
instance.title.should be == 'Lorem Ipsum'
|
570
481
|
end
|
571
|
-
|
572
482
|
end
|
573
|
-
|
574
483
|
end
|
575
|
-
|
576
484
|
end
|
577
485
|
|
578
486
|
context "when building a class that has a property which is required and has no default" do
|
579
|
-
|
580
487
|
subject(:klass) do
|
581
488
|
Class.new.tap do |c|
|
582
489
|
c.send(:include, described_class)
|
@@ -587,41 +494,31 @@ describe SmartProperties do
|
|
587
494
|
end
|
588
495
|
|
589
496
|
context 'instances of that class' do
|
590
|
-
|
591
497
|
context 'when created with a set of attributes that explicitly contains nil for the title' do
|
592
|
-
|
593
498
|
subject(:instance) { klass.new :title => 'Lorem Ipsum' }
|
594
499
|
|
595
500
|
it "should have no title" do
|
596
501
|
instance.title.should be == 'Lorem Ipsum'
|
597
502
|
end
|
598
|
-
|
599
503
|
end
|
600
504
|
|
601
505
|
context 'when created with an block specifying that property' do
|
602
|
-
|
603
506
|
subject(:instance) { klass.new { |i| i.title = 'Lorem Ipsum' } }
|
604
507
|
|
605
508
|
it "should have the default title" do
|
606
509
|
instance.title.should be == 'Lorem Ipsum'
|
607
510
|
end
|
608
|
-
|
609
511
|
end
|
610
512
|
|
611
513
|
context "when created with no arguments" do
|
612
|
-
|
613
514
|
it "should raise an error stating that required properties are missing" do
|
614
|
-
expect {
|
515
|
+
expect { klass.new }.to raise_error(ArgumentError, "Dummy requires the following properties to be set: title")
|
615
516
|
end
|
616
|
-
|
617
517
|
end
|
618
|
-
|
619
518
|
end
|
620
|
-
|
621
519
|
end
|
622
520
|
|
623
521
|
context "when building a class that has a property which is required depending on the value of another property" do
|
624
|
-
|
625
522
|
subject(:klass) do
|
626
523
|
described_class = self.described_class
|
627
524
|
|
@@ -650,11 +547,9 @@ describe SmartProperties do
|
|
650
547
|
expect { klass.new name: "John Doe", anonymous: false }.to_not raise_error
|
651
548
|
end
|
652
549
|
end
|
653
|
-
|
654
550
|
end
|
655
551
|
|
656
552
|
context "when building a class that has a property which is required and has false as default" do
|
657
|
-
|
658
553
|
subject(:klass) do
|
659
554
|
Class.new.tap do |c|
|
660
555
|
c.send(:include, described_class)
|
@@ -665,39 +560,29 @@ describe SmartProperties do
|
|
665
560
|
end
|
666
561
|
|
667
562
|
context 'instances of that class' do
|
668
|
-
|
669
563
|
context 'when created with a set of attributes that explicitly contains nil for the title' do
|
670
|
-
|
671
564
|
subject(:instance) { klass.new :flag => true }
|
672
565
|
|
673
566
|
it "should have no title" do
|
674
567
|
instance.flag.should be_true
|
675
568
|
end
|
676
|
-
|
677
569
|
end
|
678
570
|
|
679
571
|
context 'when created with an block specifying that property' do
|
680
|
-
|
681
572
|
subject(:instance) { klass.new { |i| i.flag = true } }
|
682
573
|
|
683
574
|
it "should have the default title" do
|
684
575
|
instance.flag.should be_true
|
685
576
|
end
|
686
|
-
|
687
577
|
end
|
688
578
|
|
689
579
|
context "when created with no arguments" do
|
690
|
-
|
691
580
|
subject(:instance) { klass.new }
|
692
581
|
|
693
582
|
it "should have false as default flag" do
|
694
583
|
instance.flag.should be_false
|
695
584
|
end
|
696
|
-
|
697
585
|
end
|
698
|
-
|
699
586
|
end
|
700
|
-
|
701
587
|
end
|
702
|
-
|
703
588
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_properties
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Tennhard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.14'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
26
|
+
version: '2.14'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|