Skip to content

Commit

Permalink
Merge pull request #15798 from eduardoj/refactoring/rubocop_offenses_…
Browse files Browse the repository at this point in the history
…part_3_ii

Autocorrect RSpec/LeadingSubject RuboCop offenses, part II
  • Loading branch information
hennevogel committed Mar 15, 2024
2 parents 8b16411 + a75810f commit 022bdf9
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
before do
sql = "UPDATE `notifications` SET `event_payload` = '#{yaml}' WHERE id = #{notification.id}"
ActiveRecord::Base.connection.execute(sql)
end

subject! { ConvertNotificationsEventPayloadToJson.up }
subject.up
end

it 'converts the notifications event_payload from yaml to json' do
json_hash = { 'hello' => 'world', 'how' => ['are', 'you', 'today?'], 'im' => 'fine thanks' }
Expand Down
4 changes: 2 additions & 2 deletions src/api/spec/db/data/migrate_comment_payload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def comment_event?(event)
event.set_payload(payload, payload.keys)
event.save!
end
end

subject! { MigrateCommentPayload.new.up }
subject.up
end

it 'converts comment events in the old format' do
Event::Base.find_each do |event|
Expand Down
16 changes: 8 additions & 8 deletions src/api/spec/jobs/bs_request_action_webui_infos_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

describe '#perform' do
context 'for a target package' do
subject { BsRequestActionWebuiInfosJob.new.perform(request_action) }

let(:diff_result) do
<<-DIFF
@@ -1,1 +1,1 @@
Expand All @@ -25,8 +27,6 @@
DIFF
end

subject { BsRequestActionWebuiInfosJob.new.perform(request_action) }

it 'creates the diff' do
# gsub because of rubocop Lint/Syntax error when using <<~
# we need to upgrade to use ruby 2.5 parser first
Expand All @@ -35,6 +35,8 @@
end

context 'with non existing target project' do
subject { BsRequestActionWebuiInfosJob.new.perform(request_action) }

let(:request) do
request = build(:bs_request_with_submit_action,
source_package: source_package,
Expand All @@ -48,13 +50,13 @@
end
let(:request_action) { request.bs_request_actions.first }

subject { BsRequestActionWebuiInfosJob.new.perform(request_action) }

it { expect { subject }.not_to raise_error }
it { expect(subject).to be_nil }
end

context 'with non existing source package' do
subject { BsRequestActionWebuiInfosJob.new.perform(request_action) }

let(:request) do
request = build(:bs_request_with_submit_action,
source_project: 'does-not-exist',
Expand All @@ -68,8 +70,6 @@
end
let(:request_action) { request.bs_request_actions.first }

subject { BsRequestActionWebuiInfosJob.new.perform(request_action) }

it { expect { subject }.not_to raise_error }
it { expect(subject).to be_nil }
end
Expand Down Expand Up @@ -102,9 +102,9 @@

before do
request.update(superseded_by: superseding_request.number, state: :superseded)
end

subject! { BsRequestActionWebuiInfosJob.new.perform(superseding_request_action) }
BsRequestActionWebuiInfosJob.new.perform(superseding_request_action)
end

# The Job always returns the result for the target package, therefore we need check for the request to be made
it { expect(a_request(:post, path)).to have_been_made.once }
Expand Down
10 changes: 5 additions & 5 deletions src/api/spec/jobs/bs_request_clean_tasks_cache_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
let!(:cache_key) { user.cache_key_with_version }
let(:user) { create(:admin_user) }

subject! { BsRequestCleanTasksCacheJob.new.perform(request.id) }
before { BsRequestCleanTasksCacheJob.new.perform(request.id) }

it { expect(user.reload.cache_key_with_version).not_to eq(cache_key) }
end
Expand All @@ -33,7 +33,7 @@
let!(:cache_key) { user.cache_key_with_version }
let(:user) { relationship_project_user.user }

subject! { BsRequestCleanTasksCacheJob.new.perform(request.id) }
before { BsRequestCleanTasksCacheJob.new.perform(request.id) }

it { expect(user.reload.cache_key_with_version).not_to eq(cache_key) }
end
Expand All @@ -53,7 +53,7 @@
let!(:cache_key) { user.cache_key_with_version }
let(:user) { groups_user.user }

subject! { BsRequestCleanTasksCacheJob.new.perform(request.id) }
before { BsRequestCleanTasksCacheJob.new.perform(request.id) }

it { expect(user.reload.cache_key_with_version).not_to eq(cache_key) }
end
Expand All @@ -64,7 +64,7 @@
let!(:cache_key) { user.cache_key_with_version }
let(:user) { relationship_package_user.user }

subject! { BsRequestCleanTasksCacheJob.new.perform(request.id) }
before { BsRequestCleanTasksCacheJob.new.perform(request.id) }

it { expect(user.reload.cache_key_with_version).not_to eq(cache_key) }
end
Expand All @@ -77,7 +77,7 @@
let!(:cache_key) { user.cache_key_with_version }
let(:user) { groups_user.user }

subject! { BsRequestCleanTasksCacheJob.new.perform(request.id) }
before { BsRequestCleanTasksCacheJob.new.perform(request.id) }

it { expect(user.reload.cache_key_with_version).not_to eq(cache_key) }
end
Expand Down
4 changes: 2 additions & 2 deletions src/api/spec/jobs/configuration_write_to_backend_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
before do
allow(Configuration).to receive(:find).and_return(configuration)
allow(configuration).to receive(:write_to_backend)
end

subject! { ConfigurationWriteToBackendJob.new.perform(configuration.id) }
ConfigurationWriteToBackendJob.new.perform(configuration.id)
end

it 'writes to the backend' do
expect(configuration).to have_received(:write_to_backend)
Expand Down
4 changes: 2 additions & 2 deletions src/api/spec/jobs/issue_tracker_fetch_issues_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
before do
allow(IssueTracker).to receive(:find_by).and_return(issue_tracker)
allow(issue_tracker).to receive(:fetch_issues)
end

subject! { IssueTrackerFetchIssuesJob.new.perform(issue_tracker.id) }
IssueTrackerFetchIssuesJob.new.perform(issue_tracker.id)
end

it 'fetches the issues' do
expect(issue_tracker).to have_received(:fetch_issues)
Expand Down
4 changes: 2 additions & 2 deletions src/api/spec/jobs/issue_tracker_update_issues_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
before do
allow(IssueTracker).to receive(:find_by).and_return(issue_tracker)
allow(issue_tracker).to receive(:update_issues)
end

subject! { IssueTrackerUpdateIssuesJob.new.perform(issue_tracker.id) }
IssueTrackerUpdateIssuesJob.new.perform(issue_tracker.id)
end

it 'updates the issues' do
expect(issue_tracker).to have_received(:update_issues)
Expand Down
4 changes: 2 additions & 2 deletions src/api/spec/jobs/issue_tracker_write_to_backend_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
include ActiveJob::TestHelper

describe '#perform' do
subject { IssueTrackerWriteToBackendJob.new.perform }

let!(:issue_tracker) { create(:issue_tracker, enable_fetch: true, url: 'https://github.com/opensuse/issues') }
let!(:issue) { travel_to(4.days.ago) { create(:issue, name: '123', issue_tracker_id: issue_tracker.id) } }
let(:backend_response) { '<status code="ok" />' }
Expand All @@ -10,8 +12,6 @@
stub_request(:put, "#{CONFIG['source_url']}/issue_trackers").and_return(body: backend_response)
end

subject { IssueTrackerWriteToBackendJob.new.perform }

it 'writes to the backend' do
expect(subject).to eq(backend_response)
end
Expand Down
4 changes: 2 additions & 2 deletions src/api/spec/jobs/package_update_if_dirty_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
include ActiveJob::TestHelper

describe '#perform' do
subject { PackageUpdateIfDirtyJob.new.perform(package.id) }

let!(:project) { create(:project, name: 'apache') }
let!(:package) { create(:package_with_file, name: 'mod_ssl', project: project) }

subject { PackageUpdateIfDirtyJob.new.perform(package.id) }

it 'creates a BackendPackge for the Package' do
expect { subject }.to change(BackendPackage, :count).by(1)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
end

describe '#perform' do
subject { described_class.perform_now }

let(:admin) { create(:admin_user, login: 'Admin') }
let(:project) { create(:project, name: 'ProjectA') }
let(:attribute) { create(:auto_cleanup_attrib, project: project) }

subject { described_class.perform_now }

before do
allow(Configuration).to receive(:cleanup_after_days).and_return(3)
login(admin)
Expand Down
10 changes: 5 additions & 5 deletions src/api/spec/jobs/send_event_emails_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
let!(:subscription5) { create(:event_subscription_comment_for_project, receiver_role: 'maintainer', user: nil, group: group1, channel: :web) }
let!(:subscription6) { create(:event_subscription_comment_for_project, receiver_role: 'maintainer', user: nil, group: group2, channel: :web) }

subject! { SendEventEmailsJob.new.perform }
before { described_class.new.perform }

it 'sends an email to the subscribers' do
email = ActionMailer::Base.deliveries.first
Expand Down Expand Up @@ -66,9 +66,9 @@

before do
user.regenerate_rss_secret
end

subject! { SendEventEmailsJob.new.perform }
SendEventEmailsJob.new.perform
end

it 'creates a rss notification' do
notification = Notification.find_by(subscriber: user, rss: true)
Expand All @@ -81,7 +81,7 @@
end

context 'without any subscriptions to the event' do
subject! { SendEventEmailsJob.new.perform }
before { SendEventEmailsJob.new.perform }

it 'updates the event mails_sent = true' do
event = Event::CommentForProject.first
Expand All @@ -97,7 +97,7 @@
let(:project) { create(:forbidden_project, name: 'comment_project', maintainer: user) }
let!(:subscription) { create(:event_subscription_comment_for_project, receiver_role: 'maintainer', user: user) }

subject! { SendEventEmailsJob.new.perform }
before { SendEventEmailsJob.new.perform }

it 'does not queue a mail' do
expect(ActionMailer::Base.deliveries).to be_empty
Expand Down
12 changes: 6 additions & 6 deletions src/api/spec/jobs/status_history_rescaler_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
context 'newer than 2 hours records' do
before do
5.times { |i| StatusHistory.create(time: (Time.now.utc - i.seconds).to_i, key: 'busy_x86_64', value: i * 10) }
end

subject! { StatusHistoryRescalerJob.perform_now }
StatusHistoryRescalerJob.perform_now
end

it 'keeps the StatusHistory with key = busy_x86_64' do
expect(status_histories.count).to eq(5)
Expand All @@ -22,9 +22,9 @@
before do
2.times { |i| StatusHistory.create(time: 9.days.ago + i.minutes, key: 'busy_x86_64', value: i * 10) }
2.times { |i| StatusHistory.create(time: 3.hours.ago + i.minutes, key: 'busy_x86_64', value: i * 10) }
end

subject! { StatusHistoryRescalerJob.perform_now }
StatusHistoryRescalerJob.perform_now
end

it 'reduces the records older than 7 days to 1' do
expect(StatusHistory.count).to eq(3)
Expand All @@ -38,9 +38,9 @@
2.times { |i| StatusHistory.create(time: 9.months.ago + i.minutes, key: 'busy_x86_64', value: i * 10) }
2.times { |i| StatusHistory.create(time: 3.months.ago + i.minutes, key: 'busy_x86_64', value: i * 10) }
2.times { |i| StatusHistory.create(time: 3.hours.ago + i.minutes, key: 'busy_x86_64', value: i * 10) }
end

subject! { StatusHistoryRescalerJob.perform_now }
StatusHistoryRescalerJob.perform_now
end

it 'reduces the records older than 1 month to 1' do
expect(StatusHistory.count).to eq(4)
Expand Down
12 changes: 6 additions & 6 deletions src/api/spec/jobs/update_backend_infos_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
before do
allow(Package).to receive(:find_by_project_and_name).and_return(package)
allow(package).to receive(:update_backendinfo)
end

subject! { event } # UpdateBackendInfosJob gets called when the event is created
event # UpdateBackendInfosJob gets called when the event is created
end

it { expect(package).to have_received(:update_backendinfo) }
end
Expand All @@ -26,9 +26,9 @@
allow(Package).to receive_messages(find_by_project_and_name: package, find_by_id: package2)
allow(package).to receive(:update_backendinfo)
allow(package2).to receive(:update_backendinfo)
end

subject! { event } # UpdateBackendInfosJob gets called when the event is created
event # UpdateBackendInfosJob gets called when the event is created
end

it { expect(package).to have_received(:update_backendinfo) }
it { expect(package2).to have_received(:update_backendinfo) }
Expand All @@ -43,9 +43,9 @@
before do
allow(Package).to receive(:find_by_project_and_name).and_return(package)
allow(package).to receive(:update_backendinfo)
end

subject! { event_without_package } # UpdateBackendInfosJob gets called when the event is created
event_without_package # UpdateBackendInfosJob gets called when the event is created
end

it { expect(package).not_to have_received(:update_backendinfo) }
end
Expand Down
4 changes: 2 additions & 2 deletions src/api/spec/jobs/update_package_meta_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@

describe '#scan_links' do
# If the package has a link it will check if a BackendPackage exists, otherwise, it will create it.
subject { UpdatePackageMetaJob.new.scan_links }

before do
User.session = user
branch_package.branch
end

subject { UpdatePackageMetaJob.new.scan_links }

context 'with a BranchPackage that does have an entry in BackendPackage' do
before do
# It's needed to create a BackendPackage entry
Expand Down
4 changes: 2 additions & 2 deletions src/api/spec/jobs/update_packages_if_dirty_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

describe '#perform' do
context 'the project is found' do
subject { UpdatePackagesIfDirtyJob.new.perform(project.id) }

let!(:project) { create(:project, name: 'apache') }
let!(:package) { create(:package_with_file, project: project, name: 'mod_ssl') }

subject { UpdatePackagesIfDirtyJob.new.perform(project.id) }

it 'creates a BackendPackge for the Package' do
expect { subject }.to change(BackendPackage, :count).by(1)
end
Expand Down
12 changes: 6 additions & 6 deletions src/api/spec/jobs/update_released_binaries_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
context 'for an event with a repo' do
before do
allow(BinaryRelease).to receive(:update_binary_releases)
end

subject! { UpdateReleasedBinariesJob.perform_now(event.id) }
UpdateReleasedBinariesJob.perform_now(event.id)
end

it { expect(BinaryRelease).to have_received(:update_binary_releases) }
end
Expand All @@ -21,9 +21,9 @@

before do
allow(BinaryRelease).to receive(:update_binary_releases)
end

subject! { UpdateReleasedBinariesJob.perform_now(event_without_repo.id) }
UpdateReleasedBinariesJob.perform_now(event_without_repo.id)
end

it { expect(BinaryRelease).not_to have_received(:update_binary_releases) }
end
Expand All @@ -33,9 +33,9 @@
allow(BinaryRelease).to receive(:update_binary_releases).and_raise(StandardError)
allow($stdout).to receive(:write) # Needed to avoid the puts of the error method
allow(Airbrake).to receive(:notify)
end

subject! { UpdateReleasedBinariesJob.perform_now(event.id) }
UpdateReleasedBinariesJob.perform_now(event.id)
end

it 'notifies airbrake' do
expect(Airbrake).to have_received(:notify)
Expand Down
Loading

0 comments on commit 022bdf9

Please sign in to comment.