Permalink
Browse files

Closing stories on PT only when both fields filled or none

  • Loading branch information...
pbrudny committed May 11, 2011
1 parent 26f77b6 commit bdfcda0ff36fa977ac352cf8fb50dbe6cad83100
Showing with 13 additions and 38 deletions.
  1. +12 −8 lib/issue_patch.rb
  2. +0 −29 test/unit/lib/pivotal_handler_test.rb
  3. +1 −1 test/unit/lib/trackmine_test.rb
View
@@ -8,16 +8,20 @@ def self.included(klass) # :nodoc:
klass.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
- # When Issue status changed to 'closed' or 'rejected' finishes story
+ # Finishes story when Issue status changed to 'closed' or 'rejected'
before_update do |issue|
- if issue.status_id_changed?
- if issue.status.is_closed? && issue.pivotal_story_id != 0
- begin
+ if issue.status_id_changed? && issue.status.is_closed?
+ begin
+ if issue.pivotal_story_id != 0 && issue.pivotal_project_id != 0
Trackmine.finish_story( issue.pivotal_project_id, issue.pivotal_story_id )
- rescue => e
- TrackmineMailer.deliver_error_mail("Error while closing story: " + e)
- end
- end
+ elsif issue.pivotal_story_id == 0 && issue.pivotal_project_id == 0
+ #Do nothing when both are empty
+ else
+ raise Exception.new("You should fill both fields (Pivotal Story ID, Pivotal Project ID) in issue: '#{self.subject}' or none")
+ end
+ rescue => e
+ TrackmineMailer.deliver_error_mail("Error while closing story: " + e)
+ end
end
end
@@ -14,36 +14,7 @@ def app
get '/'
assert !last_response.ok?
end
-
-# context 'POST /pivotal_activity.xml' do
-# context 'having a correct activity message with Redmine mapping' do
-# setup do
-# @tracker_activity = File.read( File.dirname(__FILE__) + "/../../fixtures/activity.xml")
-# Factory.create :mapping, :tracker_project_id => 102622, :label => 'shields'
-# Factory.create :mapping, :tracker_project_id => 102622, :label => 'transporter'
-# end
-#
-# should "return OK status" do
-# post 'pivotal_activity.xml', @tracker_activity
-# assert last_response.ok?
-# assert_equal last_response.status, 200
-# end
-# end
-
-# context "with invalid activity message format" do
-# setup { post '/pivotal_activity.xml', {}.to_xml }
-# should("return accepted status") { assert_equal 202, last_response.status}
-# end
-# context "with wrong activity message data" do
-# setup do
-# post '/pivotal_activity.xml', '<?xml version="1.0" encoding="UTF-8"?><activity><event_type>story_update</event_type></activity>'
-# end
-#
-# should("return accepted status") { assert_equal 202, last_response.status}
-# should("send email with an error notification") { assert !ActionMailer::Base.deliveries.empty? }
-# end
-# end
end
end
@@ -68,7 +68,7 @@ def setup
context 'having wrong activity data' do
setup do
@activity = { 'project_id' => 102622,
- 'stories' => [{ 'id' => 90909 }]}
+ 'stories' => [{ 'id' => 90909 }]}
FakeWeb.register_uri :get, "https://www.pivotaltracker.com/services/v3/projects/102622/stories/90909" ,
:body => '',
:content_type => "text/plain"

0 comments on commit bdfcda0

Please sign in to comment.