accept_values_for 0.1.0 → 0.1.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.
- data/VERSION +1 -1
- data/lib/accept_values_for.rb +1 -1
- data/spec/accept_values_for_spec.rb +3 -1
- data/spec/spec_helper.rb +12 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/accept_values_for.rb
CHANGED
@@ -37,7 +37,7 @@ class AcceptValuesFor #:nodoc:
|
|
37
37
|
@model = model
|
38
38
|
return false unless model.is_a?(ActiveRecord::Base)
|
39
39
|
@values.each do |value|
|
40
|
-
model
|
40
|
+
model.send("#{@attribute}=", value)
|
41
41
|
unless model.valid?
|
42
42
|
@failed_value = value
|
43
43
|
return false
|
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "AcceptValuesFor" do
|
4
|
-
subject { Person.new }
|
4
|
+
subject { Person.new(:gender => "MALE", :group => Group.new(:name => "Primary")) }
|
5
5
|
|
6
6
|
it {should accept_values_for(:gender, "MALE", "FEMALE")}
|
7
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) }
|
8
10
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,17 +12,29 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
12
12
|
|
13
13
|
create_table :people do |t|
|
14
14
|
t.string :gender
|
15
|
+
t.integer :group_id
|
16
|
+
end
|
17
|
+
|
18
|
+
create_table :groups do |t|
|
19
|
+
t.string :name
|
15
20
|
end
|
16
21
|
end
|
17
22
|
|
18
23
|
Spec::Runner.configure do |config|
|
19
24
|
config.before(:each) do
|
25
|
+
class ::Group < ActiveRecord::Base
|
26
|
+
|
27
|
+
end
|
28
|
+
|
20
29
|
class ::Person < ActiveRecord::Base
|
30
|
+
belongs_to :group
|
21
31
|
validates_inclusion_of :gender, :in => ["MALE", "FEMALE"]
|
32
|
+
validates_presence_of :group
|
22
33
|
end
|
23
34
|
end
|
24
35
|
|
25
36
|
config.after(:each) do
|
26
37
|
Object.send(:remove_const, :Person)
|
38
|
+
Object.send(:remove_const, :Group)
|
27
39
|
end
|
28
40
|
end
|