From cddc5cacfb833fbd188d2f5982381f66dd3eee3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Tue, 25 Jul 2017 19:09:00 +0200 Subject: Use described_class when possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- spec/models/ability_spec.rb | 2 +- spec/models/application_setting_spec.rb | 6 +- spec/models/broadcast_message_spec.rb | 8 +- spec/models/ci/pipeline_schedule_spec.rb | 4 +- spec/models/ci/runner_spec.rb | 14 +-- spec/models/global_milestone_spec.rb | 14 +-- spec/models/group_milestone_spec.rb | 4 +- spec/models/group_spec.rb | 2 +- spec/models/guest_spec.rb | 10 +- spec/models/hooks/project_hook_spec.rb | 4 +- spec/models/hooks/system_hook_spec.rb | 2 +- spec/models/member_spec.rb | 2 +- spec/models/members/project_member_spec.rb | 2 +- spec/models/merge_request_diff_spec.rb | 2 +- spec/models/milestone_spec.rb | 10 +- spec/models/namespace_spec.rb | 14 +-- spec/models/note_spec.rb | 2 +- spec/models/project_services/asana_service_spec.rb | 2 +- .../project_services/assembla_service_spec.rb | 2 +- .../project_services/campfire_service_spec.rb | 2 +- .../project_services/flowdock_service_spec.rb | 2 +- .../project_services/gemnasium_service_spec.rb | 2 +- .../gitlab_issue_tracker_service_spec.rb | 4 +- .../project_services/hipchat_service_spec.rb | 2 +- spec/models/project_services/irker_service_spec.rb | 2 +- spec/models/project_services/jira_service_spec.rb | 8 +- .../pivotaltracker_service_spec.rb | 2 +- .../project_services/pushover_service_spec.rb | 2 +- spec/models/project_spec.rb | 18 +-- spec/models/project_wiki_spec.rb | 2 +- spec/models/protected_branch_spec.rb | 36 +++--- spec/models/redirect_route_spec.rb | 2 +- spec/models/route_spec.rb | 4 +- spec/models/sent_notification_spec.rb | 4 +- spec/models/user_spec.rb | 128 ++++++++++----------- spec/models/wiki_directory_spec.rb | 4 +- spec/models/wiki_page_spec.rb | 14 +-- 37 files changed, 172 insertions(+), 172 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index cb57626b597..aa019288700 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Ability do context 'using a nil subject' do it 'has no permissions' do - expect(Ability.policy_for(nil, nil)).to be_banned + expect(described_class.policy_for(nil, nil)).to be_banned end end diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 41129b945b6..359753b600e 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe ApplicationSetting do - let(:setting) { ApplicationSetting.create_from_defaults } + let(:setting) { described_class.create_from_defaults } it { expect(setting).to be_valid } it { expect(setting.uuid).to be_present } @@ -159,10 +159,10 @@ describe ApplicationSetting do context 'redis unavailable' do it 'returns an ApplicationSetting' do allow(Rails.cache).to receive(:fetch).and_call_original - allow(ApplicationSetting).to receive(:last).and_return(:last) + allow(described_class).to receive(:last).and_return(:last) expect(Rails.cache).to receive(:fetch).with(ApplicationSetting::CACHE_KEY).and_raise(ArgumentError) - expect(ApplicationSetting.current).to eq(:last) + expect(described_class.current).to eq(:last) end end end diff --git a/spec/models/broadcast_message_spec.rb b/spec/models/broadcast_message_spec.rb index 75e7c7d42bd..a8ca1d110e4 100644 --- a/spec/models/broadcast_message_spec.rb +++ b/spec/models/broadcast_message_spec.rb @@ -24,26 +24,26 @@ describe BroadcastMessage do it 'returns message if time match' do message = create(:broadcast_message) - expect(BroadcastMessage.current).to include(message) + expect(described_class.current).to include(message) end it 'returns multiple messages if time match' do message1 = create(:broadcast_message) message2 = create(:broadcast_message) - expect(BroadcastMessage.current).to contain_exactly(message1, message2) + expect(described_class.current).to contain_exactly(message1, message2) end it 'returns empty list if time not come' do create(:broadcast_message, :future) - expect(BroadcastMessage.current).to be_empty + expect(described_class.current).to be_empty end it 'returns empty list if time has passed' do create(:broadcast_message, :expired) - expect(BroadcastMessage.current).to be_empty + expect(described_class.current).to be_empty end end diff --git a/spec/models/ci/pipeline_schedule_spec.rb b/spec/models/ci/pipeline_schedule_spec.rb index 3ae86ab2b4b..9a278212efc 100644 --- a/spec/models/ci/pipeline_schedule_spec.rb +++ b/spec/models/ci/pipeline_schedule_spec.rb @@ -46,7 +46,7 @@ describe Ci::PipelineSchedule do end it 'updates next_run_at automatically' do - expect(Ci::PipelineSchedule.last.next_run_at).to eq(expected_next_run_at) + expect(described_class.last.next_run_at).to eq(expected_next_run_at) end end @@ -61,7 +61,7 @@ describe Ci::PipelineSchedule do it 'updates next_run_at automatically' do pipeline_schedule.update!(cron: new_cron) - expect(Ci::PipelineSchedule.last.next_run_at).to eq(expected_next_run_at) + expect(described_class.last.next_run_at).to eq(expected_next_run_at) end end end diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index 9a4ed86990a..8d12a9c09ca 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -50,7 +50,7 @@ describe Ci::Runner do end describe '.online' do - subject { Ci::Runner.online } + subject { described_class.online } before do @runner1 = FactoryGirl.create(:ci_runner, :shared, contacted_at: 1.year.ago) @@ -352,13 +352,13 @@ describe Ci::Runner do end context 'does not give owned runner' do - subject { Ci::Runner.assignable_for(project) } + subject { described_class.assignable_for(project) } it { is_expected.to be_empty } end context 'does not give shared runner' do - subject { Ci::Runner.assignable_for(another_project) } + subject { described_class.assignable_for(another_project) } it { is_expected.to be_empty } end @@ -366,13 +366,13 @@ describe Ci::Runner do context 'with unlocked runner' do context 'does not give owned runner' do - subject { Ci::Runner.assignable_for(project) } + subject { described_class.assignable_for(project) } it { is_expected.to be_empty } end context 'does give a specific runner' do - subject { Ci::Runner.assignable_for(another_project) } + subject { described_class.assignable_for(another_project) } it { is_expected.to contain_exactly(runner) } end @@ -384,13 +384,13 @@ describe Ci::Runner do end context 'does not give owned runner' do - subject { Ci::Runner.assignable_for(project) } + subject { described_class.assignable_for(project) } it { is_expected.to be_empty } end context 'does not give a locked runner' do - subject { Ci::Runner.assignable_for(another_project) } + subject { described_class.assignable_for(another_project) } it { is_expected.to be_empty } end diff --git a/spec/models/global_milestone_spec.rb b/spec/models/global_milestone_spec.rb index 17462f70a6d..5584a1a5a31 100644 --- a/spec/models/global_milestone_spec.rb +++ b/spec/models/global_milestone_spec.rb @@ -72,7 +72,7 @@ describe GlobalMilestone do project3 ] - @global_milestones = GlobalMilestone.build_collection(projects, {}) + @global_milestones = described_class.build_collection(projects, {}) end it 'has all project milestones' do @@ -106,7 +106,7 @@ describe GlobalMilestone do it 'returns the quantity of global milestones in each possible state' do expected_count = { opened: 1, closed: 2, all: 2 } - count = GlobalMilestone.states_count(Project.all) + count = described_class.states_count(Project.all) expect(count).to eq(expected_count) end @@ -120,7 +120,7 @@ describe GlobalMilestone do it 'returns 0 as the quantity of global milestones in each state' do expected_count = { opened: 0, closed: 0, all: 0 } - count = GlobalMilestone.states_count(Project.all) + count = described_class.states_count(Project.all) expect(count).to eq(expected_count) end @@ -141,7 +141,7 @@ describe GlobalMilestone do ] milestones_relation = Milestone.where(id: milestones.map(&:id)) - @global_milestone = GlobalMilestone.new(milestone1_project1.title, milestones_relation) + @global_milestone = described_class.new(milestone1_project1.title, milestones_relation) end it 'has exactly one group milestone' do @@ -157,7 +157,7 @@ describe GlobalMilestone do let(:milestone) { create(:milestone, title: "git / test", project: project1) } it 'strips out slashes and spaces' do - global_milestone = GlobalMilestone.new(milestone.title, Milestone.where(id: milestone.id)) + global_milestone = described_class.new(milestone.title, Milestone.where(id: milestone.id)) expect(global_milestone.safe_title).to eq('git-test') end @@ -171,7 +171,7 @@ describe GlobalMilestone do create(:active_milestone, title: title), create(:closed_milestone, title: title) ] - global_milestone = GlobalMilestone.new(title, milestones) + global_milestone = described_class.new(title, milestones) expect(global_milestone.state).to eq('active') end @@ -184,7 +184,7 @@ describe GlobalMilestone do create(:closed_milestone, title: title), create(:closed_milestone, title: title) ] - global_milestone = GlobalMilestone.new(title, milestones) + global_milestone = described_class.new(title, milestones) expect(global_milestone.state).to eq('closed') end diff --git a/spec/models/group_milestone_spec.rb b/spec/models/group_milestone_spec.rb index 6d1a7f188c8..ac76c927c39 100644 --- a/spec/models/group_milestone_spec.rb +++ b/spec/models/group_milestone_spec.rb @@ -9,7 +9,7 @@ describe GroupMilestone do describe '.build' do it 'returns milestone with group assigned' do - milestone = GroupMilestone.build( + milestone = described_class.build( group, [project], project_milestone.title @@ -25,7 +25,7 @@ describe GroupMilestone do end it 'returns array of milestones, each with group assigned' do - milestones = GroupMilestone.build_collection(group, [project], {}) + milestones = described_class.build_collection(group, [project], {}) expect(milestones).to all(have_attributes(group: group)) end end diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 3f66d9b0ab9..112bd605a64 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -357,7 +357,7 @@ describe Group do subject { build(:group, :nested) } it { is_expected.to be_valid } - it { expect(subject.parent).to be_kind_of(Group) } + it { expect(subject.parent).to be_kind_of(described_class) } end describe '#members_with_parents', :nested_groups do diff --git a/spec/models/guest_spec.rb b/spec/models/guest_spec.rb index ac9aaa76550..0e9b94aac97 100644 --- a/spec/models/guest_spec.rb +++ b/spec/models/guest_spec.rb @@ -8,13 +8,13 @@ describe Guest do describe '.can_pull?' do context 'when project is private' do it 'does not allow to pull the repo' do - expect(Guest.can?(:download_code, private_project)).to eq(false) + expect(described_class.can?(:download_code, private_project)).to eq(false) end end context 'when project is internal' do it 'does not allow to pull the repo' do - expect(Guest.can?(:download_code, internal_project)).to eq(false) + expect(described_class.can?(:download_code, internal_project)).to eq(false) end end @@ -23,7 +23,7 @@ describe Guest do it 'does not allow to pull the repo' do public_project.project_feature.update_attribute(:repository_access_level, ProjectFeature::DISABLED) - expect(Guest.can?(:download_code, public_project)).to eq(false) + expect(described_class.can?(:download_code, public_project)).to eq(false) end end @@ -31,13 +31,13 @@ describe Guest do it 'does not allow to pull the repo' do public_project.project_feature.update_attribute(:repository_access_level, ProjectFeature::PRIVATE) - expect(Guest.can?(:download_code, public_project)).to eq(false) + expect(described_class.can?(:download_code, public_project)).to eq(false) end end context 'when repository is enabled' do it 'allows to pull the repo' do - expect(Guest.can?(:download_code, public_project)).to eq(true) + expect(described_class.can?(:download_code, public_project)).to eq(true) end end end diff --git a/spec/models/hooks/project_hook_spec.rb b/spec/models/hooks/project_hook_spec.rb index c9b948fb747..5dd31b1b5de 100644 --- a/spec/models/hooks/project_hook_spec.rb +++ b/spec/models/hooks/project_hook_spec.rb @@ -13,7 +13,7 @@ describe ProjectHook do it 'returns hooks for push events only' do hook = create(:project_hook, push_events: true) create(:project_hook, push_events: false) - expect(ProjectHook.push_hooks).to eq([hook]) + expect(described_class.push_hooks).to eq([hook]) end end @@ -21,7 +21,7 @@ describe ProjectHook do it 'returns hooks for tag push events only' do hook = create(:project_hook, tag_push_events: true) create(:project_hook, tag_push_events: false) - expect(ProjectHook.tag_push_hooks).to eq([hook]) + expect(described_class.tag_push_hooks).to eq([hook]) end end end diff --git a/spec/models/hooks/system_hook_spec.rb b/spec/models/hooks/system_hook_spec.rb index 812dcb437f5..eadc232a989 100644 --- a/spec/models/hooks/system_hook_spec.rb +++ b/spec/models/hooks/system_hook_spec.rb @@ -122,7 +122,7 @@ describe SystemHook do it 'returns hooks for repository update events only' do hook = create(:system_hook, repository_update_events: true) create(:system_hook, repository_update_events: false) - expect(SystemHook.repository_update_hooks).to eq([hook]) + expect(described_class.repository_update_hooks).to eq([hook]) end end diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index 22e62ee0823..8bfd70b8d46 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -6,7 +6,7 @@ describe Member do end describe "Validation" do - subject { Member.new(access_level: Member::GUEST) } + subject { described_class.new(access_level: Member::GUEST) } it { is_expected.to validate_presence_of(:user) } it { is_expected.to validate_presence_of(:source) } diff --git a/spec/models/members/project_member_spec.rb b/spec/models/members/project_member_spec.rb index 93df1b2fb6c..025fb2bf441 100644 --- a/spec/models/members/project_member_spec.rb +++ b/spec/models/members/project_member_spec.rb @@ -139,7 +139,7 @@ describe ProjectMember do @project_1.team << [@user_1, :developer] @project_2.team << [@user_2, :reporter] - ProjectMember.truncate_teams([@project_1.id, @project_2.id]) + described_class.truncate_teams([@project_1.id, @project_2.id]) end it { expect(@project_1.users).to be_empty } diff --git a/spec/models/merge_request_diff_spec.rb b/spec/models/merge_request_diff_spec.rb index d09f880423b..0cfaa17676e 100644 --- a/spec/models/merge_request_diff_spec.rb +++ b/spec/models/merge_request_diff_spec.rb @@ -98,7 +98,7 @@ describe MergeRequestDiff do end it 'saves empty state' do - allow_any_instance_of(MergeRequestDiff).to receive_message_chain(:compare, :commits) + allow_any_instance_of(described_class).to receive_message_chain(:compare, :commits) .and_return([]) mr_diff = create(:merge_request).merge_request_diff diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb index 0dd8a86106b..aa376e242e8 100644 --- a/spec/models/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -37,13 +37,13 @@ describe Milestone do describe "unique milestone title" do context "per project" do it "does not accept the same title in a project twice" do - new_milestone = Milestone.new(project: milestone.project, title: milestone.title) + new_milestone = described_class.new(project: milestone.project, title: milestone.title) expect(new_milestone).not_to be_valid end it "accepts the same title in another project" do project = create(:empty_project) - new_milestone = Milestone.new(project: project, title: milestone.title) + new_milestone = described_class.new(project: project, title: milestone.title) expect(new_milestone).to be_valid end @@ -58,7 +58,7 @@ describe Milestone do end it "does not accept the same title in a group twice" do - new_milestone = Milestone.new(group: group, title: milestone.title) + new_milestone = described_class.new(group: group, title: milestone.title) expect(new_milestone).not_to be_valid end @@ -66,7 +66,7 @@ describe Milestone do it "does not accept the same title of a child project milestone" do create(:milestone, project: group.projects.first) - new_milestone = Milestone.new(group: group, title: milestone.title) + new_milestone = described_class.new(group: group, title: milestone.title) expect(new_milestone).not_to be_valid end @@ -214,7 +214,7 @@ describe Milestone do # The call to `#try` is because this returns a relation with a Postgres DB, # and an array of IDs with a MySQL DB. - let(:milestone_ids) { Milestone.upcoming_ids_by_projects(projects).map { |id| id.try(:id) || id } } + let(:milestone_ids) { described_class.upcoming_ids_by_projects(projects).map { |id| id.try(:id) || id } } it 'returns the next upcoming open milestone ID for each project' do expect(milestone_ids).to contain_exactly(current_milestone_project_1.id, current_milestone_project_2.id) diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index 827356b660e..f12fe226e6b 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -133,7 +133,7 @@ describe Namespace do it "sums all project storage counters in the namespace" do project1 project2 - statistics = Namespace.with_statistics.find(namespace.id) + statistics = described_class.with_statistics.find(namespace.id) expect(statistics.storage_size).to eq 666 expect(statistics.repository_size).to eq 111 @@ -142,7 +142,7 @@ describe Namespace do end it "correctly handles namespaces without projects" do - statistics = Namespace.with_statistics.find(namespace.id) + statistics = described_class.with_statistics.find(namespace.id) expect(statistics.storage_size).to eq 0 expect(statistics.repository_size).to eq 0 @@ -286,9 +286,9 @@ describe Namespace do @namespace = create(:namespace, name: 'WoW', path: 'woW') end - it { expect(Namespace.find_by_path_or_name('wow')).to eq(@namespace) } - it { expect(Namespace.find_by_path_or_name('WOW')).to eq(@namespace) } - it { expect(Namespace.find_by_path_or_name('unknown')).to eq(nil) } + it { expect(described_class.find_by_path_or_name('wow')).to eq(@namespace) } + it { expect(described_class.find_by_path_or_name('WOW')).to eq(@namespace) } + it { expect(described_class.find_by_path_or_name('unknown')).to eq(nil) } end describe ".clean_path" do @@ -296,8 +296,8 @@ describe Namespace do let!(:namespace) { create(:namespace, path: "JohnGitLab-etc1") } it "cleans the path and makes sure it's available" do - expect(Namespace.clean_path("-john+gitlab-ETC%.git@gmail.com")).to eq("johngitlab-ETC2") - expect(Namespace.clean_path("--%+--valid_*&%name=.git.%.atom.atom.@email.com")).to eq("valid_name") + expect(described_class.clean_path("-john+gitlab-ETC%.git@gmail.com")).to eq("johngitlab-ETC2") + expect(described_class.clean_path("--%+--valid_*&%name=.git.%.atom.atom.@email.com")).to eq("valid_name") end end diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index d20816bc31f..cbe6d42ef53 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -525,7 +525,7 @@ describe Note do it "has a discussion id" do # The discussion_id is set in `after_initialize`, so `reload` won't work - reloaded_note = Note.find(note.id) + reloaded_note = described_class.find(note.id) expect(reloaded_note.discussion_id).not_to be_nil expect(reloaded_note.discussion_id).to match(/\A\h{40}\z/) diff --git a/spec/models/project_services/asana_service_spec.rb b/spec/models/project_services/asana_service_spec.rb index 3e568ec3dad..4684c970885 100644 --- a/spec/models/project_services/asana_service_spec.rb +++ b/spec/models/project_services/asana_service_spec.rb @@ -35,7 +35,7 @@ describe AsanaService do end before do - @asana = AsanaService.new + @asana = described_class.new allow(@asana).to receive_messages( project: project, project_id: project.id, diff --git a/spec/models/project_services/assembla_service_spec.rb b/spec/models/project_services/assembla_service_spec.rb index a06bd2de0eb..5cb6d63659e 100644 --- a/spec/models/project_services/assembla_service_spec.rb +++ b/spec/models/project_services/assembla_service_spec.rb @@ -11,7 +11,7 @@ describe AssemblaService do let(:project) { create(:project, :repository) } before do - @assembla_service = AssemblaService.new + @assembla_service = described_class.new allow(@assembla_service).to receive_messages( project_id: project.id, project: project, diff --git a/spec/models/project_services/campfire_service_spec.rb b/spec/models/project_services/campfire_service_spec.rb index 176850b4c72..ed8347edffd 100644 --- a/spec/models/project_services/campfire_service_spec.rb +++ b/spec/models/project_services/campfire_service_spec.rb @@ -29,7 +29,7 @@ describe CampfireService do let(:project) { create(:project, :repository) } before do - @campfire_service = CampfireService.new + @campfire_service = described_class.new allow(@campfire_service).to receive_messages( project_id: project.id, project: project, diff --git a/spec/models/project_services/flowdock_service_spec.rb b/spec/models/project_services/flowdock_service_spec.rb index e439abb45a4..5e8e880985e 100644 --- a/spec/models/project_services/flowdock_service_spec.rb +++ b/spec/models/project_services/flowdock_service_spec.rb @@ -29,7 +29,7 @@ describe FlowdockService do let(:project) { create(:project, :repository) } before do - @flowdock_service = FlowdockService.new + @flowdock_service = described_class.new allow(@flowdock_service).to receive_messages( project_id: project.id, project: project, diff --git a/spec/models/project_services/gemnasium_service_spec.rb b/spec/models/project_services/gemnasium_service_spec.rb index d89e7ee8a2a..4c61bc0af95 100644 --- a/spec/models/project_services/gemnasium_service_spec.rb +++ b/spec/models/project_services/gemnasium_service_spec.rb @@ -31,7 +31,7 @@ describe GemnasiumService do let(:project) { create(:project, :repository) } before do - @gemnasium_service = GemnasiumService.new + @gemnasium_service = described_class.new allow(@gemnasium_service).to receive_messages( project_id: project.id, project: project, diff --git a/spec/models/project_services/gitlab_issue_tracker_service_spec.rb b/spec/models/project_services/gitlab_issue_tracker_service_spec.rb index ff0f73eff4c..d19dab8fd39 100644 --- a/spec/models/project_services/gitlab_issue_tracker_service_spec.rb +++ b/spec/models/project_services/gitlab_issue_tracker_service_spec.rb @@ -27,7 +27,7 @@ describe GitlabIssueTrackerService do context 'with absolute urls' do before do - allow(GitlabIssueTrackerService).to receive(:default_url_options).and_return(script_name: "/gitlab/root") + allow(described_class).to receive(:default_url_options).and_return(script_name: "/gitlab/root") end it 'gives the correct path' do @@ -39,7 +39,7 @@ describe GitlabIssueTrackerService do context 'with relative urls' do before do - allow(GitlabIssueTrackerService).to receive(:default_url_options).and_return(script_name: "/gitlab/root") + allow(described_class).to receive(:default_url_options).and_return(script_name: "/gitlab/root") end it 'gives the correct path' do diff --git a/spec/models/project_services/hipchat_service_spec.rb b/spec/models/project_services/hipchat_service_spec.rb index f08e6c863a4..7614bb897e8 100644 --- a/spec/models/project_services/hipchat_service_spec.rb +++ b/spec/models/project_services/hipchat_service_spec.rb @@ -25,7 +25,7 @@ describe HipchatService do end describe "Execute" do - let(:hipchat) { HipchatService.new } + let(:hipchat) { described_class.new } let(:user) { create(:user) } let(:project) { create(:project, :repository) } let(:api_url) { 'https://hipchat.example.com/v2/room/123456/notification?auth_token=verySecret' } diff --git a/spec/models/project_services/irker_service_spec.rb b/spec/models/project_services/irker_service_spec.rb index ce2b26436b3..cb9ca76fc3f 100644 --- a/spec/models/project_services/irker_service_spec.rb +++ b/spec/models/project_services/irker_service_spec.rb @@ -27,7 +27,7 @@ describe IrkerService do end describe 'Execute' do - let(:irker) { IrkerService.new } + let(:irker) { described_class.new } let(:user) { create(:user) } let(:project) { create(:project, :repository) } let(:sample_data) do diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index 62e1d51104e..c9e8d7e194d 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -78,7 +78,7 @@ describe JiraService do let(:merge_request) { create(:merge_request) } before do - @jira_service = JiraService.new + @jira_service = described_class.new allow(@jira_service).to receive_messages( project_id: project.id, project: project, @@ -167,7 +167,7 @@ describe JiraService do stub_config_setting(relative_url_root: '/gitlab') stub_config_setting(url: Settings.send(:build_gitlab_url)) - allow(JiraService).to receive(:default_url_options) do + allow(described_class).to receive(:default_url_options) do { script_name: '/gitlab' } end @@ -220,7 +220,7 @@ describe JiraService do context "when a password was previously set" do before do - @jira_service = JiraService.create!( + @jira_service = described_class.create!( project: project, properties: { url: 'http://jira.example.com/web', @@ -301,7 +301,7 @@ describe JiraService do context 'when no password was previously set' do before do - @jira_service = JiraService.create( + @jira_service = described_class.create( project: project, properties: { url: 'http://jira.example.com/rest/api/2', diff --git a/spec/models/project_services/pivotaltracker_service_spec.rb b/spec/models/project_services/pivotaltracker_service_spec.rb index 002476c1a17..f7d2372eca2 100644 --- a/spec/models/project_services/pivotaltracker_service_spec.rb +++ b/spec/models/project_services/pivotaltracker_service_spec.rb @@ -26,7 +26,7 @@ describe PivotaltrackerService do describe 'Execute' do let(:service) do - PivotaltrackerService.new.tap do |service| + described_class.new.tap do |service| service.token = 'secret_api_token' end end diff --git a/spec/models/project_services/pushover_service_spec.rb b/spec/models/project_services/pushover_service_spec.rb index e77c4ddcc78..54b8c658ff6 100644 --- a/spec/models/project_services/pushover_service_spec.rb +++ b/spec/models/project_services/pushover_service_spec.rb @@ -29,7 +29,7 @@ describe PushoverService do end describe 'Execute' do - let(:pushover) { PushoverService.new } + let(:pushover) { described_class.new } let(:user) { create(:user) } let(:project) { create(:project, :repository) } let(:sample_data) do diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 2df31a54628..473b7a88d61 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -77,7 +77,7 @@ describe Project do context 'after initialized' do it "has a project_feature" do - expect(Project.new.project_feature).to be_present + expect(described_class.new.project_feature).to be_present end end @@ -438,7 +438,7 @@ describe Project do end it 'returns valid url to repo' do - project = Project.new(path: 'somewhere') + project = described_class.new(path: 'somewhere') expect(project.url_to_repo).to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + 'somewhere.git') end @@ -917,7 +917,7 @@ describe Project do end describe '.with_shared_runners' do - subject { Project.with_shared_runners } + subject { described_class.with_shared_runners } context 'when shared runners are enabled for project' do let!(:project) { create(:empty_project, shared_runners_enabled: true) } @@ -942,10 +942,10 @@ describe Project do let!(:project2) { create(:empty_project, :public, group: group) } it 'returns total project count' do - expect(Project).to receive(:count).once.and_call_original + expect(described_class).to receive(:count).once.and_call_original 3.times do - expect(Project.cached_count).to eq(2) + expect(described_class.cached_count).to eq(2) end end end @@ -990,7 +990,7 @@ describe Project do user1.toggle_star(project1) user2.toggle_star(project2) - expect(Project.starred_by(user1)).to contain_exactly(project1) + expect(described_class.starred_by(user1)).to contain_exactly(project1) end end @@ -2012,7 +2012,7 @@ describe Project do let!(:path) { project1.namespace.full_path } it 'returns correct project' do - expect(Project.inside_path(path)).to eq([project1]) + expect(described_class.inside_path(path)).to eq([project1]) end end @@ -2216,7 +2216,7 @@ describe Project do context 'with a user' do let(:projects) do - Project.all.public_or_visible_to_user(user) + described_class.all.public_or_visible_to_user(user) end it 'includes projects the user has access to' do @@ -2230,7 +2230,7 @@ describe Project do context 'without a user' do it 'only includes public projects' do - projects = Project.all.public_or_visible_to_user + projects = described_class.all.public_or_visible_to_user expect(projects).to eq([public_project]) end diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb index fc1cdb3b1e6..7fcbeb459e0 100644 --- a/spec/models/project_wiki_spec.rb +++ b/spec/models/project_wiki_spec.rb @@ -5,7 +5,7 @@ describe ProjectWiki do let(:repository) { project.repository } let(:user) { project.owner } let(:gitlab_shell) { Gitlab::Shell.new } - let(:project_wiki) { ProjectWiki.new(project, user) } + let(:project_wiki) { described_class.new(project, user) } subject { project_wiki } diff --git a/spec/models/protected_branch_spec.rb b/spec/models/protected_branch_spec.rb index 6e8b07b44fb..a54af3bfe59 100644 --- a/spec/models/protected_branch_spec.rb +++ b/spec/models/protected_branch_spec.rb @@ -101,17 +101,17 @@ describe ProtectedBranch do production = create(:protected_branch, name: "production") staging = create(:protected_branch, name: "staging") - expect(ProtectedBranch.matching("production")).to include(production) - expect(ProtectedBranch.matching("production")).not_to include(staging) + expect(described_class.matching("production")).to include(production) + expect(described_class.matching("production")).not_to include(staging) end it "accepts a list of protected branches to search from, so as to avoid a DB call" do production = build(:protected_branch, name: "production") staging = build(:protected_branch, name: "staging") - expect(ProtectedBranch.matching("production")).to be_empty - expect(ProtectedBranch.matching("production", protected_refs: [production, staging])).to include(production) - expect(ProtectedBranch.matching("production", protected_refs: [production, staging])).not_to include(staging) + expect(described_class.matching("production")).to be_empty + expect(described_class.matching("production", protected_refs: [production, staging])).to include(production) + expect(described_class.matching("production", protected_refs: [production, staging])).not_to include(staging) end end @@ -120,17 +120,17 @@ describe ProtectedBranch do production = create(:protected_branch, name: "production/*") staging = create(:protected_branch, name: "staging/*") - expect(ProtectedBranch.matching("production/some-branch")).to include(production) - expect(ProtectedBranch.matching("production/some-branch")).not_to include(staging) + expect(described_class.matching("production/some-branch")).to include(production) + expect(described_class.matching("production/some-branch")).not_to include(staging) end it "accepts a list of protected branches to search from, so as to avoid a DB call" do production = build(:protected_branch, name: "production/*") staging = build(:protected_branch, name: "staging/*") - expect(ProtectedBranch.matching("production/some-branch")).to be_empty - expect(ProtectedBranch.matching("production/some-branch", protected_refs: [production, staging])).to include(production) - expect(ProtectedBranch.matching("production/some-branch", protected_refs: [production, staging])).not_to include(staging) + expect(described_class.matching("production/some-branch")).to be_empty + expect(described_class.matching("production/some-branch", protected_refs: [production, staging])).to include(production) + expect(described_class.matching("production/some-branch", protected_refs: [production, staging])).not_to include(staging) end end end @@ -142,23 +142,23 @@ describe ProtectedBranch do it 'returns true when the branch matches a protected branch via direct match' do create(:protected_branch, project: project, name: "foo") - expect(ProtectedBranch.protected?(project, 'foo')).to eq(true) + expect(described_class.protected?(project, 'foo')).to eq(true) end it 'returns true when the branch matches a protected branch via wildcard match' do create(:protected_branch, project: project, name: "production/*") - expect(ProtectedBranch.protected?(project, 'production/some-branch')).to eq(true) + expect(described_class.protected?(project, 'production/some-branch')).to eq(true) end it 'returns false when the branch does not match a protected branch via direct match' do - expect(ProtectedBranch.protected?(project, 'foo')).to eq(false) + expect(described_class.protected?(project, 'foo')).to eq(false) end it 'returns false when the branch does not match a protected branch via wildcard match' do create(:protected_branch, project: project, name: "production/*") - expect(ProtectedBranch.protected?(project, 'staging/some-branch')).to eq(false) + expect(described_class.protected?(project, 'staging/some-branch')).to eq(false) end end @@ -168,25 +168,25 @@ describe ProtectedBranch do it 'returns false when default_protected_branch is unprotected' do stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_NONE) - expect(ProtectedBranch.protected?(project, 'master')).to be false + expect(described_class.protected?(project, 'master')).to be false end it 'returns false when default_protected_branch lets developers push' do stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_DEV_CAN_PUSH) - expect(ProtectedBranch.protected?(project, 'master')).to be false + expect(described_class.protected?(project, 'master')).to be false end it 'returns true when default_branch_protection does not let developers push but let developer merge branches' do stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_DEV_CAN_MERGE) - expect(ProtectedBranch.protected?(project, 'master')).to be true + expect(described_class.protected?(project, 'master')).to be true end it 'returns true when default_branch_protection is in full protection' do stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_FULL) - expect(ProtectedBranch.protected?(project, 'master')).to be true + expect(described_class.protected?(project, 'master')).to be true end end end diff --git a/spec/models/redirect_route_spec.rb b/spec/models/redirect_route_spec.rb index 37948ea3f86..80943877095 100644 --- a/spec/models/redirect_route_spec.rb +++ b/spec/models/redirect_route_spec.rb @@ -21,7 +21,7 @@ describe RedirectRoute do let!(:redirect5) { group.redirect_routes.create(path: 'gitlabb/test/baz') } it 'returns correct routes' do - expect(RedirectRoute.matching_path_and_descendants('gitlabb/test')).to match_array([redirect2, redirect3, redirect4, redirect5]) + expect(described_class.matching_path_and_descendants('gitlabb/test')).to match_array([redirect2, redirect3, redirect4, redirect5]) end end end diff --git a/spec/models/route_spec.rb b/spec/models/route_spec.rb index 32cd5d1d944..bdacc60fb53 100644 --- a/spec/models/route_spec.rb +++ b/spec/models/route_spec.rb @@ -34,7 +34,7 @@ describe Route do context 'after create' do it 'calls #delete_conflicting_redirects' do route.destroy - new_route = Route.new(source: group, path: group.path) + new_route = described_class.new(source: group, path: group.path) expect(new_route).to receive(:delete_conflicting_redirects) new_route.save! end @@ -49,7 +49,7 @@ describe Route do let!(:another_group_nested) { create(:group, path: 'another', name: 'another', parent: similar_group) } it 'returns correct routes' do - expect(Route.inside_path('git_lab')).to match_array([nested_group.route, deep_nested_group.route]) + expect(described_class.inside_path('git_lab')).to match_array([nested_group.route, deep_nested_group.route]) end end diff --git a/spec/models/sent_notification_spec.rb b/spec/models/sent_notification_spec.rb index 823cdb853eb..8b6b02916ae 100644 --- a/spec/models/sent_notification_spec.rb +++ b/spec/models/sent_notification_spec.rb @@ -38,7 +38,7 @@ describe SentNotification do let(:issue) { create(:issue) } it 'creates a new SentNotification' do - expect { described_class.record(issue, user.id) }.to change { SentNotification.count }.by(1) + expect { described_class.record(issue, user.id) }.to change { described_class.count }.by(1) end end @@ -47,7 +47,7 @@ describe SentNotification do let(:note) { create(:diff_note_on_merge_request) } it 'creates a new SentNotification' do - expect { described_class.record_note(note, user.id) }.to change { SentNotification.count }.by(1) + expect { described_class.record_note(note, user.id) }.to change { described_class.count }.by(1) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 105d41957c3..71aadbb4186 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -261,7 +261,7 @@ describe User do it "returns users with 2fa enabled via OTP" do user_with_2fa = create(:user, :two_factor_via_otp) user_without_2fa = create(:user) - users_with_two_factor = User.with_two_factor.pluck(:id) + users_with_two_factor = described_class.with_two_factor.pluck(:id) expect(users_with_two_factor).to include(user_with_2fa.id) expect(users_with_two_factor).not_to include(user_without_2fa.id) @@ -270,7 +270,7 @@ describe User do it "returns users with 2fa enabled via U2F" do user_with_2fa = create(:user, :two_factor_via_u2f) user_without_2fa = create(:user) - users_with_two_factor = User.with_two_factor.pluck(:id) + users_with_two_factor = described_class.with_two_factor.pluck(:id) expect(users_with_two_factor).to include(user_with_2fa.id) expect(users_with_two_factor).not_to include(user_without_2fa.id) @@ -279,7 +279,7 @@ describe User do it "returns users with 2fa enabled via OTP and U2F" do user_with_2fa = create(:user, :two_factor_via_otp, :two_factor_via_u2f) user_without_2fa = create(:user) - users_with_two_factor = User.with_two_factor.pluck(:id) + users_with_two_factor = described_class.with_two_factor.pluck(:id) expect(users_with_two_factor).to eq([user_with_2fa.id]) expect(users_with_two_factor).not_to include(user_without_2fa.id) @@ -290,7 +290,7 @@ describe User do it "excludes users with 2fa enabled via OTP" do user_with_2fa = create(:user, :two_factor_via_otp) user_without_2fa = create(:user) - users_without_two_factor = User.without_two_factor.pluck(:id) + users_without_two_factor = described_class.without_two_factor.pluck(:id) expect(users_without_two_factor).to include(user_without_2fa.id) expect(users_without_two_factor).not_to include(user_with_2fa.id) @@ -299,7 +299,7 @@ describe User do it "excludes users with 2fa enabled via U2F" do user_with_2fa = create(:user, :two_factor_via_u2f) user_without_2fa = create(:user) - users_without_two_factor = User.without_two_factor.pluck(:id) + users_without_two_factor = described_class.without_two_factor.pluck(:id) expect(users_without_two_factor).to include(user_without_2fa.id) expect(users_without_two_factor).not_to include(user_with_2fa.id) @@ -308,7 +308,7 @@ describe User do it "excludes users with 2fa enabled via OTP and U2F" do user_with_2fa = create(:user, :two_factor_via_otp, :two_factor_via_u2f) user_without_2fa = create(:user) - users_without_two_factor = User.without_two_factor.pluck(:id) + users_without_two_factor = described_class.without_two_factor.pluck(:id) expect(users_without_two_factor).to include(user_without_2fa.id) expect(users_without_two_factor).not_to include(user_with_2fa.id) @@ -324,8 +324,8 @@ describe User do create(:todo, user: current_user, author: user_2, state: :done) create(:todo, user: current_user, author: user_3, state: :pending) - expect(User.todo_authors(current_user.id, 'pending')).to eq [user_3] - expect(User.todo_authors(current_user.id, 'done')).to eq [user_2] + expect(described_class.todo_authors(current_user.id, 'pending')).to eq [user_3] + expect(described_class.todo_authors(current_user.id, 'done')).to eq [user_2] end end end @@ -609,39 +609,39 @@ describe User do let(:user) { double } it 'filters by active users by default' do - expect(User).to receive(:active).and_return([user]) + expect(described_class).to receive(:active).and_return([user]) - expect(User.filter(nil)).to include user + expect(described_class.filter(nil)).to include user end it 'filters by admins' do - expect(User).to receive(:admins).and_return([user]) + expect(described_class).to receive(:admins).and_return([user]) - expect(User.filter('admins')).to include user + expect(described_class.filter('admins')).to include user end it 'filters by blocked' do - expect(User).to receive(:blocked).and_return([user]) + expect(described_class).to receive(:blocked).and_return([user]) - expect(User.filter('blocked')).to include user + expect(described_class.filter('blocked')).to include user end it 'filters by two_factor_disabled' do - expect(User).to receive(:without_two_factor).and_return([user]) + expect(described_class).to receive(:without_two_factor).and_return([user]) - expect(User.filter('two_factor_disabled')).to include user + expect(described_class.filter('two_factor_disabled')).to include user end it 'filters by two_factor_enabled' do - expect(User).to receive(:with_two_factor).and_return([user]) + expect(described_class).to receive(:with_two_factor).and_return([user]) - expect(User.filter('two_factor_enabled')).to include user + expect(described_class.filter('two_factor_enabled')).to include user end it 'filters by wop' do - expect(User).to receive(:without_projects).and_return([user]) + expect(described_class).to receive(:without_projects).and_return([user]) - expect(User.filter('wop')).to include user + expect(described_class.filter('wop')).to include user end end @@ -662,9 +662,9 @@ describe User do project.request_access(user_without_project2) end - it { expect(User.without_projects).not_to include user } - it { expect(User.without_projects).to include user_without_project } - it { expect(User.without_projects).to include user_without_project2 } + it { expect(described_class.without_projects).not_to include user } + it { expect(described_class.without_projects).to include user_without_project } + it { expect(described_class.without_projects).to include user_without_project2 } end describe 'user creation' do @@ -680,7 +680,7 @@ describe User do end describe 'with defaults' do - let(:user) { User.new } + let(:user) { described_class.new } it "applies defaults to user" do expect(user.projects_limit).to eq(Gitlab.config.gitlab.default_projects_limit) @@ -690,7 +690,7 @@ describe User do end describe 'with default overrides' do - let(:user) { User.new(projects_limit: 123, can_create_group: false, can_create_team: true) } + let(:user) { described_class.new(projects_limit: 123, can_create_group: false, can_create_team: true) } it "applies defaults to user" do expect(user.projects_limit).to eq(123) @@ -740,18 +740,18 @@ describe User do it 'finds by primary email' do user = create(:user, email: 'foo@example.com') - expect(User.find_by_any_email(user.email)).to eq user + expect(described_class.find_by_any_email(user.email)).to eq user end it 'finds by secondary email' do email = create(:email, email: 'foo@example.com') user = email.user - expect(User.find_by_any_email(email.email)).to eq user + expect(described_class.find_by_any_email(email.email)).to eq user end it 'returns nil when nothing found' do - expect(User.find_by_any_email('')).to be_nil + expect(described_class.find_by_any_email('')).to be_nil end end @@ -899,12 +899,12 @@ describe User do let!(:user) { create(:user, username: username) } it 'gets the correct user' do - expect(User.by_login(user.email.upcase)).to eq user - expect(User.by_login(user.email)).to eq user - expect(User.by_login(username.downcase)).to eq user - expect(User.by_login(username)).to eq user - expect(User.by_login(nil)).to be_nil - expect(User.by_login('')).to be_nil + expect(described_class.by_login(user.email.upcase)).to eq user + expect(described_class.by_login(user.email)).to eq user + expect(described_class.by_login(username.downcase)).to eq user + expect(described_class.by_login(username)).to eq user + expect(described_class.by_login(nil)).to be_nil + expect(described_class.by_login('')).to be_nil end end @@ -938,12 +938,12 @@ describe User do let!(:route) { user.namespace.route } it 'returns the user' do - expect(User.find_by_full_path(route.path)).to eq(user) + expect(described_class.find_by_full_path(route.path)).to eq(user) end it 'is case-insensitive' do - expect(User.find_by_full_path(route.path.upcase)).to eq(user) - expect(User.find_by_full_path(route.path.downcase)).to eq(user) + expect(described_class.find_by_full_path(route.path.upcase)).to eq(user) + expect(described_class.find_by_full_path(route.path.downcase)).to eq(user) end end @@ -952,18 +952,18 @@ describe User do context 'without the follow_redirects option' do it 'returns nil' do - expect(User.find_by_full_path(redirect_route.path)).to eq(nil) + expect(described_class.find_by_full_path(redirect_route.path)).to eq(nil) end end context 'with the follow_redirects option set to true' do it 'returns the user' do - expect(User.find_by_full_path(redirect_route.path, follow_redirects: true)).to eq(user) + expect(described_class.find_by_full_path(redirect_route.path, follow_redirects: true)).to eq(user) end it 'is case-insensitive' do - expect(User.find_by_full_path(redirect_route.path.upcase, follow_redirects: true)).to eq(user) - expect(User.find_by_full_path(redirect_route.path.downcase, follow_redirects: true)).to eq(user) + expect(described_class.find_by_full_path(redirect_route.path.upcase, follow_redirects: true)).to eq(user) + expect(described_class.find_by_full_path(redirect_route.path.downcase, follow_redirects: true)).to eq(user) end end end @@ -971,12 +971,12 @@ describe User do context 'without a route or a redirect route matching the given path' do context 'without the follow_redirects option' do it 'returns nil' do - expect(User.find_by_full_path('unknown')).to eq(nil) + expect(described_class.find_by_full_path('unknown')).to eq(nil) end end context 'with the follow_redirects option set to true' do it 'returns nil' do - expect(User.find_by_full_path('unknown', follow_redirects: true)).to eq(nil) + expect(described_class.find_by_full_path('unknown', follow_redirects: true)).to eq(nil) end end end @@ -986,7 +986,7 @@ describe User do let!(:group) { create(:group, path: 'group_path', owner: user) } it 'returns nil' do - expect(User.find_by_full_path('group_path')).to eq(nil) + expect(described_class.find_by_full_path('group_path')).to eq(nil) end end @@ -994,7 +994,7 @@ describe User do let!(:group) { create(:group, path: 'group_path') } it 'returns nil' do - expect(User.find_by_full_path('group_path')).to eq(nil) + expect(described_class.find_by_full_path('group_path')).to eq(nil) end end end @@ -1044,7 +1044,7 @@ describe User do end describe '#requires_ldap_check?' do - let(:user) { User.new } + let(:user) { described_class.new } it 'is false when LDAP is disabled' do # Create a condition which would otherwise cause 'true' to be returned @@ -1215,7 +1215,7 @@ describe User do describe '#sort' do before do - User.delete_all + described_class.delete_all @user = create :user, created_at: Date.today, last_sign_in_at: Date.today, name: 'Alpha' @user1 = create :user, created_at: Date.today - 1, last_sign_in_at: Date.today - 1, name: 'Omega' @user2 = create :user, created_at: Date.today - 2, last_sign_in_at: nil, name: 'Beta' @@ -1223,34 +1223,34 @@ describe User do context 'when sort by recent_sign_in' do it 'sorts users by the recent sign-in time' do - expect(User.sort('recent_sign_in').first).to eq(@user) + expect(described_class.sort('recent_sign_in').first).to eq(@user) end it 'pushes users who never signed in to the end' do - expect(User.sort('recent_sign_in').third).to eq(@user2) + expect(described_class.sort('recent_sign_in').third).to eq(@user2) end end context 'when sort by oldest_sign_in' do it 'sorts users by the oldest sign-in time' do - expect(User.sort('oldest_sign_in').first).to eq(@user1) + expect(described_class.sort('oldest_sign_in').first).to eq(@user1) end it 'pushes users who never signed in to the end' do - expect(User.sort('oldest_sign_in').third).to eq(@user2) + expect(described_class.sort('oldest_sign_in').third).to eq(@user2) end end it 'sorts users in descending order by their creation time' do - expect(User.sort('created_desc').first).to eq(@user) + expect(described_class.sort('created_desc').first).to eq(@user) end it 'sorts users in ascending order by their creation time' do - expect(User.sort('created_asc').first).to eq(@user2) + expect(described_class.sort('created_asc').first).to eq(@user2) end it 'sorts users by id in descending order when nil is passed' do - expect(User.sort(nil).first).to eq(@user2) + expect(described_class.sort(nil).first).to eq(@user2) end end @@ -1770,7 +1770,7 @@ describe User do describe '.ghost' do it "creates a ghost user if one isn't already present" do - ghost = User.ghost + ghost = described_class.ghost expect(ghost).to be_ghost expect(ghost).to be_persisted @@ -1778,16 +1778,16 @@ describe User do it "does not create a second ghost user if one is already present" do expect do - User.ghost - User.ghost - end.to change { User.count }.by(1) - expect(User.ghost).to eq(User.ghost) + described_class.ghost + described_class.ghost + end.to change { described_class.count }.by(1) + expect(described_class.ghost).to eq(described_class.ghost) end context "when a regular user exists with the username 'ghost'" do it "creates a ghost user with a non-conflicting username" do create(:user, username: 'ghost') - ghost = User.ghost + ghost = described_class.ghost expect(ghost).to be_persisted expect(ghost.username).to eq('ghost1') @@ -1797,7 +1797,7 @@ describe User do context "when a regular user exists with the email 'ghost@example.com'" do it "creates a ghost user with a non-conflicting email" do create(:user, email: 'ghost@example.com') - ghost = User.ghost + ghost = described_class.ghost expect(ghost).to be_persisted expect(ghost.email).to eq('ghost1@example.com') @@ -1810,7 +1810,7 @@ describe User do end it 'creates a ghost user' do - expect(User.ghost).to be_persisted + expect(described_class.ghost).to be_persisted end end end @@ -1889,13 +1889,13 @@ describe User do context '.active' do before do - User.ghost + described_class.ghost create(:user, name: 'user', state: 'active') create(:user, name: 'user', state: 'blocked') end it 'only counts active and non internal users' do - expect(User.active.count).to eq(1) + expect(described_class.active.count).to eq(1) end end diff --git a/spec/models/wiki_directory_spec.rb b/spec/models/wiki_directory_spec.rb index c3c62c42b35..fb8575cfe2b 100644 --- a/spec/models/wiki_directory_spec.rb +++ b/spec/models/wiki_directory_spec.rb @@ -10,7 +10,7 @@ RSpec.describe WikiDirectory do describe '#initialize' do context 'when there are pages' do let(:pages) { [build(:wiki_page)] } - let(:directory) { WikiDirectory.new('/path_up_to/dir', pages) } + let(:directory) { described_class.new('/path_up_to/dir', pages) } it 'sets the slug attribute' do expect(directory.slug).to eq('/path_up_to/dir') @@ -22,7 +22,7 @@ RSpec.describe WikiDirectory do end context 'when there are no pages' do - let(:directory) { WikiDirectory.new('/path_up_to/dir') } + let(:directory) { described_class.new('/path_up_to/dir') } it 'sets the slug attribute' do expect(directory.slug).to eq('/path_up_to/dir') diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb index 77506a78459..90ad3cdeb93 100644 --- a/spec/models/wiki_page_spec.rb +++ b/spec/models/wiki_page_spec.rb @@ -5,13 +5,13 @@ describe WikiPage do let(:user) { project.owner } let(:wiki) { ProjectWiki.new(project, user) } - subject { WikiPage.new(wiki) } + subject { described_class.new(wiki) } describe '.group_by_directory' do context 'when there are no pages' do it 'returns an empty array' do - expect(WikiPage.group_by_directory(nil)).to eq([]) - expect(WikiPage.group_by_directory([])).to eq([]) + expect(described_class.group_by_directory(nil)).to eq([]) + expect(described_class.group_by_directory([])).to eq([]) end end @@ -39,7 +39,7 @@ describe WikiPage do it 'returns an array with pages and directories' do expected_grouped_entries = [page_1, dir_1, dir_1_1, dir_2] - grouped_entries = WikiPage.group_by_directory(wiki.pages) + grouped_entries = described_class.group_by_directory(wiki.pages) grouped_entries.each_with_index do |page_or_dir, i| expected_page_or_dir = expected_grouped_entries[i] @@ -56,7 +56,7 @@ describe WikiPage do expected_order = ['page_1', 'dir_1/page_2', 'dir_1/dir_1_1/page_3', 'dir_2/page_4', 'dir_2/page_5'] - grouped_entries = WikiPage.group_by_directory(wiki.pages) + grouped_entries = described_class.group_by_directory(wiki.pages) actual_order = grouped_entries.map do |page_or_dir| @@ -72,7 +72,7 @@ describe WikiPage do it 'removes hyphens from a name' do name = 'a-name--with-hyphens' - expect(WikiPage.unhyphenize(name)).to eq('a name with hyphens') + expect(described_class.unhyphenize(name)).to eq('a name with hyphens') end end @@ -81,7 +81,7 @@ describe WikiPage do before do create_page("test page", "test content") @page = wiki.wiki.paged("test page") - @wiki_page = WikiPage.new(wiki, @page, true) + @wiki_page = described_class.new(wiki, @page, true) end it "sets the slug attribute" do -- cgit v1.2.3