From 07720a8f0ef44457bdbb8030894211f69e0201af Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 19 Aug 2011 03:12:52 +0800 Subject: [PATCH] * Major reorganization of issue tracker specs. Migrated specs out of the errs_controller into their respective models. * Wrote specs for Fogbugz. Turns out that the Fogbugz API used the 'Crack' gem which happened to break mongoid by playing with the String class. See here for details: [ https://github.com/mongoid/mongoid/issues/618 ]. * This is why I had to upgrade mongoid to version 2.1.1, which included the 'Crack' fix. Upgrading Mongoid to 2.1.1 required the following changes: ** Fixing a counter_cache test on Err model ** Namespacing all of the subclassed IssueTracker models based on their parent directory ** Setting `config.mongoid.preload_models = true` in config/application.rb --- Gemfile | 2 +- Gemfile.lock | 4 ++-- app/models/issue_trackers/fogbugz_tracker.rb | 2 +- app/models/issue_trackers/github_tracker.rb | 2 +- app/models/issue_trackers/lighthouse_tracker.rb | 2 +- app/models/issue_trackers/mingle_tracker.rb | 2 +- app/models/issue_trackers/pivotal_labs_tracker.rb | 2 +- app/models/issue_trackers/redmine_tracker.rb | 2 +- config/application.rb | 3 +++ config/initializers/issue_tracker_apis.rb | 3 --- config/initializers/issue_trackers.rb | 6 ++++++ spec/controllers/errs_controller_spec.rb | 164 +------------------------------------------------------------------------------------------------------------------------------------------------------------------- spec/factories/err_factories.rb | 2 +- spec/factories/issue_tracker_factories.rb | 1 - spec/models/err_spec.rb | 2 ++ spec/models/issue_tracker_spec.rb | 5 ----- spec/models/issue_trackers/fogbugz_tracker_spec.rb | 19 ++++++------------- spec/models/issue_trackers/github_tracker_spec.rb | 41 +++++++++++++++++++++++++++++++++++++++++ spec/models/issue_trackers/lighthouse_tracker_spec.rb | 27 +++++++++++++++++++++++++++ spec/models/issue_trackers/mingle_tracker_spec.rb | 28 ++++++++++++++++++++++++++++ spec/models/issue_trackers/pivotal_labs_tracker_spec.rb | 30 ++++++++++++++++++++++++++++++ spec/models/issue_trackers/redmine_tracker_spec.rb | 26 ++++++++++++++++++++++++++ 22 files changed, 180 insertions(+), 195 deletions(-) delete mode 100644 config/initializers/issue_tracker_apis.rb create mode 100644 config/initializers/issue_trackers.rb delete mode 100644 spec/models/issue_tracker_spec.rb create mode 100644 spec/models/issue_trackers/github_tracker_spec.rb create mode 100644 spec/models/issue_trackers/lighthouse_tracker_spec.rb create mode 100644 spec/models/issue_trackers/mingle_tracker_spec.rb create mode 100644 spec/models/issue_trackers/pivotal_labs_tracker_spec.rb create mode 100644 spec/models/issue_trackers/redmine_tracker_spec.rb diff --git a/Gemfile b/Gemfile index 711e058..435abb6 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'http://rubygems.org' gem 'rails', '3.0.5' gem 'nokogiri' -gem 'mongoid', '2.0.2' +gem 'mongoid', '2.1.1' gem 'haml' gem 'will_paginate' gem 'devise', '~> 1.4.0' diff --git a/Gemfile.lock b/Gemfile.lock index e5ea8e1..6ed025f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -94,7 +94,7 @@ GEM mime-types (1.16) mongo (1.3.1) bson (>= 1.3.1) - mongoid (2.0.2) + mongoid (2.1.1) activemodel (~> 3.0) mongo (~> 1.3) tzinfo (~> 0.3.22) @@ -208,7 +208,7 @@ DEPENDENCIES hoptoad_notifier (~> 2.3) inherited_resources lighthouse-api - mongoid (= 2.0.2) + mongoid (= 2.1.1) mongoid_rails_migrations nokogiri octokit diff --git a/app/models/issue_trackers/fogbugz_tracker.rb b/app/models/issue_trackers/fogbugz_tracker.rb index 7f770dc..bbf5125 100644 --- a/app/models/issue_trackers/fogbugz_tracker.rb +++ b/app/models/issue_trackers/fogbugz_tracker.rb @@ -1,4 +1,4 @@ -class FogbugzTracker < IssueTracker +class IssueTrackers::FogbugzTracker < IssueTracker Label = "fogbugz" RequiredFields = %w(project_id account username password) diff --git a/app/models/issue_trackers/github_tracker.rb b/app/models/issue_trackers/github_tracker.rb index 57604d6..0c2a8cd 100644 --- a/app/models/issue_trackers/github_tracker.rb +++ b/app/models/issue_trackers/github_tracker.rb @@ -1,4 +1,4 @@ -class GithubTracker < IssueTracker +class IssueTrackers::GithubTracker < IssueTracker Label = "github" RequiredFields = %w(project_id username api_token) diff --git a/app/models/issue_trackers/lighthouse_tracker.rb b/app/models/issue_trackers/lighthouse_tracker.rb index 563d5c6..6ab64ae 100644 --- a/app/models/issue_trackers/lighthouse_tracker.rb +++ b/app/models/issue_trackers/lighthouse_tracker.rb @@ -1,4 +1,4 @@ -class LighthouseTracker < IssueTracker +class IssueTrackers::LighthouseTracker < IssueTracker Label = "lighthouseapp" RequiredFields = %w(account api_token project_id) diff --git a/app/models/issue_trackers/mingle_tracker.rb b/app/models/issue_trackers/mingle_tracker.rb index 41e72c8..0c9a317 100644 --- a/app/models/issue_trackers/mingle_tracker.rb +++ b/app/models/issue_trackers/mingle_tracker.rb @@ -1,4 +1,4 @@ -class MingleTracker < IssueTracker +class IssueTrackers::MingleTracker < IssueTracker Label = "mingle" RequiredFields = %w(account project_id username password) diff --git a/app/models/issue_trackers/pivotal_labs_tracker.rb b/app/models/issue_trackers/pivotal_labs_tracker.rb index 0b09872..089eb4c 100644 --- a/app/models/issue_trackers/pivotal_labs_tracker.rb +++ b/app/models/issue_trackers/pivotal_labs_tracker.rb @@ -1,4 +1,4 @@ -class PivotalLabsTracker < IssueTracker +class IssueTrackers::PivotalLabsTracker < IssueTracker Label = "pivotal" RequiredFields = %w(api_token project_id) diff --git a/app/models/issue_trackers/redmine_tracker.rb b/app/models/issue_trackers/redmine_tracker.rb index e56edcd..efe8c90 100644 --- a/app/models/issue_trackers/redmine_tracker.rb +++ b/app/models/issue_trackers/redmine_tracker.rb @@ -1,4 +1,4 @@ -class RedmineTracker < IssueTracker +class IssueTrackers::RedmineTracker < IssueTracker Label = "redmine" RequiredFields = %w(account api_token project_id) diff --git a/config/application.rb b/config/application.rb index dcf1ba6..2b1945c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -46,6 +46,9 @@ module Errbit g.test_framework :rspec, :fixture => false end + # IssueTracker subclasses use inheritance, so preloading models provides querying consistency in dev mode. + config.mongoid.preload_models = true + # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" diff --git a/config/initializers/issue_tracker_apis.rb b/config/initializers/issue_tracker_apis.rb deleted file mode 100644 index e68683d..0000000 --- a/config/initializers/issue_tracker_apis.rb +++ /dev/null @@ -1,3 +0,0 @@ -# Require all issue tracker apis in lib/issue_tracker_apis -Dir.glob(Rails.root.join('lib/issue_tracker_apis/*.rb')).each {|t| require t } - diff --git a/config/initializers/issue_trackers.rb b/config/initializers/issue_trackers.rb new file mode 100644 index 0000000..988475d --- /dev/null +++ b/config/initializers/issue_trackers.rb @@ -0,0 +1,6 @@ +# Include nested issue tracker models +include IssueTrackers + +# Require all issue tracker apis in lib/issue_tracker_apis +Dir.glob(Rails.root.join('lib/issue_tracker_apis/*.rb')).each {|t| require t } + diff --git a/spec/controllers/errs_controller_spec.rb b/spec/controllers/errs_controller_spec.rb index 396636b..39b4a6b 100644 --- a/spec/controllers/errs_controller_spec.rb +++ b/spec/controllers/errs_controller_spec.rb @@ -269,178 +269,16 @@ describe ErrsController do number = 5 @issue_link = "http://#{tracker.account}.lighthouseapp.com/projects/#{tracker.project_id}/tickets/#{number}.xml" body = "#{number}" - stub_request(:post, "http://#{tracker.account}.lighthouseapp.com/projects/#{tracker.project_id}/tickets.xml").to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => body ) - - post :create_issue, :app_id => err.app.id, :id => err.id - err.reload - end - - it "should make request to Lighthouseapp with err params" do - requested = have_requested(:post, "http://#{tracker.account}.lighthouseapp.com/projects/#{tracker.project_id}/tickets.xml") - WebMock.should requested.with(:headers => {'X-Lighthousetoken' => tracker.api_token}) - WebMock.should requested.with(:body => /errbit<\/tag>/) - WebMock.should requested.with(:body => /\[#{ err.environment }\]\[#{err.where}\] #{err.message.to_s.truncate(100)}<\/title>/) - WebMock.should requested.with(:body => /<body>.+<\/body>/m) - end - - it "should redirect to err page" do - response.should redirect_to( app_err_path(err.app, err) ) - end - - it "should create issue link for err" do - err.issue_link.should == @issue_link.sub(/\.xml$/, '') - end - end - - context "redmine tracker" do - let(:notice) { Factory :notice } - let(:tracker) { Factory :redmine_tracker, :app => notice.err.app } - let(:err) { notice.err } - - before(:each) do - number = 5 - @issue_link = "#{tracker.account}/issues/#{number}.xml?project_id=#{tracker.project_id}" - body = "<issue><subject>my subject</subject><id>#{number}</id></issue>" - stub_request(:post, "#{tracker.account}/issues.xml").to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => body ) - - post :create_issue, :app_id => err.app.id, :id => err.id - err.reload - end - - it "should make request to Redmine with err params" do - requested = have_requested(:post, "#{tracker.account}/issues.xml") - WebMock.should requested.with(:headers => {'X-Redmine-API-Key' => tracker.api_token}) - WebMock.should requested.with(:body => /<project-id>#{tracker.project_id}<\/project-id>/) - WebMock.should requested.with(:body => /<subject>\[#{ err.environment }\]\[#{err.where}\] #{err.message.to_s.truncate(100)}<\/subject>/) - WebMock.should requested.with(:body => /<description>.+<\/description>/m) - end - - it "should redirect to err page" do - response.should redirect_to( app_err_path(err.app, err) ) - end - - it "should create issue link for err" do - err.issue_link.should == @issue_link.sub(/\.xml/, '') - end - end - - context "pivotal tracker" do - let(:notice) { Factory :notice } - let(:tracker) { Factory :pivotal_labs_tracker, :app => notice.err.app, :project_id => 10 } - let(:err) { notice.err } - - before(:each) do - story_id = 5 - @issue_link = "https://www.pivotaltracker.com/story/show/#{story_id}" - - project_body = "<project><id>#{tracker.project_id}</id><name>TestProject</name></project>" - stub_request(:get, "https://www.pivotaltracker.com/services/v3/projects/#{tracker.project_id}"). - to_return(:status => 200, :headers => {'Location' => @issue_link}, :body => project_body ) - - story_body = "<story><name>Test Story</name><id>#{story_id}</id></story>" - stub_request(:post, "https://www.pivotaltracker.com/services/v3/projects/#{tracker.project_id}/stories"). - to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => story_body ) - - post :create_issue, :app_id => err.app.id, :id => err.id - err.reload - end - - it "should make request to Pivotal Tracker with err params" do - requested = have_requested(:post, "https://www.pivotaltracker.com/services/v3/projects/#{tracker.project_id}/stories") - WebMock.should requested.with(:headers => {'X-Trackertoken' => tracker.api_token}) - WebMock.should requested.with(:body => /See this exception on Errbit/) - WebMock.should requested.with(:body => /<name>\[#{ err.environment }\]\[#{err.where}\] #{err.message.to_s.truncate(100)}<\/name>/) - WebMock.should requested.with(:body => /<description>.+<\/description>/m) - end - - it "should redirect to err page" do - response.should redirect_to( app_err_path(err.app, err) ) - end - - it "should create issue link for err" do - err.issue_link.should == @issue_link - end - end - - context "mingle tracker" do - let(:notice) { Factory :notice } - let(:tracker) { Factory :mingle_tracker, :app => notice.err.app } - let(:err) { notice.err } - - before(:each) do - number = 5 - @issue_link = "#{tracker.account}/projects/#{tracker.project_id}/cards/#{number}.xml" - @basic_auth = tracker.account.gsub("://", "://#{tracker.username}:#{tracker.password}@") - body = "<card><id type=\"integer\">#{number}</id></card>" - stub_request(:post, "#{@basic_auth}/api/v1/projects/#{tracker.project_id}/cards.xml"). + stub_request(:post, "http://#{tracker.account}.lighthouseapp.com/projects/#{tracker.project_id}/tickets.xml"). to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => body ) post :create_issue, :app_id => err.app.id, :id => err.id err.reload end - it "should make request to Mingle with err params" do - requested = have_requested(:post, "#{@basic_auth}/api/v1/projects/#{tracker.project_id}/cards.xml") - WebMock.should requested.with(:headers => {'Content-Type' => 'application/xml'}) - WebMock.should requested.with(:body => /FooError: Too Much Bar/) - WebMock.should requested.with(:body => /See this exception on Errbit/) - WebMock.should requested.with(:body => /<card-type-name>Defect<\/card-type-name>/) - end - - it "should redirect to err page" do - response.should redirect_to( app_err_path(err.app, err) ) - end - - it "should create issue link for err" do - err.issue_link.should == @issue_link.sub(/\.xml$/, '') - end - end - - context "github issues tracker" do - let(:notice) { Factory :notice } - let(:tracker) { Factory :github_tracker, :app => notice.err.app } - let(:err) { notice.err } - - before(:each) do - number = 5 - @issue_link = "https://github.com/#{tracker.project_id}/issues/#{number}" - body = <<EOF -{ - "issue": { - "position": 1.0, - "number": #{number}, - "votes": 0, - "created_at": "2010/01/21 13:45:59 -0800", - "comments": 0, - "body": "Test Body", - "title": "Test Issue", - "user": "test_user", - "state": "open", - "html_url": "#{@issue_link}" - } -} -EOF - stub_request(:post, "https://#{tracker.username}%2Ftoken:#{tracker.api_token}@github.com/api/v2/json/issues/open/#{tracker.project_id}"). - to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => body ) - - post :create_issue, :app_id => err.app.id, :id => err.id - err.reload - end - - it "should make request to Github with err params" do - requested = have_requested(:post, "https://#{tracker.username}%2Ftoken:#{tracker.api_token}@github.com/api/v2/json/issues/open/#{tracker.project_id}") - WebMock.should requested.with(:headers => {'Content-Type' => 'application/x-www-form-urlencoded'}) - WebMock.should requested.with(:body => /title=%5Bproduction%5D%5Bfoo%23bar%5D%20FooError%3A%20Too%20Much%20Bar/) - WebMock.should requested.with(:body => /See%20this%20exception%20on%20Errbit/) - end - it "should redirect to err page" do response.should redirect_to( app_err_path(err.app, err) ) end - - it "should create issue link for err" do - err.issue_link.should == @issue_link - end end end diff --git a/spec/factories/err_factories.rb b/spec/factories/err_factories.rb index 9f7afd4..cb8de23 100644 --- a/spec/factories/err_factories.rb +++ b/spec/factories/err_factories.rb @@ -1,5 +1,5 @@ Factory.define :err do |e| - e.app {|p| p.association :app} + e.app {|p| p.association :app } e.klass 'FooError' e.component 'foo' e.action 'bar' diff --git a/spec/factories/issue_tracker_factories.rb b/spec/factories/issue_tracker_factories.rb index abc2938..928f0a3 100644 --- a/spec/factories/issue_tracker_factories.rb +++ b/spec/factories/issue_tracker_factories.rb @@ -23,6 +23,5 @@ end Factory.define :github_tracker, :parent => :issue_tracker, :class => :github_tracker do |e| e.project_id 'test_account/test_project' e.username 'test_username' - e.api_token '12497asfa987' end diff --git a/spec/models/err_spec.rb b/spec/models/err_spec.rb index 5eaf124..3a80394 100644 --- a/spec/models/err_spec.rb +++ b/spec/models/err_spec.rb @@ -162,9 +162,11 @@ describe Err do notice1 = Factory(:notice, :err => @err, :message => 'ERR 1') lambda { @err.notices.first.destroy + @err.reload }.should change(@err, :notices_count).from(1).to(0) end end end + diff --git a/spec/models/issue_tracker_spec.rb b/spec/models/issue_tracker_spec.rb deleted file mode 100644 index 6b5f577..0000000 --- a/spec/models/issue_tracker_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -# encoding: utf-8 -require 'spec_helper' - -describe IssueTracker do -end diff --git a/spec/models/issue_trackers/fogbugz_tracker_spec.rb b/spec/models/issue_trackers/fogbugz_tracker_spec.rb index eb12efb..e44baf4 100644 --- a/spec/models/issue_trackers/fogbugz_tracker_spec.rb +++ b/spec/models/issue_trackers/fogbugz_tracker_spec.rb @@ -1,26 +1,19 @@ -# encoding: utf-8 require 'spec_helper' describe FogbugzTracker do - let(:notice) { Factory :notice } - let(:tracker) { Factory :fogbugz_tracker, :password => "password", :app => notice.err.app } - let(:err) { notice.err } + it "should create an issue on Fogbugz with err params, and set issue link for err" do + notice = Factory :notice + tracker = Factory :fogbugz_tracker, :app => notice.err.app + err = notice.err - before do number = 123 @issue_link = "https://#{tracker.account}.fogbugz.com/default.asp?#{number}" - auth_response = "<response><token>12345</token></response>" - command_response = "<response><case><ixBug>123</ixBug></case></response>" + response = "<response><token>12345</token><case><ixBug>123</ixBug></case></response>" http_mock = mock() http_mock.should_receive(:new).and_return(http_mock) - http_mock.should_receive(:request).with(:logon, {:params=>{:email=>"test@example.com", :password=>"password"}}). - and_return(auth_response) - http_mock.should_receive(:request). - and_return(command_response) + http_mock.should_receive(:request).twice.and_return(response) Fogbugz.adapter[:http] = http_mock - end - it "should create an issue on Fogbugz with err params, and set issue link for err" do err.app.issue_tracker.create_issue(err) err.reload diff --git a/spec/models/issue_trackers/github_tracker_spec.rb b/spec/models/issue_trackers/github_tracker_spec.rb new file mode 100644 index 0000000..a14508c --- /dev/null +++ b/spec/models/issue_trackers/github_tracker_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe GithubTracker do + it "should create an issue on Github Issues with err params, and set issue link for err" do + notice = Factory :notice + tracker = Factory :github_tracker, :app => notice.err.app + err = notice.err + + number = 5 + @issue_link = "https://github.com/#{tracker.project_id}/issues/#{number}" + body = <<EOF +{ + "issue": { + "position": 1.0, + "number": #{number}, + "votes": 0, + "created_at": "2010/01/21 13:45:59 -0800", + "comments": 0, + "body": "Test Body", + "title": "Test Issue", + "user": "test_user", + "state": "open", + "html_url": "#{@issue_link}" + } +} +EOF + stub_request(:post, "https://#{tracker.username}%2Ftoken:#{tracker.api_token}@github.com/api/v2/json/issues/open/#{tracker.project_id}"). + to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => body ) + + err.app.issue_tracker.create_issue(err) + err.reload + + requested = have_requested(:post, "https://#{tracker.username}%2Ftoken:#{tracker.api_token}@github.com/api/v2/json/issues/open/#{tracker.project_id}") + WebMock.should requested.with(:headers => {'Content-Type' => 'application/x-www-form-urlencoded'}) + WebMock.should requested.with(:body => /title=%5Bproduction%5D%5Bfoo%23bar%5D%20FooError%3A%20Too%20Much%20Bar/) + WebMock.should requested.with(:body => /See%20this%20exception%20on%20Errbit/) + + err.issue_link.should == @issue_link + end +end + diff --git a/spec/models/issue_trackers/lighthouse_tracker_spec.rb b/spec/models/issue_trackers/lighthouse_tracker_spec.rb new file mode 100644 index 0000000..50fda38 --- /dev/null +++ b/spec/models/issue_trackers/lighthouse_tracker_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe LighthouseTracker do + it "should create an issue on Lighthouse with err params, and set issue link for err" do + notice = Factory :notice + tracker = Factory :lighthouse_tracker, :app => notice.err.app + err = notice.err + + number = 5 + @issue_link = "http://#{tracker.account}.lighthouseapp.com/projects/#{tracker.project_id}/tickets/#{number}.xml" + body = "<ticket><number type=\"integer\">#{number}</number></ticket>" + stub_request(:post, "http://#{tracker.account}.lighthouseapp.com/projects/#{tracker.project_id}/tickets.xml"). + to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => body ) + + err.app.issue_tracker.create_issue(err) + err.reload + + requested = have_requested(:post, "http://#{tracker.account}.lighthouseapp.com/projects/#{tracker.project_id}/tickets.xml") + WebMock.should requested.with(:headers => {'X-Lighthousetoken' => tracker.api_token}) + WebMock.should requested.with(:body => /<tag>errbit<\/tag>/) + WebMock.should requested.with(:body => /<title>\[#{ err.environment }\]\[#{err.where}\] #{err.message.to_s.truncate(100)}<\/title>/) + WebMock.should requested.with(:body => /<body>.+<\/body>/m) + + err.issue_link.should == @issue_link.sub(/\.xml$/, '') + end +end + diff --git a/spec/models/issue_trackers/mingle_tracker_spec.rb b/spec/models/issue_trackers/mingle_tracker_spec.rb new file mode 100644 index 0000000..e5619fa --- /dev/null +++ b/spec/models/issue_trackers/mingle_tracker_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe MingleTracker do + it "should create an issue on Mingle with err params, and set issue link for err" do + notice = Factory :notice + tracker = Factory :mingle_tracker, :app => notice.err.app + err = notice.err + + number = 5 + @issue_link = "#{tracker.account}/projects/#{tracker.project_id}/cards/#{number}.xml" + @basic_auth = tracker.account.gsub("://", "://#{tracker.username}:#{tracker.password}@") + body = "<card><id type=\"integer\">#{number}</id></card>" + stub_request(:post, "#{@basic_auth}/api/v1/projects/#{tracker.project_id}/cards.xml"). + to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => body ) + + err.app.issue_tracker.create_issue(err) + err.reload + + requested = have_requested(:post, "#{@basic_auth}/api/v1/projects/#{tracker.project_id}/cards.xml") + WebMock.should requested.with(:headers => {'Content-Type' => 'application/xml'}) + WebMock.should requested.with(:body => /FooError: Too Much Bar/) + WebMock.should requested.with(:body => /See this exception on Errbit/) + WebMock.should requested.with(:body => /<card-type-name>Defect<\/card-type-name>/) + + err.issue_link.should == @issue_link.sub(/\.xml$/, '') + end +end + diff --git a/spec/models/issue_trackers/pivotal_labs_tracker_spec.rb b/spec/models/issue_trackers/pivotal_labs_tracker_spec.rb new file mode 100644 index 0000000..5b9d221 --- /dev/null +++ b/spec/models/issue_trackers/pivotal_labs_tracker_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe PivotalLabsTracker do + it "should create an issue on Pivotal Tracker with err params, and set issue link for err" do + notice = Factory :notice + tracker = Factory :pivotal_labs_tracker, :app => notice.err.app, :project_id => 10 + err = notice.err + + story_id = 5 + @issue_link = "https://www.pivotaltracker.com/story/show/#{story_id}" + project_body = "<project><id>#{tracker.project_id}</id><name>TestProject</name></project>" + stub_request(:get, "https://www.pivotaltracker.com/services/v3/projects/#{tracker.project_id}"). + to_return(:status => 200, :headers => {'Location' => @issue_link}, :body => project_body ) + story_body = "<story><name>Test Story</name><id>#{story_id}</id></story>" + stub_request(:post, "https://www.pivotaltracker.com/services/v3/projects/#{tracker.project_id}/stories"). + to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => story_body ) + + err.app.issue_tracker.create_issue(err) + err.reload + + requested = have_requested(:post, "https://www.pivotaltracker.com/services/v3/projects/#{tracker.project_id}/stories") + WebMock.should requested.with(:headers => {'X-Trackertoken' => tracker.api_token}) + WebMock.should requested.with(:body => /See this exception on Errbit/) + WebMock.should requested.with(:body => /<name>\[#{ err.environment }\]\[#{err.where}\] #{err.message.to_s.truncate(100)}<\/name>/) + WebMock.should requested.with(:body => /<description>.+<\/description>/m) + + err.issue_link.should == @issue_link + end +end + diff --git a/spec/models/issue_trackers/redmine_tracker_spec.rb b/spec/models/issue_trackers/redmine_tracker_spec.rb new file mode 100644 index 0000000..0b9f4b9 --- /dev/null +++ b/spec/models/issue_trackers/redmine_tracker_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +describe RedmineTracker do + it "should create an issue on Redmine with err params, and set issue link for err" do + notice = Factory :notice + tracker = Factory :redmine_tracker, :app => notice.err.app, :project_id => 10 + err = notice.err + number = 5 + @issue_link = "#{tracker.account}/issues/#{number}.xml?project_id=#{tracker.project_id}" + body = "<issue><subject>my subject</subject><id>#{number}</id></issue>" + stub_request(:post, "#{tracker.account}/issues.xml"). + to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => body ) + + err.app.issue_tracker.create_issue(err) + err.reload + + requested = have_requested(:post, "#{tracker.account}/issues.xml") + WebMock.should requested.with(:headers => {'X-Redmine-API-Key' => tracker.api_token}) + WebMock.should requested.with(:body => /<project-id>#{tracker.project_id}<\/project-id>/) + WebMock.should requested.with(:body => /<subject>\[#{ err.environment }\]\[#{err.where}\] #{err.message.to_s.truncate(100)}<\/subject>/) + WebMock.should requested.with(:body => /<description>.+<\/description>/m) + + err.issue_link.should == @issue_link.sub(/\.xml/, '') + end +end + -- libgit2 0.21.2