diff options
author | Stan Hu <stanhu@gmail.com> | 2015-08-12 00:40:54 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2015-08-12 07:31:25 -0700 |
commit | 23790570026ce78e3b4cbbf1b2f32ada992c5f40 (patch) | |
tree | 01ca42d07aa5d3d7a12d37767a8de3e8e4e55a7d /spec | |
parent | cb6ad67f52c9e849e0f8ca34b2fff47c585bd816 (diff) | |
download | gitlab-ce-23790570026ce78e3b4cbbf1b2f32ada992c5f40.tar.gz |
Provide more feedback what went wrong if HipChat service failed test
Issue gitlab-com/support-forum#213
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/services_controller_spec.rb | 35 | ||||
-rw-r--r-- | spec/models/project_services/hipchat_service_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/service_spec.rb | 10 |
3 files changed, 53 insertions, 0 deletions
diff --git a/spec/controllers/projects/services_controller_spec.rb b/spec/controllers/projects/services_controller_spec.rb new file mode 100644 index 00000000000..d4ecd98e12d --- /dev/null +++ b/spec/controllers/projects/services_controller_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe Projects::ServicesController do + let(:project) { create(:project) } + let(:user) { create(:user) } + let(:service) { create(:service, project: project) } + + before do + sign_in(user) + project.team << [user, :master] + controller.instance_variable_set(:@project, project) + controller.instance_variable_set(:@service, service) + request.env["HTTP_REFERER"] = "/" + end + + describe "#test" do + context 'success' do + it "should redirect and show success message" do + expect(service).to receive(:test).and_return({ success: true, result: 'done' }) + get :test, namespace_id: project.namespace.id, project_id: project.id, id: service.id, format: :html + expect(response.status).to redirect_to('/') + expect(flash[:notice]).to eq('We sent a request to the provided URL') + end + end + + context 'failure' do + it "should redirect and show failure message" do + expect(service).to receive(:test).and_return({ success: false, result: 'Bad test' }) + get :test, namespace_id: project.namespace.id, project_id: project.id, id: service.id, format: :html + expect(response.status).to redirect_to('/') + expect(flash[:alert]).to eq('We tried to send a request to the provided URL but an error occurred: Bad test') + end + end + end +end diff --git a/spec/models/project_services/hipchat_service_spec.rb b/spec/models/project_services/hipchat_service_spec.rb index 4707673269a..65d16beef91 100644 --- a/spec/models/project_services/hipchat_service_spec.rb +++ b/spec/models/project_services/hipchat_service_spec.rb @@ -47,6 +47,14 @@ describe HipchatService do WebMock.stub_request(:post, api_url) end + it 'should test and return errors' do + allow(hipchat).to receive(:execute).and_raise(StandardError, 'no such room') + result = hipchat.test(push_sample_data) + + expect(result[:success]).to be_falsey + expect(result[:result].to_s).to eq('no such room') + end + it 'should use v1 if version is provided' do allow(hipchat).to receive(:api_version).and_return('v1') expect(HipChat::Client).to receive(:new). diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index ca11758ee06..a213ffe6c4b 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -46,6 +46,16 @@ describe Service do describe :can_test do it { expect(@testable).to eq(true) } end + + describe :test do + let(:data) { 'test' } + + it 'test runs execute' do + expect(@service).to receive(:execute).with(data) + + @service.test(data) + end + end end describe "With commits" do |