Commit ded6ff9c02293197efa6df4c01ffa222a1ffb3ef

Authored by Stephen Crosby
1 parent 715101b8
Exists in master and in 1 other branch production

fix tests

Gemfile.lock
... ... @@ -93,7 +93,7 @@ GEM
93 93 errbit_github_plugin (0.1.0)
94 94 errbit_plugin
95 95 octokit
96   - errbit_plugin (0.2.0)
  96 + errbit_plugin (0.3.0)
97 97 erubis (2.7.0)
98 98 execjs (2.0.2)
99 99 fabrication (2.9.0)
... ...
spec/controllers/apps_controller_spec.rb
... ... @@ -312,9 +312,8 @@ describe AppsController do
312 312 ErrbitPlugin::Registry.issue_trackers.each do |key, klass|
313 313 context key do
314 314 it "should save tracker params" do
315   - issue_tracker_klass = klass.new(@app, {})
316 315 params = {
317   - :options => issue_tracker_klass.fields.inject({}){|hash,f| hash[f[0]] = "test_value"; hash },
  316 + :options => klass.fields.inject({}){|hash,f| hash[f[0]] = "test_value"; hash },
318 317 :type_tracker => key.dup.to_s
319 318 }
320 319 put :update, :id => @app.id, :app => {:issue_tracker_attributes => params}
... ... @@ -322,8 +321,8 @@ describe AppsController do
322 321 @app.reload
323 322  
324 323 tracker = @app.issue_tracker
325   - expect(tracker.tracker).to be_a(ErrbitPlugin::Registry.issue_tracker(key))
326   - issue_tracker_klass.fields.each do |field, field_info|
  324 + expect(tracker.tracker).to be_a(ErrbitPlugin::Registry.issue_trackers[key])
  325 + klass.fields.each do |field, field_info|
327 326 case field
328 327 when :ticket_properties; tracker.send(field.to_sym).should == 'card_type = defect'
329 328 else tracker.options[field.to_s].should == 'test_value'
... ...
spec/decorators/issue_tracker_decorator_spec.rb
1 1 require 'spec_helper'
2 2  
3 3 describe IssueTrackerDecorator do
  4 + let(:fake_tracker) do
  5 + Class.new(ErrbitPlugin::IssueTracker) do
  6 + def self.label; 'fake'; end
  7 + def self.note; 'a note'; end
  8 + def self.fields
  9 + {
  10 + :foo => {:label => 'foo'},
  11 + :bar => {:label => 'bar'}
  12 + }
  13 + end
4 14  
5   - let(:none_tracker) do
6   - ErrbitPlugin::NoneIssueTracker.new(Object.new, 'none')
7   - end
8   -
9   - let(:tracker) do
10   - ErrbitPlugin::FakeIssueTracker.new(Object.new, 'fake')
  15 + def configured?; true; end
11 16 end
  17 + end
12 18  
13   - let(:decorator) do
14   - IssueTrackerDecorator.new(tracker, 'fake')
15   - end
  19 + let(:decorator) do
  20 + IssueTrackerDecorator.new(fake_tracker, 'fake')
  21 + end
16 22  
17 23 describe "#note" do
18   -
19 24 it 'return the html_safe of Note' do
20   - expect(decorator.note).to eql tracker.note
  25 + expect(decorator.note).to eql fake_tracker.note
21 26 end
22 27 end
23 28  
... ...
spec/fabricators/issue_tracker_fabricator.rb
1 1 Fabricator :issue_tracker do
  2 + type_tracker 'fake'
  3 + options {{
  4 + :foo => 'one',
  5 + :bar => 'two'
  6 + }}
  7 +
2 8 app
3 9 end
... ...
spec/interactors/issue_creation_spec.rb
1 1 require 'spec_helper'
2 2  
3 3 describe IssueCreation do
4   - class FakeIssueTracker
5   - def initialize(app, params); end
6   - def configured?; true; end
7   - def create_issue(problem,user) ; true; end
8   - end
9 4 subject(:issue_creation) do
10   - IssueCreation.new(problem, user, tracker_name, request)
  5 + IssueCreation.new(problem, user, tracker_name, request)
11 6 end
12 7  
13 8 let(:request) do
... ... @@ -29,9 +24,7 @@ describe IssueCreation do
29 24 end
30 25  
31 26 it 'creates an issue if issue tracker is configured' do
32   - a = problem.app
33   - a.build_issue_tracker
34   - expect(ErrbitPlugin::Registry).to receive(:issue_tracker).and_return(FakeIssueTracker)
  27 + problem.app.issue_tracker = Fabricate(:issue_tracker)
35 28 issue_creation.execute
36 29 expect(errors).to be_empty
37 30 end
... ...
spec/models/problem_spec.rb
... ... @@ -391,22 +391,19 @@ describe Problem do
391 391  
392 392 context "with issue_tracker valid associate to app" do
393 393 let(:issue_tracker) do
394   - it = IssueTracker.new
395   - it.stub(:tracker).and_return(double(:configured? => true, :label => 'foo'))
396   - it
  394 + Fabricate(:issue_tracker)
397 395 end
398 396  
399 397 it 'return the issue_tracker label' do
400   - expect(problem.issue_type).to eql 'foo'
  398 + expect(problem.issue_type).to eql 'fake'
401 399 end
402 400 end
403 401  
404 402 context "with issue_tracker not valid associate to app" do
405 403 let(:issue_tracker) do
406   - it = IssueTracker.new
407   - it.stub(:tracker).and_return(double(:configured? => false))
408   - it
  404 + IssueTracker.new(:type_tracker => 'fake')
409 405 end
  406 +
410 407 it 'return nil' do
411 408 expect(problem.issue_type).to be_nil
412 409 end
... ...
spec/views/problems/show.html.haml_spec.rb
1 1 require 'spec_helper'
2 2  
3 3 describe "problems/show.html.haml" do
4   - class PivotalLabsTracker
5   - def initialize(app, params); end
6   - def label; 'pivotal'; end
7   - def configured?; true; end
8   - def comments_allowed?; false; end
9   - end
10   -
11   - class GithubIssuesTracker
12   - def initialize(app, params); end
13   - def label; 'github'; end
14   - def configured?; true; end
15   - def comments_allowed?; false; end
16   - end
17   -
18 4 let(:problem) { Fabricate(:problem) }
19 5 let(:comment) { Fabricate(:comment) }
  6 + let(:pivotal_tracker) {
  7 + Class.new(ErrbitPlugin::IssueTracker) do
  8 + def self.label; 'pivotal'; end
  9 + def initialize(app, params); end
  10 + def configured?; true; end
  11 + def comments_allowed?; false; end
  12 + end
  13 + }
  14 + let(:github_tracker) {
  15 + Class.new(ErrbitPlugin::IssueTracker) do
  16 + def initialize(app, params); end
  17 + def label; 'github'; end
  18 + def configured?; true; end
  19 + def comments_allowed?; false; end
  20 + end
  21 + }
  22 + let(:trackers) {
  23 + {
  24 + 'github' => github_tracker,
  25 + 'pivotal' => pivotal_tracker
  26 + }
  27 + }
20 28  
21 29 before do
22 30 view.stub(:app).and_return(problem.app)
... ... @@ -31,7 +39,7 @@ describe "problems/show.html.haml" do
31 39  
32 40 def with_issue_tracker(tracker, problem)
33 41 problem.app.issue_tracker = IssueTracker.new :type_tracker => tracker, :options => {:api_token => "token token token", :project_id => "1234"}
34   - ErrbitPlugin::Registry.stub(:issue_tracker).with(tracker).and_return(tracker.constantize)
  42 + ErrbitPlugin::Registry.stub(:issue_trackers).and_return(trackers)
35 43 view.stub(:problem).and_return(problem)
36 44 view.stub(:app).and_return(problem.app)
37 45 end
... ... @@ -90,7 +98,7 @@ describe "problems/show.html.haml" do
90 98  
91 99 it 'should allow creating issue for github if application has a github tracker' do
92 100 problem = Fabricate(:problem_with_comments, :app => Fabricate(:app, :github_repo => "test_user/test_repo"))
93   - with_issue_tracker("GithubIssuesTracker", problem)
  101 + with_issue_tracker("github", problem)
94 102 view.stub(:problem).and_return(problem)
95 103 view.stub(:app).and_return(problem.app)
96 104 render
... ... @@ -113,7 +121,7 @@ describe "problems/show.html.haml" do
113 121  
114 122 context "with tracker associate on app" do
115 123 before do
116   - with_issue_tracker("PivotalLabsTracker", problem)
  124 + with_issue_tracker("pivotal", problem)
117 125 end
118 126  
119 127 context "with app having github_repo" do
... ... @@ -185,7 +193,7 @@ describe "problems/show.html.haml" do
185 193 context "with issue tracker" do
186 194 it 'should not display the comments section' do
187 195 problem = Fabricate(:problem)
188   - with_issue_tracker("PivotalLabsTracker", problem)
  196 + with_issue_tracker("pivotal", problem)
189 197 render
190 198 expect(view.view_flow.get(:comments)).to be_blank
191 199 end
... ... @@ -193,7 +201,7 @@ describe "problems/show.html.haml" do
193 201 it 'should display existing comments' do
194 202 problem = Fabricate(:problem_with_comments)
195 203 problem.reload
196   - with_issue_tracker("PivotalLabsTracker", problem)
  204 + with_issue_tracker("pivotal", problem)
197 205 render
198 206  
199 207 expect(view.content_for(:comments)).to include('Test comment')
... ...