Commit 5e0ed1f2e0bbaf080f477c710a697c281cdb27ef

Authored by Nick Recobra
1 parent e51f7975
Exists in master and in 1 other branch production

Minimal test for request to lighthouseapp.

Gemfile
... ... @@ -14,6 +14,7 @@ end
14 14  
15 15 group :development, :test do
16 16 gem 'rspec-rails', '~> 2.5'
  17 + gem 'webmock'
17 18 end
18 19  
19 20 group :test do
... ...
Gemfile.lock
... ... @@ -28,11 +28,13 @@ GEM
28 28 activemodel (= 3.0.5)
29 29 activesupport (= 3.0.5)
30 30 activesupport (3.0.5)
  31 + addressable (2.2.4)
31 32 arel (2.0.9)
32 33 bcrypt-ruby (2.1.4)
33 34 bson (1.2.4)
34 35 bson_ext (1.2.4)
35 36 builder (2.1.2)
  37 + crack (0.1.8)
36 38 database_cleaner (0.6.5)
37 39 devise (1.1.8)
38 40 bcrypt-ruby (~> 2.1.2)
... ... @@ -102,6 +104,9 @@ GEM
102 104 tzinfo (0.3.25)
103 105 warden (1.0.3)
104 106 rack (>= 1.0.0)
  107 + webmock (1.6.2)
  108 + addressable (>= 2.2.2)
  109 + crack (>= 0.1.7)
105 110 will_paginate (3.0.pre2)
106 111  
107 112 PLATFORMS
... ... @@ -119,4 +124,5 @@ DEPENDENCIES
119 124 rails (= 3.0.5)
120 125 rspec (~> 2.5)
121 126 rspec-rails (~> 2.5)
  127 + webmock
122 128 will_paginate
... ...
app/models/issue_tracker.rb
... ... @@ -11,6 +11,17 @@ class IssueTracker
11 11 field :project_id, :type => String
12 12 field :issue_tracker_type, :type => String, :default => 'lighthouseapp'
13 13  
  14 + def create_issue err
  15 + Lighthouse.account = account
  16 + Lighthouse.token = api_token
  17 +
  18 + ticket = Lighthouse::Ticket.new(:project_id => project_id)
  19 + ticket.title = "[#{ err.where }] #{err.message.to_s.truncate(27)}"
  20 + #ticket.body = err.backtrace.join("\n")
  21 + ticket.tags << "errbit"
  22 + ticket.save
  23 + end
  24 +
14 25 protected
15 26 def check_lighthouseapp_params
16 27 blank_flags = %w( api_token project_id account ).map {|m| self[m].blank? }
... ...
spec/factories.rb
1 1 Factory.sequence(:name) {|n| "John #{n} Doe"}
  2 +Factory.sequence(:word) {|n| "word#{n}"}
2 3 Factory.sequence(:app_name) {|n| "App ##{n}"}
3 4 Factory.sequence(:email) {|n| "email#{n}@example.com"}
4 5 Factory.sequence(:user_email) {|n| "user.#{n}@example.com"}
... ...
spec/factories/app_factories.rb
... ... @@ -25,4 +25,4 @@ Factory.define(:deploy) do |d|
25 25 d.repository 'git@github.com/jdpace/errbit.git'
26 26 d.environment 'production'
27 27 d.revision ActiveSupport::SecureRandom.hex(10)
28   -end
29 28 \ No newline at end of file
  29 +end
... ...
spec/factories/issue_tracker_factories.rb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +Factory.define :lighthouseapp_tracker, :class => IssueTracker do |e|
  2 + e.issue_tracker_type 'lighthouseapp'
  3 + e.account { Factory.next :word }
  4 + e.api_token { Factory.next :word }
  5 + e.project_id { Factory.next :word }
  6 + e.association :app, :factory => :app
  7 +end
0 8 \ No newline at end of file
... ...
spec/models/issue_tracker_spec.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +# encoding: utf-8
  2 +require 'spec_helper'
  3 +
  4 +describe IssueTracker do
  5 + describe "#create_issue" do
  6 + context "lighthouseapp tracker" do
  7 + let(:tracker) { Factory :lighthouseapp_tracker }
  8 + let(:err) { Factory :err }
  9 +
  10 + it "should make request to Lighthouseapp with err params" do
  11 + stub_request(:post, "http://#{tracker.account}.lighthouseapp.com/projects/#{tracker.project_id}/tickets.xml")
  12 + tracker.create_issue err
  13 + WebMock.should have_requested(:post, "http://#{tracker.account}.lighthouseapp.com/projects/#{tracker.project_id}/tickets.xml")
  14 + end
  15 + end
  16 + end
  17 +end
... ...
spec/spec_helper.rb
... ... @@ -4,6 +4,7 @@ ENV[&quot;RAILS_ENV&quot;] ||= &#39;test&#39;
4 4 require File.expand_path("../../config/environment", __FILE__)
5 5 require 'rspec/rails'
6 6 require 'database_cleaner'
  7 +require 'webmock/rspec'
7 8  
8 9 # Requires supporting files with custom matchers and macros, etc,
9 10 # in ./support/ and its subdirectories.
... ... @@ -21,4 +22,5 @@ RSpec.configure do |config|
21 22 DatabaseCleaner[:mongoid].strategy = :truncation
22 23 DatabaseCleaner.clean
23 24 end
  25 + config.include WebMock::API
24 26 end
25 27 \ No newline at end of file
... ...