From ef30ce8902bac20830700b66f054da96c0b88930 Mon Sep 17 00:00:00 2001 From: Andrey Korobkov Date: Wed, 17 May 2017 16:55:33 +0400 Subject: [PATCH 01/13] update rubocop --- .rubocop_todo.yml | 196 +++++++++++++++++++++++++++++++++++++++------- Gemfile.lock | 4 +- 2 files changed, 168 insertions(+), 32 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 513deda9d8..d2d3abde82 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,11 +1,29 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2016-12-19 13:16:13 +0400 using RuboCop version 0.46.0. +# on 2017-05-17 16:53:34 +0400 using RuboCop version 0.48.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. +# Offense count: 1 +# Configuration parameters: Include. +# Include: **/Gemfile, **/gems.rb +Bundler/DuplicatedGem: + Exclude: + - 'Gemfile' + +# Offense count: 19 +Lint/AmbiguousBlockAssociation: + Exclude: + - 'lib/active_scaffold/helpers/action_link_helpers.rb' + - 'lib/active_scaffold/helpers/search_column_helpers.rb' + - 'lib/active_scaffold/marked_model.rb' + - 'test/bridges/paperclip_test.rb' + - 'test/data_structures/action_columns_test.rb' + - 'test/data_structures/columns_test.rb' + - 'test/misc/configurable_test.rb' + # Offense count: 2 Lint/AmbiguousOperator: Exclude: @@ -21,8 +39,8 @@ Lint/AssignmentInCondition: # Offense count: 10 # Cop supports --auto-correct. -# Configuration parameters: AlignWith, SupportedStyles, AutoCorrect. -# SupportedStyles: keyword, variable, start_of_line +# Configuration parameters: EnforcedStyleAlignWith, SupportedStylesAlignWith, AutoCorrect. +# SupportedStylesAlignWith: keyword, variable, start_of_line Lint/EndAlignment: Exclude: - 'lib/active_scaffold/actions/field_search.rb' @@ -40,55 +58,75 @@ Lint/InheritException: Exclude: - 'lib/active_scaffold.rb' -# Offense count: 5 -Lint/NestedMethodDefinition: +# Offense count: 1 +Lint/NonLocalExitFromIterator: Exclude: - 'lib/active_scaffold/config/base.rb' - - 'test/extensions/active_record_test.rb' # Offense count: 1 -Lint/NonLocalExitFromIterator: +Lint/ShadowedException: Exclude: - - 'lib/active_scaffold/config/base.rb' + - 'lib/active_scaffold/configurable.rb' + +# Offense count: 2 +Lint/UselessAssignment: + Exclude: + - 'lib/active_scaffold/bridges/shared/date_bridge.rb' + - 'lib/active_scaffold/finder.rb' -# Offense count: 247 +# Offense count: 256 Metrics/AbcSize: - Max: 133 + Max: 125 # Offense count: 2 -# Configuration parameters: CountComments. +# Configuration parameters: CountComments, ExcludedMethods. Metrics/BlockLength: Max: 57 -# Offense count: 22 +# Offense count: 18 +# Configuration parameters: CountBlocks. Metrics/BlockNesting: Max: 5 -# Offense count: 96 +# Offense count: 97 Metrics/CyclomaticComplexity: Max: 27 -# Offense count: 1783 +# Offense count: 1856 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: Max: 994 -# Offense count: 188 +# Offense count: 193 # Configuration parameters: CountComments. Metrics/MethodLength: - Max: 78 + Max: 65 # Offense count: 2 # Configuration parameters: CountKeywordArgs. Metrics/ParameterLists: Max: 6 -# Offense count: 90 +# Offense count: 91 Metrics/PerceivedComplexity: - Max: 31 + Max: 29 -# Offense count: 4 +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: NilOrEmpty, NotPresent, UnlessPresent. +Rails/Blank: + Exclude: + - 'lib/active_scaffold/actions/core.rb' + - 'lib/active_scaffold/actions/field_search.rb' + - 'lib/active_scaffold/actions/list.rb' + - 'lib/active_scaffold/bridges/dragonfly/list_ui.rb' + - 'lib/active_scaffold/data_structures/sorting.rb' + - 'lib/active_scaffold/finder.rb' + - 'lib/active_scaffold/helpers/list_column_helpers.rb' + - 'lib/active_scaffold/helpers/search_column_helpers.rb' + +# Offense count: 5 # Cop supports --auto-correct. # Configuration parameters: Whitelist. # Whitelist: find_by_sql @@ -98,10 +136,15 @@ Rails/DynamicFindBy: - 'lib/active_scaffold/tableless.rb' - 'test/data_structures/columns_test.rb' -# Offense count: 21 +# Offense count: 2 +Rails/FilePath: + Exclude: + - 'lib/active_scaffold/config/core.rb' + - 'test/test_helper.rb' + +# Offense count: 19 Rails/OutputSafety: Exclude: - - 'lib/active_scaffold/bridges/carrierwave/form_ui.rb' - 'lib/active_scaffold/bridges/carrierwave/list_ui.rb' - 'lib/active_scaffold/bridges/file_column/form_ui.rb' - 'lib/active_scaffold/bridges/shared/date_bridge.rb' @@ -113,6 +156,38 @@ Rails/OutputSafety: - 'lib/active_scaffold/helpers/search_column_helpers.rb' - 'test/helpers/list_column_helpers_test.rb' +# Offense count: 18 +# Cop supports --auto-correct. +# Configuration parameters: NotNilAndNotEmpty, NotBlank, UnlessBlank. +Rails/Present: + Exclude: + - 'lib/active_scaffold/actions/core.rb' + - 'lib/active_scaffold/actions/field_search.rb' + - 'lib/active_scaffold/actions/search.rb' + - 'lib/active_scaffold/attribute_params.rb' + - 'lib/active_scaffold/bridges/date_picker/helper.rb' + - 'lib/active_scaffold/config/list.rb' + - 'lib/active_scaffold/data_structures/sorting.rb' + - 'lib/active_scaffold/extensions/localize.rb' + - 'lib/active_scaffold/finder.rb' + - 'lib/active_scaffold/helpers/action_link_helpers.rb' + - 'lib/active_scaffold/helpers/search_column_helpers.rb' + - 'lib/active_scaffold/helpers/view_helpers.rb' + - 'lib/active_scaffold/tableless.rb' + +# Offense count: 1 +# Configuration parameters: Blacklist. +# Blacklist: decrement!, decrement_counter, increment!, increment_counter, toggle!, touch, update_all, update_attribute, update_column, update_columns, update_counters +Rails/SkipsModelValidations: + Exclude: + - 'lib/active_scaffold/attribute_params.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Security/YAMLLoad: + Exclude: + - 'test/data_structures/error_message_test.rb' + # Offense count: 7 Style/AccessorMethodName: Exclude: @@ -136,7 +211,7 @@ Style/CaseEquality: Exclude: - 'lib/active_scaffold/core.rb' -# Offense count: 84 +# Offense count: 85 # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: nested, compact Style/ClassAndModuleChildren: @@ -148,7 +223,7 @@ Style/ClassVars: # Offense count: 2 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly. +# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions. # SupportedStyles: assign_to_condition, assign_inside_condition Style/ConditionalAssignment: Exclude: @@ -171,7 +246,52 @@ Style/EmptyCaseCondition: Exclude: - 'lib/active_scaffold/data_structures/column.rb' -# Offense count: 18 +# Offense count: 3 +# Cop supports --auto-correct. +Style/EmptyLineAfterMagicComment: + Exclude: + - 'active_scaffold.gemspec' + - 'lib/active_scaffold/helpers/list_column_helpers.rb' + - 'test/helpers/list_column_helpers_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/EmptyLinesAroundExceptionHandlingKeywords: + Exclude: + - 'lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: compact, expanded +Style/EmptyMethod: + Exclude: + - 'lib/active_scaffold/data_structures/bridge.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. +Style/ExtraSpacing: + Exclude: + - 'test/mock_app/config.ru' + +# Offense count: 3 +# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS +Style/FileName: + Exclude: + - 'Gemfile' + - 'Rakefile' + - 'test/mock_app/Rakefile' + +# Offense count: 1 +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: format, sprintf, percent +Style/FormatString: + Exclude: + - 'lib/active_scaffold/finder.rb' + +# Offense count: 19 # Configuration parameters: MinBodyLength. Style/GuardClause: Exclude: @@ -212,6 +332,13 @@ Style/IfInsideElse: - 'lib/active_scaffold/helpers/search_column_helpers.rb' - 'lib/active_scaffold/helpers/show_column_helpers.rb' +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: InverseMethods, InverseBlocks. +Style/InverseMethods: + Exclude: + - 'lib/active_scaffold/helpers/form_column_helpers.rb' + # Offense count: 4 Style/MethodMissing: Exclude: @@ -219,7 +346,7 @@ Style/MethodMissing: - 'lib/active_scaffold/configurable.rb' - 'lib/active_scaffold/data_structures/action_links.rb' -# Offense count: 11 +# Offense count: 8 # Cop supports --auto-correct. Style/ParallelAssignment: Exclude: @@ -227,13 +354,16 @@ Style/ParallelAssignment: - 'lib/active_scaffold/bridges/cancan/cancan_bridge.rb' - 'lib/active_scaffold/delayed_setup.rb' - 'lib/active_scaffold/helpers/form_column_helpers.rb' - - 'lib/active_scaffold/helpers/list_column_helpers.rb' - 'lib/active_scaffold/helpers/view_helpers.rb' - 'lib/active_scaffold/paginator.rb' - - 'test/bridges/bridge_test.rb' - - 'test/bridges/paperclip_test.rb' - 'test/config/update_test.rb' +# Offense count: 80 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Enabled: false + # Offense count: 8 # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist. # NamePrefix: is_, has_, have_ @@ -263,7 +393,7 @@ Style/RegexpLiteral: - 'lib/active_scaffold/extensions/action_view_rendering.rb' - 'lib/active_scaffold/helpers/form_column_helpers.rb' -# Offense count: 13 +# Offense count: 12 # Cop supports --auto-correct. Style/RescueModifier: Exclude: @@ -273,10 +403,16 @@ Style/RescueModifier: - 'lib/active_scaffold/bridges/record_select/helpers.rb' - 'lib/active_scaffold/config/core.rb' - 'lib/active_scaffold/data_structures/association/active_record.rb' - - 'lib/active_scaffold/data_structures/column.rb' - 'lib/active_scaffold/finder.rb' - 'lib/active_scaffold/helpers/association_helpers.rb' +# Offense count: 67 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: percent, brackets +Style/SymbolArray: + Enabled: false + # Offense count: 7 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, AllowSafeAssignment. diff --git a/Gemfile.lock b/Gemfile.lock index 3bb7953037..901c1b5290 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -142,8 +142,8 @@ GEM http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) - rubocop (0.46.0) - parser (>= 2.3.1.1, < 3.0) + rubocop (0.48.1) + parser (>= 2.3.3.1, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.7) From d310255e76144f1234c8b6395f2125d6881e6989 Mon Sep 17 00:00:00 2001 From: Andrey Korobkov Date: Wed, 17 May 2017 17:02:25 +0400 Subject: [PATCH 02/13] Rubocop: fix Rails/Blank violations --- .rubocop_todo.yml | 18 ++---------------- lib/active_scaffold/actions/core.rb | 2 +- lib/active_scaffold/actions/field_search.rb | 2 +- lib/active_scaffold/actions/list.rb | 2 +- .../bridges/dragonfly/list_ui.rb | 2 +- lib/active_scaffold/data_structures/sorting.rb | 2 +- lib/active_scaffold/finder.rb | 2 +- .../helpers/list_column_helpers.rb | 2 +- .../helpers/search_column_helpers.rb | 2 +- 9 files changed, 10 insertions(+), 24 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d2d3abde82..0af445b011 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-05-17 16:53:34 +0400 using RuboCop version 0.48.1. +# on 2017-05-17 17:01:48 +0400 using RuboCop version 0.48.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -92,7 +92,7 @@ Metrics/BlockNesting: Metrics/CyclomaticComplexity: Max: 27 -# Offense count: 1856 +# Offense count: 1855 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: @@ -112,20 +112,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 29 -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: NilOrEmpty, NotPresent, UnlessPresent. -Rails/Blank: - Exclude: - - 'lib/active_scaffold/actions/core.rb' - - 'lib/active_scaffold/actions/field_search.rb' - - 'lib/active_scaffold/actions/list.rb' - - 'lib/active_scaffold/bridges/dragonfly/list_ui.rb' - - 'lib/active_scaffold/data_structures/sorting.rb' - - 'lib/active_scaffold/finder.rb' - - 'lib/active_scaffold/helpers/list_column_helpers.rb' - - 'lib/active_scaffold/helpers/search_column_helpers.rb' - # Offense count: 5 # Cop supports --auto-correct. # Configuration parameters: Whitelist. diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 9f5fb03495..b3ca761805 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -289,7 +289,7 @@ def active_scaffold_embedded_params def clear_storage session_index = active_scaffold_session_storage_key - session.delete(session_index) unless session[session_index].present? + session.delete(session_index) if session[session_index].blank? end # at some point we need to pass the session and params into config. we'll just take care of that before any particular action occurs by passing those hashes off to the UserSettings class of each action. diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index 7600ac0435..3d86d970f2 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -122,7 +122,7 @@ def list_columns end def grouped_columns - return unless active_scaffold_config.field_search.grouped_columns.present? + return if active_scaffold_config.field_search.grouped_columns.blank? active_scaffold_config.field_search.grouped_columns.map do |col| active_scaffold_config.columns[col] end.compact diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index b32ee76170..c3e634be1e 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -172,7 +172,7 @@ def list_authorized? end def action_update_respond_to_js - do_refresh_list unless @record.present? + do_refresh_list if @record.blank? super end diff --git a/lib/active_scaffold/bridges/dragonfly/list_ui.rb b/lib/active_scaffold/bridges/dragonfly/list_ui.rb index d4f78587af..a175b26b82 100644 --- a/lib/active_scaffold/bridges/dragonfly/list_ui.rb +++ b/lib/active_scaffold/bridges/dragonfly/list_ui.rb @@ -3,7 +3,7 @@ module Helpers module ListColumnHelpers def active_scaffold_column_dragonfly(record, column) attachment = record.send(column.name.to_s) - return nil unless attachment.present? + return nil if attachment.blank? content = if attachment.image? image_tag(attachment.thumb(column.options[:thumb] || ActiveScaffold::Bridges::Dragonfly::DragonflyBridgeHelpers.thumbnail_style).url, :border => 0) diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index 3deafc88ef..e8c2d3c704 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -117,7 +117,7 @@ def clause(grouped_columns_calculations = nil) each do |sort_column, sort_direction| next if constraint_columns.include? sort_column.name sql = grouped_columns_calculations.try(:dig, sort_column.name) || sort_column.sort[:sql] - next unless sql.present? + next if sql.blank? sql = sql.to_sql if sql.respond_to?(:to_sql) parts = Array(sql).map do |column| diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 2b404c92da..817449e1db 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -217,7 +217,7 @@ def format_for_datetime(column, value) format = "#{I18n.t('date.formats.default')} #{time_parts.join(':')} #{'%z' if parts[:offset].present?}" else [[:hour, '%H'], [:min, ':%M'], [:sec, ':%S']].each do |part, f| - format.gsub!(f, '') unless parts[part].present? + format.gsub!(f, '') if parts[part].blank? end format += ' %z' if parts[:offset].present? && format !~ /%z/i end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 78eb8c74d9..8984a8b0e3 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -108,7 +108,7 @@ def tel_to(text) def active_scaffold_column_telephone(record, column) phone = record.send column.name - return unless phone.present? + return if phone.blank? phone = number_to_phone(phone) unless column.options[:format] == false tel_to phone end diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index cbad5daa4a..029d80989c 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -155,7 +155,7 @@ def active_scaffold_group_search_options end def active_scaffold_group_column - return unless active_scaffold_config.field_search.group_options.present? + return if active_scaffold_config.field_search.group_options.blank? @_active_scaffold_group_column ||= begin column = ActiveScaffold::DataStructures::Column.new(:active_scaffold_group, active_scaffold_config.model) column.label = :group_by From 09bcc06d8f155a5758815bd5d9529102b25702bc Mon Sep 17 00:00:00 2001 From: Andrey Korobkov Date: Wed, 17 May 2017 17:07:19 +0400 Subject: [PATCH 03/13] Rubocop: fix Rails/FilePath violations --- .rubocop_todo.yml | 8 +------- lib/active_scaffold/config/core.rb | 2 +- test/test_helper.rb | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0af445b011..2fa2b30362 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-05-17 17:01:48 +0400 using RuboCop version 0.48.1. +# on 2017-05-17 17:06:37 +0400 using RuboCop version 0.48.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -122,12 +122,6 @@ Rails/DynamicFindBy: - 'lib/active_scaffold/tableless.rb' - 'test/data_structures/columns_test.rb' -# Offense count: 2 -Rails/FilePath: - Exclude: - - 'lib/active_scaffold/config/core.rb' - - 'test/test_helper.rb' - # Offense count: 19 Rails/OutputSafety: Exclude: diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index a0264fce2b..b00903a7a0 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -257,7 +257,7 @@ def self.javascripts(frontend = self.frontend) end def self.available_frontends - frontends_dir = File.join(Rails.root, 'vendor', 'plugins', ActiveScaffold::Config::Core.plugin_directory, 'frontends') + frontends_dir = Rails.root.join('vendor', 'plugins', ActiveScaffold::Config::Core.plugin_directory, 'frontends') Dir.entries(frontends_dir).reject { |e| e.match(/^\./) } # Get rid of files that start with . end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 4d2bbee3e1..70fea13c0e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -12,7 +12,7 @@ def load_schema stdout = $stdout $stdout = StringIO.new # suppress output while building the schema - load File.join(Rails.root, 'db', 'schema.rb') + load Rails.root.join('db', 'schema.rb') $stdout = stdout end load_schema From c6d2df2451b4c1e09eed909ecfaf612243577287 Mon Sep 17 00:00:00 2001 From: Andrey Korobkov Date: Wed, 17 May 2017 17:11:36 +0400 Subject: [PATCH 04/13] Rubocop: fix Rails/Present violations --- .rubocop_todo.yml | 21 +------------------ lib/active_scaffold/actions/core.rb | 2 +- lib/active_scaffold/actions/field_search.rb | 2 +- lib/active_scaffold/actions/search.rb | 2 +- lib/active_scaffold/attribute_params.rb | 2 +- .../bridges/date_picker/helper.rb | 2 +- lib/active_scaffold/config/list.rb | 2 +- .../data_structures/sorting.rb | 2 +- lib/active_scaffold/extensions/localize.rb | 2 +- lib/active_scaffold/finder.rb | 6 +++--- .../helpers/action_link_helpers.rb | 2 +- .../helpers/search_column_helpers.rb | 4 ++-- lib/active_scaffold/helpers/view_helpers.rb | 6 +++--- lib/active_scaffold/tableless.rb | 2 +- 14 files changed, 19 insertions(+), 38 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2fa2b30362..0082002c7c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-05-17 17:06:37 +0400 using RuboCop version 0.48.1. +# on 2017-05-17 17:16:22 +0400 using RuboCop version 0.48.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -136,25 +136,6 @@ Rails/OutputSafety: - 'lib/active_scaffold/helpers/search_column_helpers.rb' - 'test/helpers/list_column_helpers_test.rb' -# Offense count: 18 -# Cop supports --auto-correct. -# Configuration parameters: NotNilAndNotEmpty, NotBlank, UnlessBlank. -Rails/Present: - Exclude: - - 'lib/active_scaffold/actions/core.rb' - - 'lib/active_scaffold/actions/field_search.rb' - - 'lib/active_scaffold/actions/search.rb' - - 'lib/active_scaffold/attribute_params.rb' - - 'lib/active_scaffold/bridges/date_picker/helper.rb' - - 'lib/active_scaffold/config/list.rb' - - 'lib/active_scaffold/data_structures/sorting.rb' - - 'lib/active_scaffold/extensions/localize.rb' - - 'lib/active_scaffold/finder.rb' - - 'lib/active_scaffold/helpers/action_link_helpers.rb' - - 'lib/active_scaffold/helpers/search_column_helpers.rb' - - 'lib/active_scaffold/helpers/view_helpers.rb' - - 'lib/active_scaffold/tableless.rb' - # Offense count: 1 # Configuration parameters: Blacklist. # Blacklist: decrement!, decrement_counter, increment!, increment_counter, toggle!, touch, update_all, update_attribute, update_column, update_columns, update_counters diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index b3ca761805..6a2c0aa15f 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -258,7 +258,7 @@ def new_model config = active_scaffold_config_for(relation.klass) if nested? && nested.plural_association? if config && config._columns_hash[column = relation.klass.inheritance_column] model_name = params.delete(column) # in new action inheritance_column must be in params - model_name ||= params[:record].delete(column) unless params[:record].blank? # in create action must be inside record key + model_name ||= params[:record].delete(column) if params[:record].present? # in create action must be inside record key model_name = model_name.camelize if model_name model_name ||= active_scaffold_config.model.name build_options = {column.to_sym => model_name} if model_name diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index 3d86d970f2..73eec65fec 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -160,7 +160,7 @@ def do_search active_scaffold_conditions << search_condition filtered_columns << column end - unless filtered_columns.blank? + if filtered_columns.present? @filtered = active_scaffold_config.field_search.human_conditions ? filtered_columns : true end diff --git a/lib/active_scaffold/actions/search.rb b/lib/active_scaffold/actions/search.rb index f72fe310d9..a70b43c434 100644 --- a/lib/active_scaffold/actions/search.rb +++ b/lib/active_scaffold/actions/search.rb @@ -23,7 +23,7 @@ def do_search text_search = active_scaffold_config.search.text_search query = query.split(active_scaffold_config.search.split_terms) if active_scaffold_config.search.split_terms search_conditions = self.class.conditions_for_columns(query, columns, text_search) - @filtered = !search_conditions.blank? + @filtered = search_conditions.present? active_scaffold_conditions.concat search_conditions if @filtered references, outer_joins = columns.partition do |column| diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index b7243c0e9c..b81a536cbb 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -193,7 +193,7 @@ def column_value_from_param_simple_value(parent_record, column, value) def column_plural_assocation_value_from_value(column, value) # it's an array of ids - if value && !value.empty? + if value.present? ids = value.select(&:present?) ids.empty? ? [] : column.association.klass.find(ids) else diff --git a/lib/active_scaffold/bridges/date_picker/helper.rb b/lib/active_scaffold/bridges/date_picker/helper.rb index 3968030412..19e37f6ec6 100644 --- a/lib/active_scaffold/bridges/date_picker/helper.rb +++ b/lib/active_scaffold/bridges/date_picker/helper.rb @@ -49,7 +49,7 @@ def self.date_options(locale) Rails.logger.warn "ActiveScaffold: Missing date picker localization for your locale: #{locale}" if as_date_picker_options.blank? js_format = to_datepicker_format(I18n.translate!('date.formats.default', :locale => locale, :default => '')) - date_picker_options[:dateFormat] = js_format unless js_format.blank? + date_picker_options[:dateFormat] = js_format if js_format.present? date_picker_options rescue raise if locale == I18n.locale diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index bd434352a0..a366c17357 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -180,7 +180,7 @@ def filtered_message attr_writer :always_show_search def always_show_search - @always_show_search && !search_partial.blank? + @always_show_search && search_partial.present? end def search_partial diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index e8c2d3c704..43d6f8babf 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -159,7 +159,7 @@ def default_sorting? def set_sorting_from_order_clause(order_clause, model_table_name = nil) clear order_clause.to_s.split(',').each do |criterion| - unless criterion.blank? + if criterion.present? order_parts = extract_order_parts(criterion) add(order_parts[:column_name], order_parts[:direction]) unless different_table?(model_table_name, order_parts[:table_name]) || get_column(order_parts[:column_name]).nil? end diff --git a/lib/active_scaffold/extensions/localize.rb b/lib/active_scaffold/extensions/localize.rb index 4ca47ef1d3..c58f3078af 100644 --- a/lib/active_scaffold/extensions/localize.rb +++ b/lib/active_scaffold/extensions/localize.rb @@ -1,6 +1,6 @@ class Object def as_(key, options = {}) - unless key.blank? + if key.present? text = I18n.translate(key.to_s, {:scope => [:active_scaffold, *options.delete(:scope)], :default => key.is_a?(String) ? key : key.to_s.titleize}.merge(options)).html_safe # text = nil if text.include?('translation missing:') end diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 817449e1db..f7c8874844 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -95,7 +95,7 @@ def condition_for_column(column, value, text_search = :full) if respond_to?("condition_for_#{column.name}_column") return send("condition_for_#{column.name}_column", column, value, like_pattern) end - return unless column && column.search_sql && !value.blank? + return unless column && column.search_sql && value.present? search_ui = column.search_ui || column.column_type begin sql, *values = @@ -431,7 +431,7 @@ def finder_options(options = {}) end def count_items(query, find_options = {}, count_includes = nil) - count_includes ||= find_options[:includes] unless find_options[:conditions].blank? + count_includes ||= find_options[:includes] if find_options[:conditions].present? options = find_options.reject { |k, _| [:select, :reorder, :order].include? k } # NOTE: we must use includes in the count query, because some conditions may reference other tables options[:includes] = count_includes @@ -486,7 +486,7 @@ def calculate_last_modified(query) def calculate_query conditions = all_conditions includes = active_scaffold_config.list.count_includes - includes ||= active_scaffold_references unless conditions.blank? + includes ||= active_scaffold_references if conditions.present? left_joins = active_scaffold_outer_joins left_joins += includes if includes primary_key = active_scaffold_config.model.primary_key diff --git a/lib/active_scaffold/helpers/action_link_helpers.rb b/lib/active_scaffold/helpers/action_link_helpers.rb index 1afb129ccf..fe6f8c63fe 100644 --- a/lib/active_scaffold/helpers/action_link_helpers.rb +++ b/lib/active_scaffold/helpers/action_link_helpers.rb @@ -85,7 +85,7 @@ def render_action_link(link, record = nil, options = {}) options.delete :link if link.crud_type == :create end if link.action.nil? || (link.type == :member && options.key?(:authorized) && !options[:authorized]) - action_link_html(link, nil, {:link => action_link_text(link, options), :class => "disabled #{link.action}#{" #{link.html_options[:class]}" unless link.html_options[:class].blank?}", :title => options[:not_authorized_reason]}, record) + action_link_html(link, nil, {:link => action_link_text(link, options), :class => "disabled #{link.action}#{" #{link.html_options[:class]}" if link.html_options[:class].present?}", :title => options[:not_authorized_reason]}, record) else url = action_link_url(link, record) html_options = action_link_html_options(link, record, options) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 029d80989c..ad61189708 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -297,9 +297,9 @@ def searched_by?(column) value = field_search_params[column.name.to_s] case value when Hash - !value['from'].blank? + value['from'].present? when String - !value.blank? + value.present? else false end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 89e966a906..6094b616bd 100644 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -209,7 +209,7 @@ def active_scaffold_error_messages_for(*params) [:id, :class].each do |key| if options.include?(key) value = options[key] - html[key] = value unless value.blank? + html[key] = value if value.present? else html[key] = 'errorExplanation' end @@ -238,8 +238,8 @@ def active_scaffold_error_messages_for(*params) end contents = [] - contents << content_tag(options[:header_tag] || :h2, header_message) unless header_message.blank? - contents << content_tag(:p, message) unless message.blank? + contents << content_tag(options[:header_tag] || :h2, header_message) if header_message.present? + contents << content_tag(:p, message) if message.present? contents << error_messages contents = safe_join(contents) options[:container_tag] ? content_tag(options[:container_tag], contents, html) : contents diff --git a/lib/active_scaffold/tableless.rb b/lib/active_scaffold/tableless.rb index abbab01d76..1414b202b9 100644 --- a/lib/active_scaffold/tableless.rb +++ b/lib/active_scaffold/tableless.rb @@ -128,7 +128,7 @@ def initialize_copy(other) end def where(opts, *rest) - unless opts.blank? + if opts.present? opts = opts.with_indifferent_access if opts.is_a? Hash @conditions << (rest.empty? ? opts : [opts, *rest]) end From 9a5968012cce0ceabb57ba7e7849e04bb2754b63 Mon Sep 17 00:00:00 2001 From: Andrey Korobkov Date: Wed, 17 May 2017 17:18:16 +0400 Subject: [PATCH 05/13] Rubocop: fix Security/YAMLLoad violation --- .rubocop_todo.yml | 8 +------- test/data_structures/error_message_test.rb | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0082002c7c..e27d35b171 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-05-17 17:16:22 +0400 using RuboCop version 0.48.1. +# on 2017-05-17 17:17:39 +0400 using RuboCop version 0.48.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -143,12 +143,6 @@ Rails/SkipsModelValidations: Exclude: - 'lib/active_scaffold/attribute_params.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Security/YAMLLoad: - Exclude: - - 'test/data_structures/error_message_test.rb' - # Offense count: 7 Style/AccessorMethodName: Exclude: diff --git a/test/data_structures/error_message_test.rb b/test/data_structures/error_message_test.rb index dce1df8b3c..8e585123aa 100644 --- a/test/data_structures/error_message_test.rb +++ b/test/data_structures/error_message_test.rb @@ -18,7 +18,7 @@ def test_xml end def test_yaml - yml = YAML.load(@error.to_yaml) + yml = YAML.safe_load(@error.to_yaml) assert yml.key?(:error) assert_equal 'foo', yml[:error] end From 64d51c13aadd47e6d8fcce0117045e052bc9ccd0 Mon Sep 17 00:00:00 2001 From: Andrey Korobkov Date: Wed, 17 May 2017 17:26:36 +0400 Subject: [PATCH 06/13] Rubocop: fix Style/EmptyLineAfterMagicComment violations --- .rubocop_todo.yml | 10 +--------- active_scaffold.gemspec | 1 + lib/active_scaffold/helpers/list_column_helpers.rb | 1 + test/helpers/list_column_helpers_test.rb | 1 + 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e27d35b171..14af1955c8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-05-17 17:17:39 +0400 using RuboCop version 0.48.1. +# on 2017-05-17 17:26:01 +0400 using RuboCop version 0.48.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -201,14 +201,6 @@ Style/EmptyCaseCondition: Exclude: - 'lib/active_scaffold/data_structures/column.rb' -# Offense count: 3 -# Cop supports --auto-correct. -Style/EmptyLineAfterMagicComment: - Exclude: - - 'active_scaffold.gemspec' - - 'lib/active_scaffold/helpers/list_column_helpers.rb' - - 'test/helpers/list_column_helpers_test.rb' - # Offense count: 1 # Cop supports --auto-correct. Style/EmptyLinesAroundExceptionHandlingKeywords: diff --git a/active_scaffold.gemspec b/active_scaffold.gemspec index 6200e8e365..78e3805d26 100644 --- a/active_scaffold.gemspec +++ b/active_scaffold.gemspec @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- + $LOAD_PATH.unshift File.expand_path('../lib', __FILE__) require 'active_scaffold/version' diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 8984a8b0e3..dbe7e98aa7 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -1,4 +1,5 @@ # coding: utf-8 + module ActiveScaffold module Helpers # Helpers that assist with the rendering of a List Column diff --git a/test/helpers/list_column_helpers_test.rb b/test/helpers/list_column_helpers_test.rb index fbd93d1f7b..09647514d1 100644 --- a/test/helpers/list_column_helpers_test.rb +++ b/test/helpers/list_column_helpers_test.rb @@ -1,4 +1,5 @@ # encoding: utf-8 + require 'test_helper' class ListColumnHelpersTest < ActionView::TestCase From f87769dc0cce418ce908fbc644ec249004a66b23 Mon Sep 17 00:00:00 2001 From: Andrey Korobkov Date: Wed, 17 May 2017 17:28:22 +0400 Subject: [PATCH 07/13] Rubocop: fix Style/EmptyLinesAroundExceptionHandlingKeywords violation --- .rubocop_todo.yml | 8 +------- .../bridges/file_column/as_file_column_bridge.rb | 1 - 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 14af1955c8..01fea1f21a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-05-17 17:26:01 +0400 using RuboCop version 0.48.1. +# on 2017-05-17 17:27:48 +0400 using RuboCop version 0.48.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -201,12 +201,6 @@ Style/EmptyCaseCondition: Exclude: - 'lib/active_scaffold/data_structures/column.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Style/EmptyLinesAroundExceptionHandlingKeywords: - Exclude: - - 'lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb' - # Offense count: 3 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb b/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb index 5e9aa687f0..f1fe183762 100644 --- a/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +++ b/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb @@ -33,7 +33,6 @@ def configure_file_column_field(field) # set null to false so active_scaffold wont set it to null # delete_file_column will take care of deleting a file or not. _columns_hash[field.to_s].instance_variable_set('@null', false) - rescue false end From 04c0fa8085047c6fbe16d8c3fc6b04fbc0f9f0af Mon Sep 17 00:00:00 2001 From: Andrey Korobkov Date: Wed, 17 May 2017 17:30:38 +0400 Subject: [PATCH 08/13] Rubocop: fix Style/EmptyMethod violations --- .rubocop_todo.yml | 10 +--------- lib/active_scaffold/data_structures/bridge.rb | 9 +++------ 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 01fea1f21a..1d9cc3dc73 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-05-17 17:27:48 +0400 using RuboCop version 0.48.1. +# on 2017-05-17 17:29:52 +0400 using RuboCop version 0.48.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -201,14 +201,6 @@ Style/EmptyCaseCondition: Exclude: - 'lib/active_scaffold/data_structures/column.rb' -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: compact, expanded -Style/EmptyMethod: - Exclude: - - 'lib/active_scaffold/data_structures/bridge.rb' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. diff --git a/lib/active_scaffold/data_structures/bridge.rb b/lib/active_scaffold/data_structures/bridge.rb index 6d8e704a74..711662ebb6 100644 --- a/lib/active_scaffold/data_structures/bridge.rb +++ b/lib/active_scaffold/data_structures/bridge.rb @@ -4,8 +4,7 @@ def self.install raise RunTimeError, "install not defined for bridge #{name}" end - def self.prepare - end + def self.prepare; end # by convention and default, use the bridge name as the required constant for installation def self.install? @@ -16,10 +15,8 @@ def self.run install if install? end - def self.stylesheets - end + def self.stylesheets; end - def self.javascripts - end + def self.javascripts; end end end From e311dfb2a596cb00e91af65d8db5238565c00885 Mon Sep 17 00:00:00 2001 From: Andrey Korobkov Date: Wed, 17 May 2017 17:32:19 +0400 Subject: [PATCH 09/13] Rubocop: fix Style/ExtraSpacing violation --- .rubocop_todo.yml | 9 +-------- test/mock_app/config.ru | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1d9cc3dc73..c53cae0849 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-05-17 17:29:52 +0400 using RuboCop version 0.48.1. +# on 2017-05-17 17:31:50 +0400 using RuboCop version 0.48.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -201,13 +201,6 @@ Style/EmptyCaseCondition: Exclude: - 'lib/active_scaffold/data_structures/column.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. -Style/ExtraSpacing: - Exclude: - - 'test/mock_app/config.ru' - # Offense count: 3 # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS diff --git a/test/mock_app/config.ru b/test/mock_app/config.ru index 86a587d07d..143ac784ae 100644 --- a/test/mock_app/config.ru +++ b/test/mock_app/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) +require ::File.expand_path('../config/environment', __FILE__) run TestApp::Application From 9e8464e90992bed539e0ed8d57782fb9d15ab8be Mon Sep 17 00:00:00 2001 From: Andrey Korobkov Date: Wed, 17 May 2017 17:37:16 +0400 Subject: [PATCH 10/13] Rubocop: fix Style/InverseMethods violations --- .rubocop_todo.yml | 9 +-------- lib/active_scaffold/helpers/form_column_helpers.rb | 4 ++-- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c53cae0849..cc4f9ea7da 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-05-17 17:31:50 +0400 using RuboCop version 0.48.1. +# on 2017-05-17 17:36:45 +0400 using RuboCop version 0.48.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -258,13 +258,6 @@ Style/IfInsideElse: - 'lib/active_scaffold/helpers/search_column_helpers.rb' - 'lib/active_scaffold/helpers/show_column_helpers.rb' -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: InverseMethods, InverseBlocks. -Style/InverseMethods: - Exclude: - - 'lib/active_scaffold/helpers/form_column_helpers.rb' - # Offense count: 4 Style/MethodMissing: Exclude: diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 2db823a3cb..b549d6472f 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -640,8 +640,8 @@ def numerical_constraints_for_column(column, options) numerical_constraints[:step] ||= "0.#{'0' * (column.column.scale - 1)}1" if column.column && column.column.scale.to_i > 0 elsif options[:min] && options[:min].respond_to?(:even?) && (only_odd_valid || only_even_valid) numerical_constraints[:step] = 2 - numerical_constraints[:min] += 1 if only_odd_valid && !options[:min].odd? - numerical_constraints[:min] += 1 if only_even_valid && !options[:min].even? + numerical_constraints[:min] += 1 if only_odd_valid && options[:min].even? + numerical_constraints[:min] += 1 if only_even_valid && options[:min].odd? end numerical_constraints[:step] ||= 'any' unless only_integer end From 89b933d6159cb0d2a9d2f28489b0266afe37a25e Mon Sep 17 00:00:00 2001 From: Andrey Korobkov Date: Wed, 17 May 2017 17:39:40 +0400 Subject: [PATCH 11/13] Rubocop: fix Style/PercentLiteralDelimiters violations --- .rubocop_todo.yml | 8 +------- lib/active_scaffold/actions/core.rb | 2 +- lib/active_scaffold/actions/list.rb | 4 ++-- lib/active_scaffold/bridges/date_picker/helper.rb | 2 +- .../bridges/file_column/test/test_helper.rb | 2 +- lib/active_scaffold/bridges/shared/date_bridge.rb | 12 ++++++------ .../usa_state_select/usa_state_select_helper.rb | 2 +- lib/active_scaffold/data_structures/action_links.rb | 2 +- .../data_structures/association/active_mongoid.rb | 8 ++++---- .../data_structures/association/mongoid.rb | 2 +- lib/active_scaffold/data_structures/sorting.rb | 4 ++-- lib/active_scaffold/finder.rb | 2 +- lib/active_scaffold/orm_checks.rb | 6 +++--- test/bridges/paperclip_test.rb | 2 +- test/helpers/form_column_helpers_test.rb | 8 ++++---- test/helpers/list_column_helpers_test.rb | 4 ++-- test/misc/active_record_permissions_test.rb | 2 +- test/misc/finder_test.rb | 2 +- test/misc/parse_datetime_test.rb | 4 ++-- test/run_all.rb | 2 +- test/test_helper.rb | 2 +- 21 files changed, 38 insertions(+), 44 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index cc4f9ea7da..d148efa797 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-05-17 17:36:45 +0400 using RuboCop version 0.48.1. +# on 2017-05-17 17:39:06 +0400 using RuboCop version 0.48.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -277,12 +277,6 @@ Style/ParallelAssignment: - 'lib/active_scaffold/paginator.rb' - 'test/config/update_test.rb' -# Offense count: 80 -# Cop supports --auto-correct. -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Enabled: false - # Offense count: 8 # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist. # NamePrefix: is_, has_, have_ diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 6a2c0aa15f..78f0c4cb2f 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -239,7 +239,7 @@ def conditions_from_params next if active_scaffold_constraints[key] next if nested? && nested.param_name == key - range = %i(date datetime).include?(column.type) && value.is_a?(String) && value.scan('..').size == 1 + range = %i[date datetime].include?(column.type) && value.is_a?(String) && value.scan('..').size == 1 value = value.split('..') if range conditions[key] = if value.is_a?(Array) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index c3e634be1e..29e54cd1b3 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -22,7 +22,7 @@ def row end def list - if %w(index list).include? action_name + if %w[index list].include? action_name do_list else do_refresh_list @@ -114,7 +114,7 @@ def do_list options = {:sorting => active_scaffold_config.list.user.sorting, :count_includes => active_scaffold_config.list.user.count_includes} - paginate = params[:format].nil? ? (accepts? :html, :js) : %w(html js).include?(params[:format]) + paginate = params[:format].nil? ? (accepts? :html, :js) : %w[html js].include?(params[:format]) options[:pagination] = active_scaffold_config.list.pagination if paginate if options[:pagination] options[:per_page] = active_scaffold_config.list.user.per_page diff --git a/lib/active_scaffold/bridges/date_picker/helper.rb b/lib/active_scaffold/bridges/date_picker/helper.rb index 19e37f6ec6..36d41d7d30 100644 --- a/lib/active_scaffold/bridges/date_picker/helper.rb +++ b/lib/active_scaffold/bridges/date_picker/helper.rb @@ -105,7 +105,7 @@ def self.to_datepicker_format(rails_format) def self.split_datetime_format(datetime_format) date_format = datetime_format time_format = nil - time_start_indicators = %w(HH hh mm tt ss) + time_start_indicators = %w[HH hh mm tt ss] unless datetime_format.nil? start_indicator = time_start_indicators.detect { |indicator| datetime_format.include?(indicator) } unless start_indicator.nil? diff --git a/lib/active_scaffold/bridges/file_column/test/test_helper.rb b/lib/active_scaffold/bridges/file_column/test/test_helper.rb index 3fabc03126..5b3550a641 100644 --- a/lib/active_scaffold/bridges/file_column/test/test_helper.rb +++ b/lib/active_scaffold/bridges/file_column/test/test_helper.rb @@ -2,6 +2,6 @@ require 'rubygems' require 'active_support' -%w(../lib/delete_file_column.rb mock_model.rb).each do |file| +%w[../lib/delete_file_column.rb mock_model.rb].each do |file| require File.expand_path(File.join(File.dirname(__FILE__), file)) end diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index a0a55b9ad7..3d74df6108 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -141,7 +141,7 @@ def date_bridge_from_to(column, value) values.collect!(&conversion) if conversion != :to_time values else - %w(from to).collect { |field| condition_value_for_datetime(column, value[field], conversion) } + %w[from to].collect { |field| condition_value_for_datetime(column, value[field], conversion) } end end @@ -186,7 +186,7 @@ def date_bridge_from_to_for_range(column, value) [date_bridge_now.in(1.day).beginning_of_day, date_bridge_now.in(1.day).end_of_day] else range_type, range = value['range'].downcase.split('_') - raise ArgumentError unless %w(week month year).include?(range) + raise ArgumentError unless %w[week month year].include?(range) case range_type when 'this' return date_bridge_now.send("beginning_of_#{range}".to_sym), date_bridge_now.send("end_of_#{range}") @@ -214,7 +214,7 @@ def date_bridge_column_date?(column) end end -ActiveScaffold::Finder.const_set('DATE_COMPARATORS', %w(PAST FUTURE RANGE)) -ActiveScaffold::Finder.const_set('DATE_UNITS', %w(DAYS WEEKS MONTHS YEARS)) -ActiveScaffold::Finder.const_set('TIME_UNITS', %w(SECONDS MINUTES HOURS)) -ActiveScaffold::Finder.const_set('DATE_RANGES', %w(TODAY YESTERDAY TOMORROW THIS_WEEK PREV_WEEK NEXT_WEEK THIS_MONTH PREV_MONTH NEXT_MONTH THIS_YEAR PREV_YEAR NEXT_YEAR)) +ActiveScaffold::Finder.const_set('DATE_COMPARATORS', %w[PAST FUTURE RANGE]) +ActiveScaffold::Finder.const_set('DATE_UNITS', %w[DAYS WEEKS MONTHS YEARS]) +ActiveScaffold::Finder.const_set('TIME_UNITS', %w[SECONDS MINUTES HOURS]) +ActiveScaffold::Finder.const_set('DATE_RANGES', %w[TODAY YESTERDAY TOMORROW THIS_WEEK PREV_WEEK NEXT_WEEK THIS_MONTH PREV_MONTH NEXT_MONTH THIS_YEAR PREV_YEAR NEXT_YEAR]) diff --git a/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb b/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb index 079a637b47..9941c43822 100644 --- a/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +++ b/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb @@ -32,7 +32,7 @@ def usa_state_options_for_select(selected = nil, priority_states = nil) state_options end - USASTATES = [%w(Alabama AL), %w(Alaska AK), %w(Arizona AZ), %w(Arkansas AR), %w(California CA), %w(Colorado CO), %w(Connecticut CT), %w(Delaware DE), ['District of Columbia', 'DC'], %w(Florida FL), %w(Georgia GA), %w(Hawaii HI), %w(Idaho ID), %w(Illinois IL), %w(Indiana IN), %w(Iowa IA), %w(Kansas KS), %w(Kentucky KY), %w(Louisiana LA), %w(Maine ME), %w(Maryland MD), %w(Massachusetts MA), %w(Michigan MI), %w(Minnesota MN), %w(Mississippi MS), %w(Missouri MO), %w(Montana MT), %w(Nebraska NE), %w(Nevada NV), ['New Hampshire', 'NH'], ['New Jersey', 'NJ'], ['New Mexico', 'NM'], ['New York', 'NY'], ['North Carolina', 'NC'], ['North Dakota', 'ND'], %w(Ohio OH), %w(Oklahoma OK), %w(Oregon OR), %w(Pennsylvania PA), ['Rhode Island', 'RI'], ['South Carolina', 'SC'], ['South Dakota', 'SD'], %w(Tennessee TN), %w(Texas TX), %w(Utah UT), %w(Vermont VT), %w(Virginia VA), %w(Washington WA), %w(Wisconsin WI), ['West Virginia', 'WV'], %w(Wyoming WY)].freeze unless const_defined?('USASTATES') + USASTATES = [%w[Alabama AL], %w[Alaska AK], %w[Arizona AZ], %w[Arkansas AR], %w[California CA], %w[Colorado CO], %w[Connecticut CT], %w[Delaware DE], ['District of Columbia', 'DC'], %w[Florida FL], %w[Georgia GA], %w[Hawaii HI], %w[Idaho ID], %w[Illinois IL], %w[Indiana IN], %w[Iowa IA], %w[Kansas KS], %w[Kentucky KY], %w[Louisiana LA], %w[Maine ME], %w[Maryland MD], %w[Massachusetts MA], %w[Michigan MI], %w[Minnesota MN], %w[Mississippi MS], %w[Missouri MO], %w[Montana MT], %w[Nebraska NE], %w[Nevada NV], ['New Hampshire', 'NH'], ['New Jersey', 'NJ'], ['New Mexico', 'NM'], ['New York', 'NY'], ['North Carolina', 'NC'], ['North Dakota', 'ND'], %w[Ohio OH], %w[Oklahoma OK], %w[Oregon OR], %w[Pennsylvania PA], ['Rhode Island', 'RI'], ['South Carolina', 'SC'], ['South Dakota', 'SD'], %w[Tennessee TN], %w[Texas TX], %w[Utah UT], %w[Vermont VT], %w[Virginia VA], %w[Washington WA], %w[Wisconsin WI], ['West Virginia', 'WV'], %w[Wyoming WY]].freeze unless const_defined?('USASTATES') end module InstanceTagMethods diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index cb50cfe305..151c7beca3 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -135,7 +135,7 @@ def subgroup(name, label = nil) group = ActiveScaffold::DataStructures::ActionLinks.new group.label = label || name group.name = name - group.default_type = self.name == :root ? (name.to_sym if %w(member collection).include?(name.to_s)) : default_type + group.default_type = self.name == :root ? (name.to_sym if %w[member collection].include?(name.to_s)) : default_type add_to_set group end group diff --git a/lib/active_scaffold/data_structures/association/active_mongoid.rb b/lib/active_scaffold/data_structures/association/active_mongoid.rb index 778a42f52b..b616bb0c2a 100644 --- a/lib/active_scaffold/data_structures/association/active_mongoid.rb +++ b/lib/active_scaffold/data_structures/association/active_mongoid.rb @@ -14,19 +14,19 @@ def allow_join? end def belongs_to? - %i(belongs_to_record belongs_to_document).include?(@association.macro) + %i[belongs_to_record belongs_to_document].include?(@association.macro) end def has_one? - %i(has_one_record has_one_document).include?(@association.macro) + %i[has_one_record has_one_document].include?(@association.macro) end def has_many? - %i(has_many_records has_many_documents).include?(@association.macro) + %i[has_many_records has_many_documents].include?(@association.macro) end def collection? - %i(has_many_documents has_many_records).include?(@association.macro) + %i[has_many_documents has_many_records].include?(@association.macro) end def table_name diff --git a/lib/active_scaffold/data_structures/association/mongoid.rb b/lib/active_scaffold/data_structures/association/mongoid.rb index 89d2a943dd..7004a9c4c0 100644 --- a/lib/active_scaffold/data_structures/association/mongoid.rb +++ b/lib/active_scaffold/data_structures/association/mongoid.rb @@ -2,7 +2,7 @@ module ActiveScaffold::DataStructures::Association class Mongoid < Abstract delegate :inverse_klass, :as, :dependent, :inverse, to: :@association def collection? - %i(has_many has_and_belongs_to_many).include?(@association.macro) + %i[has_many has_and_belongs_to_many].include?(@association.macro) end # polymorphic belongs_to diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index 43d6f8babf..21e53c73ec 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -82,8 +82,8 @@ def direction_of(column) clause[1] end - SORTING_STAGES = Hash[%w(reset ASC DESC reset).each_cons(2).to_a].freeze - DEFAULT_SORTING_STAGES = Hash[%w(ASC DESC ASC).each_cons(2).to_a].freeze + SORTING_STAGES = Hash[%w[reset ASC DESC reset].each_cons(2).to_a].freeze + DEFAULT_SORTING_STAGES = Hash[%w[ASC DESC ASC].each_cons(2).to_a].freeze def next_sorting_of(column, sorted_by_default) stages = sorted_by_default ? DEFAULT_SORTING_STAGES : SORTING_STAGES stages[direction_of(column)] || 'ASC' diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index f7c8874844..8156e69b62 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -328,7 +328,7 @@ def condition_for_null_type(column, value, like_pattern = nil) :begins_with => '?%', :ends_with => '%?' }.freeze - NULL_COMPARATORS = %w(null not_null).freeze + NULL_COMPARATORS = %w[null not_null].freeze def self.included(klass) klass.extend ClassMethods diff --git a/lib/active_scaffold/orm_checks.rb b/lib/active_scaffold/orm_checks.rb index 4c1eb87408..04f9c6249f 100644 --- a/lib/active_scaffold/orm_checks.rb +++ b/lib/active_scaffold/orm_checks.rb @@ -88,19 +88,19 @@ def column_type(klass, column_name) end end - %i(active_record? mongoid? tableless?).each do |method| + %i[active_record? mongoid? tableless?].each do |method| define_method method do ActiveScaffold::OrmChecks.send method, active_record_class end end - %i(_table_name _quoted_table_name _columns _columns_hash _reflect_on_all_associations _content_columns).each do |method| + %i[_table_name _quoted_table_name _columns _columns_hash _reflect_on_all_associations _content_columns].each do |method| define_method method do ActiveScaffold::OrmChecks.send method.to_s[1..-1], active_record_class end end - %i(type_for_attribute column_type).each do |method| + %i[type_for_attribute column_type].each do |method| define_method method do |column_name| ActiveScaffold::OrmChecks.send method, active_record_class, column_name end diff --git a/test/bridges/paperclip_test.rb b/test/bridges/paperclip_test.rb index 51a13e7c01..fb19d79054 100644 --- a/test/bridges/paperclip_test.rb +++ b/test/bridges/paperclip_test.rb @@ -25,7 +25,7 @@ def test_initialization assert config.update.multipart? assert_equal :paperclip, config.columns[:logo].form_ui assert_equal [:delete_logo], config.columns[:logo].params.to_a - %w(logo_file_name logo_file_size logo_updated_at logo_content_type).each do |attr| + %w[logo_file_name logo_file_size logo_updated_at logo_content_type].each do |attr| refute config.columns._inheritable.include?(attr.to_sym) end assert Company.method_defined?(:delete_logo) diff --git a/test/helpers/form_column_helpers_test.rb b/test/helpers/form_column_helpers_test.rb index 012873faa9..84e9a44e9d 100644 --- a/test/helpers/form_column_helpers_test.rb +++ b/test/helpers/form_column_helpers_test.rb @@ -12,10 +12,10 @@ def test_choices_for_select_form_ui_for_simple_column @column.options[:options] = [:value_1, :value_2, :value_3] assert_dom_equal "", active_scaffold_input_select(@column, :object => @record) - @column.options[:options] = %w(value_1 value_2 value_3) + @column.options[:options] = %w[value_1 value_2 value_3] assert_dom_equal "", active_scaffold_input_select(@column, :object => @record) - @column.options[:options] = [%w(text_1 value_1), %w(text_2 value_2), %w(text_3 value_3)] + @column.options[:options] = [%w[text_1 value_1], %w[text_2 value_2], %w[text_3 value_3]] assert_dom_equal "", active_scaffold_input_select(@column, :object => @record) @column.options[:options] = [[:text_1, :value_1], [:text_2, :value_2], [:text_3, :value_3]] @@ -23,8 +23,8 @@ def test_choices_for_select_form_ui_for_simple_column end def test_options_for_select_form_ui_for_simple_column - @column.options = {:include_blank => 'None', :selected => 'value_2', :disabled => %w(value_1 value_3)} - @column.options[:options] = %w(value_1 value_2 value_3) + @column.options = {:include_blank => 'None', :selected => 'value_2', :disabled => %w[value_1 value_3]} + @column.options[:options] = %w[value_1 value_2 value_3] @column.options[:html_options] = {:class => 'big'} assert_dom_equal "", active_scaffold_input_select(@column, :object => @record) end diff --git a/test/helpers/list_column_helpers_test.rb b/test/helpers/list_column_helpers_test.rb index 09647514d1..5fa528f3ce 100644 --- a/test/helpers/list_column_helpers_test.rb +++ b/test/helpers/list_column_helpers_test.rb @@ -20,10 +20,10 @@ def test_options_for_select_list_ui_for_simple_column @column.options[:options] = [:value_1, :value_2, :value_3] assert_equal 'Value 2', format_column_value(@record, @column) - @column.options[:options] = %w(value_1 value_2 value_3) + @column.options[:options] = %w[value_1 value_2 value_3] assert_equal 'value_2', format_column_value(@record, @column) - @column.options[:options] = [%w(text_1 value_1), %w(text_2 value_2), %w(text_3 value_3)] + @column.options[:options] = [%w[text_1 value_1], %w[text_2 value_2], %w[text_3 value_3]] assert_equal 'text_2', format_column_value(@record, @column) @column.options[:options] = [[:text_1, :value_1], [:text_2, :value_2], [:text_3, :value_3]] diff --git a/test/misc/active_record_permissions_test.rb b/test/misc/active_record_permissions_test.rb index 985dcadf32..6121284f59 100644 --- a/test/misc/active_record_permissions_test.rb +++ b/test/misc/active_record_permissions_test.rb @@ -4,7 +4,7 @@ class PermissionModel < ActiveRecord::Base include ActiveScaffold::ActiveRecordPermissions::ModelUserAccess::Model def self.columns @columns ||= [ColumnMock.new('id', '', 'int(11)')] + - %w(a1 a2 a3 b1 b2 b3 c1 c2 c3).map { |c| ColumnMock.new(c, '', 'varchar(255)') } + %w[a1 a2 a3 b1 b2 b3 c1 c2 c3].map { |c| ColumnMock.new(c, '', 'varchar(255)') } end def self.columns_hash diff --git a/test/misc/finder_test.rb b/test/misc/finder_test.rb index aa070076c2..69bb8479f9 100644 --- a/test/misc/finder_test.rb +++ b/test/misc/finder_test.rb @@ -12,7 +12,7 @@ def test_create_conditions_for_columns ActiveScaffold::DataStructures::Column.new(:a, ModelStub), ActiveScaffold::DataStructures::Column.new(:b, ModelStub) ] - tokens = %w(foo bar) + tokens = %w[foo bar] expected_conditions = [ ['"model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?', '%foo%', '%foo%'], diff --git a/test/misc/parse_datetime_test.rb b/test/misc/parse_datetime_test.rb index 05f07534c1..635d2097c3 100644 --- a/test/misc/parse_datetime_test.rb +++ b/test/misc/parse_datetime_test.rb @@ -34,8 +34,8 @@ def setup formats: {picker: '%a, %d %b %Y %H:%M:%S'} }, date: { - day_names: %w(Domingo Lunes Martes Miércoles Jueves Viernes Sábado), - abbr_day_names: %w(Dom Lun Mar Mié Jue Vie Sáb), + day_names: %w[Domingo Lunes Martes Miércoles Jueves Viernes Sábado], + abbr_day_names: %w[Dom Lun Mar Mié Jue Vie Sáb], month_names: [nil, 'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], abbr_month_names: [nil, 'Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'], formats: {default: '%Y-%m-%d', long: '%d de %B de %Y'} diff --git a/test/run_all.rb b/test/run_all.rb index 5e21896d43..c67ab198e6 100644 --- a/test/run_all.rb +++ b/test/run_all.rb @@ -1,4 +1,4 @@ -test_folders = %w(bridges config data_structures extensions misc) +test_folders = %w[bridges config data_structures extensions misc] all_tests = test_folders.inject([]) do |folder, output| output << Dir[File.join(File.dirname(__FILE__), "#{folder}/**/*.rb")] diff --git a/test/test_helper.rb b/test/test_helper.rb index 70fea13c0e..7c104d7ce7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -17,7 +17,7 @@ def load_schema end load_schema -%w(model_stub const_mocker company).each do |file| +%w[model_stub const_mocker company].each do |file| require File.join(File.dirname(__FILE__), file) end From 7266010b7bc8749071a146cf03ee5bab8e82a32a Mon Sep 17 00:00:00 2001 From: Andrey Korobkov Date: Wed, 17 May 2017 17:43:04 +0400 Subject: [PATCH 12/13] Rubocop: fix Style/SymbolArray violations --- .rubocop_todo.yml | 11 ++--------- lib/active_scaffold/actions/core.rb | 4 ++-- lib/active_scaffold/actions/create.rb | 2 +- lib/active_scaffold/actions/list.rb | 2 +- lib/active_scaffold/actions/update.rb | 2 +- lib/active_scaffold/active_record_permissions.rb | 2 +- .../bridges/bitfields/bitfields_bridge.rb | 2 +- .../bridges/calendar_date_select/as_cds_bridge.rb | 2 +- lib/active_scaffold/bridges/chosen.rb | 2 +- lib/active_scaffold/bridges/date_picker/ext.rb | 2 +- .../bridges/dragonfly/dragonfly_bridge.rb | 2 +- .../bridges/paperclip/paperclip_bridge.rb | 2 +- .../bridges/semantic_attributes/column.rb | 2 +- lib/active_scaffold/bridges/shared/date_bridge.rb | 4 ++-- lib/active_scaffold/config/base.rb | 2 +- lib/active_scaffold/config/core.rb | 2 +- lib/active_scaffold/constraints.rb | 2 +- lib/active_scaffold/core.rb | 2 +- lib/active_scaffold/data_structures/action_link.rb | 4 ++-- lib/active_scaffold/data_structures/column.rb | 8 ++++---- lib/active_scaffold/data_structures/sorting.rb | 2 +- lib/active_scaffold/extensions/routing_mapper.rb | 2 +- lib/active_scaffold/extensions/to_label.rb | 2 +- lib/active_scaffold/finder.rb | 4 ++-- lib/active_scaffold/helpers/action_link_helpers.rb | 2 +- lib/active_scaffold/helpers/controller_helpers.rb | 4 ++-- lib/active_scaffold/helpers/form_column_helpers.rb | 6 +++--- lib/active_scaffold/helpers/list_column_helpers.rb | 4 ++-- lib/active_scaffold/helpers/search_column_helpers.rb | 4 ++-- lib/active_scaffold/helpers/view_helpers.rb | 2 +- test/config/core_test.rb | 2 +- test/config/create_test.rb | 2 +- test/config/list_test.rb | 4 ++-- test/config/update_test.rb | 6 +++--- test/data_structures/action_columns_test.rb | 6 +++--- test/data_structures/columns_test.rb | 4 ++-- test/data_structures/set_test.rb | 4 ++-- test/data_structures/sorting_test.rb | 2 +- test/helpers/form_column_helpers_test.rb | 4 ++-- test/helpers/list_column_helpers_test.rb | 4 ++-- test/mock_app/config/routes.rb | 4 ++-- test/model_stub.rb | 2 +- 42 files changed, 65 insertions(+), 72 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d148efa797..9ecd1f8981 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-05-17 17:39:06 +0400 using RuboCop version 0.48.1. +# on 2017-05-17 17:42:33 +0400 using RuboCop version 0.48.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -92,7 +92,7 @@ Metrics/BlockNesting: Metrics/CyclomaticComplexity: Max: 27 -# Offense count: 1855 +# Offense count: 1853 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: @@ -319,13 +319,6 @@ Style/RescueModifier: - 'lib/active_scaffold/finder.rb' - 'lib/active_scaffold/helpers/association_helpers.rb' -# Offense count: 67 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: percent, brackets -Style/SymbolArray: - Enabled: false - # Offense count: 7 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, AllowSafeAssignment. diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 78f0c4cb2f..bcb6e677e8 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -171,7 +171,7 @@ def marked_records end def default_formats - [:html, :js, :json, :xml] + %i[html js json xml] end # Returns true if the client accepts one of the MIME types passed to it @@ -235,7 +235,7 @@ def conditions_from_params column = active_scaffold_config._columns_hash[key.to_s] next unless column key = key.to_sym - not_string = [:string, :text].exclude?(column.type) + not_string = %i[string text].exclude?(column.type) next if active_scaffold_constraints[key] next if nested? && nested.param_name == key diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index c01b4e282f..bbae8668e5 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -1,7 +1,7 @@ module ActiveScaffold::Actions module Create def self.included(base) - base.before_action :create_authorized_filter, :only => [:new, :create] + base.before_action :create_authorized_filter, :only => %i[new create] end def new diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 29e54cd1b3..bea0541f0b 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -200,7 +200,7 @@ def list_formats alias index_formats list_formats def row_formats - ([:html, :js] + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq + (%i[html js] + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq end def action_update_formats diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index e6781933c0..a3d58de524 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -1,7 +1,7 @@ module ActiveScaffold::Actions module Update def self.included(base) - base.before_action :update_authorized_filter, :only => [:edit, :update] + base.before_action :update_authorized_filter, :only => %i[edit update] base.helper_method :update_refresh_list? end diff --git a/lib/active_scaffold/active_record_permissions.rb b/lib/active_scaffold/active_record_permissions.rb index e56389bcb5..417309110a 100644 --- a/lib/active_scaffold/active_record_permissions.rb +++ b/lib/active_scaffold/active_record_permissions.rb @@ -97,7 +97,7 @@ module SecurityMethods # options[:action] is the name of a method # options[:reason] if returning reason is expected, it will return array with authorized and reason, or nil if no reason def authorized_for?(options = {}) - raise ArgumentError, "unknown crud type #{options[:crud_type]}" if options[:crud_type] && ![:create, :read, :update, :delete].include?(options[:crud_type]) + raise ArgumentError, "unknown crud type #{options[:crud_type]}" if options[:crud_type] && !%i[create read update delete].include?(options[:crud_type]) not_authorized_reason = ActiveRecordPermissions.not_authorized_reason # collect other possibly-related methods that actually exist diff --git a/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb b/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb index 11f9f8cf4a..8afd5d8eba 100644 --- a/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +++ b/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb @@ -19,7 +19,7 @@ def _load_action_columns if model.respond_to?(:bitfields) && model.bitfields.present? model.bitfields.each do |column_name, options| columns = options.keys.sort_by { |column| self.columns[column].weight } - [:create, :update, :show, :subform].each do |action| + %i[create update show subform].each do |action| next unless actions.include? action if send(action).columns.include? column_name send(action).columns.exclude column_name diff --git a/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb index ccfd821987..7b8c20775e 100644 --- a/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +++ b/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb @@ -5,7 +5,7 @@ module CalendarDateSelectBridge def initialize(model_id) initialize_without_calendar_date_select(model_id) - calendar_date_select_fields = _columns.collect { |c| c.name.to_sym if [:date, :datetime].include?(c.type) }.compact + calendar_date_select_fields = _columns.collect { |c| c.name.to_sym if %i[date datetime].include?(c.type) }.compact # check to see if file column was used on the model return if calendar_date_select_fields.empty? diff --git a/lib/active_scaffold/bridges/chosen.rb b/lib/active_scaffold/bridges/chosen.rb index 920a5368b0..19abc706f9 100644 --- a/lib/active_scaffold/bridges/chosen.rb +++ b/lib/active_scaffold/bridges/chosen.rb @@ -4,7 +4,7 @@ def self.install end def self.install? - super && [:jquery, :prototype].include?(ActiveScaffold.js_framework) + super && %i[jquery prototype].include?(ActiveScaffold.js_framework) end def self.stylesheets diff --git a/lib/active_scaffold/bridges/date_picker/ext.rb b/lib/active_scaffold/bridges/date_picker/ext.rb index 4bf9e9b6c2..2520f0e8a7 100644 --- a/lib/active_scaffold/bridges/date_picker/ext.rb +++ b/lib/active_scaffold/bridges/date_picker/ext.rb @@ -11,7 +11,7 @@ module DatePickerBridge def initialize(model_id) super - date_picker_fields = _columns.collect { |c| {:name => c.name.to_sym, :type => c.type} if [:date, :datetime].include?(c.type) }.compact + date_picker_fields = _columns.collect { |c| {:name => c.name.to_sym, :type => c.type} if %i[date datetime].include?(c.type) }.compact # check to see if file column was used on the model return if date_picker_fields.empty? diff --git a/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb b/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb index b939b90e9e..165157f8bd 100644 --- a/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +++ b/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb @@ -21,7 +21,7 @@ def configure_dragonfly_field(field) columns[field].form_ui ||= :dragonfly columns[field].params.add "remove_#{field}" - [:name, :uid].each do |f| + %i[name uid].each do |f| columns.exclude("#{field}_#{f}".to_sym) end end diff --git a/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb b/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb index 9a7f254539..3febb2960e 100644 --- a/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +++ b/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb @@ -23,7 +23,7 @@ def configure_paperclip_field(field) columns[field].form_ui ||= :paperclip columns[field].params.add "delete_#{field}" - [:file_name, :content_type, :file_size, :updated_at].each do |f| + %i[file_name content_type file_size updated_at].each do |f| columns.exclude("#{field}_#{f}".to_sym) end end diff --git a/lib/active_scaffold/bridges/semantic_attributes/column.rb b/lib/active_scaffold/bridges/semantic_attributes/column.rb index 146706db4b..7bfcd7a154 100644 --- a/lib/active_scaffold/bridges/semantic_attributes/column.rb +++ b/lib/active_scaffold/bridges/semantic_attributes/column.rb @@ -5,7 +5,7 @@ def initialize(name, active_record_class) self.required = !active_record_class.semantic_attributes[self.name].predicates.find { |p| p.allow_empty? == false }.nil? active_record_class.semantic_attributes[self.name].predicates.find do |p| sem_type = p.class.to_s.split('::')[1].underscore.to_sym - next if [:required, :association].include?(sem_type) + next if %i[required association].include?(sem_type) @form_ui = sem_type end end diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index 3d74df6108..c5b180f61b 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -70,7 +70,7 @@ def active_scaffold_search_date_bridge_range_tag(column, options, current_search end def column_datetime?(column) - (!column.column.nil? && [:datetime, :time].include?(column.column.type)) + (!column.column.nil? && %i[datetime time].include?(column.column.type)) end end @@ -201,7 +201,7 @@ def date_bridge_from_to_for_range(column, value) end def date_bridge_column_date?(column) - if [:date_picker, :datetime_picker].include? column.form_ui + if %i[date_picker datetime_picker].include? column.form_ui column.form_ui == :date_picker else (!column.column.nil? && [:date].include?(column.column.type)) diff --git a/lib/active_scaffold/config/base.rb b/lib/active_scaffold/config/base.rb index d892abf463..2e61d78f82 100644 --- a/lib/active_scaffold/config/base.rb +++ b/lib/active_scaffold/config/base.rb @@ -21,7 +21,7 @@ class << subclass protected def crud_type=(val) - raise ArgumentError, "unknown CRUD type #{val}" unless [:create, :read, :update, :delete].include?(val.to_sym) + raise ArgumentError, "unknown CRUD type #{val}" unless %i[create read update delete].include?(val.to_sym) @crud_type = val.to_sym end end diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index b00903a7a0..ec67db12c7 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -10,7 +10,7 @@ class Core < ActiveScaffold::Config::Base def self.actions=(val) @@actions = ActiveScaffold::DataStructures::Actions.new(*val) end - self.actions = [:create, :list, :search, :update, :delete, :show, :nested, :subform] + self.actions = %i[create list search update delete show nested subform] # configures where the ActiveScaffold plugin itself is located. there is no instance version of this. cattr_accessor :plugin_directory diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index c93bd83662..054657c092 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -19,7 +19,7 @@ def register_constraints_with_action_columns(constrained_fields = nil) constrained_fields ||= [] constrained_fields |= active_scaffold_constraints.reject { |_, v| v.is_a? Hash }.keys.collect(&:to_sym) exclude_actions = [] - [:list, :update].each do |action_name| + %i[list update].each do |action_name| if active_scaffold_config.actions.include? action_name exclude_actions << action_name unless active_scaffold_config.send(action_name).hide_nested_column end diff --git a/lib/active_scaffold/core.rb b/lib/active_scaffold/core.rb index 1d024f5681..16c4344865 100644 --- a/lib/active_scaffold/core.rb +++ b/lib/active_scaffold/core.rb @@ -121,7 +121,7 @@ def link_for_association(column, options = {}) ActiveScaffold::DataStructures::ActionLink.new('index', options.merge(:refresh_on_close => true)) else actions = controller.active_scaffold_config.actions unless controller == :polymorph - actions ||= [:create, :update, :show] + actions ||= %i[create update show] column.actions_for_association_links.delete :new unless actions.include? :create column.actions_for_association_links.delete :edit unless actions.include? :update column.actions_for_association_links.delete :show unless actions.include? :show diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 9388d95091..cc90b7f8f5 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -10,8 +10,8 @@ def initialize(action, options = {}) self.inline = true self.method = :get self.crud_type = :delete if [:destroy].include?(action.try(:to_sym)) - self.crud_type = :create if [:create, :new].include?(action.try(:to_sym)) - self.crud_type = :update if [:edit, :update].include?(action.try(:to_sym)) + self.crud_type = :create if %i[create new].include?(action.try(:to_sym)) + self.crud_type = :update if %i[edit update].include?(action.try(:to_sym)) self.crud_type ||= :read self.column = nil self.image = nil diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 10211f34f1..c4f893a41d 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -253,7 +253,7 @@ def show_blank_record?(associated) # methods for automatic links in singular association columns cattr_accessor :actions_for_association_links, instance_accessor: false - @@actions_for_association_links = [:new, :edit, :show] + @@actions_for_association_links = %i[new edit show] attr_accessor :actions_for_association_links cattr_accessor :association_form_ui @@ -457,7 +457,7 @@ def default_select_columns end def column_number? - return [:float, :decimal, :integer].include? @column.type if active_record? + return %i[float decimal integer].include? @column.type if active_record? return @column.type < Numeric if mongoid? end @@ -505,9 +505,9 @@ def estimate_weight 400 elsif association.try(:collection?) 500 - elsif [:created_at, :updated_at].include?(name) + elsif %i[created_at updated_at].include?(name) 600 - elsif [:name, :label, :title].include?(name) + elsif %i[name label title].include?(name) 100 elsif required? 200 diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index 21e53c73ec..ec0e78b0a2 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -39,7 +39,7 @@ def add(column_name, direction = nil) direction = direction.to_s.upcase column = get_column(column_name) raise ArgumentError, "Could not find column #{column_name}" if column.nil? - raise ArgumentError, 'Sorting direction unknown' unless [:ASC, :DESC].include? direction.to_sym + raise ArgumentError, 'Sorting direction unknown' unless %i[ASC DESC].include? direction.to_sym @clauses << [column, direction.untaint] if column.sortable? raise ArgumentError, "Can't mix :method- and :sql-based sorting" if mixed_sorting? end diff --git a/lib/active_scaffold/extensions/routing_mapper.rb b/lib/active_scaffold/extensions/routing_mapper.rb index 545ff739cb..68610658b4 100644 --- a/lib/active_scaffold/extensions/routing_mapper.rb +++ b/lib/active_scaffold/extensions/routing_mapper.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Routing ACTIVE_SCAFFOLD_CORE_ROUTING = { :collection => {:show_search => :get, :render_field => :post, :mark => :post}, - :member => {:update_column => :post, :render_field => [:get, :post], :mark => :post} + :member => {:update_column => :post, :render_field => %i[get post], :mark => :post} }.freeze ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING = { :collection => {:edit_associated => :get, :new_existing => :get, :add_existing => :post}, diff --git a/lib/active_scaffold/extensions/to_label.rb b/lib/active_scaffold/extensions/to_label.rb index 9faae7fcd2..55ed5c06dd 100644 --- a/lib/active_scaffold/extensions/to_label.rb +++ b/lib/active_scaffold/extensions/to_label.rb @@ -1,7 +1,7 @@ # the ever-useful to_label method class ActiveRecord::Base def to_label - [:name, :label, :title, :to_s].each do |attribute| + %i[name label title to_s].each do |attribute| return send(attribute).to_s if respond_to?(attribute) end end diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 8156e69b62..d224852fdd 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -229,7 +229,7 @@ def format_for_datetime(column, value) def condition_value_for_datetime(column, value, conversion = :to_time) unless value.nil? || value.blank? if value.is_a? Hash - Time.zone.local(*[:year, :month, :day, :hour, :minute, :second].collect { |part| value[part].to_i }) rescue nil + Time.zone.local(*%i[year month day hour minute second].collect { |part| value[part].to_i }) rescue nil elsif value.respond_to?(:strftime) if conversion == :to_time # Explicitly get the current zone, because TimeWithZone#to_time in rails 3.2.3 returns UTC. @@ -432,7 +432,7 @@ def finder_options(options = {}) def count_items(query, find_options = {}, count_includes = nil) count_includes ||= find_options[:includes] if find_options[:conditions].present? - options = find_options.reject { |k, _| [:select, :reorder, :order].include? k } + options = find_options.reject { |k, _| %i[select reorder order].include? k } # NOTE: we must use includes in the count query, because some conditions may reference other tables options[:includes] = count_includes diff --git a/lib/active_scaffold/helpers/action_link_helpers.rb b/lib/active_scaffold/helpers/action_link_helpers.rb index fe6f8c63fe..d409eb0621 100644 --- a/lib/active_scaffold/helpers/action_link_helpers.rb +++ b/lib/active_scaffold/helpers/action_link_helpers.rb @@ -4,7 +4,7 @@ module Helpers # Also a dumping ground for uncategorized helpers. module ActionLinkHelpers # params which mustn't be copying to nested links - NESTED_PARAMS = [:eid, :embedded, :association, :parent_scaffold].freeze + NESTED_PARAMS = %i[eid embedded association parent_scaffold].freeze def skip_action_link?(link, *args) !link.ignore_method.nil? && controller.respond_to?(link.ignore_method, true) && controller.send(link.ignore_method, *args) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 1155e72457..22d6545f0b 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -38,7 +38,7 @@ def generated_id(record) # :authenticity_token is sent on some ajax requests # :_added is sent on checkbox-list with update_columns # :_removed is sent on checkbox-list with update_columns - BLACKLIST_PARAMS = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method, :dont_close, :auto_pagination, :iframe, :associated_id, :authenticity_token, :_added, :_removed].freeze + BLACKLIST_PARAMS = %i[adapter position sort sort_direction page record commit _method dont_close auto_pagination iframe associated_id authenticity_token _added _removed].freeze def params_for(options = {}) unless @params_for @@ -62,7 +62,7 @@ def main_path_to_return if params[:return_to] params[:return_to] else - exclude_parameters = [:utf8, :associated_id] + exclude_parameters = %i[utf8 associated_id] parameters = {} if params[:parent_scaffold] && nested? && nested.singular_association? parameters[:controller] = params[:parent_scaffold] diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index b549d6472f..ecb962260a 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -40,13 +40,13 @@ def active_scaffold_render_input(column, options) # final ultimate fallback: use rails' generic input method else # for textual fields we pass different options - text_types = [:text, :string, :integer, :float, :decimal, :date, :time, :datetime] + text_types = %i[text string integer float decimal date time datetime] options = active_scaffold_input_text_options(options) if text_types.include?(column.column.type) if column.column.type == :string && options[:maxlength].blank? options[:maxlength] = column.column.limit options[:size] ||= options[:maxlength].to_i > 30 ? 30 : options[:maxlength] end - options[:include_blank] = true if column.column.null && [:date, :datetime, :time].include?(column.column.type) + options[:include_blank] = true if column.column.null && %i[date datetime time].include?(column.column.type) options[:value] = format_number_value(record.send(column.name), column.options) if column.number? text_field(:record, column.name, options.merge(column.options).except(:format)) end @@ -116,7 +116,7 @@ def active_scaffold_input_options(column, scope = nil, options = {}) def current_form_columns(record, scope, subform_controller = nil) if scope subform_controller.active_scaffold_config.subform.columns.names - elsif [:new, :create, :edit, :update, :render_field].include? action_name.to_sym + elsif %i[new create edit update render_field].include? action_name.to_sym # disable update_columns for inplace_edit (GET render_field) return if action_name == 'render_field' && request.get? active_scaffold_config.send(record.new_record? ? :create : :update).columns.names diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index dbe7e98aa7..b2e831cd13 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -134,7 +134,7 @@ def override_column_ui(list_ui) def format_column_value(record, column, value = nil) value ||= record.send(column.name) unless record.nil? if column.association.nil? - if [:select, :radio].include?(column.form_ui) && column.options[:options] + if %i[select radio].include?(column.form_ui) && column.options[:options] text, val = column.options[:options].find { |t, v| (v.nil? ? t : v).to_s == value.to_s } value = active_scaffold_translated_option(column, text, val).first if text end @@ -320,7 +320,7 @@ def inplace_edit_data(column) data[:ie_mode] = :clone elsif column.inplace_edit == :ajax url = url_for(params_for(:controller => params_for[:controller], :action => 'render_field', :id => '__id__', :update_column => column.name)) - plural = column.association.try(:collection?) && !override_form_field?(column) && [:select, :record_select].include?(column.form_ui) + plural = column.association.try(:collection?) && !override_form_field?(column) && %i[select record_select].include?(column.form_ui) data[:ie_render_url] = url data[:ie_mode] = :ajax data[:ie_plural] = plural diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index ad61189708..dfd0aaf349 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -43,7 +43,7 @@ def active_scaffold_search_for(column, options = nil) # final ultimate fallback: use rails' generic input method else # for textual fields we pass different options - text_types = [:text, :string, :integer, :float, :decimal] + text_types = %i[text string integer float decimal] options = active_scaffold_input_text_options(options) if text_types.include?(column.column.type) text_field(:record, column.name, options.merge(column.options)) end @@ -66,7 +66,7 @@ def search_attribute(column, record) end def search_label_for(column, options) - options[:id] unless [:range, :integer, :decimal, :float, :string, :date_picker, :datetime_picker, :calendar_date_select].include? column.search_ui + options[:id] unless %i[range integer decimal float string date_picker datetime_picker calendar_date_select].include? column.search_ui end ## diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 6094b616bd..f49bb54873 100644 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -206,7 +206,7 @@ def active_scaffold_error_messages_for(*params) '' else html = {} - [:id, :class].each do |key| + %i[id class].each do |key| if options.include?(key) value = options[key] html[key] = value if value.present? diff --git a/test/config/core_test.rb b/test/config/core_test.rb index af17c983c0..9683f32f32 100644 --- a/test/config/core_test.rb +++ b/test/config/core_test.rb @@ -13,7 +13,7 @@ def setup def test_default_options refute @config.add_sti_create_links? refute @config.sti_children - assert_equal [:create, :list, :search, :update, :delete, :show, :nested, :subform], @config.actions.to_a + assert_equal %i[create list search update delete show nested subform], @config.actions.to_a assert_equal :default, @config.frontend assert_equal :default, @config.theme assert_equal 'Model stub', @config.label(:count => 1) diff --git a/test/config/create_test.rb b/test/config/create_test.rb index 6f77689958..9de2493733 100644 --- a/test/config/create_test.rb +++ b/test/config/create_test.rb @@ -12,7 +12,7 @@ def teardown end def test_default_columns - assert_equal [:a, :d, :other_model, :other_models], @config.create.columns.names + assert_equal %i[a d other_model other_models], @config.create.columns.names end def test_default_options diff --git a/test/config/list_test.rb b/test/config/list_test.rb index 6ab86d3f31..4291353392 100644 --- a/test/config/list_test.rb +++ b/test/config/list_test.rb @@ -127,8 +127,8 @@ def test_always_show_search_when_field_search end def test_count_includes - @config.list.count_includes = [:assoc_1, :assoc_2] - assert_equal [:assoc_1, :assoc_2], @config.list.count_includes + @config.list.count_includes = %i[assoc_1 assoc_2] + assert_equal %i[assoc_1 assoc_2], @config.list.count_includes end end end diff --git a/test/config/update_test.rb b/test/config/update_test.rb index e7ad937c85..cebb663192 100644 --- a/test/config/update_test.rb +++ b/test/config/update_test.rb @@ -7,11 +7,11 @@ def setup end def test_copy_columns_from_create - @config.create.columns = [:a, :c, :d] - assert_equal [:a, :d], @config.create.columns.names + @config.create.columns = %i[a c d] + assert_equal %i[a d], @config.create.columns.names @config.update.columns = @config.create.columns @config._load_action_columns - assert_equal [:a, :c, :d], @config.update.columns.names + assert_equal %i[a c d], @config.update.columns.names end def test__params_for_columns__returns_all_params diff --git a/test/data_structures/action_columns_test.rb b/test/data_structures/action_columns_test.rb index 85d90f5510..84eb54946b 100644 --- a/test/data_structures/action_columns_test.rb +++ b/test/data_structures/action_columns_test.rb @@ -4,7 +4,7 @@ class ActionColumnsTest < MiniTest::Test def setup - @columns = ActiveScaffold::DataStructures::ActionColumns.new([:a, :b]) + @columns = ActiveScaffold::DataStructures::ActionColumns.new(%i[a b]) @columns.action = stub(:core => stub(:model_id => 'model_stub')) end @@ -35,7 +35,7 @@ def test_exclude def test_exclude_array # exclude with a symbol assert @columns.include?(:b) - @columns.exclude [:a, :b] + @columns.exclude %i[a b] refute @columns.include?(:b) refute @columns.include?(:a) end @@ -58,7 +58,7 @@ def test_add # try adding an array of columns refute @columns.include?(:f) - @columns.add [:f, :g] + @columns.add %i[f g] assert @columns.include?(:f) assert @columns.include?(:g) end diff --git a/test/data_structures/columns_test.rb b/test/data_structures/columns_test.rb index b3e72a5d13..5546318b84 100644 --- a/test/data_structures/columns_test.rb +++ b/test/data_structures/columns_test.rb @@ -25,7 +25,7 @@ def test_add # try adding an array of columns refute @columns.include?(:f) - @columns.add [:f, :g] + @columns.add %i[f g] assert @columns.include?(:f) assert @columns.include?(:g) end @@ -47,7 +47,7 @@ def test_finders def test_each @columns.each do |column| - assert [:a, :b].include?(column.name) + assert %i[a b].include?(column.name) end end diff --git a/test/data_structures/set_test.rb b/test/data_structures/set_test.rb index feeabc4b93..86ea1c3b27 100644 --- a/test/data_structures/set_test.rb +++ b/test/data_structures/set_test.rb @@ -26,7 +26,7 @@ def test_exclude def test_exclude_array # exclude with a symbol assert @items.include?(:b) - @items.exclude [:a, :b] + @items.exclude %i[a b] refute @items.include?(:b) refute @items.include?(:a) end @@ -55,7 +55,7 @@ def test_add # try adding an array of columns refute @items.include?(:f) - @items.add [:f, :g] + @items.add %i[f g] assert @items.include?(:f) assert @items.include?(:g) end diff --git a/test/data_structures/sorting_test.rb b/test/data_structures/sorting_test.rb index 0253ad6ea0..84c9a43720 100644 --- a/test/data_structures/sorting_test.rb +++ b/test/data_structures/sorting_test.rb @@ -25,7 +25,7 @@ def test_add # test adding a lowercase string direction assert_equal 'DESC', @sorting.direction_of(:c) - @sorting << [:d, :desc] + @sorting << %i[d desc] # testing adding with the alias assert @sorting.sorts_on?(:d) assert_equal 'DESC', @sorting.direction_of(:d) diff --git a/test/helpers/form_column_helpers_test.rb b/test/helpers/form_column_helpers_test.rb index 84e9a44e9d..404bca8c78 100644 --- a/test/helpers/form_column_helpers_test.rb +++ b/test/helpers/form_column_helpers_test.rb @@ -9,7 +9,7 @@ def setup end def test_choices_for_select_form_ui_for_simple_column - @column.options[:options] = [:value_1, :value_2, :value_3] + @column.options[:options] = %i[value_1 value_2 value_3] assert_dom_equal "", active_scaffold_input_select(@column, :object => @record) @column.options[:options] = %w[value_1 value_2 value_3] @@ -18,7 +18,7 @@ def test_choices_for_select_form_ui_for_simple_column @column.options[:options] = [%w[text_1 value_1], %w[text_2 value_2], %w[text_3 value_3]] assert_dom_equal "", active_scaffold_input_select(@column, :object => @record) - @column.options[:options] = [[:text_1, :value_1], [:text_2, :value_2], [:text_3, :value_3]] + @column.options[:options] = [%i[text_1 value_1], %i[text_2 value_2], %i[text_3 value_3]] assert_dom_equal "", active_scaffold_input_select(@column, :object => @record) end diff --git a/test/helpers/list_column_helpers_test.rb b/test/helpers/list_column_helpers_test.rb index 5fa528f3ce..450c768dc7 100644 --- a/test/helpers/list_column_helpers_test.rb +++ b/test/helpers/list_column_helpers_test.rb @@ -17,7 +17,7 @@ def setup end def test_options_for_select_list_ui_for_simple_column - @column.options[:options] = [:value_1, :value_2, :value_3] + @column.options[:options] = %i[value_1 value_2 value_3] assert_equal 'Value 2', format_column_value(@record, @column) @column.options[:options] = %w[value_1 value_2 value_3] @@ -26,7 +26,7 @@ def test_options_for_select_list_ui_for_simple_column @column.options[:options] = [%w[text_1 value_1], %w[text_2 value_2], %w[text_3 value_3]] assert_equal 'text_2', format_column_value(@record, @column) - @column.options[:options] = [[:text_1, :value_1], [:text_2, :value_2], [:text_3, :value_3]] + @column.options[:options] = [%i[text_1 value_1], %i[text_2 value_2], %i[text_3 value_3]] assert_equal 'Text 2', format_column_value(@record, @column) end diff --git a/test/mock_app/config/routes.rb b/test/mock_app/config/routes.rb index 7825a553b6..a3543d604c 100644 --- a/test/mock_app/config/routes.rb +++ b/test/mock_app/config/routes.rb @@ -4,9 +4,9 @@ resources :addresses, concerns: :active_scaffold resources :buildings, except: :index do - concerns :active_scaffold, except: [:mark, :add_existing, :new_existing, :destroy_existing] + concerns :active_scaffold, except: %i[mark add_existing new_existing destroy_existing] end - resources :cars, only: [:edit, :update] do + resources :cars, only: %i[edit update] do concerns :active_scaffold, association: false, except: [:mark] end diff --git a/test/model_stub.rb b/test/model_stub.rb index 2c19646731..4e810fd3aa 100644 --- a/test/model_stub.rb +++ b/test/model_stub.rb @@ -4,7 +4,7 @@ class ModelStub < ActiveRecord::Base has_many :other_models, :class_name => 'ModelStub' cattr_accessor :stubbed_columns - self.stubbed_columns = [:a, :b, :c, :d, :id, :created_at] + self.stubbed_columns = %i[a b c d id created_at] attr_accessor(*stubbed_columns) self.primary_key = :id From 0b27055fd00cce88d7406757e294ab31dd1f6498 Mon Sep 17 00:00:00 2001 From: Sergio Cambra Date: Wed, 17 May 2017 17:29:54 +0200 Subject: [PATCH 13/13] remove unused class and test --- .../data_structures/error_message.rb | 22 ---------------- test/data_structures/error_message_test.rb | 25 ------------------- 2 files changed, 47 deletions(-) delete mode 100644 lib/active_scaffold/data_structures/error_message.rb delete mode 100644 test/data_structures/error_message_test.rb diff --git a/lib/active_scaffold/data_structures/error_message.rb b/lib/active_scaffold/data_structures/error_message.rb deleted file mode 100644 index 6f2f7424c2..0000000000 --- a/lib/active_scaffold/data_structures/error_message.rb +++ /dev/null @@ -1,22 +0,0 @@ -module ActiveScaffold::DataStructures - # Wrapper for error strings so that they may be exported using to_xxx - class ErrorMessage - def initialize(error) - @error = error - end - - def public_attributes - {:error => @error} - end - - def to_xml - public_attributes.to_xml(:root => 'errors') - end - - delegate :to_yaml, :to => :public_attributes - - def to_s - @error - end - end -end diff --git a/test/data_structures/error_message_test.rb b/test/data_structures/error_message_test.rb deleted file mode 100644 index 8e585123aa..0000000000 --- a/test/data_structures/error_message_test.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'test_helper' - -class ErrorMessageTest < MiniTest::Test - def setup - @error = ActiveScaffold::DataStructures::ErrorMessage.new 'foo' - end - - def test_attributes - assert @error.public_attributes.key?(:error) - assert_equal 'foo', @error.public_attributes[:error] - end - - def test_xml - xml = Hash.from_xml(@error.to_xml) - assert xml.key?('errors') - assert xml['errors'].key?('error') - assert_equal 'foo', xml['errors']['error'] - end - - def test_yaml - yml = YAML.safe_load(@error.to_yaml) - assert yml.key?(:error) - assert_equal 'foo', yml[:error] - end -end