validates_belongs_to 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
data/lib/validates_belongs_to.rb
CHANGED
@@ -19,7 +19,7 @@ module ValidatesBelongsTo
|
|
19
19
|
record_value = get_id_by_association(record, options[:with])
|
20
20
|
owner_value = get_id_by_association(owner, options[:with])
|
21
21
|
|
22
|
-
unless record_value == owner_value
|
22
|
+
unless record_value == owner_value || owner_value.nil?
|
23
23
|
record.errors.add(attribute, :belongs_to, options.merge(:value => options[:with]))
|
24
24
|
end
|
25
25
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ValidatesBelongsTo do
|
4
4
|
|
5
|
-
|
5
|
+
describe :validation do
|
6
6
|
|
7
7
|
let(:user) { User.create }
|
8
8
|
let(:user_2) { User.create }
|
@@ -15,6 +15,20 @@ describe ValidatesBelongsTo do
|
|
15
15
|
it { should allow_value(warehouse).for(:warehouse) }
|
16
16
|
it { should_not allow_value(warehouse_2).for(:warehouse).with_message('does not belong to user') }
|
17
17
|
|
18
|
+
describe 'when association owner is set to nil' do
|
19
|
+
|
20
|
+
it { should allow_value(Warehouse.create).for(:warehouse) }
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'when record owner is set to nil' do
|
25
|
+
|
26
|
+
subject { Car.new }
|
27
|
+
|
28
|
+
it { should_not allow_value(warehouse).for(:warehouse) }
|
29
|
+
|
30
|
+
end
|
31
|
+
|
18
32
|
end
|
19
33
|
|
20
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validates_belongs_to
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
segments:
|
111
111
|
- 0
|
112
|
-
hash:
|
112
|
+
hash: 934803748451263386
|
113
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
114
|
none: false
|
115
115
|
requirements:
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
segments:
|
120
120
|
- 0
|
121
|
-
hash:
|
121
|
+
hash: 934803748451263386
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project: validates_belongs_to
|
124
124
|
rubygems_version: 1.8.24
|