From 14fee7a1ae86eddeee4380d2222a81564319217c Mon Sep 17 00:00:00 2001 From: Forest Carlisle Date: Thu, 5 Jan 2017 16:05:53 -0800 Subject: [PATCH] Added story#add_owner --- lib/tracker_api/resources/story.rb | 17 ++++++++++++++- test/story_test.rb | 33 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/tracker_api/resources/story.rb b/lib/tracker_api/resources/story.rb index 565aab6..bc95924 100644 --- a/lib/tracker_api/resources/story.rb +++ b/lib/tracker_api/resources/story.rb @@ -75,7 +75,22 @@ def add_label(label) end # Use attribute writer to get coercion and dirty tracking. - self.labels = (labels ? labels.dup : []).push(new_label) + self.labels = (labels ? labels.dup : []).push(new_label).uniq + end + + # Adds a new owner to the story. + # + # @param [Person|Fixnum] owner + def add_owner(owner) + owner_id = if owner.kind_of?(Fixnum) + owner_id = owner + else + raise ArgumentError, 'Valid Person expected.' unless owner.instance_of?(Resources::Person) + owner_id = owner.id + end + + # Use attribute writer to get coercion and dirty tracking. + self.owner_ids = (owner_ids ? owner_ids.dup : []).push(owner_id).uniq 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 5f7f83e..9daa8b2 100644 --- a/test/story_test.rb +++ b/test/story_test.rb @@ -153,6 +153,39 @@ end end + describe '.add_owner' do + it 'add owner to a story' do + VCR.use_cassette('get story', record: :new_episodes) do + story = project.story(story_id) + + # clear current owners + story.owner_ids = [] + + story.add_owner(TrackerApi::Resources::Person.new(id: 123)) + + story.owner_ids.wont_be_empty + story.owner_ids.must_equal [123] + end + end + + it 'add owners by id to a story' do + VCR.use_cassette('get story', record: :new_episodes) do + story = project.story(story_id) + + # clear current owners + story.owner_ids = [] + + story.add_owner(123) + story.add_owner(456) + # test dups are not added + story.add_owner(123) + + story.owner_ids.wont_be_empty + story.owner_ids.must_equal [123, 456] + end + end + end + describe '.tasks' do it 'gets all tasks for this story with eager loading' do VCR.use_cassette('get story with tasks', record: :new_episodes) do