Skip to content

Commit fad8b50

Browse files
vhyzakarmi
authored andcommitted
[STORE] Added @mymodel.id= setter method
(For example, it seems FactoryGirl is setting attributes using instance setter methods...) Closes elastic#149
1 parent fc55ab3 commit fad8b50

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

elasticsearch-persistence/lib/elasticsearch/persistence/model/base.rb

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ def id
2525
@_id
2626
end; alias :_id :id
2727

28+
# Set the document `_id`
29+
#
30+
def id=(value)
31+
@_id = value
32+
end; alias :_id= :id=
33+
2834
# Return the document `_index`
2935
#
3036
def _index

elasticsearch-persistence/test/unit/model_base_test.rb

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ class DummyBaseModel
2727
assert_equal 2, m.id
2828
end
2929

30+
should "set the ID using setter method" do
31+
m = DummyBaseModel.new id: 1
32+
assert_equal 1, m.id
33+
34+
m.id = 2
35+
assert_equal 2, m.id
36+
end
37+
3038
should "have ID in attributes" do
3139
m = DummyBaseModel.new id: 1, name: 'Test'
3240
assert_equal 1, m.attributes[:id]

0 commit comments

Comments
 (0)