Skip to content

Commit

Permalink
Fix bug in add_label to story w/o existing labels (#82)
Browse files Browse the repository at this point in the history
* Fix bug add_label to story w/o existing labels
* Fixes #81
* Bump version to 1.4.1
  • Loading branch information
robinw777 authored and forest committed Oct 21, 2016
1 parent 22cedd2 commit ef88044
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/tracker_api/resources/story.rb
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/tracker_api/version.rb
@@ -1,3 +1,3 @@
module TrackerApi
VERSION = '1.4.0'
VERSION = '1.4.1'
end
16 changes: 16 additions & 0 deletions test/story_test.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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"})
Expand Down
1 change: 1 addition & 0 deletions 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"}
@@ -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"}

0 comments on commit ef88044

Please sign in to comment.