Skip to content

Commit 8245a9a

Browse files
authored
Merge pull request zendesk#483 from zendesk/issue321-ticket-comments
Fix zendesk#321 GO! Ticket Comments should be sent unchanged
2 parents 6963221 + 4ea2284 commit 8245a9a

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

lib/zendesk_api/resource.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff 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

lib/zendesk_api/resources.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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

spec/live/ticket_spec.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require '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

0 commit comments

Comments
 (0)