assignable_values 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -1
- data/lib/assignable_values/active_record/restriction/base.rb +5 -1
- data/lib/assignable_values/active_record/restriction/belongs_to_association.rb +4 -0
- data/lib/assignable_values/version.rb +1 -1
- data/spec/rails-2.3/Gemfile.lock +1 -1
- data/spec/rails-3.0/Gemfile.lock +1 -1
- data/spec/rails-3.2/Gemfile.lock +1 -1
- data/spec/shared/assignable_values/active_record_spec.rb +15 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -193,7 +193,10 @@ Listing and validating als works the same:
|
|
193
193
|
song.artist = lt2
|
194
194
|
song.valid? # => false
|
195
195
|
|
196
|
-
Similiar to scalar attributes, associations are only validated when the foreign key (`artist_id` in the example) changes.
|
196
|
+
Similiar to scalar attributes, associations are only validated when the foreign key (`artist_id` in the example above) changes.
|
197
|
+
Previously saved values will remain assignable until another association has been saved.
|
198
|
+
|
199
|
+
Validation errors will be attached to the association's foreign key (`artist_id` in the example above).
|
197
200
|
|
198
201
|
|
199
202
|
How assignable values are evaluated
|
@@ -21,7 +21,7 @@ module AssignableValues
|
|
21
21
|
unless allow_blank? && value.blank?
|
22
22
|
begin
|
23
23
|
unless assignable_value?(record, value)
|
24
|
-
record.errors.add(
|
24
|
+
record.errors.add(error_property, not_included_error_message)
|
25
25
|
end
|
26
26
|
rescue DelegateUnavailable
|
27
27
|
# if the delegate is unavailable, the validation is skipped
|
@@ -29,6 +29,10 @@ module AssignableValues
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
def error_property
|
33
|
+
property
|
34
|
+
end
|
35
|
+
|
32
36
|
def not_included_error_message
|
33
37
|
I18n.t('errors.messages.inclusion', :default => 'is not included in the list')
|
34
38
|
end
|
data/spec/rails-2.3/Gemfile.lock
CHANGED
data/spec/rails-3.0/Gemfile.lock
CHANGED
data/spec/rails-3.2/Gemfile.lock
CHANGED
@@ -105,6 +105,21 @@ describe AssignableValues::ActiveRecord do
|
|
105
105
|
klass.new(:artist => disallowed_association).should_not be_valid
|
106
106
|
end
|
107
107
|
|
108
|
+
it 'should attach errors to the foreign key of the association, not the association itself ' do
|
109
|
+
allowed_association = Artist.create!
|
110
|
+
disallowed_association = Artist.create!
|
111
|
+
klass = Song.disposable_copy do
|
112
|
+
assignable_values_for :artist do
|
113
|
+
[allowed_association]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
record = klass.new(:artist => disallowed_association)
|
117
|
+
record.valid?
|
118
|
+
errors = record.errors[:artist_id]
|
119
|
+
error = errors.is_a?(Array) ? errors.first : errors # the return value sometimes was a string, sometimes an Array in Rails
|
120
|
+
error.should == I18n.t('errors.messages.inclusion')
|
121
|
+
end
|
122
|
+
|
108
123
|
it 'should allow a nil association if the :allow_blank option is set' do
|
109
124
|
klass = Song.disposable_copy do
|
110
125
|
assignable_values_for :artist, :allow_blank => true 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
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 3
|
10
|
+
version: 0.5.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Henning Koch
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-12-
|
18
|
+
date: 2012-12-19 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|