Skip to content

Commit

Permalink
Tracker story labels
Browse files Browse the repository at this point in the history
  • Loading branch information
tpope committed Dec 9, 2008
1 parent ed8ba40 commit 553e358
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/pickler/tracker/story.rb
Expand Up @@ -6,7 +6,7 @@ class Story < Abstract
STATES = %w(unscheduled unstarted started finished delivered rejected accepted)

attr_reader :project, :iteration
reader :url, :labels
reader :url
date_reader :created_at, :accepted_at, :deadline
accessor :current_state, :name, :description, :owned_by, :requested_by, :story_type

Expand All @@ -16,6 +16,14 @@ def initialize(project, attributes = {})
super(attributes)
end

def labels
Array(@attributes["labels"]).join(", ").strip.split(/\s*,\s*/).freeze
end

def labels=(array)
@attributes["labels"] = array
end

def transition!(state)
raise Pickler::Tracker::Error, "Invalid state #{state}", caller unless STATES.include?(state)
self.current_state = state
Expand Down Expand Up @@ -96,7 +104,7 @@ def to_xml
hash = @attributes.reject do |k,v|
!%w(current_state deadline description estimate name owned_by requested_by story_type).include?(k)
end
hash["labels"] = Array(@attributes["labels"]).join(", ")
hash["labels"] = labels.join(", ")
hash.to_xml(:dasherize => false, :root => "story")
end

Expand Down
8 changes: 8 additions & 0 deletions spec/pickler/tracker/story_spec.rb
Expand Up @@ -36,6 +36,14 @@
@story.accepted_at.should be_kind_of(Date)
end

it "should have a labels Array" do
@project.new_story(:labels => nil).should have(0).labels
@project.new_story(:labels => ' ').should have(0).labels
@project.new_story(:labels => 'foo').should have(1).labels
@project.new_story(:labels => %w(x y)).should have(2).labels
@project.new_story(:labels => 'x, y').should have(2).labels
end

it "should have an iteration" do
@story.iteration.should be_kind_of(Pickler::Tracker::Iteration)
end
Expand Down

0 comments on commit 553e358

Please sign in to comment.