Skip to content
Browse files

Added support for slurping stories with tasks

  • Loading branch information...
1 parent 7be74fc commit 16a03833e566f93dde25c1bce6b0b7342258230b @archfear committed Nov 21, 2011
Showing with 185 additions and 10 deletions.
  1. +3 −0 README.rdoc
  2. +10 −0 lib/slurper.rb
  3. +14 −0 lib/story.rb
  4. +36 −0 lib/task.rb
  5. +14 −0 spec/fixtures/story_with_tasks.slurper
  6. +12 −0 spec/slurper_spec.rb
  7. +34 −10 spec/story_spec.rb
  8. +62 −0 spec/task_spec.rb
View
3 README.rdoc
@@ -63,6 +63,9 @@ Or even
Set Up Staging Environment
description:
Set up and configure staging environment for approval of stories
+ tasks:
+ - set up staging db server
+ - set up staging app server
labels:
View
10 lib/slurper.rb
@@ -2,6 +2,7 @@
require 'logger'
require 'active_resource'
require 'story'
+require 'task'
YAML::ENGINE.yamler='syck' if RUBY_VERSION > '1.9'
@@ -40,8 +41,17 @@ def create_stories
puts "Preparing to slurp #{stories.size} stories into Tracker..."
stories.each_with_index do |story, index|
begin
+ tasks = story.extract_tasks
if story.save
puts "#{index+1}. #{story.name}"
+ tasks.each do |task|
+ task.prefix_options[:story_id] = story.id
+ if task.save
+ puts "- #{task.description}"
+ else
+ puts "Slurp failed. #{task.errors.full_messages}"
+ end
+ end
else
puts "Slurp failed. #{story.errors.full_messages}"
end
View
14 lib/story.rb
@@ -25,6 +25,20 @@ def prepare
default_requested_by
end
+ def to_xml(options={})
+ options[:except] ||= []
+ options[:except] << :tasks
+ super(options)
+ end
+
+ def extract_tasks
+ if respond_to?(:tasks)
+ tasks.collect {|task| Task.new(:description => task)}
+ else
+ []
+ end
+ end
+
protected
def scrub_description
View
36 lib/task.rb
@@ -0,0 +1,36 @@
+class Task < ActiveResource::Base
+
+ def self.yaml
+ YAML.load_file('slurper_config.yml')
+ end
+
+ def self.config
+ @@config = yaml
+ scheme = if !!@@config['ssl']
+ self.ssl_options = { :verify_mode => OpenSSL::SSL::VERIFY_PEER,
+ :ca_file => File.join(File.dirname(__FILE__), "cacert.pem") }
+ "https"
+ else
+ "http"
+ end
+ self.site = "#{scheme}://www.pivotaltracker.com/services/v3/projects/#{@@config['project_id']}/stories/:story_id"
+ @@config
+ end
+
+
+ headers['X-TrackerToken'] = config.delete("token")
+
+ def prepare
+ scrub_description
+ end
+
+ protected
+
+ def scrub_description
+ if respond_to?(:description)
+ self.description = description.gsub(" ", "")
+ self.attributes["description"] = nil if description == ""
+ end
+ end
+
+end
View
14 spec/fixtures/story_with_tasks.slurper
@@ -0,0 +1,14 @@
+==
+story_type:
+ feature
+name:
+ Profit
+description:
+ In order to do something
+ As a role
+ I want to click a thingy
+tasks:
+- do the thing
+- don't forget the other thing
+labels:
+ money,power,fame
View
12 spec/slurper_spec.rb
@@ -65,4 +65,16 @@
end
end
+ context "with tasks" do
+ before do
+ slurper = Slurper.new(File.join(File.dirname(__FILE__), "fixtures", "story_with_tasks.slurper"))
+ slurper.load_stories
+ @story = slurper.stories.first
+ end
+
+ it "parses the tasks correctly" do
+ @story.tasks.should == ["do the thing", "don't forget the other thing"]
+ end
+ end
+
end
View
44 spec/story_spec.rb
@@ -4,6 +4,21 @@
describe Story do
+ it "uses http by default" do
+ Story.site.scheme.should == "http"
+ Story.yaml['ssl'].should be_nil
+ end
+
+ it "uses https if set in the config" do
+ Story.stub(:yaml => {"ssl" => true})
+ Story.config['ssl'].should be_true
+ Story.site.scheme.should == "https"
+ Story.ssl_options[:verify_mode].should == 1
+
+ # Not sure what this next line is testing
+ File.open(File.expand_path('lib/cacert.pem')).readlines.find_all{ |l| l.starts_with?("Equifax") }.count.should == 4
+ end
+
context "#prepare" do
it "scrubs the description" do
story = Story.new
@@ -18,20 +33,29 @@
story.should_receive(:default_requested_by)
story.prepare
end
+ end
- it "uses http by default" do
- Story.site.scheme.should == "http"
- Story.yaml['ssl'].should be_nil
+ context "#to_xml" do
+ it "excludes the tasks attribute" do
+ story = Story.new(
+ :story_type => "feature",
+ :name => "Profit",
+ :tasks => ["build something epic", "charge a lot for it"])
+ story.to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<story>\n <story-type>feature</story-type>\n <name>Profit</name>\n</story>\n"
end
+ end
- it "uses https if set in the config" do
- Story.stub(:yaml => {"ssl" => true})
- Story.config['ssl'].should be_true
- Story.site.scheme.should == "https"
- Story.ssl_options[:verify_mode].should == 1
+ context "#extract_tasks" do
+ it "returns an empty array for a story with no tasks" do
+ story = Story.new
+ story.extract_tasks.should == []
+ end
- # Not sure what this next line is testing
- File.open(File.expand_path('lib/cacert.pem')).readlines.find_all{ |l| l.starts_with?("Equifax") }.count.should == 4
+ it "returns an array of Tasks with the appropriate descriptions for a story with tasks" do
+ story = Story.new(:tasks => ["build something epic"])
+ task = story.extract_tasks[0]
+ task.should be_an_instance_of(Task)
+ task.description.should == "build something epic"
end
end
View
62 spec/task_spec.rb
@@ -0,0 +1,62 @@
+require 'rubygems'
+require 'spec'
+require 'slurper'
+
+describe Task do
+
+ it "uses http by default" do
+ Task.site.scheme.should == "http"
+ Task.yaml['ssl'].should be_nil
+ end
+
+ it "uses https if set in the config" do
+ Task.stub(:yaml => {"ssl" => true})
+ Task.config['ssl'].should be_true
+ Task.site.scheme.should == "https"
+ Task.ssl_options[:verify_mode].should == 1
+
+ # Not sure what this next line is testing
+ File.open(File.expand_path('lib/cacert.pem')).readlines.find_all{ |l| l.starts_with?("Equifax") }.count.should == 4
+ end
+
+ context "#prepare" do
+ it "scrubs the description" do
+ task = Task.new
+ task.stub!(:default_requested_by)
+ task.should_receive(:scrub_description)
+ task.prepare
+ end
+ end
+
+ context "scrubs the descriptions correctly" do
+ it "when the description is blank" do
+ task = Task.new(:description => "")
+ task.send(:scrub_description)
+ task.description.should be_nil
+ end
+
+ it "when there is no description given" do
+ task = Task.new
+ lambda {
+ task.send(:scrub_description)
+ }.should_not raise_error
+ end
+
+ it "when it contains quotes" do
+ desc = <<-STRING
+ I have a "quote"
+ STRING
+ task = Task.new(:description => desc)
+ task.send(:scrub_description)
+ task.description.should == "I have a \"quote\"\n"
+ end
+
+ it "when it is full of whitespace" do
+ desc = " Do this task "
+ task = Task.new(:description => desc)
+ task.send(:scrub_description)
+ task.description.should == "Do this task"
+ end
+ end
+
+end

0 comments on commit 16a0383

Please sign in to comment.
Something went wrong with that request. Please try again.