Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
dist: trusty
language: ruby
rvm:
# - "1.9.3"
- "2.0.0"
- "2.1.0"
- "2.2.3"
- 2.1
- 2.2
- 2.3
- 2.4
# - "jruby"
# - rbx
# - "1.8.7"
Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.test_files = FileList['test/**/*_test.rb']
t.verbose = true
t.verbose = false
t.warning = false
end

task :default => :test
4 changes: 2 additions & 2 deletions lib/tracker_api/resources/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Story
attribute :integration_id, Integer
attribute :kind, String
attribute :label_ids, [Integer]
attribute :labels, [Label]
attribute :labels, [Label], default: nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason defaulting the labels attribute fixes this issue has to do with the UpdateRepersenter class that specifies that an empty collection should be rendered. This is done so that if you want to clear all the labels you can set story.labels = [] and it will get rendered to json instead of ignored.
collection :labels, class: Label, decorator: Label::UpdateRepresenter, render_empty: true

Here is some example code and output that shows the behavior.

st = Story.new(self.dirty_attributes)
st.labels
>nil
UpdateRepresenter.new(Story.new(st.dirty_attributes)).to_json
>{}
st.labels = []
[]
UpdateRepresenter.new(Story.new(st.dirty_attributes)).to_json
{"labels":[]}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@whysthatso does this make sense?

I am actually working on another branch that will remove the existing dirty tracking. It has caused way more issues than it is worth. IMO.

attribute :name, String
attribute :owned_by_id, Integer # deprecated!
attribute :owned_by, Person
Expand Down Expand Up @@ -62,7 +62,7 @@ class UpdateRepresenter < Representable::Decorator
# @return [String] Comma separated list of labels.
def label_list
@label_list ||= begin
return if labels.nil?
return if labels.nil?
labels.collect(&:name).join(',')
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/project_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@

current = iterations.first
current.velocity.must_equal 10.0
current.points.must_equal 10
current.points.must_equal 9.0
current.accepted_points.must_equal 0
current.effective_points.must_equal 10.0
current.effective_points.must_equal 9.0
end
end

Expand Down
25 changes: 25 additions & 0 deletions test/story_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
let(:project_id) { pt_user_1[:project_id] }
let(:project) { VCR.use_cassette('get project') { client.project(project_id) } }
let(:story_id) { '66728004' }
let(:story_in_epic_id) { '66728030' }
let(:another_story_id) { '66728000' }
let(:story_id_no_existing_labels) { '82330712' }
let(:story) { VCR.use_cassette('get story') { project.story(story_id) } }
Expand Down Expand Up @@ -69,6 +70,30 @@
story.labels.map(&:name).must_include new_label_name
end

it 'does not remove existing labels when updating story fields' do
story_in_epic = nil
VCR.use_cassette('get story in epic') do
story_in_epic = project.story(story_in_epic_id)
end

original_labels = story_in_epic.labels
original_label_list = story_in_epic.label_list

VCR.use_cassette('create story comment', record: :new_episodes) do
story_in_epic.create_comment text: "This is a test comment."
end

story_in_epic.estimate = 2
story_in_epic.current_state = 'started'

VCR.use_cassette('save story in epic', record: :new_episodes) do
story_in_epic.save
end

story_in_epic.labels.must_equal original_labels
story_in_epic.label_list.must_equal original_label_list
end

it 'does not send unmodified fields when saving' do
story_with_one_change = TrackerApi::Resources::Story::UpdateRepresenter.new(TrackerApi::Resources::Story.new(name: "new_name"))
expected_json = MultiJson.dump({name: "new_name"})
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/vcr/cassettes/client_get_single_epic_by_epic_id.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"http_interactions":[{"request":{"method":"get","uri":"https://www.pivotaltracker.com/services/v5/epics/1087314?fields=%3Adefault%2Clabel_id","body":{"encoding":"US-ASCII","string":""},"headers":{"User-Agent":["Ruby/2.2.3 (x86_64-darwin15; ruby) TrackerApi/0.2.12 Faraday/0.9.2"],"X-TrackerToken":["d55c3bc1f74346b843ca84ba340b29bf"]}},"response":{"status":{"code":200,"message":null},"headers":{"Content-Type":["application/json; charset=utf-8"],"Status":["200 OK"],"Cache-Control":["max-age=0, private, must-revalidate"],"Date":["Sat, 13 Feb 2016 23:35:52 GMT"],"X-Tracker-Project-Version":["110"],"X-Request-Id":["798d97291a0d37c3945ad19ecb8ca7cc"],"X-UA-Compatible":["IE=Edge,chrome=1"],"ETag":["\"16fa2db17e653781a8158dcd83c85549\""],"X-Runtime":["0.056851"],"X-Rack-Cache":["miss"],"X-Powered-By":["Phusion Passenger Enterprise"],"Server":["nginx + Phusion Passenger"],"Access-Control-Allow-Origin":["*"],"Access-Control-Allow-Credentials":["false"],"Access-Control-Allow-Methods":["GET, POST, PUT, DELETE, OPTIONS"],"Access-Control-Allow-Headers":["X-TrackerToken,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Tracker-Warn-Unless-Project-Version-Is"],"X-Tracker-Client-Pinger-Interval":["12"]},"body":{"encoding":"UTF-8","string":"{\"id\":1087314,\"kind\":\"epic\",\"created_at\":\"2014-03-02T07:11:07Z\",\"updated_at\":\"2014-03-02T07:11:07Z\",\"project_id\":1027488,\"name\":\"Admin Users\",\"label_id\":7849080,\"description\":\"Get the Admin users working on the site\",\"url\":\"https://www.pivotaltracker.com/epic/show/1087314\",\"label\":{\"id\":7849080,\"project_id\":1027488,\"kind\":\"label\",\"name\":\"admin\",\"created_at\":\"2014-03-02T07:11:04Z\",\"updated_at\":\"2014-03-02T07:11:04Z\"}}"},"http_version":null},"recorded_at":"Sat, 13 Feb 2016 23:35:52 GMT"}],"recorded_with":"VCR 2.9.3"}
{"http_interactions":[{"request":{"method":"get","uri":"https://www.pivotaltracker.com/services/v5/epics/1087314?fields=%3Adefault%2Clabel_id","body":{"encoding":"US-ASCII","string":""},"headers":{"User-Agent":["Ruby/2.3.1 (x86_64-darwin15; ruby) TrackerApi/1.7.0 Faraday/0.9.2"],"X-TrackerToken":["d55c3bc1f74346b843ca84ba340b29bf"]}},"response":{"status":{"code":200,"message":null},"headers":{"Access-Control-Allow-Credentials":["false"],"Access-Control-Allow-Headers":["X-TrackerToken,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Tracker-Warn-Unless-Project-Version-Is"],"Access-Control-Allow-Methods":["GET, POST, PUT, DELETE, OPTIONS"],"Access-Control-Allow-Origin":["*"],"Cache-Control":["max-age=0, private, must-revalidate"],"Content-Type":["application/json; charset=utf-8"],"Date":["Wed, 03 May 2017 23:29:50 GMT"],"Etag":["\"16fa2db17e653781a8158dcd83c85549\""],"Server":["nginx + Phusion Passenger"],"Status":["200 OK"],"Strict-Transport-Security":["max-age=31536000; includeSubDomains; preload"],"X-Content-Type-Options":["nosniff"],"X-Powered-By":["Phusion Passenger Enterprise"],"X-Rack-Cache":["miss"],"X-Request-Id":["83a1d5edaef1ef6083fcb6068dd06bfb"],"X-Runtime":["0.057815"],"X-Tracker-Client-Pinger-Interval":["20"],"X-Tracker-Project-Version":["241"],"X-Ua-Compatible":["IE=Edge,chrome=1"],"X-Vcap-Request-Id":["102072a1-25b8-4ba6-4773-560f7eb224b8"],"X-Xss-Protection":["1; mode=block"],"Content-Length":["420"],"Connection":["keep-alive"]},"body":{"encoding":"ASCII-8BIT","string":"{\"id\":1087314,\"kind\":\"epic\",\"created_at\":\"2014-03-02T07:11:07Z\",\"updated_at\":\"2014-03-02T07:11:07Z\",\"project_id\":1027488,\"name\":\"Admin Users\",\"label_id\":7849080,\"description\":\"Get the Admin users working on the site\",\"url\":\"https://www.pivotaltracker.com/epic/show/1087314\",\"label\":{\"id\":7849080,\"project_id\":1027488,\"kind\":\"label\",\"name\":\"admin\",\"created_at\":\"2014-03-02T07:11:04Z\",\"updated_at\":\"2014-03-02T07:11:04Z\"}}"},"http_version":null},"recorded_at":"Wed, 03 May 2017 23:29:50 GMT"}],"recorded_with":"VCR 2.9.3"}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"http_interactions":[{"request":{"method":"get","uri":"https://www.pivotaltracker.com/services/v5/stories/66728004?fields=%3Adefault%2Cowned_by","body":{"encoding":"US-ASCII","string":""},"headers":{"User-Agent":["Ruby/2.2.3 (x86_64-darwin15; ruby) TrackerApi/0.2.12 Faraday/0.9.2"],"X-TrackerToken":["d55c3bc1f74346b843ca84ba340b29bf"]}},"response":{"status":{"code":200,"message":null},"headers":{"Content-Type":["application/json; charset=utf-8"],"Status":["200 OK"],"Cache-Control":["max-age=0, private, must-revalidate"],"Date":["Sat, 13 Feb 2016 23:35:36 GMT"],"X-Tracker-Project-Version":["107"],"X-Request-Id":["a8861b6b68bd9e9bbb4829391334f828"],"X-UA-Compatible":["IE=Edge,chrome=1"],"ETag":["\"64f7e7eb0899d244453e1aed4be1cc3a\""],"X-Runtime":["0.060215"],"X-Rack-Cache":["miss"],"X-Powered-By":["Phusion Passenger Enterprise"],"Server":["nginx + Phusion Passenger"],"Access-Control-Allow-Origin":["*"],"Access-Control-Allow-Credentials":["false"],"Access-Control-Allow-Methods":["GET, POST, PUT, DELETE, OPTIONS"],"Access-Control-Allow-Headers":["X-TrackerToken,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Tracker-Warn-Unless-Project-Version-Is"],"X-Tracker-Client-Pinger-Interval":["12"]},"body":{"encoding":"UTF-8","string":"{\"kind\":\"story\",\"id\":66728004,\"created_at\":\"2014-02-17T00:00:00Z\",\"updated_at\":\"2016-02-12T23:45:31Z\",\"story_type\":\"bug\",\"name\":\"Some product photos not scaled properly when browsing products++++\",\"description\":\"+++++\",\"current_state\":\"started\",\"requested_by_id\":1266314,\"url\":\"https://www.pivotaltracker.com/story/show/66728004\",\"project_id\":1027488,\"owned_by\":{\"kind\":\"person\",\"id\":1266314,\"name\":\"Tracker API User1\",\"email\":\"forestcarlisle+trackerapi1@gmail.com\",\"initials\":\"TU1\",\"username\":\"trackerapi1\"},\"owner_ids\":[1266314,1266316],\"labels\":[{\"id\":11049868,\"project_id\":1027488,\"kind\":\"label\",\"name\":\"label1\",\"created_at\":\"2015-03-07T12:51:39Z\",\"updated_at\":\"2015-03-07T12:51:39Z\"},{\"id\":11049870,\"project_id\":1027488,\"kind\":\"label\",\"name\":\"label2\",\"created_at\":\"2015-03-07T12:51:39Z\",\"updated_at\":\"2015-03-07T12:51:39Z\"},{\"id\":14060665,\"project_id\":1027488,\"kind\":\"label\",\"name\":\"super-special-label\",\"created_at\":\"2016-02-12T23:45:13Z\",\"updated_at\":\"2016-02-12T23:45:13Z\"}]}"},"http_version":null},"recorded_at":"Sat, 13 Feb 2016 23:35:35 GMT"},{"request":{"method":"get","uri":"https://www.pivotaltracker.com/services/v5/projects//stories//comments","body":{"encoding":"US-ASCII","string":""},"headers":{"User-Agent":["Ruby/2.2.3 (x86_64-darwin15; ruby) TrackerApi/0.2.12 Faraday/0.9.2"],"X-TrackerToken":["d55c3bc1f74346b843ca84ba340b29bf"]}},"response":{"status":{"code":404,"message":null},"headers":{"Content-Type":["application/json; charset=utf-8"],"Status":["404 Not Found"],"Date":["Mon, 15 Feb 2016 19:50:24 GMT"],"X-Request-Id":["1c5eedf378a6959173ad03e7747e40be"],"X-Runtime":["0.041317"],"X-Rack-Cache":["miss"],"X-Powered-By":["Phusion Passenger Enterprise"],"Server":["nginx + Phusion Passenger"]},"body":{"encoding":"UTF-8","string":"{\"code\":\"route_not_found\",\"kind\":\"error\",\"error\":\"The path you requested has no valid endpoint.\"}"},"http_version":null},"recorded_at":"Mon, 15 Feb 2016 19:50:24 GMT"}],"recorded_with":"VCR 2.9.3"}
{"http_interactions":[{"request":{"method":"get","uri":"https://www.pivotaltracker.com/services/v5/stories/66728004?fields=%3Adefault%2Cowned_by","body":{"encoding":"US-ASCII","string":""},"headers":{"User-Agent":["Ruby/2.3.1 (x86_64-darwin15; ruby) TrackerApi/1.7.0 Faraday/0.9.2"],"X-TrackerToken":["d55c3bc1f74346b843ca84ba340b29bf"]}},"response":{"status":{"code":200,"message":null},"headers":{"Access-Control-Allow-Credentials":["false"],"Access-Control-Allow-Headers":["X-TrackerToken,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Tracker-Warn-Unless-Project-Version-Is"],"Access-Control-Allow-Methods":["GET, POST, PUT, DELETE, OPTIONS"],"Access-Control-Allow-Origin":["*"],"Cache-Control":["max-age=0, private, must-revalidate"],"Content-Type":["application/json; charset=utf-8"],"Date":["Wed, 03 May 2017 23:30:03 GMT"],"Etag":["\"ecbeb5a97319b337e5f11374e371b2be\""],"Server":["nginx + Phusion Passenger"],"Status":["200 OK"],"Strict-Transport-Security":["max-age=31536000; includeSubDomains; preload"],"X-Content-Type-Options":["nosniff"],"X-Powered-By":["Phusion Passenger Enterprise"],"X-Rack-Cache":["miss"],"X-Request-Id":["95f9c3475f72a6044bb0aed45924b35d"],"X-Runtime":["0.082890"],"X-Tracker-Client-Pinger-Interval":["20"],"X-Tracker-Project-Version":["242"],"X-Ua-Compatible":["IE=Edge,chrome=1"],"X-Vcap-Request-Id":["f97d056d-d0ba-4fa5-6bfb-37eb812ddc38"],"X-Xss-Protection":["1; mode=block"],"Content-Length":["993"],"Connection":["keep-alive"]},"body":{"encoding":"ASCII-8BIT","string":"{\"kind\":\"story\",\"id\":66728004,\"created_at\":\"2014-02-17T00:00:00Z\",\"updated_at\":\"2017-05-03T23:30:01Z\",\"story_type\":\"bug\",\"name\":\"Some product photos not scaled properly when browsing products+++++++++\",\"description\":\"++++++++++\",\"current_state\":\"started\",\"requested_by_id\":1266314,\"url\":\"https://www.pivotaltracker.com/story/show/66728004\",\"project_id\":1027488,\"owned_by\":{\"kind\":\"person\",\"id\":1266314,\"name\":\"Tracker API User1\",\"email\":\"forestcarlisle+trackerapi1@gmail.com\",\"initials\":\"TU1\",\"username\":\"trackerapi1\"},\"owner_ids\":[1266314,1266316],\"labels\":[{\"id\":11049868,\"project_id\":1027488,\"kind\":\"label\",\"name\":\"label1\",\"created_at\":\"2015-03-07T12:51:39Z\",\"updated_at\":\"2015-03-07T12:51:39Z\"},{\"id\":11049870,\"project_id\":1027488,\"kind\":\"label\",\"name\":\"label2\",\"created_at\":\"2015-03-07T12:51:39Z\",\"updated_at\":\"2015-03-07T12:51:39Z\"},{\"id\":14060665,\"project_id\":1027488,\"kind\":\"label\",\"name\":\"super-special-label\",\"created_at\":\"2016-02-12T23:45:13Z\",\"updated_at\":\"2016-02-12T23:45:13Z\"}]}"},"http_version":null},"recorded_at":"Wed, 03 May 2017 23:30:03 GMT"}],"recorded_with":"VCR 2.9.3"}
2 changes: 1 addition & 1 deletion test/vcr/cassettes/create_comment.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"http_interactions":[{"request":{"method":"post","uri":"https://www.pivotaltracker.com/services/v5/projects/1027488/stories/66728004/comments","body":{"encoding":"UTF-8","string":"{\"text\":\"Test creating a comment\"}"},"headers":{"User-Agent":["Ruby/2.2.3 (x86_64-darwin14; ruby) TrackerApi/1.4.1 Faraday/0.9.2"],"X-TrackerToken":["d55c3bc1f74346b843ca84ba340b29bf"],"Content-Type":["application/json"]}},"response":{"status":{"code":200,"message":null},"headers":{"Access-Control-Allow-Credentials":["false"],"Access-Control-Allow-Headers":["X-TrackerToken,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Tracker-Warn-Unless-Project-Version-Is"],"Access-Control-Allow-Methods":["GET, POST, PUT, DELETE, OPTIONS"],"Access-Control-Allow-Origin":["*"],"Cache-Control":["max-age=0, private, must-revalidate"],"Content-Type":["application/json; charset=utf-8"],"Date":["Wed, 16 Nov 2016 14:17:47 GMT"],"Etag":["\"05a4afa88e8d89128c99e3803eb746cd\""],"Server":["nginx + Phusion Passenger"],"Status":["200 OK"],"Strict-Transport-Security":["max-age=31536000; includeSubDomains"],"X-Powered-By":["Phusion Passenger"],"X-Rack-Cache":["invalidate, pass"],"X-Request-Id":["c64522554bfcacb90f63fea5c9025473"],"X-Runtime":["0.148598"],"X-Tracker-Client-Pinger-Interval":["20"],"X-Tracker-Project-Version":["155"],"X-Ua-Compatible":["IE=Edge,chrome=1"],"X-Vcap-Request-Id":["27b5c8de-19f9-46c8-42b0-8fd3f82ed5cb"],"Content-Length":["178"],"Connection":["keep-alive"]},"body":{"encoding":"ASCII-8BIT","string":"{\"kind\":\"comment\",\"id\":155658605,\"story_id\":66728004,\"text\":\"Test creating a comment\",\"person_id\":1266314,\"created_at\":\"2016-11-16T14:17:47Z\",\"updated_at\":\"2016-11-16T14:17:47Z\"}"},"http_version":null},"recorded_at":"Wed, 16 Nov 2016 14:17:48 GMT"}],"recorded_with":"VCR 3.0.3"}
{"http_interactions":[{"request":{"method":"post","uri":"https://www.pivotaltracker.com/services/v5/projects/1027488/stories/66728004/comments","body":{"encoding":"UTF-8","string":"{\"text\":\"Test creating a comment\"}"},"headers":{"User-Agent":["Ruby/2.3.1 (x86_64-darwin15; ruby) TrackerApi/1.7.0 Faraday/0.9.2"],"X-TrackerToken":["d55c3bc1f74346b843ca84ba340b29bf"],"Content-Type":["application/json"]}},"response":{"status":{"code":200,"message":null},"headers":{"Access-Control-Allow-Credentials":["false"],"Access-Control-Allow-Headers":["X-TrackerToken,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Tracker-Warn-Unless-Project-Version-Is"],"Access-Control-Allow-Methods":["GET, POST, PUT, DELETE, OPTIONS"],"Access-Control-Allow-Origin":["*"],"Cache-Control":["max-age=0, private, must-revalidate"],"Content-Type":["application/json; charset=utf-8"],"Date":["Wed, 03 May 2017 23:29:39 GMT"],"Etag":["\"da92c553a8b55689359d240720a6f827\""],"Server":["nginx + Phusion Passenger"],"Status":["200 OK"],"Strict-Transport-Security":["max-age=31536000; includeSubDomains; preload"],"X-Content-Type-Options":["nosniff"],"X-Powered-By":["Phusion Passenger Enterprise"],"X-Rack-Cache":["invalidate, pass"],"X-Request-Id":["6d3b5cb0981a0bc97a2d9f0961324dcc"],"X-Runtime":["0.205489"],"X-Tracker-Client-Pinger-Interval":["20"],"X-Tracker-Project-Version":["232"],"X-Ua-Compatible":["IE=Edge,chrome=1"],"X-Vcap-Request-Id":["dadd7537-fe99-477d-653f-1951652b588e"],"X-Xss-Protection":["1; mode=block"],"Content-Length":["178"],"Connection":["keep-alive"]},"body":{"encoding":"ASCII-8BIT","string":"{\"kind\":\"comment\",\"id\":170363243,\"story_id\":66728004,\"text\":\"Test creating a comment\",\"person_id\":1266314,\"created_at\":\"2017-05-03T23:29:39Z\",\"updated_at\":\"2017-05-03T23:29:39Z\"}"},"http_version":null},"recorded_at":"Wed, 03 May 2017 23:29:39 GMT"}],"recorded_with":"VCR 2.9.3"}
Loading