diff --git a/Gemfile.lock b/Gemfile.lock index 42612c9..ce9402a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -93,7 +93,7 @@ GEM errbit_github_plugin (0.1.0) errbit_plugin octokit - errbit_plugin (0.2.0) + errbit_plugin (0.3.0) erubis (2.7.0) execjs (2.0.2) fabrication (2.9.0) diff --git a/spec/controllers/apps_controller_spec.rb b/spec/controllers/apps_controller_spec.rb index 27d7b62..889c013 100644 --- a/spec/controllers/apps_controller_spec.rb +++ b/spec/controllers/apps_controller_spec.rb @@ -312,9 +312,8 @@ describe AppsController do ErrbitPlugin::Registry.issue_trackers.each do |key, klass| context key do it "should save tracker params" do - issue_tracker_klass = klass.new(@app, {}) params = { - :options => issue_tracker_klass.fields.inject({}){|hash,f| hash[f[0]] = "test_value"; hash }, + :options => klass.fields.inject({}){|hash,f| hash[f[0]] = "test_value"; hash }, :type_tracker => key.dup.to_s } put :update, :id => @app.id, :app => {:issue_tracker_attributes => params} @@ -322,8 +321,8 @@ describe AppsController do @app.reload tracker = @app.issue_tracker - expect(tracker.tracker).to be_a(ErrbitPlugin::Registry.issue_tracker(key)) - issue_tracker_klass.fields.each do |field, field_info| + expect(tracker.tracker).to be_a(ErrbitPlugin::Registry.issue_trackers[key]) + klass.fields.each do |field, field_info| case field when :ticket_properties; tracker.send(field.to_sym).should == 'card_type = defect' else tracker.options[field.to_s].should == 'test_value' diff --git a/spec/decorators/issue_tracker_decorator_spec.rb b/spec/decorators/issue_tracker_decorator_spec.rb index 2567e3e..72a58b8 100644 --- a/spec/decorators/issue_tracker_decorator_spec.rb +++ b/spec/decorators/issue_tracker_decorator_spec.rb @@ -1,23 +1,28 @@ require 'spec_helper' describe IssueTrackerDecorator do + let(:fake_tracker) do + Class.new(ErrbitPlugin::IssueTracker) do + def self.label; 'fake'; end + def self.note; 'a note'; end + def self.fields + { + :foo => {:label => 'foo'}, + :bar => {:label => 'bar'} + } + end - let(:none_tracker) do - ErrbitPlugin::NoneIssueTracker.new(Object.new, 'none') - end - - let(:tracker) do - ErrbitPlugin::FakeIssueTracker.new(Object.new, 'fake') + def configured?; true; end end + end - let(:decorator) do - IssueTrackerDecorator.new(tracker, 'fake') - end + let(:decorator) do + IssueTrackerDecorator.new(fake_tracker, 'fake') + end describe "#note" do - it 'return the html_safe of Note' do - expect(decorator.note).to eql tracker.note + expect(decorator.note).to eql fake_tracker.note end end diff --git a/spec/fabricators/issue_tracker_fabricator.rb b/spec/fabricators/issue_tracker_fabricator.rb index ff75151..fe11a5c 100644 --- a/spec/fabricators/issue_tracker_fabricator.rb +++ b/spec/fabricators/issue_tracker_fabricator.rb @@ -1,3 +1,9 @@ Fabricator :issue_tracker do + type_tracker 'fake' + options {{ + :foo => 'one', + :bar => 'two' + }} + app end diff --git a/spec/interactors/issue_creation_spec.rb b/spec/interactors/issue_creation_spec.rb index 2f02630..bd7ae99 100644 --- a/spec/interactors/issue_creation_spec.rb +++ b/spec/interactors/issue_creation_spec.rb @@ -1,13 +1,8 @@ require 'spec_helper' describe IssueCreation do - class FakeIssueTracker - def initialize(app, params); end - def configured?; true; end - def create_issue(problem,user) ; true; end - end subject(:issue_creation) do - IssueCreation.new(problem, user, tracker_name, request) + IssueCreation.new(problem, user, tracker_name, request) end let(:request) do @@ -29,9 +24,7 @@ describe IssueCreation do end it 'creates an issue if issue tracker is configured' do - a = problem.app - a.build_issue_tracker - expect(ErrbitPlugin::Registry).to receive(:issue_tracker).and_return(FakeIssueTracker) + problem.app.issue_tracker = Fabricate(:issue_tracker) issue_creation.execute expect(errors).to be_empty end diff --git a/spec/models/problem_spec.rb b/spec/models/problem_spec.rb index 412f02a..d9d2c6f 100644 --- a/spec/models/problem_spec.rb +++ b/spec/models/problem_spec.rb @@ -391,22 +391,19 @@ describe Problem do context "with issue_tracker valid associate to app" do let(:issue_tracker) do - it = IssueTracker.new - it.stub(:tracker).and_return(double(:configured? => true, :label => 'foo')) - it + Fabricate(:issue_tracker) end it 'return the issue_tracker label' do - expect(problem.issue_type).to eql 'foo' + expect(problem.issue_type).to eql 'fake' end end context "with issue_tracker not valid associate to app" do let(:issue_tracker) do - it = IssueTracker.new - it.stub(:tracker).and_return(double(:configured? => false)) - it + IssueTracker.new(:type_tracker => 'fake') end + it 'return nil' do expect(problem.issue_type).to be_nil end diff --git a/spec/views/problems/show.html.haml_spec.rb b/spec/views/problems/show.html.haml_spec.rb index bfb4d3b..d5823f1 100644 --- a/spec/views/problems/show.html.haml_spec.rb +++ b/spec/views/problems/show.html.haml_spec.rb @@ -1,22 +1,30 @@ require 'spec_helper' describe "problems/show.html.haml" do - class PivotalLabsTracker - def initialize(app, params); end - def label; 'pivotal'; end - def configured?; true; end - def comments_allowed?; false; end - end - - class GithubIssuesTracker - def initialize(app, params); end - def label; 'github'; end - def configured?; true; end - def comments_allowed?; false; end - end - let(:problem) { Fabricate(:problem) } let(:comment) { Fabricate(:comment) } + let(:pivotal_tracker) { + Class.new(ErrbitPlugin::IssueTracker) do + def self.label; 'pivotal'; end + def initialize(app, params); end + def configured?; true; end + def comments_allowed?; false; end + end + } + let(:github_tracker) { + Class.new(ErrbitPlugin::IssueTracker) do + def initialize(app, params); end + def label; 'github'; end + def configured?; true; end + def comments_allowed?; false; end + end + } + let(:trackers) { + { + 'github' => github_tracker, + 'pivotal' => pivotal_tracker + } + } before do view.stub(:app).and_return(problem.app) @@ -31,7 +39,7 @@ describe "problems/show.html.haml" do def with_issue_tracker(tracker, problem) problem.app.issue_tracker = IssueTracker.new :type_tracker => tracker, :options => {:api_token => "token token token", :project_id => "1234"} - ErrbitPlugin::Registry.stub(:issue_tracker).with(tracker).and_return(tracker.constantize) + ErrbitPlugin::Registry.stub(:issue_trackers).and_return(trackers) view.stub(:problem).and_return(problem) view.stub(:app).and_return(problem.app) end @@ -90,7 +98,7 @@ describe "problems/show.html.haml" do it 'should allow creating issue for github if application has a github tracker' do problem = Fabricate(:problem_with_comments, :app => Fabricate(:app, :github_repo => "test_user/test_repo")) - with_issue_tracker("GithubIssuesTracker", problem) + with_issue_tracker("github", problem) view.stub(:problem).and_return(problem) view.stub(:app).and_return(problem.app) render @@ -113,7 +121,7 @@ describe "problems/show.html.haml" do context "with tracker associate on app" do before do - with_issue_tracker("PivotalLabsTracker", problem) + with_issue_tracker("pivotal", problem) end context "with app having github_repo" do @@ -185,7 +193,7 @@ describe "problems/show.html.haml" do context "with issue tracker" do it 'should not display the comments section' do problem = Fabricate(:problem) - with_issue_tracker("PivotalLabsTracker", problem) + with_issue_tracker("pivotal", problem) render expect(view.view_flow.get(:comments)).to be_blank end @@ -193,7 +201,7 @@ describe "problems/show.html.haml" do it 'should display existing comments' do problem = Fabricate(:problem_with_comments) problem.reload - with_issue_tracker("PivotalLabsTracker", problem) + with_issue_tracker("pivotal", problem) render expect(view.content_for(:comments)).to include('Test comment') -- libgit2 0.21.2