Skip to content

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

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.rb
index 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 do
let(:instance) { described_class.new(custom_value) }
- let(:custom_value) do
- double("CustomValue",
- value:)
- end
+ let(:custom_value) { instance_double(CustomValue, value:) }
describe "#value_present?" do
subject { described_class.new(custom_value).value_present? }
- context "value is nil" do
+ context "when value is nil" do
let(:value) { nil }
it { is_expected.to be false }
end
- context "value is empty string" do
+ context "when value is an empty string" do
let(:value) { "" }
it { is_expected.to be false }
end
- context "value is present string" do
+ context "when value is a present string" do
let(:value) { "1" }
it { is_expected.to be true }
end
- context "value is true" do
+ context "when value is true" do
let(:value) { true }
it { is_expected.to be true }
end
- context "value is false" do
+ context "when value is false" do
let(:value) { false }
it { is_expected.to be true }
@@ -74,37 +71,37 @@ RSpec.describe CustomValue::BoolStrategy do
describe "#typed_value" do
subject { instance.typed_value }
- context "value corresponds to true" do
+ context "when value corresponds to true" do
let(:value) { "1" }
it { is_expected.to be true }
end
- context "value corresponds to false" do
+ context "when value corresponds to false" do
let(:value) { "0" }
it { is_expected.to be false }
end
- context "value is blank" do
+ context "when value is blank" do
let(:value) { "" }
it { is_expected.to be_nil }
end
- context "value is nil" do
+ context "when value is nil" do
let(:value) { nil }
it { is_expected.to be_nil }
end
- context "value is true" do
+ context "when value is true" do
let(:value) { true }
it { is_expected.to be true }
end
- context "value is false" do
+ context "when value is false" do
let(:value) { false }
it { is_expected.to be false }
@@ -114,7 +111,7 @@ RSpec.describe CustomValue::BoolStrategy do
describe "#formatted_value" do
subject { instance.formatted_value }
- context "value is present string" do
+ context "when value corresponds to true" do
let(:value) { "1" }
it "is the true string" do
@@ -122,7 +119,7 @@ RSpec.describe CustomValue::BoolStrategy do
end
end
- context "value is zero string" do
+ context "when value corresponds to false" do
let(:value) { "0" }
it "is the false string" do
@@ -130,7 +127,7 @@ RSpec.describe CustomValue::BoolStrategy do
end
end
- context "value is true" do
+ context "when value is true" do
let(:value) { true }
it "is the true string" do
@@ -138,7 +135,7 @@ RSpec.describe CustomValue::BoolStrategy do
end
end
- context "value is false" do
+ context "when value is false" do
let(:value) { false }
it "is the false string" do
@@ -146,7 +143,7 @@ RSpec.describe CustomValue::BoolStrategy do
end
end
- context "value is nil" do
+ context "when value is nil" do
let(:value) { nil }
it "is the false string" do
@@ -154,7 +151,7 @@ RSpec.describe CustomValue::BoolStrategy do
end
end
- context "value is blank" do
+ context "when value is blank" do
let(:value) { "" }
it "is the false string" do
@@ -166,7 +163,7 @@ RSpec.describe CustomValue::BoolStrategy do
describe "#validate_type_of_value" do
subject { instance.validate_type_of_value }
- context "value corresponds to true" do
+ context "when value corresponds to true" do
let(:value) { "1" }
it "accepts" do
@@ -174,7 +171,7 @@ RSpec.describe CustomValue::BoolStrategy do
end
end
- context "value corresponds to false" do
+ context "when value corresponds to false" do
let(:value) { "0" }
it "accepts" do
@@ -182,7 +179,7 @@ RSpec.describe CustomValue::BoolStrategy do
end
end
- context "value is true" do
+ context "when value is true" do
let(:value) { true }
it "accepts" do
@@ -190,7 +187,7 @@ RSpec.describe CustomValue::BoolStrategy do
end
end
- context "value is false" do
+ context "when value is false" do
let(:value) { false }
it "accepts" do
diff --git a/spec/models/custom_value/date_strategy_spec.rb b/spec/models/custom_value/date_strategy_spec.rb
index 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 do
let(: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" do
subject { instance.typed_value }
diff --git a/spec/models/custom_value/float_strategy_spec.rb b/spec/models/custom_value/float_strategy_spec.rb
index 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 do
let(:instance) { described_class.new(custom_value) }
- let(:custom_value) do
- double("CustomValue",
- value:)
- end
+ let(:custom_value) { instance_double(CustomValue, value:) }
describe "#typed_value" do
subject { instance.typed_value }
- context "value is some float string" do
+ context "when value is a float string" do
let(:value) { "3.14" }
it { is_expected.to be(3.14) }
end
- context "value is blank" do
+ context "when value is blank" do
let(:value) { "" }
it { is_expected.to be_nil }
end
- context "value is nil" do
+ context "when value is nil" do
let(:value) { nil }
it { is_expected.to be_nil }
@@ -62,7 +59,7 @@ RSpec.describe CustomValue::FloatStrategy do
describe "#formatted_value" do
subject { instance.formatted_value }
- context "value is some float string" do
+ context "when value is a float string" do
let(:value) { "3.14" }
it "is the float string" do
@@ -76,7 +73,7 @@ RSpec.describe CustomValue::FloatStrategy do
end
end
- context "value is blank" do
+ context "when value is blank" do
let(:value) { "" }
it "is a blank string" do
@@ -84,7 +81,7 @@ RSpec.describe CustomValue::FloatStrategy do
end
end
- context "value is nil" do
+ context "when value is nil" do
let(:value) { nil }
it "is a blank string" do
@@ -96,7 +93,7 @@ RSpec.describe CustomValue::FloatStrategy do
describe "#validate_type_of_value" do
subject { instance.validate_type_of_value }
- context "value is float string in decimal notation" do
+ context "when value is float string in decimal notation" do
let(:value) { "3.14" }
it "accepts" do
@@ -104,7 +101,7 @@ RSpec.describe CustomValue::FloatStrategy do
end
end
- context "value is float string in exp. notation" do
+ context "when value is float string in exp. notation" do
let(:value) { "5.0e-14" }
it "accepts" do
@@ -112,7 +109,7 @@ RSpec.describe CustomValue::FloatStrategy do
end
end
- context "value is not a float string" do
+ context "when value is not a float string" do
let(:value) { "banana" }
it "rejects" do
@@ -120,7 +117,7 @@ RSpec.describe CustomValue::FloatStrategy do
end
end
- context "value is float" do
+ context "when value is float" do
let(:value) { 3.14 }
it "accepts" do
@@ -128,7 +125,7 @@ RSpec.describe CustomValue::FloatStrategy do
end
end
- context "value is int" do
+ context "when value is int" do
let(:value) { 3 }
it "accepts" do
diff --git a/spec/models/custom_value/format_strategy_spec.rb b/spec/models/custom_value/format_strategy_spec.rb
index 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?" do
subject { described_class.new(custom_value).value_present? }
- context "value is nil" do
+ context "when value is nil" do
let(:value) { nil }
it { is_expected.to be(false) }
end
- context "value is empty string" do
+ context "when value is an empty string" do
let(:value) { "" }
it { is_expected.to be(false) }
end
- context "value is present string" do
+ context "when value is a present string" do
let(:value) { "foo" }
it { is_expected.to be(true) }
end
- context "value is present integer" do
+ context "when value is a present integer" do
let(: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.rb
index 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 do
let(:instance) { described_class.new(custom_value) }
- let(:custom_value) do
- double("CustomValue",
- value:)
- end
+ let(:custom_value) { instance_double(CustomValue, value:) }
describe "#typed_value" do
subject { instance.typed_value }
- context "value is some float string" do
+ context "when value is a float string" do
let(:value) { "10" }
it { is_expected.to be(10) }
end
- context "value is blank" do
+ context "when value is blank" do
let(:value) { "" }
it { is_expected.to be_nil }
end
- context "value is nil" do
+ context "when value is nil" do
let(:value) { nil }
it { is_expected.to be_nil }
@@ -62,19 +59,19 @@ RSpec.describe CustomValue::IntStrategy do
describe "#formatted_value" do
subject { instance.typed_value }
- context "value is some int string" do
+ context "when value is an int string" do
let(:value) { "10" }
it { is_expected.to be(10) }
end
- context "value is blank" do
+ context "when value is blank" do
let(:value) { "" }
it { is_expected.to be_nil }
end
- context "value is nil" do
+ context "when value is nil" do
let(:value) { nil }
it { is_expected.to be_nil }
@@ -84,7 +81,7 @@ RSpec.describe CustomValue::IntStrategy do
describe "#validate_type_of_value" do
subject { instance.validate_type_of_value }
- context "value is positive int string" do
+ context "when value is a positive int string" do
let(:value) { "10" }
it "accepts" do
@@ -92,7 +89,7 @@ RSpec.describe CustomValue::IntStrategy do
end
end
- context "value is negative int string" do
+ context "when value is a negative int string" do
let(:value) { "-10" }
it "accepts" do
@@ -100,7 +97,7 @@ RSpec.describe CustomValue::IntStrategy do
end
end
- context "value is not an int string" do
+ context "when value is not an int string" do
let(:value) { "unicorn" }
it "rejects" do
@@ -108,7 +105,7 @@ RSpec.describe CustomValue::IntStrategy do
end
end
- context "value is an actual int" do
+ context "when value is an actual int" do
let(:value) { 10 }
it "accepts" do
@@ -116,7 +113,7 @@ RSpec.describe CustomValue::IntStrategy do
end
end
- context "value is a float" do
+ context "when value is a float" do
let(:value) { 2.3 }
it "rejects" do
diff --git a/spec/models/custom_value/list_strategy_spec.rb b/spec/models/custom_value/list_strategy_spec.rb
index 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 do
let(: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
+ end
describe "#parse_value/#typed_value" do
subject { instance }
@@ -46,12 +47,11 @@ RSpec.describe CustomValue::ListStrategy do
let(: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_s
expect(subject.typed_value).to eql value.value
+
+ expect(CustomOption).not_to have_received(:where)
end
end
@@ -65,29 +65,27 @@ RSpec.describe CustomValue::ListStrategy do
end
end
- context "value is blank" do
+ context "when value is blank" do
let(: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_nil
expect(subject.typed_value).to be_nil
+
+ expect(CustomOption).not_to have_received(:where)
end
end
- context "value is nil" do
+ context "when value is nil" do
let(: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_nil
expect(subject.typed_value).to be_nil
+
+ expect(CustomOption).not_to have_received(:where)
end
end
end
@@ -101,10 +99,9 @@ RSpec.describe CustomValue::ListStrategy do
it "is the custom option to_s (without db access)" do
instance.parse_value(value)
- expect(CustomOption)
- .not_to receive(:where)
-
expect(subject).to eql value.to_s
+
+ expect(CustomOption).not_to have_received(:where)
end
end
@@ -116,7 +113,7 @@ RSpec.describe CustomValue::ListStrategy do
end
end
- context "value is blank" do
+ context "when value is blank" do
let(:value) { "" }
it "is blank" do
@@ -124,7 +121,7 @@ RSpec.describe CustomValue::ListStrategy do
end
end
- context "value is nil" do
+ context "when value is nil" do
let(:value) { nil }
it "is blank" do
@@ -136,7 +133,7 @@ RSpec.describe CustomValue::ListStrategy do
describe "#validate_type_of_value" do
subject { instance.validate_type_of_value }
- context "value is included" do
+ context "when value is included" do
let(:value) { custom_field.custom_options.first.id.to_s }
it "accepts" do
@@ -144,7 +141,7 @@ RSpec.describe CustomValue::ListStrategy do
end
end
- context "value is not included" do
+ context "when value is not included" do
let(:value) { "cat" }
it "rejects" do
diff --git a/spec/models/custom_value/string_strategy_spec.rb b/spec/models/custom_value/string_strategy_spec.rb
index 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 do
let(:instance) { described_class.new(custom_value) }
- let(:custom_value) do
- double("CustomValue",
- value:)
- end
+ let(:custom_value) { instance_double(CustomValue, value:) }
describe "#typed_value" do
subject { instance.typed_value }
- context "value is some string" do
+ context "when value is a present string" do
let(:value) { "foo bar!" }
it { is_expected.to eql(value) }
end
- context "value is blank" do
+ context "when value is blank" do
let(:value) { "" }
it { is_expected.to eql(value) }
end
- context "value is nil" do
+ context "when value is nil" do
let(:value) { nil }
it { is_expected.to be_nil }
@@ -62,7 +59,7 @@ RSpec.describe CustomValue::StringStrategy do
describe "#formatted_value" do
subject { instance.formatted_value }
- context "value is some string" do
+ context "when value is a present string" do
let(:value) { "foo bar!" }
it "is the string" do
@@ -70,7 +67,7 @@ RSpec.describe CustomValue::StringStrategy do
end
end
- context "value is blank" do
+ context "when value is blank" do
let(:value) { "" }
it "is a blank string" do
@@ -78,7 +75,7 @@ RSpec.describe CustomValue::StringStrategy do
end
end
- context "value is nil" do
+ context "when value is nil" do
let(:value) { nil }
it "is a blank string" do
@@ -90,7 +87,7 @@ RSpec.describe CustomValue::StringStrategy do
describe "#validate_type_of_value" do
subject { instance.validate_type_of_value }
- context "value is some string" do
+ context "when value is a present string" do
let(:value) { "foo bar!" }
it "accepts" do
@@ -98,7 +95,7 @@ RSpec.describe CustomValue::StringStrategy do
end
end
- context "value is empty string" do
+ context "when value is empty string" do
let(:value) { "" }
it "accepts" do
diff --git a/spec/models/custom_value/user_strategy_spec.rb b/spec/models/custom_value/user_strategy_spec.rb
index 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 do
let(: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" do
subject { instance }
@@ -49,12 +48,11 @@ RSpec.describe CustomValue::UserStrategy do
let(: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_s
expect(subject.typed_value).to eql value
+
+ expect(Principal).not_to have_received(:find_by)
end
end
@@ -73,29 +71,27 @@ RSpec.describe CustomValue::UserStrategy do
end
end
- context "value is blank" do
+ context "when value is blank" do
let(: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_nil
expect(subject.typed_value).to be_nil
+
+ expect(Principal).not_to have_received(:find_by)
end
end
- context "value is nil" do
+ context "when value is nil" do
let(: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_nil
expect(subject.typed_value).to be_nil
+
+ expect(Principal).not_to have_received(:find_by)
end
end
end
@@ -109,10 +105,9 @@ RSpec.describe CustomValue::UserStrategy do
it "is the user to_s (without db access)" do
instance.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)
end
end
@@ -129,7 +124,7 @@ RSpec.describe CustomValue::UserStrategy do
end
end
- context "value is blank" do
+ context "when value is blank" do
let(:value) { "" }
it "is blank and does not look for the user" do
@@ -137,7 +132,7 @@ RSpec.describe CustomValue::UserStrategy do
end
end
- context "value is nil" do
+ context "when value is nil" do
let(:value) { nil }
it "is blank and does not look for the user" do
@@ -155,7 +150,7 @@ RSpec.describe CustomValue::UserStrategy do
allow(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" do
let(:value) { "12" }
it "accepts" do
@@ -163,7 +158,7 @@ RSpec.describe CustomValue::UserStrategy do
end
end
- context "value is id of non included element" do
+ context "when value is an id of non included element" do
let(:value) { "10" }
it "rejects" do
diff --git a/spec/models/custom_value/version_strategy_spec.rb b/spec/models/custom_value/version_strategy_spec.rb
index 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 do
let(: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" do
subject { instance }
@@ -49,12 +48,11 @@ RSpec.describe CustomValue::VersionStrategy do
let(: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_s
expect(subject.typed_value).to eql value
+
+ expect(Version).not_to have_received(:find_by)
end
end
@@ -73,29 +71,27 @@ RSpec.describe CustomValue::VersionStrategy do
end
end
- context "value is blank" do
+ context "when value is blank" do
let(: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_nil
expect(subject.typed_value).to be_nil
+
+ expect(Version).not_to have_received(:find_by)
end
end
- context "value is nil" do
+ context "when value is nil" do
let(: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_nil
expect(subject.typed_value).to be_nil
+
+ expect(Version).not_to have_received(:find_by)
end
end
end
@@ -107,12 +103,11 @@ RSpec.describe CustomValue::VersionStrategy do
let(: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)
end
end
@@ -129,25 +124,23 @@ RSpec.describe CustomValue::VersionStrategy do
end
end
- context "value is blank" do
+ context "when value is blank" do
let(: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)
end
end
- context "value is nil" do
+ context "when value is nil" do
let(: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)
end
end
end
@@ -161,7 +154,7 @@ RSpec.describe CustomValue::VersionStrategy do
allow(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" do
let(:value) { "12" }
it "accepts" do
@@ -169,7 +162,7 @@ RSpec.describe CustomValue::VersionStrategy do
end
end
- context "value is id of non included element" do
+ context "when value is an id of non included element" do
let(:value) { "10" }
it "rejects" do