OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
fix rubocop violations in spec/models/custom_value/ (#19705)
Ivan Kuchin250ce04b77d0
diff --git a/spec/models/custom_value/bool_strategy_spec.rb b/spec/models/custom_value/bool_strategy_spec.rbindex 63c63d9002d..59ef6127105 100644--- a/spec/models/custom_value/bool_strategy_spec.rb+++ b/spec/models/custom_value/bool_strategy_spec.rb@@ -32,39 +32,36 @@ require "spec_helper"RSpec.describe CustomValue::BoolStrategy dolet(:instance) { described_class.new(custom_value) }- let(:custom_value) do- double("CustomValue",- value:)- end+ let(:custom_value) { instance_double(CustomValue, value:) }describe "#value_present?" dosubject { described_class.new(custom_value).value_present? }- context "value is nil" do+ context "when value is nil" dolet(:value) { nil }it { is_expected.to be false }end- context "value is empty string" do+ context "when value is an empty string" dolet(:value) { "" }it { is_expected.to be false }end- context "value is present string" do+ context "when value is a present string" dolet(:value) { "1" }it { is_expected.to be true }end- context "value is true" do+ context "when value is true" dolet(:value) { true }it { is_expected.to be true }end- context "value is false" do+ context "when value is false" dolet(:value) { false }it { is_expected.to be true }@@ -74,37 +71,37 @@ RSpec.describe CustomValue::BoolStrategy dodescribe "#typed_value" dosubject { instance.typed_value }- context "value corresponds to true" do+ context "when value corresponds to true" dolet(:value) { "1" }it { is_expected.to be true }end- context "value corresponds to false" do+ context "when value corresponds to false" dolet(:value) { "0" }it { is_expected.to be false }end- context "value is blank" do+ context "when value is blank" dolet(:value) { "" }it { is_expected.to be_nil }end- context "value is nil" do+ context "when value is nil" dolet(:value) { nil }it { is_expected.to be_nil }end- context "value is true" do+ context "when value is true" dolet(:value) { true }it { is_expected.to be true }end- context "value is false" do+ context "when value is false" dolet(:value) { false }it { is_expected.to be false }@@ -114,7 +111,7 @@ RSpec.describe CustomValue::BoolStrategy dodescribe "#formatted_value" dosubject { instance.formatted_value }- context "value is present string" do+ context "when value corresponds to true" dolet(:value) { "1" }it "is the true string" do@@ -122,7 +119,7 @@ RSpec.describe CustomValue::BoolStrategy doendend- context "value is zero string" do+ context "when value corresponds to false" dolet(:value) { "0" }it "is the false string" do@@ -130,7 +127,7 @@ RSpec.describe CustomValue::BoolStrategy doendend- context "value is true" do+ context "when value is true" dolet(:value) { true }it "is the true string" do@@ -138,7 +135,7 @@ RSpec.describe CustomValue::BoolStrategy doendend- context "value is false" do+ context "when value is false" dolet(:value) { false }it "is the false string" do@@ -146,7 +143,7 @@ RSpec.describe CustomValue::BoolStrategy doendend- context "value is nil" do+ context "when value is nil" dolet(:value) { nil }it "is the false string" do@@ -154,7 +151,7 @@ RSpec.describe CustomValue::BoolStrategy doendend- context "value is blank" do+ context "when value is blank" dolet(:value) { "" }it "is the false string" do@@ -166,7 +163,7 @@ RSpec.describe CustomValue::BoolStrategy dodescribe "#validate_type_of_value" dosubject { instance.validate_type_of_value }- context "value corresponds to true" do+ context "when value corresponds to true" dolet(:value) { "1" }it "accepts" do@@ -174,7 +171,7 @@ RSpec.describe CustomValue::BoolStrategy doendend- context "value corresponds to false" do+ context "when value corresponds to false" dolet(:value) { "0" }it "accepts" do@@ -182,7 +179,7 @@ RSpec.describe CustomValue::BoolStrategy doendend- context "value is true" do+ context "when value is true" dolet(:value) { true }it "accepts" do@@ -190,7 +187,7 @@ RSpec.describe CustomValue::BoolStrategy doendend- context "value is false" do+ context "when value is false" dolet(:value) { false }it "accepts" dodiff --git a/spec/models/custom_value/date_strategy_spec.rb b/spec/models/custom_value/date_strategy_spec.rbindex b6f5fdc9c9a..7f94776d728 100644--- a/spec/models/custom_value/date_strategy_spec.rb+++ b/spec/models/custom_value/date_strategy_spec.rb@@ -32,9 +32,7 @@ require "spec_helper"RSpec.describe CustomValue::DateStrategy dolet(:instance) { described_class.new(custom_value) }- let(:custom_value) do- instance_double(CustomValue, value:)- end+ let(:custom_value) { instance_double(CustomValue, value:) }describe "#typed_value" dosubject { instance.typed_value }diff --git a/spec/models/custom_value/float_strategy_spec.rb b/spec/models/custom_value/float_strategy_spec.rbindex a2182eeaaa7..9b8a3480eb7 100644--- a/spec/models/custom_value/float_strategy_spec.rb+++ b/spec/models/custom_value/float_strategy_spec.rb@@ -32,27 +32,24 @@ require "spec_helper"RSpec.describe CustomValue::FloatStrategy dolet(:instance) { described_class.new(custom_value) }- let(:custom_value) do- double("CustomValue",- value:)- end+ let(:custom_value) { instance_double(CustomValue, value:) }describe "#typed_value" dosubject { instance.typed_value }- context "value is some float string" do+ context "when value is a float string" dolet(:value) { "3.14" }it { is_expected.to be(3.14) }end- context "value is blank" do+ context "when value is blank" dolet(:value) { "" }it { is_expected.to be_nil }end- context "value is nil" do+ context "when value is nil" dolet(:value) { nil }it { is_expected.to be_nil }@@ -62,7 +59,7 @@ RSpec.describe CustomValue::FloatStrategy dodescribe "#formatted_value" dosubject { instance.formatted_value }- context "value is some float string" do+ context "when value is a float string" dolet(:value) { "3.14" }it "is the float string" do@@ -76,7 +73,7 @@ RSpec.describe CustomValue::FloatStrategy doendend- context "value is blank" do+ context "when value is blank" dolet(:value) { "" }it "is a blank string" do@@ -84,7 +81,7 @@ RSpec.describe CustomValue::FloatStrategy doendend- context "value is nil" do+ context "when value is nil" dolet(:value) { nil }it "is a blank string" do@@ -96,7 +93,7 @@ RSpec.describe CustomValue::FloatStrategy dodescribe "#validate_type_of_value" dosubject { instance.validate_type_of_value }- context "value is float string in decimal notation" do+ context "when value is float string in decimal notation" dolet(:value) { "3.14" }it "accepts" do@@ -104,7 +101,7 @@ RSpec.describe CustomValue::FloatStrategy doendend- context "value is float string in exp. notation" do+ context "when value is float string in exp. notation" dolet(:value) { "5.0e-14" }it "accepts" do@@ -112,7 +109,7 @@ RSpec.describe CustomValue::FloatStrategy doendend- context "value is not a float string" do+ context "when value is not a float string" dolet(:value) { "banana" }it "rejects" do@@ -120,7 +117,7 @@ RSpec.describe CustomValue::FloatStrategy doendend- context "value is float" do+ context "when value is float" dolet(:value) { 3.14 }it "accepts" do@@ -128,7 +125,7 @@ RSpec.describe CustomValue::FloatStrategy doendend- context "value is int" do+ context "when value is int" dolet(:value) { 3 }it "accepts" dodiff --git a/spec/models/custom_value/format_strategy_spec.rb b/spec/models/custom_value/format_strategy_spec.rbindex 0ea11d2a52f..de34fe238a9 100644--- a/spec/models/custom_value/format_strategy_spec.rb+++ b/spec/models/custom_value/format_strategy_spec.rb@@ -31,33 +31,30 @@require "spec_helper"RSpec.describe CustomValue::FormatStrategy do- let(:custom_value) do- double("CustomValue",- value:)- end+ let(:custom_value) { instance_double(CustomValue, value:) }describe "#value_present?" dosubject { described_class.new(custom_value).value_present? }- context "value is nil" do+ context "when value is nil" dolet(:value) { nil }it { is_expected.to be(false) }end- context "value is empty string" do+ context "when value is an empty string" dolet(:value) { "" }it { is_expected.to be(false) }end- context "value is present string" do+ context "when value is a present string" dolet(:value) { "foo" }it { is_expected.to be(true) }end- context "value is present integer" do+ context "when value is a present integer" dolet(:value) { 42 }it { is_expected.to be(true) }diff --git a/spec/models/custom_value/int_strategy_spec.rb b/spec/models/custom_value/int_strategy_spec.rbindex ed9df1ce695..8987483cc20 100644--- a/spec/models/custom_value/int_strategy_spec.rb+++ b/spec/models/custom_value/int_strategy_spec.rb@@ -32,27 +32,24 @@ require "spec_helper"RSpec.describe CustomValue::IntStrategy dolet(:instance) { described_class.new(custom_value) }- let(:custom_value) do- double("CustomValue",- value:)- end+ let(:custom_value) { instance_double(CustomValue, value:) }describe "#typed_value" dosubject { instance.typed_value }- context "value is some float string" do+ context "when value is a float string" dolet(:value) { "10" }it { is_expected.to be(10) }end- context "value is blank" do+ context "when value is blank" dolet(:value) { "" }it { is_expected.to be_nil }end- context "value is nil" do+ context "when value is nil" dolet(:value) { nil }it { is_expected.to be_nil }@@ -62,19 +59,19 @@ RSpec.describe CustomValue::IntStrategy dodescribe "#formatted_value" dosubject { instance.typed_value }- context "value is some int string" do+ context "when value is an int string" dolet(:value) { "10" }it { is_expected.to be(10) }end- context "value is blank" do+ context "when value is blank" dolet(:value) { "" }it { is_expected.to be_nil }end- context "value is nil" do+ context "when value is nil" dolet(:value) { nil }it { is_expected.to be_nil }@@ -84,7 +81,7 @@ RSpec.describe CustomValue::IntStrategy dodescribe "#validate_type_of_value" dosubject { instance.validate_type_of_value }- context "value is positive int string" do+ context "when value is a positive int string" dolet(:value) { "10" }it "accepts" do@@ -92,7 +89,7 @@ RSpec.describe CustomValue::IntStrategy doendend- context "value is negative int string" do+ context "when value is a negative int string" dolet(:value) { "-10" }it "accepts" do@@ -100,7 +97,7 @@ RSpec.describe CustomValue::IntStrategy doendend- context "value is not an int string" do+ context "when value is not an int string" dolet(:value) { "unicorn" }it "rejects" do@@ -108,7 +105,7 @@ RSpec.describe CustomValue::IntStrategy doendend- context "value is an actual int" do+ context "when value is an actual int" dolet(:value) { 10 }it "accepts" do@@ -116,7 +113,7 @@ RSpec.describe CustomValue::IntStrategy doendend- context "value is a float" do+ context "when value is a float" dolet(:value) { 2.3 }it "rejects" dodiff --git a/spec/models/custom_value/list_strategy_spec.rb b/spec/models/custom_value/list_strategy_spec.rbindex 6832bd83b7f..336fc9657c0 100644--- a/spec/models/custom_value/list_strategy_spec.rb+++ b/spec/models/custom_value/list_strategy_spec.rb@@ -33,11 +33,12 @@ require "spec_helper"RSpec.describe CustomValue::ListStrategy dolet(:instance) { described_class.new(custom_value) }let(:custom_field) { create(:list_wp_custom_field) }- let(:custom_value) do- double("CustomField", value:, custom_field:, customized:)- end+ let(:custom_value) { instance_double(CustomValue, value:, custom_field:, customized:) }+ let(:customized) { instance_double(Project) }- let(:customized) { double("customized") }+ before do+ allow(CustomOption).to receive(:where).and_call_original+ enddescribe "#parse_value/#typed_value" dosubject { instance }@@ -46,12 +47,11 @@ RSpec.describe CustomValue::ListStrategy dolet(:value) { custom_field.custom_options.first }it "returns the CustomOption and sets it for later retrieval" do- expect(CustomOption)- .not_to receive(:where)-expect(subject.parse_value(value)).to eql value.id.to_sexpect(subject.typed_value).to eql value.value++ expect(CustomOption).not_to have_received(:where)endend@@ -65,29 +65,27 @@ RSpec.describe CustomValue::ListStrategy doendend- context "value is blank" do+ context "when value is blank" dolet(:value) { "" }it "is nil and does not look for the CustomOption" do- expect(CustomOption)- .not_to receive(:where)-expect(subject.parse_value(value)).to be_nilexpect(subject.typed_value).to be_nil++ expect(CustomOption).not_to have_received(:where)endend- context "value is nil" do+ context "when value is nil" dolet(:value) { nil }it "is nil and does not look for the CustomOption" do- expect(CustomOption)- .not_to receive(:where)-expect(subject.parse_value(value)).to be_nilexpect(subject.typed_value).to be_nil++ expect(CustomOption).not_to have_received(:where)endendend@@ -101,10 +99,9 @@ RSpec.describe CustomValue::ListStrategy doit "is the custom option to_s (without db access)" doinstance.parse_value(value)- expect(CustomOption)- .not_to receive(:where)-expect(subject).to eql value.to_s++ expect(CustomOption).not_to have_received(:where)endend@@ -116,7 +113,7 @@ RSpec.describe CustomValue::ListStrategy doendend- context "value is blank" do+ context "when value is blank" dolet(:value) { "" }it "is blank" do@@ -124,7 +121,7 @@ RSpec.describe CustomValue::ListStrategy doendend- context "value is nil" do+ context "when value is nil" dolet(:value) { nil }it "is blank" do@@ -136,7 +133,7 @@ RSpec.describe CustomValue::ListStrategy dodescribe "#validate_type_of_value" dosubject { instance.validate_type_of_value }- context "value is included" do+ context "when value is included" dolet(:value) { custom_field.custom_options.first.id.to_s }it "accepts" do@@ -144,7 +141,7 @@ RSpec.describe CustomValue::ListStrategy doendend- context "value is not included" do+ context "when value is not included" dolet(:value) { "cat" }it "rejects" dodiff --git a/spec/models/custom_value/string_strategy_spec.rb b/spec/models/custom_value/string_strategy_spec.rbindex c214e4ae90d..ebd96fff85b 100644--- a/spec/models/custom_value/string_strategy_spec.rb+++ b/spec/models/custom_value/string_strategy_spec.rb@@ -32,27 +32,24 @@ require "spec_helper"RSpec.describe CustomValue::StringStrategy dolet(:instance) { described_class.new(custom_value) }- let(:custom_value) do- double("CustomValue",- value:)- end+ let(:custom_value) { instance_double(CustomValue, value:) }describe "#typed_value" dosubject { instance.typed_value }- context "value is some string" do+ context "when value is a present string" dolet(:value) { "foo bar!" }it { is_expected.to eql(value) }end- context "value is blank" do+ context "when value is blank" dolet(:value) { "" }it { is_expected.to eql(value) }end- context "value is nil" do+ context "when value is nil" dolet(:value) { nil }it { is_expected.to be_nil }@@ -62,7 +59,7 @@ RSpec.describe CustomValue::StringStrategy dodescribe "#formatted_value" dosubject { instance.formatted_value }- context "value is some string" do+ context "when value is a present string" dolet(:value) { "foo bar!" }it "is the string" do@@ -70,7 +67,7 @@ RSpec.describe CustomValue::StringStrategy doendend- context "value is blank" do+ context "when value is blank" dolet(:value) { "" }it "is a blank string" do@@ -78,7 +75,7 @@ RSpec.describe CustomValue::StringStrategy doendend- context "value is nil" do+ context "when value is nil" dolet(:value) { nil }it "is a blank string" do@@ -90,7 +87,7 @@ RSpec.describe CustomValue::StringStrategy dodescribe "#validate_type_of_value" dosubject { instance.validate_type_of_value }- context "value is some string" do+ context "when value is a present string" dolet(:value) { "foo bar!" }it "accepts" do@@ -98,7 +95,7 @@ RSpec.describe CustomValue::StringStrategy doendend- context "value is empty string" do+ context "when value is empty string" dolet(:value) { "" }it "accepts" dodiff --git a/spec/models/custom_value/user_strategy_spec.rb b/spec/models/custom_value/user_strategy_spec.rbindex d55c215ec9a..12fb0f8669b 100644--- a/spec/models/custom_value/user_strategy_spec.rb+++ b/spec/models/custom_value/user_strategy_spec.rb@@ -32,16 +32,15 @@ require "spec_helper"RSpec.describe CustomValue::UserStrategy dolet(:instance) { described_class.new(custom_value) }- let(:custom_value) do- double("CustomValue",- value:,- custom_field:,- customized:)- end- let(:customized) { double("customized") }+ let(:custom_value) { instance_double(CustomValue, value:, custom_field:, customized:) }+ let(:customized) { instance_double(Project) }let(:custom_field) { build(:custom_field) }let(:user) { build_stubbed(:user) }+ before do+ allow(Principal).to receive(:find_by)+ end+describe "#parse_value/#typed_value" dosubject { instance }@@ -49,12 +48,11 @@ RSpec.describe CustomValue::UserStrategy dolet(:value) { user }it "returns the user and sets it for later retrieval" do- expect(Principal)- .not_to receive(:find_by)-expect(subject.parse_value(value)).to eql user.id.to_sexpect(subject.typed_value).to eql value++ expect(Principal).not_to have_received(:find_by)endend@@ -73,29 +71,27 @@ RSpec.describe CustomValue::UserStrategy doendend- context "value is blank" do+ context "when value is blank" dolet(:value) { "" }it "is nil and does not look for the user" do- expect(Principal)- .not_to receive(:find_by)-expect(subject.parse_value(value)).to be_nilexpect(subject.typed_value).to be_nil++ expect(Principal).not_to have_received(:find_by)endend- context "value is nil" do+ context "when value is nil" dolet(:value) { nil }it "is nil and does not look for the user" do- expect(Principal)- .not_to receive(:find_by)-expect(subject.parse_value(value)).to be_nilexpect(subject.typed_value).to be_nil++ expect(Principal).not_to have_received(:find_by)endendend@@ -109,10 +105,9 @@ RSpec.describe CustomValue::UserStrategy doit "is the user to_s (without db access)" doinstance.parse_value(value)- expect(Principal)- .not_to receive(:find_by)-expect(subject).to eql value.to_s++ expect(Principal).not_to have_received(:find_by)endend@@ -129,7 +124,7 @@ RSpec.describe CustomValue::UserStrategy doendend- context "value is blank" do+ context "when value is blank" dolet(:value) { "" }it "is blank and does not look for the user" do@@ -137,7 +132,7 @@ RSpec.describe CustomValue::UserStrategy doendend- context "value is nil" do+ context "when value is nil" dolet(:value) { nil }it "is blank and does not look for the user" do@@ -155,7 +150,7 @@ RSpec.describe CustomValue::UserStrategy doallow(custom_field).to receive(:possible_values).with(customized).and_return(allowed_ids)end- context "value is id of included element" do+ context "when value is an id of included element" dolet(:value) { "12" }it "accepts" do@@ -163,7 +158,7 @@ RSpec.describe CustomValue::UserStrategy doendend- context "value is id of non included element" do+ context "when value is an id of non included element" dolet(:value) { "10" }it "rejects" dodiff --git a/spec/models/custom_value/version_strategy_spec.rb b/spec/models/custom_value/version_strategy_spec.rbindex 7ab2f38fcd6..959737d4d17 100644--- a/spec/models/custom_value/version_strategy_spec.rb+++ b/spec/models/custom_value/version_strategy_spec.rb@@ -32,16 +32,15 @@ require "spec_helper"RSpec.describe CustomValue::VersionStrategy dolet(:instance) { described_class.new(custom_value) }- let(:custom_value) do- double("CustomValue",- value:,- custom_field:,- customized:)- end- let(:customized) { double("customized") }+ let(:custom_value) { instance_double(CustomValue, value:, custom_field:, customized:) }+ let(:customized) { instance_double(Project) }let(:custom_field) { build(:custom_field) }let(:version) { build_stubbed(:version) }+ before do+ allow(Version).to receive(:find_by)+ end+describe "#parse_value/#typed_value" dosubject { instance }@@ -49,12 +48,11 @@ RSpec.describe CustomValue::VersionStrategy dolet(:value) { version }it "returns the version and sets it for later retrieval" do- expect(Version)- .not_to receive(:find_by)-expect(subject.parse_value(value)).to eql version.id.to_sexpect(subject.typed_value).to eql value++ expect(Version).not_to have_received(:find_by)endend@@ -73,29 +71,27 @@ RSpec.describe CustomValue::VersionStrategy doendend- context "value is blank" do+ context "when value is blank" dolet(:value) { "" }it "is nil and does not look for the version" do- expect(Version)- .not_to receive(:find_by)-expect(subject.parse_value(value)).to be_nilexpect(subject.typed_value).to be_nil++ expect(Version).not_to have_received(:find_by)endend- context "value is nil" do+ context "when value is nil" dolet(:value) { nil }it "is nil and does not look for the version" do- expect(Version)- .not_to receive(:find_by)-expect(subject.parse_value(value)).to be_nilexpect(subject.typed_value).to be_nil++ expect(Version).not_to have_received(:find_by)endendend@@ -107,12 +103,11 @@ RSpec.describe CustomValue::VersionStrategy dolet(:value) { version }it "is the version to_s (without db access)" do- expect(Version)- .not_to receive(:find_by)-instance.parse_value(value)expect(subject).to eql value.to_s++ expect(Version).not_to have_received(:find_by)endend@@ -129,25 +124,23 @@ RSpec.describe CustomValue::VersionStrategy doendend- context "value is blank" do+ context "when value is blank" dolet(:value) { "" }it "is blank and does not look for the version" do- expect(Version)- .not_to receive(:find_by)-expect(subject).to eql ""++ expect(Version).not_to have_received(:find_by)endend- context "value is nil" do+ context "when value is nil" dolet(:value) { nil }it "is blank and does not look for the version" do- expect(Version)- .not_to receive(:find_by)-expect(subject).to eql ""++ expect(Version).not_to have_received(:find_by)endendend@@ -161,7 +154,7 @@ RSpec.describe CustomValue::VersionStrategy doallow(custom_field).to receive(:possible_values).with(customized).and_return(allowed_ids)end- context "value is id of included element" do+ context "when value is an id of included element" dolet(:value) { "12" }it "accepts" do@@ -169,7 +162,7 @@ RSpec.describe CustomValue::VersionStrategy doendend- context "value is id of non included element" do+ context "when value is an id of non included element" dolet(:value) { "10" }it "rejects" do