Commit ded6ff9c02293197efa6df4c01ffa222a1ffb3ef
1 parent
715101b8
Exists in
master
and in
1 other branch
fix tests
Showing
7 changed files
with
59 additions
and
51 deletions
Show diff stats
Gemfile.lock
| @@ -93,7 +93,7 @@ GEM | @@ -93,7 +93,7 @@ GEM | ||
| 93 | errbit_github_plugin (0.1.0) | 93 | errbit_github_plugin (0.1.0) |
| 94 | errbit_plugin | 94 | errbit_plugin |
| 95 | octokit | 95 | octokit |
| 96 | - errbit_plugin (0.2.0) | 96 | + errbit_plugin (0.3.0) |
| 97 | erubis (2.7.0) | 97 | erubis (2.7.0) |
| 98 | execjs (2.0.2) | 98 | execjs (2.0.2) |
| 99 | fabrication (2.9.0) | 99 | fabrication (2.9.0) |
spec/controllers/apps_controller_spec.rb
| @@ -312,9 +312,8 @@ describe AppsController do | @@ -312,9 +312,8 @@ describe AppsController do | ||
| 312 | ErrbitPlugin::Registry.issue_trackers.each do |key, klass| | 312 | ErrbitPlugin::Registry.issue_trackers.each do |key, klass| |
| 313 | context key do | 313 | context key do |
| 314 | it "should save tracker params" do | 314 | it "should save tracker params" do |
| 315 | - issue_tracker_klass = klass.new(@app, {}) | ||
| 316 | params = { | 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 | :type_tracker => key.dup.to_s | 317 | :type_tracker => key.dup.to_s |
| 319 | } | 318 | } |
| 320 | put :update, :id => @app.id, :app => {:issue_tracker_attributes => params} | 319 | put :update, :id => @app.id, :app => {:issue_tracker_attributes => params} |
| @@ -322,8 +321,8 @@ describe AppsController do | @@ -322,8 +321,8 @@ describe AppsController do | ||
| 322 | @app.reload | 321 | @app.reload |
| 323 | 322 | ||
| 324 | tracker = @app.issue_tracker | 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 | case field | 326 | case field |
| 328 | when :ticket_properties; tracker.send(field.to_sym).should == 'card_type = defect' | 327 | when :ticket_properties; tracker.send(field.to_sym).should == 'card_type = defect' |
| 329 | else tracker.options[field.to_s].should == 'test_value' | 328 | else tracker.options[field.to_s].should == 'test_value' |
spec/decorators/issue_tracker_decorator_spec.rb
| 1 | require 'spec_helper' | 1 | require 'spec_helper' |
| 2 | 2 | ||
| 3 | describe IssueTrackerDecorator do | 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 | end | 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 | describe "#note" do | 23 | describe "#note" do |
| 18 | - | ||
| 19 | it 'return the html_safe of Note' do | 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 | end | 26 | end |
| 22 | end | 27 | end |
| 23 | 28 |
spec/fabricators/issue_tracker_fabricator.rb
spec/interactors/issue_creation_spec.rb
| 1 | require 'spec_helper' | 1 | require 'spec_helper' |
| 2 | 2 | ||
| 3 | describe IssueCreation do | 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 | subject(:issue_creation) do | 4 | subject(:issue_creation) do |
| 10 | - IssueCreation.new(problem, user, tracker_name, request) | 5 | + IssueCreation.new(problem, user, tracker_name, request) |
| 11 | end | 6 | end |
| 12 | 7 | ||
| 13 | let(:request) do | 8 | let(:request) do |
| @@ -29,9 +24,7 @@ describe IssueCreation do | @@ -29,9 +24,7 @@ describe IssueCreation do | ||
| 29 | end | 24 | end |
| 30 | 25 | ||
| 31 | it 'creates an issue if issue tracker is configured' do | 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 | issue_creation.execute | 28 | issue_creation.execute |
| 36 | expect(errors).to be_empty | 29 | expect(errors).to be_empty |
| 37 | end | 30 | end |
spec/models/problem_spec.rb
| @@ -391,22 +391,19 @@ describe Problem do | @@ -391,22 +391,19 @@ describe Problem do | ||
| 391 | 391 | ||
| 392 | context "with issue_tracker valid associate to app" do | 392 | context "with issue_tracker valid associate to app" do |
| 393 | let(:issue_tracker) do | 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 | end | 395 | end |
| 398 | 396 | ||
| 399 | it 'return the issue_tracker label' do | 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 | end | 399 | end |
| 402 | end | 400 | end |
| 403 | 401 | ||
| 404 | context "with issue_tracker not valid associate to app" do | 402 | context "with issue_tracker not valid associate to app" do |
| 405 | let(:issue_tracker) do | 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 | end | 405 | end |
| 406 | + | ||
| 410 | it 'return nil' do | 407 | it 'return nil' do |
| 411 | expect(problem.issue_type).to be_nil | 408 | expect(problem.issue_type).to be_nil |
| 412 | end | 409 | end |
spec/views/problems/show.html.haml_spec.rb
| 1 | require 'spec_helper' | 1 | require 'spec_helper' |
| 2 | 2 | ||
| 3 | describe "problems/show.html.haml" do | 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 | let(:problem) { Fabricate(:problem) } | 4 | let(:problem) { Fabricate(:problem) } |
| 19 | let(:comment) { Fabricate(:comment) } | 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 | before do | 29 | before do |
| 22 | view.stub(:app).and_return(problem.app) | 30 | view.stub(:app).and_return(problem.app) |
| @@ -31,7 +39,7 @@ describe "problems/show.html.haml" do | @@ -31,7 +39,7 @@ describe "problems/show.html.haml" do | ||
| 31 | 39 | ||
| 32 | def with_issue_tracker(tracker, problem) | 40 | def with_issue_tracker(tracker, problem) |
| 33 | problem.app.issue_tracker = IssueTracker.new :type_tracker => tracker, :options => {:api_token => "token token token", :project_id => "1234"} | 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 | view.stub(:problem).and_return(problem) | 43 | view.stub(:problem).and_return(problem) |
| 36 | view.stub(:app).and_return(problem.app) | 44 | view.stub(:app).and_return(problem.app) |
| 37 | end | 45 | end |
| @@ -90,7 +98,7 @@ describe "problems/show.html.haml" do | @@ -90,7 +98,7 @@ describe "problems/show.html.haml" do | ||
| 90 | 98 | ||
| 91 | it 'should allow creating issue for github if application has a github tracker' do | 99 | it 'should allow creating issue for github if application has a github tracker' do |
| 92 | problem = Fabricate(:problem_with_comments, :app => Fabricate(:app, :github_repo => "test_user/test_repo")) | 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 | view.stub(:problem).and_return(problem) | 102 | view.stub(:problem).and_return(problem) |
| 95 | view.stub(:app).and_return(problem.app) | 103 | view.stub(:app).and_return(problem.app) |
| 96 | render | 104 | render |
| @@ -113,7 +121,7 @@ describe "problems/show.html.haml" do | @@ -113,7 +121,7 @@ describe "problems/show.html.haml" do | ||
| 113 | 121 | ||
| 114 | context "with tracker associate on app" do | 122 | context "with tracker associate on app" do |
| 115 | before do | 123 | before do |
| 116 | - with_issue_tracker("PivotalLabsTracker", problem) | 124 | + with_issue_tracker("pivotal", problem) |
| 117 | end | 125 | end |
| 118 | 126 | ||
| 119 | context "with app having github_repo" do | 127 | context "with app having github_repo" do |
| @@ -185,7 +193,7 @@ describe "problems/show.html.haml" do | @@ -185,7 +193,7 @@ describe "problems/show.html.haml" do | ||
| 185 | context "with issue tracker" do | 193 | context "with issue tracker" do |
| 186 | it 'should not display the comments section' do | 194 | it 'should not display the comments section' do |
| 187 | problem = Fabricate(:problem) | 195 | problem = Fabricate(:problem) |
| 188 | - with_issue_tracker("PivotalLabsTracker", problem) | 196 | + with_issue_tracker("pivotal", problem) |
| 189 | render | 197 | render |
| 190 | expect(view.view_flow.get(:comments)).to be_blank | 198 | expect(view.view_flow.get(:comments)).to be_blank |
| 191 | end | 199 | end |
| @@ -193,7 +201,7 @@ describe "problems/show.html.haml" do | @@ -193,7 +201,7 @@ describe "problems/show.html.haml" do | ||
| 193 | it 'should display existing comments' do | 201 | it 'should display existing comments' do |
| 194 | problem = Fabricate(:problem_with_comments) | 202 | problem = Fabricate(:problem_with_comments) |
| 195 | problem.reload | 203 | problem.reload |
| 196 | - with_issue_tracker("PivotalLabsTracker", problem) | 204 | + with_issue_tracker("pivotal", problem) |
| 197 | render | 205 | render |
| 198 | 206 | ||
| 199 | expect(view.content_for(:comments)).to include('Test comment') | 207 | expect(view.content_for(:comments)).to include('Test comment') |