From 374d33d29e328a5eab979cd5c9c9097e46d3c00e Mon Sep 17 00:00:00 2001 From: Zubin Wang Date: Wed, 19 Oct 2016 15:05:44 -0700 Subject: [PATCH 1/2] Fix bug add_label to story w/o existing labels Fixes https://github.com/dashofcode/tracker_api/issues/81 --- lib/tracker_api/resources/story.rb | 2 +- test/story_test.rb | 16 ++++++++++++++++ .../cassettes/get_story_no_existing_labels.json | 1 + ...previously_no_label_story_with_new_label.json | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/vcr/cassettes/get_story_no_existing_labels.json create mode 100644 test/vcr/cassettes/save_previously_no_label_story_with_new_label.json diff --git a/lib/tracker_api/resources/story.rb b/lib/tracker_api/resources/story.rb index b523118..c42b59d 100644 --- a/lib/tracker_api/resources/story.rb +++ b/lib/tracker_api/resources/story.rb @@ -74,7 +74,7 @@ def add_label(label) end # Use attribute writer to get coercion and dirty tracking. - self.labels = @labels.dup.push(new_label) + self.labels = (labels ? labels.dup : []).push(new_label) end # Provides a list of all the activity performed on the story. diff --git a/test/story_test.rb b/test/story_test.rb index a2547fe..a4c8d52 100644 --- a/test/story_test.rb +++ b/test/story_test.rb @@ -7,6 +7,7 @@ let(:project) { VCR.use_cassette('get project') { client.project(project_id) } } let(:story_id) { '66728004' } let(:another_story_id) { '66728000' } + let(:story_id_no_existing_labels) { '82330712' } let(:story) { VCR.use_cassette('get story') { project.story(story_id) } } it 'can update an existing story' do @@ -50,6 +51,21 @@ story.labels.map(&:name).must_include new_label_name end + it 'can add new labels to an existing story without existing labels' do + story = VCR.use_cassette('get story no existing labels') { project.story(story_id_no_existing_labels) } + story.labels.must_be_nil + + new_label_name = "super-special-label" + story.add_label(new_label_name) + + VCR.use_cassette('save previously no label story with new label', record: :new_episodes) do + story.save + end + + story.labels.wont_be_empty + story.labels.map(&:name).must_include new_label_name + 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"}) diff --git a/test/vcr/cassettes/get_story_no_existing_labels.json b/test/vcr/cassettes/get_story_no_existing_labels.json new file mode 100644 index 0000000..59b51ba --- /dev/null +++ b/test/vcr/cassettes/get_story_no_existing_labels.json @@ -0,0 +1 @@ +{"http_interactions":[{"request":{"method":"get","uri":"https://www.pivotaltracker.com/services/v5/projects/1027488/stories/82330712","body":{"encoding":"US-ASCII","string":""},"headers":{"User-Agent":["Ruby/2.2.1 (x86_64-darwin14; ruby) TrackerApi/1.4.0 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":["Wed, 19 Oct 2016 22:02:43 GMT"],"X-Tracker-Project-Version":["152"],"X-Request-Id":["0785925ab787c672fc149a4fc45a5a4c"],"X-UA-Compatible":["IE=Edge,chrome=1"],"ETag":["\"c417249619fc699ecb6ef773d35cf7dd\""],"X-Runtime":["0.050834"],"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":"ASCII-8BIT","string":"{\"kind\":\"story\",\"id\":82330712,\"created_at\":\"2014-11-08T00:23:58Z\",\"updated_at\":\"2015-01-27T00:35:58Z\",\"estimate\":1,\"story_type\":\"feature\",\"name\":\"Test story\",\"current_state\":\"started\",\"requested_by_id\":1266314,\"url\":\"https://www.pivotaltracker.com/story/show/82330712\",\"project_id\":1027488,\"owner_ids\":[1266316,1266314],\"labels\":[],\"owned_by_id\":1266316}"},"http_version":null},"recorded_at":"Wed, 19 Oct 2016 22:02:43 GMT"}],"recorded_with":"VCR 3.0.3"} \ No newline at end of file diff --git a/test/vcr/cassettes/save_previously_no_label_story_with_new_label.json b/test/vcr/cassettes/save_previously_no_label_story_with_new_label.json new file mode 100644 index 0000000..2ddf199 --- /dev/null +++ b/test/vcr/cassettes/save_previously_no_label_story_with_new_label.json @@ -0,0 +1 @@ +{"http_interactions":[{"request":{"method":"put","uri":"https://www.pivotaltracker.com/services/v5/projects/1027488/stories/82330712","body":{"encoding":"UTF-8","string":"{\"labels\":[{\"name\":\"super-special-label\"}]}"},"headers":{"User-Agent":["Ruby/2.2.1 (x86_64-darwin14; ruby) TrackerApi/1.4.0 Faraday/0.9.2"],"X-TrackerToken":["d55c3bc1f74346b843ca84ba340b29bf"],"Content-Type":["application/json"]}},"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":["Wed, 19 Oct 2016 22:03:47 GMT"],"X-Tracker-Project-Version":["153"],"X-Request-Id":["9309467ba390eac143a26031f9efcbcd"],"X-UA-Compatible":["IE=Edge,chrome=1"],"ETag":["\"702ec0ceab01c6c09792aeba14f63817\""],"X-Runtime":["0.199548"],"X-Rack-Cache":["invalidate, pass"],"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":"ASCII-8BIT","string":"{\"kind\":\"story\",\"id\":82330712,\"project_id\":1027488,\"name\":\"Test story\",\"story_type\":\"feature\",\"current_state\":\"started\",\"estimate\":1,\"requested_by_id\":1266314,\"owned_by_id\":1266316,\"owner_ids\":[1266316,1266314],\"labels\":[{\"kind\":\"label\",\"id\":14060665,\"project_id\":1027488,\"name\":\"super-special-label\",\"created_at\":\"2016-02-12T23:45:13Z\",\"updated_at\":\"2016-02-12T23:45:13Z\"}],\"created_at\":\"2014-11-08T00:23:58Z\",\"updated_at\":\"2016-10-19T22:03:47Z\",\"url\":\"https://www.pivotaltracker.com/story/show/82330712\"}"},"http_version":null},"recorded_at":"Wed, 19 Oct 2016 22:03:47 GMT"}],"recorded_with":"VCR 3.0.3"} \ No newline at end of file From 67356180839ba397f85016ba758e9af4c82457e3 Mon Sep 17 00:00:00 2001 From: Zubin Wang Date: Wed, 19 Oct 2016 15:21:50 -0700 Subject: [PATCH 2/2] Bump version to 1.4.1 --- lib/tracker_api/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tracker_api/version.rb b/lib/tracker_api/version.rb index a3fa6bd..aa6ae72 100644 --- a/lib/tracker_api/version.rb +++ b/lib/tracker_api/version.rb @@ -1,3 +1,3 @@ module TrackerApi - VERSION = '1.4.0' + VERSION = '1.4.1' end