diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-06 12:07:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-06 12:07:42 +0300 |
commit | 669c24d9276db9a73bbcea40aeab98273aae9e5e (patch) | |
tree | 9548cfccd841b4aae3703cdd1b5bf5c167d5a8dc /spec | |
parent | 13076511c60f62ce0f8baba22ca9b94755a7d3cb (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/git_http_controller_spec.rb | 24 | ||||
-rw-r--r-- | spec/lib/gitlab/plugin_spec.rb | 57 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 7 | ||||
-rw-r--r-- | spec/services/users/activity_service_spec.rb | 4 |
4 files changed, 80 insertions, 12 deletions
diff --git a/spec/controllers/projects/git_http_controller_spec.rb b/spec/controllers/projects/git_http_controller_spec.rb index b7568346cdc..a898e1afd8f 100644 --- a/spec/controllers/projects/git_http_controller_spec.rb +++ b/spec/controllers/projects/git_http_controller_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' describe Projects::GitHttpController do + include GitHttpHelpers + let_it_be(:project) { create(:project, :public, :repository) } let(:project_params) do { @@ -31,6 +33,28 @@ describe Projects::GitHttpController do expect(response.status).to eq(401) end + context 'with authorized user' do + let(:user) { project.owner } + + before do + request.headers.merge! auth_env(user.username, user.password, nil) + end + + it 'returns 200' do + get :info_refs, params: params + + expect(response.status).to eq(200) + end + + it 'updates the user activity' do + expect_next_instance_of(Users::ActivityService) do |activity_service| + expect(activity_service).to receive(:execute) + end + + get :info_refs, params: params + end + end + context 'with exceptions' do before do allow(controller).to receive(:verify_workhorse_api!).and_return(true) diff --git a/spec/lib/gitlab/plugin_spec.rb b/spec/lib/gitlab/plugin_spec.rb index a8ddd774f3f..5d9f6d04caa 100644 --- a/spec/lib/gitlab/plugin_spec.rb +++ b/spec/lib/gitlab/plugin_spec.rb @@ -3,22 +3,59 @@ require 'spec_helper' describe Gitlab::Plugin do + let(:plugin) { Rails.root.join('plugins', 'test.rb') } + let(:tmp_file) { Tempfile.new('plugin-dump') } + + let(:plugin_source) do + <<~EOS + #!/usr/bin/env ruby + x = STDIN.read + File.write('#{tmp_file.path}', x) + EOS + end + + context 'with plugins present' do + before do + File.write(plugin, plugin_source) + end + + after do + FileUtils.rm(plugin) + end + + describe '.any?' do + it 'returns true' do + expect(described_class.any?).to be true + end + end + + describe '.files?' do + it 'returns a list of plugins' do + expect(described_class.files).to match_array([plugin.to_s]) + end + end + end + + context 'without any plugins' do + describe '.any?' do + it 'returns false' do + expect(described_class.any?).to be false + end + end + + describe '.files' do + it 'returns an empty list' do + expect(described_class.files).to be_empty + end + end + end + describe '.execute' do let(:data) { Gitlab::DataBuilder::Push::SAMPLE_DATA } - let(:plugin) { Rails.root.join('plugins', 'test.rb') } - let(:tmp_file) { Tempfile.new('plugin-dump') } let(:result) { described_class.execute(plugin.to_s, data) } let(:success) { result.first } let(:message) { result.last } - let(:plugin_source) do - <<~EOS - #!/usr/bin/env ruby - x = STDIN.read - File.write('#{tmp_file.path}', x) - EOS - end - before do File.write(plugin, plugin_source) end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 169201a9e90..c1c29ac9c29 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -4721,6 +4721,13 @@ describe Project do expect(project.has_active_hooks?(:merge_request_events)).to be_falsey expect(project.has_active_hooks?).to be_truthy end + + it 'returns true when a plugin exists' do + expect(Gitlab::Plugin).to receive(:any?).twice.and_return(true) + + expect(project.has_active_hooks?(:merge_request_events)).to be_truthy + expect(project.has_active_hooks?).to be_truthy + end end describe '#has_active_services?' do diff --git a/spec/services/users/activity_service_spec.rb b/spec/services/users/activity_service_spec.rb index d8d2be87fd3..f477eee1dd6 100644 --- a/spec/services/users/activity_service_spec.rb +++ b/spec/services/users/activity_service_spec.rb @@ -7,7 +7,7 @@ describe Users::ActivityService do let(:user) { create(:user, last_activity_on: last_activity_on) } - subject { described_class.new(user, 'type') } + subject { described_class.new(user) } describe '#execute', :clean_gitlab_redis_shared_state do context 'when last activity is nil' do @@ -40,7 +40,7 @@ describe Users::ActivityService do let(:fake_object) { double(username: 'hello') } it 'does not record activity' do - service = described_class.new(fake_object, 'pull') + service = described_class.new(fake_object) expect(service).not_to receive(:record_activity) |