accept_values_for 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -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[@attribute] = value
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
@@ -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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Bogdan Gusiev