simple_eav 0.4.0 → 0.5.0

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/lib/simple_eav.rb CHANGED
@@ -17,6 +17,10 @@ module SimpleEav
17
17
  end
18
18
 
19
19
  private
20
+ def nested_attributes
21
+ associations_of_class.map{|assoc| "#{assoc}_attributes".to_sym }
22
+ end
23
+
20
24
  def associations_of_class
21
25
  self.class.reflect_on_all_associations.map{|assoc| assoc.name.to_sym }
22
26
  end
@@ -27,7 +31,7 @@ module SimpleEav
27
31
 
28
32
  public
29
33
  def reserved_attributes
30
- associations_of_class + actual_columns_of_table
34
+ associations_of_class + actual_columns_of_table + nested_attributes
31
35
  end
32
36
 
33
37
  def reserved_attribute?(attribute)
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SimpleEav
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -17,13 +17,17 @@ describe SimpleEav do
17
17
  @child = Child.create
18
18
  @person = Person.create(:child=>@child)
19
19
  end
20
+ it "knows the nested attributes of the object" do
21
+ @person.send(:nested_attributes).should include(:child_attributes)
22
+ end
20
23
  it "knows the associations of the object" do
21
24
  @person.send(:associations_of_class).should include(:child)
22
25
  end
23
26
  it "knows the reserved attributes" do
24
27
  @person.should_receive(:associations_of_class).and_return([:child])
25
28
  @person.should_receive(:actual_columns_of_table).and_return([:name])
26
- @person.reserved_attributes.should eql([:child, :name])
29
+ @person.should_receive(:nested_attributes).and_return([:child_attributes])
30
+ @person.reserved_attributes.should eql([:child, :name, :child_attributes])
27
31
  end
28
32
  it "does not accept reserved attributes for eav" do
29
33
  @person.should_receive(:reserved_attributes).and_return([:name, :number])
@@ -57,6 +61,21 @@ describe SimpleEav do
57
61
  @person.simple_eav_attributes.should_not have_key(:child)
58
62
  @person.child.should eql(@child)
59
63
  end
64
+ it "assigns the has_one via the accessor" do
65
+ @person.child = @child
66
+ @person.save!
67
+ @person.simple_eav_attributes.should_not have_key(:child)
68
+ @person.child.should eql(@child)
69
+ end
70
+ end
71
+ describe "nested attributes" do
72
+ it "nests the attributes properly" do
73
+ child = Child.create :name=>'Joe Jr.'
74
+ person = Person.create :child=>child
75
+ lambda{
76
+ person.update_attributes :child_attributes=>{:name=>'John Jr.'}
77
+ }.should change(person.child, :name).from('Joe Jr.').to('John Jr.')
78
+ end
60
79
  end
61
80
  describe "serialization" do
62
81
  it "serializes and deserializes the simple_eav attributes" do
@@ -6,5 +6,6 @@ class Person < ActiveRecord::Base
6
6
  configure_simple_eav :simple_attributes
7
7
 
8
8
  has_one :child
9
+ accepts_nested_attributes_for :child
9
10
  end
10
11
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: simple_eav
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.0
5
+ version: 0.5.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tim Linquist