assignable_values 0.4.0 → 0.4.1
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.
@@ -49,11 +49,15 @@ module AssignableValues
|
|
49
49
|
def set_default(record)
|
50
50
|
if record.new_record? && record.send(property).nil?
|
51
51
|
default_value = evaluate_default(record, default)
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
begin
|
53
|
+
if secondary_default? && !assignable_value?(record, default_value)
|
54
|
+
secondary_default_value = evaluate_default(record, secondary_default)
|
55
|
+
if assignable_value?(record, secondary_default_value)
|
56
|
+
default_value = secondary_default_value
|
57
|
+
end
|
56
58
|
end
|
59
|
+
rescue AssignableValues::DelegateUnavailable
|
60
|
+
# skip secondary defaults if querying assignable values from a nil delegate
|
57
61
|
end
|
58
62
|
record.send("#{property}=", default_value)
|
59
63
|
end
|
@@ -321,6 +321,15 @@ describe AssignableValues::ActiveRecord do
|
|
321
321
|
klass.new.genre.should == 'pop'
|
322
322
|
end
|
323
323
|
|
324
|
+
it "should not raise an error or change the primary default if assignable values are retrieved through a delegate, and the delegate is nil" do
|
325
|
+
klass = disposable_song_class do
|
326
|
+
assignable_values_for :genre, :default => 'techno', :secondary_default => 'pop', :through => lambda { nil }
|
327
|
+
end
|
328
|
+
expect do
|
329
|
+
klass.new.genre.should == 'techno'
|
330
|
+
end.to_not raise_error
|
331
|
+
end
|
332
|
+
|
324
333
|
it 'should not cause the list of assignable values to be evaluated if the :secondary_default option is not used' do
|
325
334
|
klass = disposable_song_class do
|
326
335
|
assignable_values_for :genre, :default => 'techno' do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assignable_values
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 1
|
10
|
+
version: 0.4.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Henning Koch
|