accept_values_for 0.4.2 → 0.4.3
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.
- data/Changelog.textile +1 -1
- data/VERSION +1 -1
- data/lib/accept_values_for.rb +6 -0
- data/spec/accept_values_for_spec.rb +12 -4
- metadata +4 -4
data/Changelog.textile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.3
|
data/lib/accept_values_for.rb
CHANGED
@@ -37,6 +37,7 @@ class AcceptValuesFor #:nodoc:
|
|
37
37
|
def matches?(model)
|
38
38
|
@model = model
|
39
39
|
return false unless model.class.included_modules.include?(ActiveModel::Validations)
|
40
|
+
old_value = @model.send(@attribute)
|
40
41
|
@values.each do |value|
|
41
42
|
model.send("#{@attribute}=", value)
|
42
43
|
model.valid?
|
@@ -46,11 +47,14 @@ class AcceptValuesFor #:nodoc:
|
|
46
47
|
end
|
47
48
|
end
|
48
49
|
return true
|
50
|
+
ensure
|
51
|
+
@model.send("#{@attribute}=", old_value) if defined?(old_value)
|
49
52
|
end
|
50
53
|
|
51
54
|
def does_not_match?(model)
|
52
55
|
@model = model
|
53
56
|
return false unless model.class.included_modules.include?(ActiveModel::Validations)
|
57
|
+
old_value = @model.send(@attribute)
|
54
58
|
@values.each do |value|
|
55
59
|
model.send("#{@attribute}=", value)
|
56
60
|
model.valid?
|
@@ -60,6 +64,8 @@ class AcceptValuesFor #:nodoc:
|
|
60
64
|
end
|
61
65
|
end
|
62
66
|
return true
|
67
|
+
ensure
|
68
|
+
@model.send("#{@attribute}=", old_value) if defined?(old_value)
|
63
69
|
end
|
64
70
|
|
65
71
|
def failure_message_for_should
|
@@ -3,10 +3,6 @@ require 'spec_helper'
|
|
3
3
|
describe "AcceptValuesFor" do
|
4
4
|
subject { Person.new(:gender => "MALE", :group => Group.new(:name => "Primary")) }
|
5
5
|
|
6
|
-
it {should accept_values_for(:gender, "MALE", "FEMALE")}
|
7
|
-
it {should_not accept_values_for(:gender, "INVALID", nil)}
|
8
|
-
it { should_not accept_values_for(:group, nil) }
|
9
|
-
it { should accept_values_for(:group, Group.new) }
|
10
6
|
|
11
7
|
it "should have custom condition for should_not" do
|
12
8
|
accept_values_for(:gender, "INVALID", "MALE").does_not_match?(subject).should be_false
|
@@ -20,5 +16,17 @@ describe "AcceptValuesFor" do
|
|
20
16
|
matcher.failure_message_for_should.should == "expected #{subject.inspect} to accept value \"INVALID\" for :gender, but it was not\n" +
|
21
17
|
"Errors: gender is not included in the list"
|
22
18
|
end
|
19
|
+
|
20
|
+
it "should assign the old value for attribute after #matches? " do
|
21
|
+
matcher.matches?(subject).should be_false
|
22
|
+
subject.gender.should == "MALE"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "api" do
|
27
|
+
it { should accept_values_for(:gender, "MALE", "FEMALE")}
|
28
|
+
it { should_not accept_values_for(:gender, "INVALID", nil)}
|
29
|
+
it { should_not accept_values_for(:group, nil) }
|
30
|
+
it { should accept_values_for(:group, Group.new) }
|
23
31
|
end
|
24
32
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: accept_values_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 3
|
10
|
+
version: 0.4.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bogdan Gusiev
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-30 00:00:00 +03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|