|
17 | 17 | "color"=>"cyan" |
18 | 18 | }} |
19 | 19 | end |
| 20 | + |
| 21 | + let(:object_hash) do |
| 22 | + { |
| 23 | + type: "company", |
| 24 | + id: "aaaaaaaaaaaaaaaaaaaaaaaa", |
| 25 | + app_id: "some-app-id", |
| 26 | + name: "SuperSuite", |
| 27 | + plan_id: 1, |
| 28 | + remote_company_id: "8", |
| 29 | + remote_created_at: 103201, |
| 30 | + created_at: 1374056196, |
| 31 | + user_count: 1, |
| 32 | + custom_attributes: { type: "ping" }, |
| 33 | + metadata: { |
| 34 | + type: "user", |
| 35 | + color: "cyan" |
| 36 | + } |
| 37 | + } |
| 38 | + end |
| 39 | + |
20 | 40 | let(:api_resource) { DummyClass.new.extend(Intercom::Traits::ApiResource)} |
21 | 41 |
|
22 | 42 | before(:each) { api_resource.from_response(object_json) } |
|
76 | 96 | proc { api_resource.send(:flubber=, 'a', 'b') }.must_raise NoMethodError |
77 | 97 | end |
78 | 98 |
|
79 | | - it "an initialized ApiResource is equal to on generated from a response" do |
| 99 | + it "an initialized ApiResource is equal to one generated from a response" do |
80 | 100 | class ConcreteApiResource; include Intercom::Traits::ApiResource; end |
81 | 101 | initialized_api_resource = ConcreteApiResource.new(object_json) |
82 | 102 | except(object_json, 'type').keys.each do |attribute| |
83 | 103 | assert_equal initialized_api_resource.send(attribute), api_resource.send(attribute) |
84 | 104 | end |
85 | 105 | end |
86 | | - |
| 106 | + |
| 107 | + it "initialized ApiResource using hash is equal to one generated from response" do |
| 108 | + class ConcreteApiResource; include Intercom::Traits::ApiResource; end |
| 109 | + |
| 110 | + api_resource.from_hash(object_hash) |
| 111 | + initialized_api_resource = ConcreteApiResource.new(object_hash) |
| 112 | + |
| 113 | + except(object_json, 'type').keys.each do |attribute| |
| 114 | + assert_equal initialized_api_resource.send(attribute), api_resource.send(attribute) |
| 115 | + end |
| 116 | + end |
| 117 | + |
87 | 118 | def except(h, *keys) |
88 | 119 | keys.each { |key| h.delete(key) } |
89 | 120 | h |
90 | 121 | end |
91 | | - |
| 122 | + |
92 | 123 | class DummyClass; end |
93 | 124 | end |
0 commit comments