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