forked from elastic/elasticsearch-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepository_serialize_test.rb
57 lines (42 loc) · 1.4 KB
/
repository_serialize_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'test_helper'
class Elasticsearch::Persistence::RepositorySerializeTest < Test::Unit::TestCase
context "The repository serialization" do
class DummyDocument
def to_hash
{ foo: 'bar' }
end
end
class MyDocument; end
setup do
@shoulda_subject = Class.new() { include Elasticsearch::Persistence::Repository::Serialize }.new
end
context "serialize" do
should "call #to_hash on passed object" do
document = DummyDocument.new
assert_equal( { foo: 'bar' }, subject.serialize(document))
end
end
context "deserialize" do
should "get the class name from #klass" do
subject.expects(:klass)
.returns(MyDocument)
MyDocument.expects(:new)
subject.deserialize( {} )
end
should "get the class name from Elasticsearch _type" do
subject.expects(:klass)
.returns(nil)
subject.expects(:__get_klass_from_type)
.returns(MyDocument)
MyDocument.expects(:new)
subject.deserialize( {} )
end
should "create the class instance with _source attributes" do
subject.expects(:klass).returns(nil)
subject.expects(:__get_klass_from_type).returns(MyDocument)
MyDocument.expects(:new).with({ 'foo' => 'bar' })
subject.deserialize( {'_source' => { 'foo' => 'bar' } } )
end
end
end
end