Skip to content

Commit

Permalink
Added story#add_owner
Browse files Browse the repository at this point in the history
  • Loading branch information
forest committed Jan 6, 2017
1 parent fbbb085 commit 14fee7a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/tracker_api/resources/story.rb
Expand Up @@ -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.
Expand Down
33 changes: 33 additions & 0 deletions test/story_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 14fee7a

Please sign in to comment.