summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/issues_controller_spec.rb37
-rw-r--r--spec/controllers/projects/services_controller_spec.rb35
-rw-r--r--spec/lib/gitlab/markup_helper_spec.rb2
-rw-r--r--spec/models/project_services/flowdock_service_spec.rb12
-rw-r--r--spec/models/project_services/hipchat_service_spec.rb8
-rw-r--r--spec/models/repository_spec.rb20
-rw-r--r--spec/models/service_spec.rb10
7 files changed, 119 insertions, 5 deletions
diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb
new file mode 100644
index 00000000000..871b9219ca9
--- /dev/null
+++ b/spec/controllers/projects/issues_controller_spec.rb
@@ -0,0 +1,37 @@
+require('spec_helper')
+
+describe Projects::IssuesController do
+ let(:project) { create(:project) }
+ let(:user) { create(:user) }
+ let(:issue) { create(:issue, project: project) }
+
+ before do
+ sign_in(user)
+ project.team << [user, :developer]
+ controller.instance_variable_set(:@project, project)
+ end
+
+ describe "GET #index" do
+ it "returns index" do
+ get :index, namespace_id: project.namespace.id, project_id: project.id
+
+ expect(response.status).to eq(200)
+ end
+
+ it "returns 404 when issues are disabled" do
+ project.issues_enabled = false
+ project.save
+
+ get :index, namespace_id: project.namespace.id, project_id: project.id
+ expect(response.status).to eq(404)
+ end
+
+ it "returns 404 when external issue tracker is enabled" do
+ allow(project).to receive(:default_issues_tracker?).and_return(false)
+
+ get :index, namespace_id: project.namespace.id, project_id: project.id
+ expect(response.status).to eq(404)
+ end
+
+ end
+end
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/lib/gitlab/markup_helper_spec.rb b/spec/lib/gitlab/markup_helper_spec.rb
index 7e716e866b1..e610fab05da 100644
--- a/spec/lib/gitlab/markup_helper_spec.rb
+++ b/spec/lib/gitlab/markup_helper_spec.rb
@@ -15,7 +15,7 @@ describe Gitlab::MarkupHelper do
end
describe '#gitlab_markdown?' do
- %w(mdown md markdown).each do |type|
+ %w(mdown mkd mkdn md markdown).each do |type|
it "returns true for #{type} files" do
expect(Gitlab::MarkupHelper.gitlab_markdown?("README.#{type}")).to be_truthy
end
diff --git a/spec/models/project_services/flowdock_service_spec.rb b/spec/models/project_services/flowdock_service_spec.rb
index 7e5b15cb09e..16296607a94 100644
--- a/spec/models/project_services/flowdock_service_spec.rb
+++ b/spec/models/project_services/flowdock_service_spec.rb
@@ -39,15 +39,19 @@ describe FlowdockService do
token: 'verySecret'
)
@sample_data = Gitlab::PushDataBuilder.build_sample(project, user)
- @api_url = 'https://api.flowdock.com/v1/git/verySecret'
+ @api_url = 'https://api.flowdock.com/v1/messages'
WebMock.stub_request(:post, @api_url)
end
it "should call FlowDock API" do
@flowdock_service.execute(@sample_data)
- expect(WebMock).to have_requested(:post, @api_url).with(
- body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/
- ).once
+ @sample_data[:commits].each do |commit|
+ # One request to Flowdock per new commit
+ next if commit[:id] == @sample_data[:before]
+ expect(WebMock).to have_requested(:post, @api_url).with(
+ body: /#{commit[:id]}.*#{project.path}/
+ ).once
+ 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/repository_spec.rb b/spec/models/repository_spec.rb
index d96244f23e0..05e51532eb8 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -34,6 +34,14 @@ describe Repository do
end
end
+ describe :merged_to_root_ref? do
+ context 'merged branch' do
+ subject { repository.merged_to_root_ref?('improve/awesome') }
+
+ it { is_expected.to be_truthy }
+ end
+ end
+
describe :can_be_merged? do
context 'mergeable branches' do
subject { repository.can_be_merged?('0b4bc9a49b562e85de7cc9e834518ea6828729b9', 'master') }
@@ -46,6 +54,18 @@ describe Repository do
it { is_expected.to be_falsey }
end
+
+ context 'non merged branch' do
+ subject { repository.merged_to_root_ref?('fix') }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'non existent branch' do
+ subject { repository.merged_to_root_ref?('non_existent_branch') }
+
+ it { is_expected.to be_nil }
+ end
end
describe "search_files" do
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