active_node 0.0.5 → 0.0.6

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.
@@ -15,5 +15,15 @@ module ActiveNode::Associations::Builder
15
15
  end
16
16
  CODE
17
17
  end
18
+
19
+ def define_writers
20
+ super
21
+
22
+ mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
23
+ def #{name}_id=(value)
24
+ association(:#{name}).id_writer(value)
25
+ end
26
+ CODE
27
+ end
18
28
  end
19
29
  end
@@ -12,6 +12,10 @@ module ActiveNode
12
12
  def ids_reader
13
13
  [target.try(:id)].compact
14
14
  end
15
+
16
+ def id_writer(id)
17
+ writer(klass.find(id.to_i))
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveNode
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -92,6 +92,14 @@ describe ActiveNode::Associations do
92
92
  father.children.should == [child]
93
93
  end
94
94
 
95
+ it 'can set has_one relation by id' do
96
+ father = Person.create!
97
+ child = Person.create!
98
+ child.father_id = father.id
99
+ child.save
100
+ father.children.should == [child]
101
+ end
102
+
95
103
  it "can access new association without being saved" do
96
104
  father = Person.create!
97
105
  child = Person.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_node
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-23 00:00:00.000000000 Z
12
+ date: 2013-10-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: active_attr