spec/lib/flapjack/gateways/api/entity_methods_spec.rb in flapjack-0.7.27 vs spec/lib/flapjack/gateways/api/entity_methods_spec.rb in flapjack-0.7.28

- old
+ new

@@ -5,21 +5,21 @@ def app Flapjack::Gateways::API end - let(:entity) { mock(Flapjack::Data::Entity) } - let(:entity_check) { mock(Flapjack::Data::EntityCheck) } + let(:entity) { double(Flapjack::Data::Entity) } + let(:entity_check) { double(Flapjack::Data::EntityCheck) } let(:entity_name) { 'www.example.net'} let(:entity_name_esc) { URI.escape(entity_name) } let(:check) { 'ping' } - let(:entity_presenter) { mock(Flapjack::Gateways::API::EntityPresenter) } - let(:entity_check_presenter) { mock(Flapjack::Gateways::API::EntityCheckPresenter) } + let(:entity_presenter) { double(Flapjack::Gateways::API::EntityPresenter) } + let(:entity_check_presenter) { double(Flapjack::Gateways::API::EntityCheckPresenter) } - let(:redis) { mock(::Redis) } + let(:redis) { double(::Redis) } before(:all) do Flapjack::Gateways::API.class_eval { set :raise_errors, true } @@ -46,11 +46,11 @@ end context 'non-bulk API calls' do it "returns the status for all checks on an entity" do - status = mock('status', :to_json => 'status!'.to_json) + status = double('status', :to_json => 'status!'.to_json) result = {:entity => entity_name, :check => check, :status => status} entity_presenter.should_receive(:status).and_return(result) Flapjack::Gateways::API::EntityPresenter.should_receive(:new). with(entity, :redis => redis).and_return(entity_presenter) @@ -70,11 +70,11 @@ get "/status/#{entity_name_esc}" last_response.should be_forbidden end it "returns the status for a check on an entity" do - status = mock('status', :to_json => 'status!'.to_json) + status = double('status', :to_json => 'status!'.to_json) entity_check_presenter.should_receive(:status).and_return(status) Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new). with(entity_check).and_return(entity_check_presenter) @@ -107,11 +107,11 @@ get "/status/#{entity_name_esc}/#{check}" last_response.should be_forbidden end it "returns a list of scheduled maintenance periods for an entity" do - sched = mock('sched', :to_json => 'sched!'.to_json) + sched = double('sched', :to_json => 'sched!'.to_json) result = {:entity => entity_name, :check => check, :scheduled_maintenances => sched} entity_presenter.should_receive(:scheduled_maintenances).with(nil, nil).and_return(result) Flapjack::Gateways::API::EntityPresenter.should_receive(:new). with(entity, :redis => redis).and_return(entity_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). @@ -124,11 +124,11 @@ it "returns a list of scheduled maintenance periods within a time window for an entity" do start = Time.parse('1 Jan 2012') finish = Time.parse('6 Jan 2012') - sched = mock('sched', :to_json => 'sched!'.to_json) + sched = double('sched', :to_json => 'sched!'.to_json) result = {:entity => entity_name, :check => check, :scheduled_maintenances => sched} entity_presenter.should_receive(:scheduled_maintenances).with(start.to_i, finish.to_i).and_return(result) Flapjack::Gateways::API::EntityPresenter.should_receive(:new). with(entity, :redis => redis).and_return(entity_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). @@ -139,11 +139,11 @@ last_response.should be_ok last_response.body.should == [{:check => check, :scheduled_maintenance => sched}].to_json end it "returns a list of scheduled maintenance periods for a check on an entity" do - sched = mock('sched', :to_json => 'sched!'.to_json) + sched = double('sched', :to_json => 'sched!'.to_json) entity_check_presenter.should_receive(:scheduled_maintenances).with(nil, nil).and_return(sched) Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new). with(entity_check).and_return(entity_check_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) @@ -169,11 +169,11 @@ post "/acknowledgements/#{entity_name_esc}/#{check}" last_response.status.should == 204 end it "returns a list of unscheduled maintenance periods for an entity" do - unsched = mock('unsched', :to_json => 'unsched!'.to_json) + unsched = double('unsched', :to_json => 'unsched!'.to_json) result = {:entity => entity_name, :check => check, :unscheduled_maintenances => unsched} entity_presenter.should_receive(:unscheduled_maintenances).with(nil, nil).and_return(result) Flapjack::Gateways::API::EntityPresenter.should_receive(:new). with(entity, :redis => redis).and_return(entity_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). @@ -183,11 +183,11 @@ last_response.should be_ok last_response.body.should == [{:check => check, :unscheduled_maintenance => unsched}].to_json end it "returns a list of unscheduled maintenance periods for a check on an entity" do - unsched = mock('unsched', :to_json => 'unsched!'.to_json) + unsched = double('unsched', :to_json => 'unsched!'.to_json) entity_check_presenter.should_receive(:unscheduled_maintenances).with(nil, nil).and_return(unsched) Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new). with(entity_check).and_return(entity_check_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) @@ -201,11 +201,11 @@ it "returns a list of unscheduled maintenance periods within a time window for a check an entity" do start = Time.parse('1 Jan 2012') finish = Time.parse('6 Jan 2012') - unsched = mock('unsched', :to_json => 'unsched!'.to_json) + unsched = double('unsched', :to_json => 'unsched!'.to_json) entity_check_presenter.should_receive(:unscheduled_maintenances).with(start.to_i, finish.to_i).and_return(unsched) Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new). with(entity_check).and_return(entity_check_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) @@ -217,11 +217,11 @@ last_response.should be_ok last_response.body.should == 'unsched!'.to_json end it "returns a list of outages for an entity" do - out = mock('out', :to_json => 'out!'.to_json) + out = double('out', :to_json => 'out!'.to_json) result = {:entity => entity_name, :check => check, :outages => out} entity_presenter.should_receive(:outages).with(nil, nil).and_return(result) Flapjack::Gateways::API::EntityPresenter.should_receive(:new). with(entity, :redis => redis).and_return(entity_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). @@ -231,11 +231,11 @@ last_response.should be_ok last_response.body.should == [{:check => check, :outages => out}].to_json end it "returns a list of outages for a check on an entity" do - out = mock('out', :to_json => 'out!'.to_json) + out = double('out', :to_json => 'out!'.to_json) entity_check_presenter.should_receive(:outages).with(nil, nil).and_return(out) Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new). with(entity_check).and_return(entity_check_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) @@ -246,11 +246,11 @@ last_response.should be_ok last_response.body.should == 'out!'.to_json end it "returns a list of downtimes for an entity" do - down = mock('down', :to_json => 'down!'.to_json) + down = double('down', :to_json => 'down!'.to_json) result = {:entity => entity_name, :check => check, :downtime => down} entity_presenter.should_receive(:downtime).with(nil, nil).and_return(result) Flapjack::Gateways::API::EntityPresenter.should_receive(:new). with(entity, :redis => redis).and_return(entity_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). @@ -260,11 +260,11 @@ last_response.should be_ok last_response.body.should == [{:check => check, :downtime => down}].to_json end it "returns a list of downtimes for a check on an entity" do - down = mock('down', :to_json => 'down!'.to_json) + down = double('down', :to_json => 'down!'.to_json) entity_check_presenter.should_receive(:downtime).with(nil, nil).and_return(down) Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new). with(entity_check).and_return(entity_check_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) @@ -296,11 +296,11 @@ end context 'bulk API calls' do it "returns the status for all checks on an entity" do - status = mock('status') + status = double('status') result = [{:entity => entity_name, :check => check, :status => status}] entity_presenter.should_receive(:status).and_return(result) Flapjack::Gateways::API::EntityPresenter.should_receive(:new). with(entity, :redis => redis).and_return(entity_presenter) @@ -319,11 +319,11 @@ get "/status", :entity => entity_name last_response.should be_forbidden end it "returns the status for a check on an entity" do - status = mock('status') + status = double('status') result = [{:entity => entity_name, :check => check, :status => status}] entity_check_presenter.should_receive(:status).and_return(status) Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new). with(entity_check).and_return(entity_check_presenter) @@ -433,11 +433,11 @@ end it "deletes scheduled maintenance periods for multiple entity checks" do start_time = Time.now + (60 * 60) # an hour from now - entity_check_2 = mock(Flapjack::Data::EntityCheck) + entity_check_2 = double(Flapjack::Data::EntityCheck) entity_check.should_receive(:end_scheduled_maintenance).with(start_time.to_i) entity_check_2.should_receive(:end_scheduled_maintenance).with(start_time.to_i) Flapjack::Data::EntityCheck.should_receive(:for_entity). @@ -451,11 +451,11 @@ delete "/scheduled_maintenances", :check => {entity_name => [check, 'foo']}, :start_time => start_time.iso8601 last_response.status.should == 204 end it "returns a list of scheduled maintenance periods for an entity" do - sm = mock('sched_maint') + sm = double('sched_maint') result = [{:entity => entity_name, :check => check, :scheduled_maintenances => sm}] entity_presenter.should_receive(:scheduled_maintenances).with(nil, nil).and_return(result) Flapjack::Gateways::API::EntityPresenter.should_receive(:new). @@ -471,11 +471,11 @@ it "returns a list of scheduled maintenance periods within a time window for an entity" do start = Time.parse('1 Jan 2012') finish = Time.parse('6 Jan 2012') - sm = mock('sched_maint') + sm = double('sched_maint') result = [{:entity => entity_name, :check => check, :scheduled_maintenances => sm}] entity_presenter.should_receive(:scheduled_maintenances).with(start.to_i, finish.to_i).and_return(result) Flapjack::Gateways::API::EntityPresenter.should_receive(:new). @@ -489,11 +489,11 @@ last_response.should be_ok last_response.body.should == result.to_json end it "returns a list of scheduled maintenance periods for a check on an entity" do - sm = mock('sched_maint') + sm = double('sched_maint') result = [{:entity => entity_name, :check => check, :scheduled_maintenances => sm}] entity_check_presenter.should_receive(:scheduled_maintenances).with(nil, nil).and_return(sm) Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new). @@ -509,11 +509,11 @@ last_response.should be_ok last_response.body.should == result.to_json end it "returns a list of unscheduled maintenance periods for an entity" do - um = mock('unsched_maint') + um = double('unsched_maint') result = [{:entity => entity_name, :check => check, :unscheduled_maintenances => um}] entity_presenter.should_receive(:unscheduled_maintenances).with(nil, nil).and_return(result) Flapjack::Gateways::API::EntityPresenter.should_receive(:new). @@ -526,11 +526,11 @@ last_response.should be_ok last_response.body.should == result.to_json end it "returns a list of unscheduled maintenance periods for a check on an entity" do - um = mock('unsched_maint') + um = double('unsched_maint') result = [{:entity => entity_name, :check => check, :unscheduled_maintenances => um}] entity_check_presenter.should_receive(:unscheduled_maintenances).with(nil, nil).and_return(um) Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new). @@ -549,11 +549,11 @@ it "returns a list of unscheduled maintenance periods within a time window for a check an entity" do start = Time.parse('1 Jan 2012') finish = Time.parse('6 Jan 2012') - um = mock('unsched_maint') + um = double('unsched_maint') result = [{:entity => entity_name, :check => check, :unscheduled_maintenances => um}] entity_check_presenter.should_receive(:unscheduled_maintenances).with(start.to_i, finish.to_i).and_return(um) Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new). @@ -570,26 +570,26 @@ last_response.should be_ok last_response.body.should == result.to_json end it "returns a list of outages, for one whole entity and two checks on another entity" do - outages_1 = mock('outages_1') - outages_2 = mock('outages_2') - outages_3 = mock('outages_3') + outages_1 = double('outages_1') + outages_2 = double('outages_2') + outages_3 = double('outages_3') entity_2_name = 'entity_2' - entity_2 = mock(Flapjack::Data::Entity) + entity_2 = double(Flapjack::Data::Entity) result = [{:entity => entity_name, :check => check, :outages => outages_1}, {:entity => entity_2_name, :check => 'foo', :outages => outages_2}, {:entity => entity_2_name, :check => 'bar', :outages => outages_3}] - foo_check = mock(Flapjack::Data::EntityCheck) - bar_check = mock(Flapjack::Data::EntityCheck) + foo_check = double(Flapjack::Data::EntityCheck) + bar_check = double(Flapjack::Data::EntityCheck) - foo_check_presenter = mock(Flapjack::Gateways::API::EntityCheckPresenter) - bar_check_presenter = mock(Flapjack::Gateways::API::EntityCheckPresenter) + foo_check_presenter = double(Flapjack::Gateways::API::EntityCheckPresenter) + bar_check_presenter = double(Flapjack::Gateways::API::EntityCheckPresenter) entity_presenter.should_receive(:outages).with(nil, nil).and_return(result[0]) foo_check_presenter.should_receive(:outages).with(nil, nil).and_return(outages_2) bar_check_presenter.should_receive(:outages).with(nil, nil).and_return(outages_3) @@ -615,11 +615,11 @@ last_response.should be_ok last_response.body.should == result.to_json end it "returns a list of outages for a check on an entity" do - outages = mock('outages') + outages = double('outages') result = [{:entity => entity_name, :check => check, :outages => outages}] entity_check_presenter.should_receive(:outages).with(nil, nil).and_return(outages) Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new). @@ -635,11 +635,11 @@ last_response.should be_ok last_response.body.should == result.to_json end it "returns a list of downtimes for an entity" do - downtime = mock('downtime') + downtime = double('downtime') result = [{:entity => entity_name, :check => check, :downtime => downtime}] entity_presenter.should_receive(:downtime).with(nil, nil).and_return(result) Flapjack::Gateways::API::EntityPresenter.should_receive(:new). @@ -652,11 +652,11 @@ last_response.should be_ok last_response.body.should == result.to_json end it "returns a list of downtimes for a check on an entity" do - downtime = mock('downtime') + downtime = double('downtime') result = [{:entity => entity_name, :check => check, :downtime => downtime}] entity_check_presenter.should_receive(:downtime).with(nil, nil).and_return(downtime) Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new). @@ -684,10 +684,10 @@ entity_check.should_receive(:check).and_return(check) Flapjack::Data::EntityCheck.should_receive(:for_entity). with(entity, check, :redis => redis).and_return(entity_check) - entity_check_2 = mock(Flapjack::Data::EntityCheck) + entity_check_2 = double(Flapjack::Data::EntityCheck) entity_check_2.should_receive(:entity).and_return(entity) entity_check_2.should_receive(:entity_name).and_return(entity_name) entity_check_2.should_receive(:check).and_return('foo') Flapjack::Data::EntityCheck.should_receive(:for_entity).