File tree Expand file tree Collapse file tree 3 files changed +37
-4
lines changed Expand file tree Collapse file tree 3 files changed +37
-4
lines changed Original file line number Diff line number Diff line change @@ -146,10 +146,16 @@ def inspect
146146
147147 alias :to_param :attributes
148148
149+ def attributes_for_save
150+ { self . class . singular_resource_name . to_sym => attribute_changes }
151+ end
152+
149153 private
150154
151- def attributes_for_save
152- { self . class . singular_resource_name . to_sym => attributes . changes }
155+ # Send only the changes, for example, if the "status" attriubte
156+ # goes from "new" to "new", we don't need to send anything
157+ def attribute_changes
158+ attributes . changes
153159 end
154160 end
155161
@@ -190,7 +196,7 @@ class Resource < DataResource
190196
191197 class SingularResource < Resource
192198 def attributes_for_save
193- { self . class . resource_name . to_sym => attributes . changes }
199+ { self . class . resource_name . to_sym => attribute_changes }
194200 end
195201 end
196202
Original file line number Diff line number Diff line change @@ -353,6 +353,13 @@ class Ticket < Resource
353353 extend UpdateMany
354354 extend DestroyMany
355355
356+ # Unlike other attributes, "comment" is not a property of the ticket,
357+ # but is used as a "comment on save", so it should be kept unchanged,
358+ # See https://github.com/zendesk/zendesk_api_client_rb/issues/321
359+ def attribute_changes
360+ attributes . changes . merge ( "comment" => attributes [ "comment" ] )
361+ end
362+
356363 class Audit < DataResource
357364 class Event < Data
358365 has :author , :class => User
Original file line number Diff line number Diff line change 11require 'core/spec_helper'
22
3- describe ZendeskAPI ::Ticket do
3+ RSpec . describe ZendeskAPI ::Ticket do
44 def valid_attributes
55 {
66 :type => "question" ,
@@ -27,6 +27,26 @@ def valid_attributes
2727 it_should_be_readable agent , :ccd_tickets , create : true
2828 it_should_be_readable organization , :tickets
2929
30+ describe "#attributes_for_save" do
31+ let :ticket do
32+ described_class . new ( instance_double ( ZendeskAPI ::Client ) , status : :new )
33+ end
34+
35+ it "keeps all the comments" , :vcr do
36+ ticket . update ( comment : { private : true , body : "Private comment" } )
37+ expect ( ticket . attributes_for_save ) . to eq ( ticket : {
38+ "status" => :new ,
39+ "comment" => { "private" => true , "body" => "Private comment" }
40+ } )
41+
42+ ticket . update ( comment : { private : true , body : "Private comment2" } )
43+ expect ( ticket . attributes_for_save ) . to eq ( ticket : {
44+ "status" => :new ,
45+ "comment" => { "private" => true , "body" => "Private comment2" }
46+ } )
47+ end
48+ end
49+
3050 context "recent tickets" do
3151 before ( :all ) do
3252 VCR . use_cassette ( "visit_recent_ticket" ) do
You can’t perform that action at this time.
0 commit comments