diff --git a/Gemfile b/Gemfile index f759356..2157737 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,7 @@ end group :development, :test do gem 'rspec-rails', '~> 2.5' + gem 'webmock' end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 02f7520..4247bf2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -28,11 +28,13 @@ GEM activemodel (= 3.0.5) activesupport (= 3.0.5) activesupport (3.0.5) + addressable (2.2.4) arel (2.0.9) bcrypt-ruby (2.1.4) bson (1.2.4) bson_ext (1.2.4) builder (2.1.2) + crack (0.1.8) database_cleaner (0.6.5) devise (1.1.8) bcrypt-ruby (~> 2.1.2) @@ -102,6 +104,9 @@ GEM tzinfo (0.3.25) warden (1.0.3) rack (>= 1.0.0) + webmock (1.6.2) + addressable (>= 2.2.2) + crack (>= 0.1.7) will_paginate (3.0.pre2) PLATFORMS @@ -119,4 +124,5 @@ DEPENDENCIES rails (= 3.0.5) rspec (~> 2.5) rspec-rails (~> 2.5) + webmock will_paginate diff --git a/app/models/issue_tracker.rb b/app/models/issue_tracker.rb index c969a13..75025f0 100644 --- a/app/models/issue_tracker.rb +++ b/app/models/issue_tracker.rb @@ -11,6 +11,17 @@ class IssueTracker field :project_id, :type => String field :issue_tracker_type, :type => String, :default => 'lighthouseapp' + def create_issue err + Lighthouse.account = account + Lighthouse.token = api_token + + ticket = Lighthouse::Ticket.new(:project_id => project_id) + ticket.title = "[#{ err.where }] #{err.message.to_s.truncate(27)}" + #ticket.body = err.backtrace.join("\n") + ticket.tags << "errbit" + ticket.save + end + protected def check_lighthouseapp_params blank_flags = %w( api_token project_id account ).map {|m| self[m].blank? } diff --git a/spec/factories.rb b/spec/factories.rb index 66fbae2..f6a3dd4 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,4 +1,5 @@ Factory.sequence(:name) {|n| "John #{n} Doe"} +Factory.sequence(:word) {|n| "word#{n}"} Factory.sequence(:app_name) {|n| "App ##{n}"} Factory.sequence(:email) {|n| "email#{n}@example.com"} Factory.sequence(:user_email) {|n| "user.#{n}@example.com"} diff --git a/spec/factories/app_factories.rb b/spec/factories/app_factories.rb index 5f65564..ed56a98 100644 --- a/spec/factories/app_factories.rb +++ b/spec/factories/app_factories.rb @@ -25,4 +25,4 @@ Factory.define(:deploy) do |d| d.repository 'git@github.com/jdpace/errbit.git' d.environment 'production' d.revision ActiveSupport::SecureRandom.hex(10) -end \ No newline at end of file +end diff --git a/spec/factories/issue_tracker_factories.rb b/spec/factories/issue_tracker_factories.rb new file mode 100644 index 0000000..b31eaae --- /dev/null +++ b/spec/factories/issue_tracker_factories.rb @@ -0,0 +1,7 @@ +Factory.define :lighthouseapp_tracker, :class => IssueTracker do |e| + e.issue_tracker_type 'lighthouseapp' + e.account { Factory.next :word } + e.api_token { Factory.next :word } + e.project_id { Factory.next :word } + e.association :app, :factory => :app +end \ No newline at end of file diff --git a/spec/models/issue_tracker_spec.rb b/spec/models/issue_tracker_spec.rb new file mode 100644 index 0000000..9b7e8c7 --- /dev/null +++ b/spec/models/issue_tracker_spec.rb @@ -0,0 +1,17 @@ +# encoding: utf-8 +require 'spec_helper' + +describe IssueTracker do + describe "#create_issue" do + context "lighthouseapp tracker" do + let(:tracker) { Factory :lighthouseapp_tracker } + let(:err) { Factory :err } + + it "should make request to Lighthouseapp with err params" do + stub_request(:post, "http://#{tracker.account}.lighthouseapp.com/projects/#{tracker.project_id}/tickets.xml") + tracker.create_issue err + WebMock.should have_requested(:post, "http://#{tracker.account}.lighthouseapp.com/projects/#{tracker.project_id}/tickets.xml") + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a190415..f4409ab 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,6 +4,7 @@ ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'database_cleaner' +require 'webmock/rspec' # Requires supporting files with custom matchers and macros, etc, # in ./support/ and its subdirectories. @@ -21,4 +22,5 @@ RSpec.configure do |config| DatabaseCleaner[:mongoid].strategy = :truncation DatabaseCleaner.clean end + config.include WebMock::API end \ No newline at end of file -- libgit2 0.21.2