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
17 changes: 16 additions & 1 deletion lib/tracker_api/resources/story.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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