Skip to content

Commit

Permalink
Sluggify story name for use as feature filename
Browse files Browse the repository at this point in the history
[Bodaniel Jeanes and Dr Nic Williams]
  • Loading branch information
tpope committed Nov 18, 2009
1 parent 592ee6d commit ab22e7a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/pickler/feature.rb
Expand Up @@ -50,8 +50,8 @@ def to_s
end

def pull(default = nil)
filename = filename() || pickler.features_path("#{default||id}.feature")
story = story() # force the read into local_body before File.open below blows it away
filename = filename() || pickler.features_path("#{story.suggested_basename(default)}.feature")
File.open(filename,'w') {|f| f.puts story.to_s(pickler.format)}
@filename = filename
end
Expand Down
6 changes: 3 additions & 3 deletions lib/pickler/runner.rb
Expand Up @@ -315,8 +315,6 @@ def modifications
summary "Download stories"
description <<-EOF
Download the given story or all well formed stories to the features/ directory.
Previously unseen stories will be given a numeric filename that you are
encouraged to change.
EOF

process do |*args|
Expand All @@ -332,7 +330,9 @@ def modifications
summary "Pull a story and mark it started"
description <<-EOF
Pull a given story and change its state to started. If basename is given
and no local file exists, features/basename.feature will be created.
and no local file exists, features/basename.feature will be created. Give a
basename of "-" to use a downcased, underscored version of the story name as
the basename.
EOF

process do |story, *args|
Expand Down
8 changes: 8 additions & 0 deletions lib/pickler/tracker/story.rb
Expand Up @@ -133,6 +133,14 @@ def estimate
@attributes["estimate"].to_i < 0 ? nil : @attributes["estimate"]
end

def suggested_basename(user_override = nil)
if user_override.to_s !~ /\A-?\z/
user_override
else
name.to_s.empty? ? id.to_s : name.gsub(/[^\w-]+/,'_').downcase
end
end

def comment!(body)
response = tracker.request_xml(:post, "#{resource_url}/notes",{:text => body}.to_xml(:dasherize => false, :root => 'note'))
if response["note"]
Expand Down
19 changes: 19 additions & 0 deletions spec/pickler/tracker/story_spec.rb
Expand Up @@ -48,4 +48,23 @@
@story.iteration.should be_kind_of(Pickler::Tracker::Iteration)
end

describe "#suggested_basename" do

it "should return the user override if it's not blank or \"-\"" do
story = @project.new_story(:name => "Name")
story.suggested_basename('foo_bar').should eql('foo_bar')
story.suggested_basename('').should_not eql('')
story.suggested_basename('-').should_not eql('-')
end

it "returns the id if no name is present" do
@project.new_story(:id => 123).suggested_basename.should eql('123')
end

it "sluggifies the name" do
@project.new_story(:name => "Foo: bar-baz").suggested_basename.should eql("foo_bar-baz")
end

end

end

0 comments on commit ab22e7a

Please sign in to comment.