File tree Expand file tree Collapse file tree 2 files changed +27
-10
lines changed Expand file tree Collapse file tree 2 files changed +27
-10
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,14 @@ def resource_path
39
39
def namespace ( namespace )
40
40
@namespace = namespace
41
41
end
42
+
43
+ def new_from_response ( client , response , includes = nil )
44
+ new ( client ) . tap do |resource |
45
+ resource . handle_response ( response )
46
+ resource . set_includes ( resource , includes , response . body ) if includes
47
+ resource . attributes . clear_changes
48
+ end
49
+ end
42
50
end
43
51
44
52
# @return [Hash] The resource's attributes
@@ -123,19 +131,16 @@ def to_s
123
131
124
132
# Compares resources by class and id. If id is nil, then by object_id
125
133
def ==( other )
134
+ return false unless other
135
+
126
136
return true if other . object_id == object_id
127
137
128
- if other && !( other . is_a? ( Data ) || other . is_a? ( Integer ) )
129
- warn "Trying to compare #{ other . class } to a Resource from #{ caller . first } "
130
- end
138
+ return other . id && ( other . id == id ) if other . is_a? ( Data )
131
139
132
- if other . is_a? ( Data )
133
- other . id && other . id == id
134
- elsif other . is_a? ( Integer )
135
- id == other
136
- else
137
- false
138
- end
140
+ return id == other if other . is_a? ( Integer )
141
+
142
+ warn "Trying to compare #{ other . class } to a Resource
143
+ from #{ caller . first } "
139
144
end
140
145
alias :eql :==
141
146
Original file line number Diff line number Diff line change
1
+ require 'core/spec_helper'
2
+
3
+ RSpec . describe ZendeskAPI ::Data do
4
+ describe ".new_from_response" do
5
+ let ( :response ) { double ( :response ) }
6
+
7
+ it "returns an instance with the response" do
8
+ expect ( described_class . new_from_response ( client , response ) )
9
+ . to be_instance_of ( described_class )
10
+ end
11
+ end
12
+ end
You can’t perform that action at this time.
0 commit comments