Fix rubocop linting errors

pull/11932/head
Christophe Bliard 2 years ago
parent ac27dba493
commit 745dafc424
No known key found for this signature in database
GPG Key ID: 2BC07603210C3FA4
  1. 2
      modules/dashboards/spec/features/project_details_spec.rb
  2. 83
      spec/lib/api/v3/utilities/custom_field_injector_spec.rb
  3. 27
      spec/models/custom_actions/actions/custom_field_spec.rb
  4. 2
      spec/models/query/results_spec.rb

@ -50,7 +50,7 @@ describe 'Project details widget on dashboard', js: true do
p.send(float_cf.attribute_setter, 4.5)
p.send(text_cf.attribute_setter, 'Some **long** text')
p.send(string_cf.attribute_setter, 'Some small text')
p.send(date_cf.attribute_setter, Date.today)
p.send(date_cf.attribute_setter, Date.current)
p.send(user_cf.attribute_setter, other_user)
p.save!(validate: false)

@ -54,12 +54,11 @@ describe API::V3::Utilities::CustomFieldInjector do
let(:schema_writable) { true }
let(:model) { build_stubbed(:work_package) }
let(:schema) do
double('WorkPackageSchema',
project_id: 42,
model:,
defines_assignable_values?: true,
available_custom_fields: [custom_field],
writable?: schema_writable)
instance_double(API::V3::WorkPackages::Schema::SpecificWorkPackageSchema,
project_id: 42,
model:,
available_custom_fields: [custom_field],
writable?: schema_writable)
end
subject { modified_class.new(schema, current_user: nil, form_embedded: true).to_json }
@ -112,7 +111,7 @@ describe API::V3::Utilities::CustomFieldInjector do
# meaning they won't as no values are specified
it_behaves_like 'indicates length requirements'
context 'custom field is not required' do
context 'when custom field is not required' do
let(:custom_field) { build(:custom_field, is_required: false) }
it 'marks the field as not required' do
@ -120,7 +119,7 @@ describe API::V3::Utilities::CustomFieldInjector do
end
end
context 'custom field has regex' do
context 'when custom field has regex' do
let(:custom_field) { build(:custom_field, regexp: 'Foo+bar') }
it 'renders the regular expression' do
@ -128,7 +127,7 @@ describe API::V3::Utilities::CustomFieldInjector do
end
end
context 'custom field has minimum length' do
context 'when custom field has minimum length' do
let(:custom_field) { build(:custom_field, min_length: 5) }
it_behaves_like 'indicates length requirements' do
@ -136,7 +135,7 @@ describe API::V3::Utilities::CustomFieldInjector do
end
end
context 'custom field has maximum length' do
context 'when custom field has maximum length' do
let(:custom_field) { build(:custom_field, max_length: 5) }
it_behaves_like 'indicates length requirements' do
@ -295,11 +294,10 @@ describe API::V3::Utilities::CustomFieldInjector do
describe 'user custom field on new project' do
let(:schema) do
double('ProjectSchema',
id: nil,
model: Project.new,
defines_assignable_values?: true,
available_custom_fields: [custom_field])
instance_double(API::V3::WorkPackages::Schema::SpecificWorkPackageSchema,
id: nil,
model: Project.new,
available_custom_fields: [custom_field])
end
let(:custom_field) do
build(:custom_field,
@ -331,13 +329,14 @@ describe API::V3::Utilities::CustomFieldInjector do
end
it 'on writing it sets on the represented' do
expected = { custom_field.id => expected_setter }
expect(represented)
.to receive(custom_field.attribute_setter)
.with(expected_setter)
allow(represented).to receive(custom_field.attribute_setter)
modified_class
.new(represented, current_user: nil)
.from_json({ cf_path => json_value }.to_json)
expect(represented)
.to have_received(custom_field.attribute_setter)
.with(expected_setter)
end
end
@ -348,7 +347,7 @@ describe API::V3::Utilities::CustomFieldInjector do
available_custom_fields: [custom_field],
custom_field.attribute_name => value)
end
let(:custom_value) { double('CustomValue', value: raw_value, typed_value:) }
let(:custom_value) { instance_double(CustomValue, value: raw_value, typed_value:) }
let(:raw_value) { nil }
let(:typed_value) { raw_value }
let(:value) { '' }
@ -361,7 +360,7 @@ describe API::V3::Utilities::CustomFieldInjector do
allow(represented).to receive(:custom_value_for).with(custom_field).and_return(custom_value)
end
context 'user custom field' do
context 'for user custom field' do
let(:raw_value) { value.id.to_s }
let(:typed_value) { value }
let(:field_format) { 'user' }
@ -383,7 +382,7 @@ describe API::V3::Utilities::CustomFieldInjector do
end
end
context 'value is nil' do
context 'when value is nil' do
let(:value) { nil }
let(:raw_value) { '' }
@ -393,7 +392,7 @@ describe API::V3::Utilities::CustomFieldInjector do
end
end
context 'version custom field' do
context 'for version custom field' do
let(:value) { build_stubbed(:version, id: 2) }
let(:raw_value) { value.id.to_s }
let(:typed_value) { value }
@ -410,7 +409,7 @@ describe API::V3::Utilities::CustomFieldInjector do
expect(subject).to be_json_eql(value.name.to_json).at_path("_embedded/#{cf_path}/name")
end
context 'value is nil' do
context 'when value is nil' do
let(:value) { nil }
let(:raw_value) { '' }
@ -420,7 +419,7 @@ describe API::V3::Utilities::CustomFieldInjector do
end
end
context 'list custom field' do
context 'for list custom field' do
let(:value) { build_stubbed(:custom_option) }
let(:typed_value) { value.value }
let(:raw_value) { value.id.to_s }
@ -432,7 +431,7 @@ describe API::V3::Utilities::CustomFieldInjector do
let(:title) { value.value }
end
context 'value is nil' do
context 'when value is nil' do
let(:value) { nil }
let(:raw_value) { '' }
let(:typed_value) { '' }
@ -442,7 +441,7 @@ describe API::V3::Utilities::CustomFieldInjector do
end
end
context 'value is some invalid string' do
context 'when value is some invalid string' do
let(:value) { 'some invalid string' }
let(:raw_value) { 'some invalid string' }
let(:typed_value) { 'some invalid string not found' }
@ -461,7 +460,7 @@ describe API::V3::Utilities::CustomFieldInjector do
end
end
context 'string custom field' do
context 'for string custom field' do
it_behaves_like 'injects property custom field' do
let(:field_format) { 'string' }
let(:value) { 'Foobar' }
@ -470,7 +469,7 @@ describe API::V3::Utilities::CustomFieldInjector do
end
end
context 'int custom field' do
context 'for int custom field' do
it_behaves_like 'injects property custom field' do
let(:field_format) { 'int' }
let(:value) { 42 }
@ -479,7 +478,7 @@ describe API::V3::Utilities::CustomFieldInjector do
end
end
context 'float custom field' do
context 'for float custom field' do
it_behaves_like 'injects property custom field' do
let(:field_format) { 'float' }
let(:value) { 3.14 }
@ -488,7 +487,7 @@ describe API::V3::Utilities::CustomFieldInjector do
end
end
context 'bool custom field' do
context 'for bool custom field' do
it_behaves_like 'injects property custom field' do
let(:field_format) { 'bool' }
let(:value) { true }
@ -497,16 +496,16 @@ describe API::V3::Utilities::CustomFieldInjector do
end
end
context 'date custom field' do
context 'for date custom field' do
it_behaves_like 'injects property custom field' do
let(:field_format) { 'date' }
let(:value) { Date.today.to_date }
let(:value) { Date.current }
let(:json_value) { value.to_date.iso8601 }
let(:expected_setter) { json_value }
end
end
context 'text custom field' do
context 'for text custom field' do
it_behaves_like 'injects property custom field' do
let(:field_format) { 'text' }
let(:value) { '**Foobar**' }
@ -530,7 +529,7 @@ describe API::V3::Utilities::CustomFieldInjector do
let(:represented) do
double('represented', available_custom_fields: [custom_field])
end
let(:custom_value) { double('CustomValue', value:, typed_value:) }
let(:custom_value) { instance_double(CustomValue, value:, typed_value:) }
let(:value) { '' }
let(:user) { build_stubbed(:user) }
let(:typed_value) { value }
@ -542,7 +541,7 @@ describe API::V3::Utilities::CustomFieldInjector do
allow(represented).to receive(custom_field.attribute_getter).and_return(typed_value)
end
context 'reading' do
context 'for reading' do
let(:value) { '2' }
let(:field_format) { 'user' }
@ -558,7 +557,7 @@ describe API::V3::Utilities::CustomFieldInjector do
end
end
context 'value is nil' do
context 'when value is nil' do
let(:value) { nil }
let(:typed_value) { nil }
@ -568,7 +567,7 @@ describe API::V3::Utilities::CustomFieldInjector do
end
end
context 'writing' do
context 'for writing' do
let(:value) { nil }
let(:field_format) { 'user' }
@ -578,8 +577,10 @@ describe API::V3::Utilities::CustomFieldInjector do
json = { cf_path => { href: path } }.to_json
expected = ['2']
expect(represented).to receive(custom_field.attribute_setter).with(expected)
allow(represented).to receive(custom_field.attribute_setter)
modified_class.new(represented, current_user: nil).from_json(json)
expect(represented).to have_received(custom_field.attribute_setter).with(expected)
end
end
@ -587,8 +588,10 @@ describe API::V3::Utilities::CustomFieldInjector do
json = { cf_path => { href: nil } }.to_json
expected = []
expect(represented).to receive(custom_field.attribute_setter).with(expected)
allow(represented).to receive(custom_field.attribute_setter)
modified_class.new(represented, current_user: nil).from_json(json)
expect(represented).to have_received(custom_field.attribute_setter).with(expected)
end
end
end

@ -105,8 +105,9 @@ describe CustomActions::Actions::CustomField do
expect(described_class.all.map(&:custom_field))
.to match_array(custom_fields)
expect(described_class.all.all? { |a| described_class >= a })
.to be_truthy
described_class.all.each do |subclass|
expect(subclass.ancestors).to include(described_class)
end
end
end
@ -334,7 +335,7 @@ describe CustomActions::Actions::CustomField do
end
end
context 'for a non multi value field' do
context 'for a multi value field' do
let(:custom_field) { list_multi_custom_field }
it 'is true' do
@ -477,6 +478,8 @@ describe CustomActions::Actions::CustomField do
end
context 'for a multi list custom field' do
let(:custom_field) { list_multi_custom_field }
it_behaves_like 'associated custom action validations' do
let(:allowed_values) do
custom_field
@ -571,7 +574,7 @@ describe CustomActions::Actions::CustomField do
end
describe '#apply' do
let(:work_package) { double('work_package') }
let(:work_package) { build(:work_package) }
%i[list
version
@ -586,13 +589,15 @@ describe CustomActions::Actions::CustomField do
let(:custom_field) { send(:"#{type}_custom_field") }
it "sets the value for #{type} custom fields" do
expect(work_package)
allow(work_package)
.to receive(custom_field.attribute_setter)
.with([42])
instance.values = 42
instance.apply(work_package)
expect(work_package)
.to have_received(custom_field.attribute_setter)
.with([42])
end
end
@ -600,13 +605,15 @@ describe CustomActions::Actions::CustomField do
let(:custom_field) { date_custom_field }
it "sets the value to today for a dynamic value" do
expect(work_package)
allow(work_package)
.to receive(custom_field.attribute_setter)
.with(Date.today)
instance.values = '%CURRENT_DATE%'
instance.apply(work_package)
expect(work_package)
.to have_received(custom_field.attribute_setter)
.with(Date.current)
end
end
end

@ -199,7 +199,7 @@ describe Query::Results, with_mail: false do
work_package1.send(custom_field.attribute_setter, first_value)
work_package1.save!
work_package2.send(custom_field.attribute_setter, [first_value,
last_value])
last_value])
work_package2.save!
end

Loading…
Cancel
Save