From a16d1cda9a197a5fac4fe602d3090e2f4ffa93c1 Mon Sep 17 00:00:00 2001 From: Christophe Bliard Date: Thu, 3 Feb 2022 16:41:35 +0100 Subject: [PATCH] make rubocop happier --- .../storages/projects_storages_table_cell.rb | 1 - .../app/cells/storages/storages_row_cell.rb | 9 ++------- .../admin/projects_storages_controller.rb | 2 +- .../storages/app/models/storages/file_link.rb | 4 ++-- .../spec/features/admin_storages_spec.rb | 2 +- modules/storages/spec/models/storage_spec.rb | 16 ++++++++-------- 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/modules/storages/app/cells/storages/projects_storages_table_cell.rb b/modules/storages/app/cells/storages/projects_storages_table_cell.rb index cd7ee97a76..197037cd23 100644 --- a/modules/storages/app/cells/storages/projects_storages_table_cell.rb +++ b/modules/storages/app/cells/storages/projects_storages_table_cell.rb @@ -38,6 +38,5 @@ module Storages ['created_at', { caption: Storages::ProjectStorage.human_attribute_name(:created_at) }] ] end - end end diff --git a/modules/storages/app/cells/storages/storages_row_cell.rb b/modules/storages/app/cells/storages/storages_row_cell.rb index 515edc2e90..4a8188273e 100644 --- a/modules/storages/app/cells/storages/storages_row_cell.rb +++ b/modules/storages/app/cells/storages/storages_row_cell.rb @@ -8,13 +8,8 @@ module Storages link_to model.name, storage_path(model) end - def host - model.host - end - - def provider_type - model.provider_type - end + delegate :host, to: :model + delegate :provider_type, to: :model def creator icon = avatar model.creator, size: :mini diff --git a/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb b/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb index c148ecc4c3..566252ba55 100644 --- a/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb +++ b/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb @@ -61,7 +61,7 @@ class Storages::Admin::ProjectsStoragesController < Projects::SettingsController end def destroy - Storages::FileLink.joins(:container).where("work_packages.project_id = ?", @project.id).delete_all + Storages::FileLink.joins(:container).where(work_packages: { project_id: @project.id }).delete_all @object.destroy redirect_to project_settings_projects_storages_path diff --git a/modules/storages/app/models/storages/file_link.rb b/modules/storages/app/models/storages/file_link.rb index cba5820f24..305a8b36d0 100644 --- a/modules/storages/app/models/storages/file_link.rb +++ b/modules/storages/app/models/storages/file_link.rb @@ -28,8 +28,8 @@ class Storages::FileLink < ApplicationRecord belongs_to :storage - belongs_to :creator, foreign_key: 'creator_id', class_name: 'User' - belongs_to :container, foreign_key: 'container_id', class_name: 'WorkPackage' # This needs to become more flexible in the future + belongs_to :creator, class_name: 'User' + belongs_to :container, class_name: 'WorkPackage' # This needs to become more flexible in the future scope :visible, ->(user = User.current) { includes(:container) diff --git a/modules/storages/spec/features/admin_storages_spec.rb b/modules/storages/spec/features/admin_storages_spec.rb index 05afd2e65b..e579b9b528 100644 --- a/modules/storages/spec/features/admin_storages_spec.rb +++ b/modules/storages/spec/features/admin_storages_spec.rb @@ -95,6 +95,6 @@ describe 'Admin storages', type: :feature, js: true do page.driver.browser.switch_to.alert.accept expect(page).to have_current_path(storages_path) - expect(page).to_not have_text("Other NC") + expect(page).not_to have_text("Other NC") end end diff --git a/modules/storages/spec/models/storage_spec.rb b/modules/storages/spec/models/storage_spec.rb index 5e437eba0b..60be43572f 100644 --- a/modules/storages/spec/models/storage_spec.rb +++ b/modules/storages/spec/models/storage_spec.rb @@ -43,34 +43,34 @@ describe ::Storages::Storage, type: :model do expect(storage).to be_valid end - it "should fail the validation if name is empty string" do + it "fails the validation if name is empty string" do expect(described_class.create(test_default_attributes.merge({ name: "" }))).to be_invalid end - it "should fail the validation if name is nil" do + it "fails the validation if name is nil" do expect(described_class.create(test_default_attributes.merge({ name: nil }))).to be_invalid end - it "should fail the validation if host is empty string" do + it "fails the validation if host is empty string" do expect(described_class.create(test_default_attributes.merge({ host: '' }))).to be_invalid end - it "should fail the validation if host is nil" do + it "fails the validation if host is nil" do expect(described_class.create(test_default_attributes.merge({ host: nil }))).to be_invalid end - context "having already one instance" do + context "when having already one instance" do let(:old_storage) { described_class.create test_default_attributes } before do old_storage end - it "should fail the validation if name is not unique" do + it "fails the validation if name is not unique" do expect(described_class.create(test_default_attributes.merge({ host: 'https://example2.com' }))).to be_invalid end - it "should fail the validation if host is not unique" do + it "fails the validation if host is not unique" do expect(described_class.create(test_default_attributes.merge({ name: 'NC 2' }))).to be_invalid end end @@ -87,7 +87,7 @@ describe ::Storages::Storage, type: :model do storage.destroy end - it "should destroy all associated ProjectStorage and FileLink records" do + it "destroys all associated ProjectStorage and FileLink records" do expect(Storages::ProjectStorage.count).to be 0 expect(Storages::FileLink.count).to be 0 end