mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #12320 from anansilva/6055-fix-rubocop-lint-duplicate-branch
Fix rubocop Lint/DuplicateBranch group
This commit is contained in:
@@ -23,16 +23,6 @@ Lint/ConstantDefinitionInBlock:
|
||||
- 'spec/validators/date_time_string_validator_spec.rb'
|
||||
- 'spec/validators/integer_array_validator_spec.rb'
|
||||
|
||||
# Offense count: 6
|
||||
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
|
||||
Lint/DuplicateBranch:
|
||||
Exclude:
|
||||
- 'app/helpers/spree/admin/base_helper.rb'
|
||||
- 'app/models/enterprise.rb'
|
||||
- 'app/models/spree/calculator.rb'
|
||||
- 'app/models/spree/preference.rb'
|
||||
- 'app/models/spree/preferences/preferable.rb'
|
||||
|
||||
# Offense count: 2
|
||||
Lint/DuplicateMethods:
|
||||
Exclude:
|
||||
|
||||
@@ -33,8 +33,6 @@ module Spree
|
||||
when :boolean
|
||||
hidden_field_tag(name, 0) +
|
||||
check_box_tag(name, 1, value, preference_field_options(options))
|
||||
when :string
|
||||
text_field_tag(name, value, preference_field_options(options))
|
||||
when :password
|
||||
password_field_tag(name, value, preference_field_options(options))
|
||||
when :text
|
||||
@@ -88,8 +86,6 @@ module Spree
|
||||
{ size: 10, class: 'input_integer', step: :any }
|
||||
when :boolean
|
||||
{}
|
||||
when :string
|
||||
{ size: 10, class: 'input_string fullwidth' }
|
||||
when :password
|
||||
{ size: 10, class: 'password_string fullwidth' }
|
||||
when :text
|
||||
|
||||
@@ -369,10 +369,10 @@ class Enterprise < ApplicationRecord
|
||||
:producer_shop # Producer with shopfront and supplies other hubs.
|
||||
when "producer_sells_none"
|
||||
:producer # Producer only supplies through others.
|
||||
when "non_producer_sells_any"
|
||||
:hub # Hub selling others products in order cycles.
|
||||
when "non_producer_sells_own"
|
||||
:hub # Wholesaler selling through own shopfront? Does this need a separate name or even exist?
|
||||
when "non_producer_sells_any", "non_producer_sells_own"
|
||||
# Hub selling others products in order cycles
|
||||
# Or Wholesaler selling through own shopfront? Does this need a separate name or even exist?
|
||||
:hub
|
||||
when "non_producer_sells_none"
|
||||
:hub_profile # Hub selling outside the system.
|
||||
end
|
||||
|
||||
@@ -44,9 +44,9 @@ module Spree
|
||||
# Given an object which might be an Order or a LineItem (amongst
|
||||
# others), return a collection of line items.
|
||||
def line_items_for(object)
|
||||
if object.is_a?(Spree::LineItem)
|
||||
[object]
|
||||
elsif object.respond_to? :line_items
|
||||
return [object] if object.is_a?(Spree::LineItem)
|
||||
|
||||
if object.respond_to? :line_items
|
||||
object.line_items
|
||||
elsif object.respond_to?(:order) && object.order.present?
|
||||
object.order.line_items
|
||||
|
||||
@@ -16,9 +16,7 @@ module Spree
|
||||
def value
|
||||
if self[:value_type].present?
|
||||
case self[:value_type].to_sym
|
||||
when :string, :text
|
||||
self[:value].to_s
|
||||
when :password
|
||||
when :string, :text, :password
|
||||
self[:value].to_s
|
||||
when :decimal
|
||||
BigDecimal(self[:value].to_s, exception: false)&.round(2, BigDecimal::ROUND_HALF_UP) ||
|
||||
|
||||
@@ -111,9 +111,7 @@ module Spree
|
||||
|
||||
def convert_preference_value(value, type)
|
||||
case type
|
||||
when :string, :text
|
||||
value.to_s
|
||||
when :password
|
||||
when :string, :text, :password
|
||||
value.to_s
|
||||
when :decimal
|
||||
value = 0 if value.blank?
|
||||
|
||||
@@ -21,4 +21,70 @@ describe Spree::Admin::BaseHelper, type: :helper do
|
||||
"name="_method" value="destroy">")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#preference_field_options" do
|
||||
subject { helper.preference_field_options(options) }
|
||||
|
||||
context 'when type is integer' do
|
||||
let(:options) { { type: :integer } }
|
||||
|
||||
it 'returns correct options' do
|
||||
expect(subject).to eq({ size: nil, class: 'input_integer', step: 1, readonly: nil,
|
||||
disabled: nil })
|
||||
end
|
||||
end
|
||||
|
||||
context 'when type is decimal' do
|
||||
let(:options) { { type: :decimal } }
|
||||
|
||||
it 'returns correct options' do
|
||||
expect(subject).to eq({ size: nil, class: 'input_integer', step: :any, readonly: nil,
|
||||
disabled: nil })
|
||||
end
|
||||
end
|
||||
|
||||
context 'when type is boolean' do
|
||||
let(:options) { { type: :boolean } }
|
||||
|
||||
it 'returns correct options' do
|
||||
expect(subject).to eq({ readonly: nil, disabled: nil, size: nil })
|
||||
end
|
||||
end
|
||||
|
||||
context 'when type is password' do
|
||||
let(:options) { { type: :password } }
|
||||
|
||||
it 'returns correct options' do
|
||||
expect(subject).to eq({ size: nil, class: 'password_string fullwidth', readonly: nil,
|
||||
disabled: nil })
|
||||
end
|
||||
end
|
||||
|
||||
context 'when type is text' do
|
||||
let(:options) { { type: :text } }
|
||||
|
||||
it 'returns correct options' do
|
||||
expect(subject).to eq({ size: nil, rows: 15, cols: 85, class: 'fullwidth', readonly: nil,
|
||||
disabled: nil })
|
||||
end
|
||||
end
|
||||
|
||||
context 'when type is string' do
|
||||
let(:options) { { type: :string } }
|
||||
|
||||
it 'returns correct options' do
|
||||
expect(subject).to eq({ size: nil, class: 'input_string fullwidth', readonly: nil,
|
||||
disabled: nil })
|
||||
end
|
||||
end
|
||||
|
||||
context 'when readonly, disabled and size are set' do
|
||||
let(:options) { { type: :integer, readonly: true, disabled: false, size: 20 } }
|
||||
|
||||
it 'returns correct options' do
|
||||
expect(subject).to eq({ size: 20, class: 'input_integer', step: 1, readonly: true,
|
||||
disabled: false })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user