Enable RuboCop `Style/HashSyntax` (#1371)
This commit is contained in:
parent
ade89a01c3
commit
2269d2679e
|
@ -30,6 +30,9 @@ Layout/SpaceInsideParens:
|
||||||
Layout/TrailingEmptyLines:
|
Layout/TrailingEmptyLines:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
Style/HashSyntax:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
Style/RedundantFileExtensionInRequire:
|
Style/RedundantFileExtensionInRequire:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
|
6
Gemfile
6
Gemfile
|
@ -28,14 +28,14 @@ when /\// # A path
|
||||||
gem 'actionpack', path: "#{rails}/actionpack"
|
gem 'actionpack', path: "#{rails}/actionpack"
|
||||||
gem 'actionview', path: "#{rails}/actionview"
|
gem 'actionview', path: "#{rails}/actionview"
|
||||||
when /^v/ # A tagged version
|
when /^v/ # A tagged version
|
||||||
git 'https://github.com/rails/rails.git', :tag => rails do
|
git 'https://github.com/rails/rails.git', tag: rails do
|
||||||
gem 'activesupport'
|
gem 'activesupport'
|
||||||
gem 'activemodel'
|
gem 'activemodel'
|
||||||
gem 'activerecord', require: false
|
gem 'activerecord', require: false
|
||||||
gem 'actionpack'
|
gem 'actionpack'
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
git 'https://github.com/rails/rails.git', :branch => rails do
|
git 'https://github.com/rails/rails.git', branch: rails do
|
||||||
gem 'activesupport'
|
gem 'activesupport'
|
||||||
gem 'activemodel'
|
gem 'activemodel'
|
||||||
gem 'activerecord', require: false
|
gem 'activerecord', require: false
|
||||||
|
@ -47,7 +47,7 @@ gem 'mysql2'
|
||||||
group :test do
|
group :test do
|
||||||
gem 'machinist', '~> 1.0.6'
|
gem 'machinist', '~> 1.0.6'
|
||||||
gem 'rspec'
|
gem 'rspec'
|
||||||
gem 'simplecov', :require => false
|
gem 'simplecov', require: false
|
||||||
end
|
end
|
||||||
|
|
||||||
gem 'rubocop', require: false
|
gem 'rubocop', require: false
|
||||||
|
|
|
@ -12,7 +12,7 @@ end
|
||||||
|
|
||||||
Ransack.configure do |config|
|
Ransack.configure do |config|
|
||||||
Ransack::Constants::AREL_PREDICATES.each do |name|
|
Ransack::Constants::AREL_PREDICATES.each do |name|
|
||||||
config.add_predicate name, :arel_predicate => name
|
config.add_predicate name, arel_predicate: name
|
||||||
end
|
end
|
||||||
Ransack::Constants::DERIVED_PREDICATES.each do |args|
|
Ransack::Constants::DERIVED_PREDICATES.each do |args|
|
||||||
config.add_predicate(*args)
|
config.add_predicate(*args)
|
||||||
|
|
|
@ -27,15 +27,15 @@ module Ransack
|
||||||
self.predicates = PredicateCollection.new
|
self.predicates = PredicateCollection.new
|
||||||
|
|
||||||
self.options = {
|
self.options = {
|
||||||
:search_key => :q,
|
search_key: :q,
|
||||||
:ignore_unknown_conditions => true,
|
ignore_unknown_conditions: true,
|
||||||
:hide_sort_order_indicators => false,
|
hide_sort_order_indicators: false,
|
||||||
:up_arrow => '▼'.freeze,
|
up_arrow: '▼'.freeze,
|
||||||
:down_arrow => '▲'.freeze,
|
down_arrow: '▲'.freeze,
|
||||||
:default_arrow => nil,
|
default_arrow: nil,
|
||||||
:sanitize_scope_args => true,
|
sanitize_scope_args: true,
|
||||||
:postgres_fields_sort_option => nil,
|
postgres_fields_sort_option: nil,
|
||||||
:strip_whitespace => true
|
strip_whitespace: true
|
||||||
}
|
}
|
||||||
|
|
||||||
def configure
|
def configure
|
||||||
|
@ -55,11 +55,11 @@ module Ransack
|
||||||
compound_name = name + suffix
|
compound_name = name + suffix
|
||||||
self.predicates[compound_name] = Predicate.new(
|
self.predicates[compound_name] = Predicate.new(
|
||||||
opts.merge(
|
opts.merge(
|
||||||
:name => compound_name,
|
name: compound_name,
|
||||||
:arel_predicate => arel_predicate_with_suffix(
|
arel_predicate: arel_predicate_with_suffix(
|
||||||
opts[:arel_predicate], suffix
|
opts[:arel_predicate], suffix
|
||||||
),
|
),
|
||||||
:compound => true
|
compound: true
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
end if compounds
|
end if compounds
|
||||||
|
|
|
@ -33,7 +33,7 @@ module Ransack
|
||||||
text = args.first
|
text = args.first
|
||||||
i18n = options[:i18n] || {}
|
i18n = options[:i18n] || {}
|
||||||
text ||= object.translate(
|
text ||= object.translate(
|
||||||
method, i18n.reverse_merge(:include_associations => true)
|
method, i18n.reverse_merge(include_associations: true)
|
||||||
) if object.respond_to? :translate
|
) if object.respond_to? :translate
|
||||||
super(method, text, options, &block)
|
super(method, text, options, &block)
|
||||||
end
|
end
|
||||||
|
@ -240,7 +240,7 @@ module Ransack
|
||||||
def get_attribute_element(action, base)
|
def get_attribute_element(action, base)
|
||||||
begin
|
begin
|
||||||
[
|
[
|
||||||
Translate.association(base, :context => object.context),
|
Translate.association(base, context: object.context),
|
||||||
collection_for_base(action, base)
|
collection_for_base(action, base)
|
||||||
]
|
]
|
||||||
rescue UntraversableAssociationError
|
rescue UntraversableAssociationError
|
||||||
|
@ -253,7 +253,7 @@ module Ransack
|
||||||
[
|
[
|
||||||
attr_from_base_and_column(base, c),
|
attr_from_base_and_column(base, c),
|
||||||
Translate.attribute(
|
Translate.attribute(
|
||||||
attr_from_base_and_column(base, c), :context => object.context
|
attr_from_base_and_column(base, c), context: object.context
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,8 +5,8 @@ module Ransack
|
||||||
|
|
||||||
attr_reader :name, :ransacker_args
|
attr_reader :name, :ransacker_args
|
||||||
|
|
||||||
delegate :blank?, :present?, :to => :name
|
delegate :blank?, :present?, to: :name
|
||||||
delegate :engine, :to => :context
|
delegate :engine, to: :context
|
||||||
|
|
||||||
def initialize(context, name = nil, ransacker_args = [])
|
def initialize(context, name = nil, ransacker_args = [])
|
||||||
super(context)
|
super(context)
|
||||||
|
|
|
@ -2,8 +2,8 @@ module Ransack
|
||||||
module Nodes
|
module Nodes
|
||||||
class Condition < Node
|
class Condition < Node
|
||||||
i18n_word :attribute, :predicate, :combinator, :value
|
i18n_word :attribute, :predicate, :combinator, :value
|
||||||
i18n_alias :a => :attribute, :p => :predicate,
|
i18n_alias a: :attribute, p: :predicate,
|
||||||
:m => :combinator, :v => :value
|
m: :combinator, v: :value
|
||||||
|
|
||||||
attr_accessor :predicate
|
attr_accessor :predicate
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@ module Ransack
|
||||||
if attributes.size > 0 && predicate
|
if attributes.size > 0 && predicate
|
||||||
condition = self.new(context)
|
condition = self.new(context)
|
||||||
condition.build(
|
condition.build(
|
||||||
:a => attributes,
|
a: attributes,
|
||||||
:p => predicate.name,
|
p: predicate.name,
|
||||||
:m => combinator,
|
m: combinator,
|
||||||
:v => predicate.wants_array ? Array(values) : [values]
|
v: predicate.wants_array ? Array(values) : [values]
|
||||||
)
|
)
|
||||||
# TODO: Figure out what to do with multiple types of attributes,
|
# TODO: Figure out what to do with multiple types of attributes,
|
||||||
# if anything. Tempted to go with "garbage in, garbage out" here.
|
# if anything. Tempted to go with "garbage in, garbage out" here.
|
||||||
|
|
|
@ -7,9 +7,9 @@ module Ransack
|
||||||
alias :m= :combinator=
|
alias :m= :combinator=
|
||||||
|
|
||||||
i18n_word :condition, :and, :or
|
i18n_word :condition, :and, :or
|
||||||
i18n_alias :c => :condition, :n => :and, :o => :or
|
i18n_alias c: :condition, n: :and, o: :or
|
||||||
|
|
||||||
delegate :each, :to => :values
|
delegate :each, to: :values
|
||||||
|
|
||||||
def initialize(context, combinator = nil)
|
def initialize(context, combinator = nil)
|
||||||
super(context)
|
super(context)
|
||||||
|
@ -22,7 +22,7 @@ module Ransack
|
||||||
|
|
||||||
def translate(key, options = {})
|
def translate(key, options = {})
|
||||||
super or Translate.attribute(
|
super or Translate.attribute(
|
||||||
key.to_s, options.merge(:context => context)
|
key.to_s, options.merge(context: context)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ module Ransack
|
||||||
module Nodes
|
module Nodes
|
||||||
class Node
|
class Node
|
||||||
attr_reader :context
|
attr_reader :context
|
||||||
delegate :contextualize, :to => :context
|
delegate :contextualize, to: :context
|
||||||
class_attribute :i18n_words
|
class_attribute :i18n_words
|
||||||
class_attribute :i18n_aliases
|
class_attribute :i18n_aliases
|
||||||
self.i18n_words = []
|
self.i18n_words = []
|
||||||
|
|
|
@ -2,7 +2,7 @@ module Ransack
|
||||||
module Nodes
|
module Nodes
|
||||||
class Value < Node
|
class Value < Node
|
||||||
attr_accessor :value
|
attr_accessor :value
|
||||||
delegate :present?, :blank?, :to => :value
|
delegate :present?, :blank?, to: :value
|
||||||
|
|
||||||
def initialize(context, value = nil)
|
def initialize(context, value = nil)
|
||||||
super(context)
|
super(context)
|
||||||
|
|
|
@ -3,7 +3,7 @@ module Ransack
|
||||||
|
|
||||||
attr_reader :name, :type, :formatter, :args
|
attr_reader :name, :type, :formatter, :args
|
||||||
|
|
||||||
delegate :call, :to => :@callable
|
delegate :call, to: :@callable
|
||||||
|
|
||||||
def initialize(klass, name, opts = {}, &block)
|
def initialize(klass, name, opts = {}, &block)
|
||||||
@klass, @name = klass, name
|
@klass, @name = klass, name
|
||||||
|
|
|
@ -9,10 +9,10 @@ module Ransack
|
||||||
|
|
||||||
attr_reader :base, :context
|
attr_reader :base, :context
|
||||||
|
|
||||||
delegate :object, :klass, :to => :context
|
delegate :object, :klass, to: :context
|
||||||
delegate :new_grouping, :new_condition,
|
delegate :new_grouping, :new_condition,
|
||||||
:build_grouping, :build_condition,
|
:build_grouping, :build_condition,
|
||||||
:translate, :to => :base
|
:translate, to: :base
|
||||||
|
|
||||||
def initialize(object, params = {}, options = {})
|
def initialize(object, params = {}, options = {})
|
||||||
strip_whitespace = options.fetch(:strip_whitespace, Ransack.options[:strip_whitespace])
|
strip_whitespace = options.fetch(:strip_whitespace, Ransack.options[:strip_whitespace])
|
||||||
|
|
|
@ -66,7 +66,7 @@ module Ransack
|
||||||
[:"ransack.associations.#{i18n_key(context.klass)}.#{key}"]
|
[:"ransack.associations.#{i18n_key(context.klass)}.#{key}"]
|
||||||
end
|
end
|
||||||
defaults << context.traverse(key).model_name.human
|
defaults << context.traverse(key).model_name.human
|
||||||
options = { :count => 1, :default => defaults }
|
options = { count: 1, default: defaults }
|
||||||
I18n.translate(defaults.shift, **options)
|
I18n.translate(defaults.shift, **options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ module Ransack
|
||||||
Ransack.configure do |config|
|
Ransack.configure do |config|
|
||||||
config.add_predicate(
|
config.add_predicate(
|
||||||
:test_predicate_without_compound,
|
:test_predicate_without_compound,
|
||||||
:compounds => false
|
compounds: false
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
expect(Ransack.predicates)
|
expect(Ransack.predicates)
|
||||||
|
@ -138,8 +138,8 @@ module Ransack
|
||||||
Ransack.configure do |config|
|
Ransack.configure do |config|
|
||||||
config.add_predicate(
|
config.add_predicate(
|
||||||
:test_array_predicate,
|
:test_array_predicate,
|
||||||
:wants_array => true,
|
wants_array: true,
|
||||||
:compounds => true
|
compounds: true
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -153,11 +153,11 @@ module Ransack
|
||||||
Ransack.configure do |config|
|
Ransack.configure do |config|
|
||||||
config.add_predicate(
|
config.add_predicate(
|
||||||
:test_in_predicate,
|
:test_in_predicate,
|
||||||
:arel_predicate => 'in'
|
arel_predicate: 'in'
|
||||||
)
|
)
|
||||||
config.add_predicate(
|
config.add_predicate(
|
||||||
:test_not_in_predicate,
|
:test_not_in_predicate,
|
||||||
:arel_predicate => 'not_in'
|
arel_predicate: 'not_in'
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -171,13 +171,13 @@ module Ransack
|
||||||
Ransack.configure do |config|
|
Ransack.configure do |config|
|
||||||
config.add_predicate(
|
config.add_predicate(
|
||||||
:test_in_predicate_no_array,
|
:test_in_predicate_no_array,
|
||||||
:arel_predicate => 'in',
|
arel_predicate: 'in',
|
||||||
:wants_array => false
|
wants_array: false
|
||||||
)
|
)
|
||||||
config.add_predicate(
|
config.add_predicate(
|
||||||
:test_not_in_predicate_no_array,
|
:test_not_in_predicate_no_array,
|
||||||
:arel_predicate => 'not_in',
|
arel_predicate: 'not_in',
|
||||||
:wants_array => false
|
wants_array: false
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ module Ransack
|
||||||
# @s.created_at_eq = date_values # This works in Rails 4.x but not 3.x
|
# @s.created_at_eq = date_values # This works in Rails 4.x but not 3.x
|
||||||
@s.created_at_eq = [2011, 1, 2, 3, 4, 5] # so we have to do this
|
@s.created_at_eq = [2011, 1, 2, 3, 4, 5] # so we have to do this
|
||||||
html = @f.datetime_select(
|
html = @f.datetime_select(
|
||||||
:created_at_eq, :use_month_numbers => true, :include_seconds => true
|
:created_at_eq, use_month_numbers: true, include_seconds: true
|
||||||
)
|
)
|
||||||
date_values.each { |val| expect(html).to include date_select_html(val) }
|
date_values.each { |val| expect(html).to include date_select_html(val) }
|
||||||
end
|
end
|
||||||
|
@ -70,13 +70,13 @@ module Ransack
|
||||||
|
|
||||||
describe '#sort_link' do
|
describe '#sort_link' do
|
||||||
it 'sort_link for ransack attribute' do
|
it 'sort_link for ransack attribute' do
|
||||||
sort_link = @f.sort_link :name, :controller => 'people'
|
sort_link = @f.sort_link :name, controller: 'people'
|
||||||
expect(sort_link).to match /people\?q(%5B|\[)s(%5D|\])=name\+asc/
|
expect(sort_link).to match /people\?q(%5B|\[)s(%5D|\])=name\+asc/
|
||||||
expect(sort_link).to match /sort_link/
|
expect(sort_link).to match /sort_link/
|
||||||
expect(sort_link).to match /Full Name<\/a>/
|
expect(sort_link).to match /Full Name<\/a>/
|
||||||
end
|
end
|
||||||
it 'sort_link for common attribute' do
|
it 'sort_link for common attribute' do
|
||||||
sort_link = @f.sort_link :id, :controller => 'people'
|
sort_link = @f.sort_link :id, controller: 'people'
|
||||||
expect(sort_link).to match /id<\/a>/
|
expect(sort_link).to match /id<\/a>/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -99,14 +99,14 @@ module Ransack
|
||||||
it 'returns ransackable attributes for associations with :associations' do
|
it 'returns ransackable attributes for associations with :associations' do
|
||||||
attributes = Person.ransackable_attributes +
|
attributes = Person.ransackable_attributes +
|
||||||
Article.ransackable_attributes.map { |a| "articles_#{a}" }
|
Article.ransackable_attributes.map { |a| "articles_#{a}" }
|
||||||
html = @f.attribute_select(:associations => ['articles'])
|
html = @f.attribute_select(associations: ['articles'])
|
||||||
expect(html.split(/\n/).size).to eq(attributes.size)
|
expect(html.split(/\n/).size).to eq(attributes.size)
|
||||||
attributes.each do |attribute|
|
attributes.each do |attribute|
|
||||||
expect(html).to match /<option value="#{attribute}">/
|
expect(html).to match /<option value="#{attribute}">/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
it 'returns option groups for base and associations with :associations' do
|
it 'returns option groups for base and associations with :associations' do
|
||||||
html = @f.attribute_select(:associations => ['articles'])
|
html = @f.attribute_select(associations: ['articles'])
|
||||||
[Person, Article].each do |model|
|
[Person, Article].each do |model|
|
||||||
expect(html).to match /<optgroup label="#{model}">/
|
expect(html).to match /<optgroup label="#{model}">/
|
||||||
end
|
end
|
||||||
|
@ -121,19 +121,19 @@ module Ransack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
it 'filters predicates with single-value :only' do
|
it 'filters predicates with single-value :only' do
|
||||||
html = @f.predicate_select :only => 'eq'
|
html = @f.predicate_select only: 'eq'
|
||||||
Predicate.names.reject { |k| k =~ /^eq/ }.each do |key|
|
Predicate.names.reject { |k| k =~ /^eq/ }.each do |key|
|
||||||
expect(html).not_to match /<option value="#{key}">/
|
expect(html).not_to match /<option value="#{key}">/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
it 'filters predicates with multi-value :only' do
|
it 'filters predicates with multi-value :only' do
|
||||||
html = @f.predicate_select :only => [:eq, :lt]
|
html = @f.predicate_select only: [:eq, :lt]
|
||||||
Predicate.names.reject { |k| k =~ /^(eq|lt)/ }.each do |key|
|
Predicate.names.reject { |k| k =~ /^(eq|lt)/ }.each do |key|
|
||||||
expect(html).not_to match /<option value="#{key}">/
|
expect(html).not_to match /<option value="#{key}">/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
it 'excludes compounds when compounds: false' do
|
it 'excludes compounds when compounds: false' do
|
||||||
html = @f.predicate_select :compounds => false
|
html = @f.predicate_select compounds: false
|
||||||
Predicate.names.select { |k| k =~ /_(any|all)$/ }.each do |key|
|
Predicate.names.select { |k| k =~ /_(any|all)$/ }.each do |key|
|
||||||
expect(html).not_to match /<option value="#{key}">/
|
expect(html).not_to match /<option value="#{key}">/
|
||||||
end
|
end
|
||||||
|
|
|
@ -474,7 +474,7 @@ module Ransack
|
||||||
describe 'with symbol q:, #sort_link should include search params' do
|
describe 'with symbol q:, #sort_link should include search params' do
|
||||||
subject { @controller.view_context.sort_link(Person.ransack, :name) }
|
subject { @controller.view_context.sort_link(Person.ransack, :name) }
|
||||||
let(:params) { ActionController::Parameters.new(
|
let(:params) { ActionController::Parameters.new(
|
||||||
{ :q => { name_eq: 'TEST' }, controller: 'people' }
|
{ q: { name_eq: 'TEST' }, controller: 'people' }
|
||||||
) }
|
) }
|
||||||
before { @controller.instance_variable_set(:@params, params) }
|
before { @controller.instance_variable_set(:@params, params) }
|
||||||
|
|
||||||
|
@ -489,7 +489,7 @@ module Ransack
|
||||||
describe 'with symbol q:, #sort_url should include search params' do
|
describe 'with symbol q:, #sort_url should include search params' do
|
||||||
subject { @controller.view_context.sort_url(Person.ransack, :name) }
|
subject { @controller.view_context.sort_url(Person.ransack, :name) }
|
||||||
let(:params) { ActionController::Parameters.new(
|
let(:params) { ActionController::Parameters.new(
|
||||||
{ :q => { name_eq: 'TEST' }, controller: 'people' }
|
{ q: { name_eq: 'TEST' }, controller: 'people' }
|
||||||
) }
|
) }
|
||||||
before { @controller.instance_variable_set(:@params, params) }
|
before { @controller.instance_variable_set(:@params, params) }
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ module Ransack
|
||||||
ar_translation = ::Namespace::Article.human_attribute_name(:title)
|
ar_translation = ::Namespace::Article.human_attribute_name(:title)
|
||||||
ransack_translation = Ransack::Translate.attribute(
|
ransack_translation = Ransack::Translate.attribute(
|
||||||
:title,
|
:title,
|
||||||
:context => ::Namespace::Article.ransack.context
|
context: ::Namespace::Article.ransack.context
|
||||||
)
|
)
|
||||||
expect(ransack_translation).to eq ar_translation
|
expect(ransack_translation).to eq ar_translation
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue