diff options
Diffstat (limited to 'spec/models')
23 files changed, 78 insertions, 38 deletions
diff --git a/spec/models/badge_spec.rb b/spec/models/badge_spec.rb index c661f5384ea..60ae579eb03 100644 --- a/spec/models/badge_spec.rb +++ b/spec/models/badge_spec.rb @@ -81,13 +81,13 @@ describe Badge do let(:badge) { build(:badge, link_url: placeholder_url, image_url: placeholder_url) } let!(:project) { create(:project) } - context '#rendered_link_url' do + describe '#rendered_link_url' do let(:method) { :link_url } it_behaves_like 'rendered_links' end - context '#rendered_image_url' do + describe '#rendered_image_url' do let(:method) { :image_url } it_behaves_like 'rendered_links' diff --git a/spec/models/badges/project_badge_spec.rb b/spec/models/badges/project_badge_spec.rb index d41c5cf2ca1..c0e85d3de87 100644 --- a/spec/models/badges/project_badge_spec.rb +++ b/spec/models/badges/project_badge_spec.rb @@ -30,13 +30,13 @@ describe ProjectBadge do let(:badge) { build(:project_badge, link_url: placeholder_url, image_url: placeholder_url) } let!(:project) { badge.project } - context '#rendered_link_url' do + describe '#rendered_link_url' do let(:method) { :link_url } it_behaves_like 'rendered_links' end - context '#rendered_image_url' do + describe '#rendered_image_url' do let(:method) { :image_url } it_behaves_like 'rendered_links' diff --git a/spec/models/ci/artifact_blob_spec.rb b/spec/models/ci/artifact_blob_spec.rb index 8a66b55cc15..99983686670 100644 --- a/spec/models/ci/artifact_blob_spec.rb +++ b/spec/models/ci/artifact_blob_spec.rb @@ -51,7 +51,7 @@ describe Ci::ArtifactBlob do allow(Gitlab.config.pages).to receive(:artifacts_server).and_return(true) end - context '.gif extension' do + describe '.gif extension' do it 'returns nil' do expect(subject.external_url(build.project, build)).to be_nil end diff --git a/spec/models/ci/persistent_ref_spec.rb b/spec/models/ci/persistent_ref_spec.rb index ece478fdd36..4cece0664cf 100644 --- a/spec/models/ci/persistent_ref_spec.rb +++ b/spec/models/ci/persistent_ref_spec.rb @@ -11,7 +11,7 @@ describe Ci::PersistentRef do pipeline.succeed! end - context '#exist?' do + describe '#exist?' do subject { pipeline.persistent_ref.exist? } let(:pipeline) { create(:ci_pipeline, sha: sha, project: project) } @@ -31,7 +31,7 @@ describe Ci::PersistentRef do end end - context '#create' do + describe '#create' do subject { pipeline.persistent_ref.create } let(:pipeline) { create(:ci_pipeline, sha: sha, project: project) } @@ -81,7 +81,7 @@ describe Ci::PersistentRef do end end - context '#delete' do + describe '#delete' do subject { pipeline.persistent_ref.delete } let(:pipeline) { create(:ci_pipeline, sha: sha, project: project) } diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index 5c9a03a26ec..3e494d19233 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -25,7 +25,7 @@ describe Ci::Runner do end end - context '#exactly_one_group' do + describe '#exactly_one_group' do let(:group) { create(:group) } let(:runner) { create(:ci_runner, :group, groups: [group]) } diff --git a/spec/models/concerns/avatarable_spec.rb b/spec/models/concerns/avatarable_spec.rb index c750be6b75c..100953549ea 100644 --- a/spec/models/concerns/avatarable_spec.rb +++ b/spec/models/concerns/avatarable_spec.rb @@ -48,14 +48,14 @@ describe Avatarable do end it 'calls local_url twice for path and URLs' do - expect(project.avatar).to receive(:local_url).exactly(2).times.and_call_original + expect(project.avatar).to receive(:local_url).twice.and_call_original expect(project.avatar_path(only_path: true)).to eq(avatar_path) expect(project.avatar_path(only_path: false)).to eq(avatar_url) end it 'calls local_url twice for different sizes' do - expect(project.avatar).to receive(:local_url).exactly(2).times.and_call_original + expect(project.avatar).to receive(:local_url).twice.and_call_original expect(project.avatar_path).to eq(avatar_path) expect(project.avatar_path(size: 40)).to eq(avatar_path + "?width=40") @@ -64,7 +64,7 @@ describe Avatarable do it 'handles unpersisted objects' do new_project = build(:project, :with_avatar) path = [relative_url_root, new_project.avatar.local_url].join - expect(new_project.avatar).to receive(:local_url).exactly(2).times.and_call_original + expect(new_project.avatar).to receive(:local_url).twice.and_call_original 2.times do expect(new_project.avatar_path).to eq(path) diff --git a/spec/models/concerns/routable_spec.rb b/spec/models/concerns/routable_spec.rb index f78a089bc2e..c891fdcb6b5 100644 --- a/spec/models/concerns/routable_spec.rb +++ b/spec/models/concerns/routable_spec.rb @@ -58,7 +58,7 @@ describe Group, 'Routable' do end end - context '.find_by_full_path' do + describe '.find_by_full_path' do let!(:nested_group) { create(:group, parent: group) } context 'without any redirect routes' do diff --git a/spec/models/concerns/triggerable_hooks_spec.rb b/spec/models/concerns/triggerable_hooks_spec.rb index ac1bc51d950..10a6c1aa821 100644 --- a/spec/models/concerns/triggerable_hooks_spec.rb +++ b/spec/models/concerns/triggerable_hooks_spec.rb @@ -49,7 +49,7 @@ RSpec.describe TriggerableHooks do TestableHook.create!(url: 'http://example2.com', push_events: true) filter1 = double(:filter1) filter2 = double(:filter2) - allow(ActiveHookFilter).to receive(:new).exactly(2).times.and_return(filter1, filter2) + allow(ActiveHookFilter).to receive(:new).twice.and_return(filter1, filter2) expect(filter1).to receive(:matches?).and_return(true) expect(filter2).to receive(:matches?).and_return(false) diff --git a/spec/models/deployment_metrics_spec.rb b/spec/models/deployment_metrics_spec.rb index 32c04e15b73..5a4ae0bbe79 100644 --- a/spec/models/deployment_metrics_spec.rb +++ b/spec/models/deployment_metrics_spec.rb @@ -87,7 +87,7 @@ describe DeploymentMetrics do expect(prometheus_adapter).to receive(:query).with(:deployment, deployment).and_return(simple_metrics) end - it { is_expected.to eq(simple_metrics.merge({ deployment_time: deployment.created_at.to_i })) } + it { is_expected.to eq(simple_metrics.merge({ deployment_time: deployment.finished_at.to_i })) } end end diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb index 0c1b259d6bf..c1beef0b759 100644 --- a/spec/models/deployment_spec.rb +++ b/spec/models/deployment_spec.rb @@ -495,7 +495,7 @@ describe Deployment do end end - context '#update_status' do + describe '#update_status' do let(:deploy) { create(:deployment, status: :running) } it 'changes the status' do diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 5aa74134692..c0501fb16c6 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -359,7 +359,7 @@ describe Issue do allow(subject.project).to receive(:repository).and_return(repository) end - context '#to_branch_name does not exists' do + describe '#to_branch_name does not exists' do before do allow(repository).to receive(:branch_exists?).and_return(false) end @@ -369,7 +369,7 @@ describe Issue do end end - context '#to_branch_name exists not ending with -index' do + describe '#to_branch_name exists not ending with -index' do before do allow(repository).to receive(:branch_exists?).and_return(true) allow(repository).to receive(:branch_exists?).with(/#{subject.to_branch_name}-\d/).and_return(false) @@ -380,7 +380,7 @@ describe Issue do end end - context '#to_branch_name exists ending with -index' do + describe '#to_branch_name exists ending with -index' do before do allow(repository).to receive(:branch_exists?).and_return(true) allow(repository).to receive(:branch_exists?).with("#{subject.to_branch_name}-3").and_return(false) diff --git a/spec/models/notification_recipient_spec.rb b/spec/models/notification_recipient_spec.rb index 2ba53818e54..f6a36dbb3fc 100644 --- a/spec/models/notification_recipient_spec.rb +++ b/spec/models/notification_recipient_spec.rb @@ -80,7 +80,7 @@ describe NotificationRecipient do end end - context '#notification_setting' do + describe '#notification_setting' do context 'for child groups' do let!(:moved_group) { create(:group) } let(:group) { create(:group) } diff --git a/spec/models/project_services/bamboo_service_spec.rb b/spec/models/project_services/bamboo_service_spec.rb index 65d227a17f9..1b946278790 100644 --- a/spec/models/project_services/bamboo_service_spec.rb +++ b/spec/models/project_services/bamboo_service_spec.rb @@ -148,7 +148,7 @@ describe BambooService, :use_clean_rails_memory_store_caching do end shared_examples 'reactive cache calculation' do - context '#build_page' do + describe '#build_page' do subject { service.calculate_reactive_cache('123', 'unused')[:build_page] } it 'returns a specific URL when status is 500' do @@ -180,7 +180,7 @@ describe BambooService, :use_clean_rails_memory_store_caching do end end - context '#commit_status' do + describe '#commit_status' do subject { service.calculate_reactive_cache('123', 'unused')[:commit_status] } it 'sets commit status to :error when status is 500' do diff --git a/spec/models/project_services/buildkite_service_spec.rb b/spec/models/project_services/buildkite_service_spec.rb index ca196069055..c622b7706c6 100644 --- a/spec/models/project_services/buildkite_service_spec.rb +++ b/spec/models/project_services/buildkite_service_spec.rb @@ -83,7 +83,7 @@ describe BuildkiteService, :use_clean_rails_memory_store_caching do end describe '#calculate_reactive_cache' do - context '#commit_status' do + describe '#commit_status' do subject { service.calculate_reactive_cache('123', 'unused')[:commit_status] } it 'sets commit status to :error when status is 500' do diff --git a/spec/models/project_services/chat_message/issue_message_spec.rb b/spec/models/project_services/chat_message/issue_message_spec.rb index d3adc62c38e..c4d10be8331 100644 --- a/spec/models/project_services/chat_message/issue_message_spec.rb +++ b/spec/models/project_services/chat_message/issue_message_spec.rb @@ -31,7 +31,7 @@ describe ChatMessage::IssueMessage do context 'without markdown' do let(:color) { '#C95823' } - context '#initialize' do + describe '#initialize' do before do args[:object_attributes][:description] = nil end diff --git a/spec/models/project_services/drone_ci_service_spec.rb b/spec/models/project_services/drone_ci_service_spec.rb index a771d1bf27f..0639a4c1f23 100644 --- a/spec/models/project_services/drone_ci_service_spec.rb +++ b/spec/models/project_services/drone_ci_service_spec.rb @@ -86,7 +86,7 @@ describe DroneCiService, :use_clean_rails_memory_store_caching do describe '#calculate_reactive_cache' do include_context :drone_ci_service - context '#commit_status' do + describe '#commit_status' do subject { drone.calculate_reactive_cache(sha, branch)[:commit_status] } it 'sets commit status to :error when status is 500' do diff --git a/spec/models/project_services/hipchat_service_spec.rb b/spec/models/project_services/hipchat_service_spec.rb index a1bd0855708..ae6e93cfe3a 100644 --- a/spec/models/project_services/hipchat_service_spec.rb +++ b/spec/models/project_services/hipchat_service_spec.rb @@ -352,7 +352,7 @@ describe HipchatService do end end - context "#message_options" do + describe "#message_options" do it "is set to the defaults" do expect(hipchat.__send__(:message_options)).to eq({ notify: false, color: 'yellow' }) end diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index c573bf7793a..832c19adf1d 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -152,7 +152,7 @@ describe JiraService do end end - context '#update' do + describe '#update' do context 'basic update' do let(:new_username) { 'new_username' } let(:new_url) { 'http://jira-new.example.com' } diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index fdcee973fa7..ae4db1c2158 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -4966,7 +4966,7 @@ describe Project do end end - context '#members_among' do + describe '#members_among' do let(:users) { create_list(:user, 3) } set(:group) { create(:group) } @@ -5507,6 +5507,18 @@ describe Project do end end + describe '#limited_protected_branches' do + let(:project) { create(:project) } + let!(:protected_branch) { create(:protected_branch, project: project) } + let!(:another_protected_branch) { create(:protected_branch, project: project) } + + subject { project.limited_protected_branches(1) } + + it 'returns limited number of protected branches based on specified limit' do + expect(subject).to eq([another_protected_branch]) + end + end + def rugged_config rugged_repo(project.repository).config end diff --git a/spec/models/protected_branch_spec.rb b/spec/models/protected_branch_spec.rb index 267434a4148..7f8a60dafa8 100644 --- a/spec/models/protected_branch_spec.rb +++ b/spec/models/protected_branch_spec.rb @@ -220,4 +220,32 @@ describe ProtectedBranch do end end end + + describe '.by_name' do + let!(:protected_branch) { create(:protected_branch, name: 'master') } + let!(:another_protected_branch) { create(:protected_branch, name: 'stable') } + + it 'returns protected branches with a matching name' do + expect(described_class.by_name(protected_branch.name)) + .to eq([protected_branch]) + end + + it 'returns protected branches with a partially matching name' do + expect(described_class.by_name(protected_branch.name[0..2])) + .to eq([protected_branch]) + end + + it 'returns protected branches with a matching name regardless of the casing' do + expect(described_class.by_name(protected_branch.name.upcase)) + .to eq([protected_branch]) + end + + it 'returns nothing when nothing matches' do + expect(described_class.by_name('unknown')).to be_empty + end + + it 'return nothing when query is blank' do + expect(described_class.by_name('')).to be_empty + end + end end diff --git a/spec/models/remote_mirror_spec.rb b/spec/models/remote_mirror_spec.rb index 79d45da8a1e..f5e718e0e09 100644 --- a/spec/models/remote_mirror_spec.rb +++ b/spec/models/remote_mirror_spec.rb @@ -227,7 +227,7 @@ describe RemoteMirror, :mailer do end end - context '#sync' do + describe '#sync' do let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first } around do |example| @@ -297,7 +297,7 @@ describe RemoteMirror, :mailer do end end - context '#ensure_remote!' do + describe '#ensure_remote!' do let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first } let(:project) { remote_mirror.project } let(:repository) { project.repository } @@ -321,7 +321,7 @@ describe RemoteMirror, :mailer do end end - context '#url=' do + describe '#url=' do let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first } it 'resets all the columns when URL changes' do @@ -340,7 +340,7 @@ describe RemoteMirror, :mailer do end end - context '#updated_since?' do + describe '#updated_since?' do let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first } let(:timestamp) { Time.now - 5.minutes } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index d441f54a0fb..ac001ec3118 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -681,7 +681,7 @@ describe User, :do_not_mock_admin_mode do end describe 'before save hook' do - context '#default_private_profile_to_false' do + describe '#default_private_profile_to_false' do let(:user) { create(:user, private_profile: true) } it 'converts nil to false' do @@ -3161,7 +3161,7 @@ describe User, :do_not_mock_admin_mode do end end - context '.active' do + describe '.active' do before do described_class.ghost create(:user, name: 'user', state: 'active') @@ -3181,7 +3181,7 @@ describe User, :do_not_mock_admin_mode do end end - context '#invalidate_issue_cache_counts' do + describe '#invalidate_issue_cache_counts' do let(:user) { build_stubbed(:user) } it 'invalidates cache for issue counter' do @@ -3195,7 +3195,7 @@ describe User, :do_not_mock_admin_mode do end end - context '#invalidate_merge_request_cache_counts' do + describe '#invalidate_merge_request_cache_counts' do let(:user) { build_stubbed(:user) } it 'invalidates cache for Merge Request counter' do @@ -3209,7 +3209,7 @@ describe User, :do_not_mock_admin_mode do end end - context '#invalidate_personal_projects_count' do + describe '#invalidate_personal_projects_count' do let(:user) { build_stubbed(:user) } it 'invalidates cache for personal projects counter' do diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb index a7c28519c5a..166620a927d 100644 --- a/spec/models/wiki_page_spec.rb +++ b/spec/models/wiki_page_spec.rb @@ -44,7 +44,7 @@ describe WikiPage do WikiDirectory.new('dir_2', pages) end - context "#list_pages" do + describe "#list_pages" do context 'sort by title' do let(:grouped_entries) { described_class.group_by_directory(wiki.list_pages) } let(:expected_grouped_entries) { [dir_1_1, dir_1, page_dir_2, dir_2, page_1, page_6] } |