diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1e2080b2bf..e570bad55f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,6 +8,18 @@ on: types: [opened, synchronize, reopened] jobs: + standardrb: + runs-on: ubuntu-latest + permissions: + contents: read + checks: write + steps: + - uses: actions/checkout@v4 + - name: StandardRB Linter + uses: testdouble/standard-ruby-action@main + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + stylelint: runs-on: ubuntu-latest steps: diff --git a/Gemfile b/Gemfile index 9d8bb9da5b..9cf6efc532 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source 'https://rubygems.org' +source "https://rubygems.org" ruby "3.2.2" unless ENV["CI"] gemspec @@ -27,6 +27,7 @@ group :development, :test do gem "factory_bot_rails" gem "i18n-tasks", "1.0.13" gem "pry" + gem "standard" gem "yard" end diff --git a/Gemfile.lock b/Gemfile.lock index cf23472760..51d3f8ddeb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -160,6 +160,7 @@ GEM terminal-table (>= 1.5.1) jsbundling-rails (1.3.0) railties (>= 6.0.0) + json (2.7.1) kaminari (1.2.2) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.2) @@ -176,8 +177,10 @@ GEM kaminari rails kgio (2.11.4) + language_server-protocol (3.17.0.3) launchy (2.5.2) addressable (~> 2.8) + lint_roller (1.1.0) loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -205,6 +208,7 @@ GEM nokogiri (1.16.0) mini_portile2 (~> 2.8.2) racc (~> 1.4) + parallel (1.24.0) parser (3.2.2.4) ast (~> 2.4.1) racc @@ -274,6 +278,23 @@ GEM rspec-mocks (~> 3.12) rspec-support (~> 3.12) rspec-support (3.12.1) + rubocop (1.59.0) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.2.2.4) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (1.13.0) rubyzip (2.3.2) selenium-webdriver (4.17.0) base64 (~> 0.2) @@ -295,6 +316,18 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) thor (1.3.0) @@ -355,6 +388,7 @@ DEPENDENCIES sentry-ruby shoulda-matchers sprockets-rails (~> 3.4) + standard timecop uglifier unicorn diff --git a/Rakefile b/Rakefile index ab9915d104..54ce26c988 100644 --- a/Rakefile +++ b/Rakefile @@ -1,19 +1,19 @@ begin - require 'bundler/setup' + require "bundler/setup" rescue LoadError - puts 'You must `gem install bundler` and `bundle install` to run rake tasks' + puts "You must `gem install bundler` and `bundle install` to run rake tasks" end -require 'rdoc/task' +require "rdoc/task" -require File.expand_path('../spec/example_app/config/application', __FILE__) +require File.expand_path("../spec/example_app/config/application", __FILE__) RDoc::Task.new(:rdoc) do |rdoc| - rdoc.rdoc_dir = 'rdoc' - rdoc.title = 'Administrate' - rdoc.options << '--line-numbers' - rdoc.rdoc_files.include('README.rdoc') - rdoc.rdoc_files.include('lib/**/*.rb') + rdoc.rdoc_dir = "rdoc" + rdoc.title = "Administrate" + rdoc.options << "--line-numbers" + rdoc.rdoc_files.include("README.rdoc") + rdoc.rdoc_files.include("lib/**/*.rb") end Bundler::GemHelper.install_tasks diff --git a/administrate.gemspec b/administrate.gemspec index 4b77c546d6..aa19dd8e0b 100644 --- a/administrate.gemspec +++ b/administrate.gemspec @@ -18,18 +18,18 @@ Gem::Specification.new do |s| s.add_dependency "activerecord", ">= 6.0", "< 8.0" s.add_dependency "kaminari", "~> 1.2.2" - s.description = <<-DESCRIPTION -Administrate is heavily inspired by projects like Rails Admin and ActiveAdmin, -but aims to provide a better user experience for site admins, -and to be easier for developers to customize. - -To do that, we're following a few simple rules: - -- No DSLs (domain-specific languages) -- Support the simplest use cases, - and let the user override defaults with standard tools - such as plain Rails controllers and views. -- Break up the library into core components and plugins, - so each component stays small and easy to maintain. + s.description = <<~DESCRIPTION + Administrate is heavily inspired by projects like Rails Admin and ActiveAdmin, + but aims to provide a better user experience for site admins, + and to be easier for developers to customize. + + To do that, we're following a few simple rules: + + - No DSLs (domain-specific languages) + - Support the simplest use cases, + and let the user override defaults with standard tools + such as plain Rails controllers and views. + - Break up the library into core components and plugins, + so each component stays small and easy to maintain. DESCRIPTION end diff --git a/app/controllers/administrate/application_controller.rb b/app/controllers/administrate/application_controller.rb index 52f182ffee..514d9741ce 100644 --- a/app/controllers/administrate/application_controller.rb +++ b/app/controllers/administrate/application_controller.rb @@ -15,13 +15,13 @@ def index resources: resources, search_term: search_term, page: page, - show_search_bar: show_search_bar?, + show_search_bar: show_search_bar? } end def show render locals: { - page: Administrate::Page::Show.new(dashboard, requested_resource), + page: Administrate::Page::Show.new(dashboard, requested_resource) } end @@ -29,13 +29,13 @@ def new resource = new_resource authorize_resource(resource) render locals: { - page: Administrate::Page::Form.new(dashboard, resource), + page: Administrate::Page::Form.new(dashboard, resource) } end def edit render locals: { - page: Administrate::Page::Form.new(dashboard, requested_resource), + page: Administrate::Page::Form.new(dashboard, requested_resource) } end @@ -47,11 +47,11 @@ def create yield(resource) if block_given? redirect_to( after_resource_created_path(resource), - notice: translate_with_resource("create.success"), + notice: translate_with_resource("create.success") ) else render :new, locals: { - page: Administrate::Page::Form.new(dashboard, resource), + page: Administrate::Page::Form.new(dashboard, resource) }, status: :unprocessable_entity end end @@ -60,11 +60,11 @@ def update if requested_resource.update(resource_params) redirect_to( after_resource_updated_path(requested_resource), - notice: translate_with_resource("update.success"), + notice: translate_with_resource("update.success") ) else render :edit, locals: { - page: Administrate::Page::Form.new(dashboard, requested_resource), + page: Administrate::Page::Form.new(dashboard, requested_resource) }, status: :unprocessable_entity end end @@ -84,12 +84,12 @@ def filter_resources(resources, search_term:) Administrate::Search.new( resources, dashboard, - search_term, + search_term ).run end def after_resource_destroyed_path(_requested_resource) - { action: :index } + {action: :index} end def after_resource_created_path(requested_resource) @@ -103,7 +103,7 @@ def after_resource_updated_path(requested_resource) helper_method :nav_link_state def nav_link_state(resource) underscore_resource = resource.to_s.split("/").join("__") - resource_name.to_s.pluralize == underscore_resource ? :active : :inactive + (resource_name.to_s.pluralize == underscore_resource) ? :active : :inactive end # Whether the named action route exists for the resource class. @@ -141,8 +141,8 @@ def order sorting_attribute, sorting_direction, association_attribute: order_by_field( - dashboard_attribute(sorting_attribute), - ), + dashboard_attribute(sorting_attribute) + ) ) end @@ -201,9 +201,9 @@ def apply_collection_includes(relation) end def resource_params - params.require(resource_class.model_name.param_key). - permit(dashboard.permitted_attributes(action_name)). - transform_values { |v| read_param_value(v) } + params.require(resource_class.model_name.param_key) + .permit(dashboard.permitted_attributes(action_name)) + .transform_values { |v| read_param_value(v) } end def read_param_value(data) @@ -236,13 +236,13 @@ def resource_resolver def translate_with_resource(key) t( "administrate.controller.#{key}", - resource: resource_resolver.resource_title, + resource: resource_resolver.resource_title ) end def show_search_bar? dashboard.attribute_types_for( - dashboard.all_attributes, + dashboard.all_attributes ).any? { |_name, attribute| attribute.searchable? } end @@ -279,7 +279,7 @@ def authorize_resource(resource) else raise Administrate::NotAuthorizedError.new( action: action_name, - resource: resource, + resource: resource ) end end diff --git a/app/controllers/concerns/administrate/punditize.rb b/app/controllers/concerns/administrate/punditize.rb index 33dacddff4..72d54ee833 100644 --- a/app/controllers/concerns/administrate/punditize.rb +++ b/app/controllers/concerns/administrate/punditize.rb @@ -1,6 +1,6 @@ module Administrate module Punditize - if Object.const_defined?("Pundit") + if Object.const_defined?(:Pundit) extend ActiveSupport::Concern if Pundit.const_defined?(:Authorization) @@ -28,7 +28,7 @@ def authorize_resource(resource) def authorized_action?(resource, action) namespaced_resource = policy_namespace + [resource] policy = Pundit.policy!(pundit_user, namespaced_resource) - policy.send("#{action}?".to_sym) + policy.send(:"#{action}?") end def policy_scope!(user, scope) @@ -38,13 +38,13 @@ def policy_scope!(user, scope) policy_scope = policy_scope_class.new(user, pundit_model(scope)) rescue ArgumentError raise(Pundit::InvalidConstructorError, - "Invalid #<#{policy_scope_class}> constructor is called") + "Invalid #<#{policy_scope_class}> constructor is called") end if policy_scope.respond_to? :resolve_admin Administrate.deprecator.warn( - "Pundit policy scope `resolve_admin` method is deprecated. " + - "Please use a namespaced pundit policy instead.", + "Pundit policy scope `resolve_admin` method is deprecated. " \ + "Please use a namespaced pundit policy instead." ) policy_scope.resolve_admin else diff --git a/app/helpers/administrate/application_helper.rb b/app/helpers/administrate/application_helper.rb index b314abd898..c72368f0e8 100644 --- a/app/helpers/administrate/application_helper.rb +++ b/app/helpers/administrate/application_helper.rb @@ -50,7 +50,7 @@ def accessible_action?(target, action_name) def display_resource_name(resource_name, opts = {}) dashboard_from_resource(resource_name).resource_name( count: opts[:singular] ? SINGULAR_COUNT : PLURAL_MANY_COUNT, - default: default_resource_name(resource_name, opts), + default: default_resource_name(resource_name, opts) ) end @@ -65,14 +65,14 @@ def sort_order(order) def resource_index_route(resource_name) url_for( action: "index", - controller: "/#{namespace}/#{resource_name}", + controller: "/#{namespace}/#{resource_name}" ) end def sanitized_order_params(page, current_field_name) collection_names = page.item_associations + [current_field_name] association_params = collection_names.map do |assoc_name| - { assoc_name => %i[order direction page per_page] } + {assoc_name => %i[order direction page per_page]} end params.permit(:search, :id, :_page, :per_page, association_params) end @@ -87,7 +87,7 @@ def clear_search_params def default_resource_name(name, opts = {}) resource_name = (opts[:singular] ? name.to_s : name.to_s.pluralize) - resource_name.gsub("/", "_").titleize + resource_name.tr("/", "_").titleize end end end diff --git a/gemfiles/pundit21.gemfile b/gemfiles/pundit21.gemfile index 6d01c80f2d..0d53037437 100644 --- a/gemfiles/pundit21.gemfile +++ b/gemfiles/pundit21.gemfile @@ -27,6 +27,7 @@ group :development, :test do gem "factory_bot_rails" gem "i18n-tasks", "1.0.13" gem "pry" + gem "standard" gem "yard" end diff --git a/gemfiles/rails60.gemfile b/gemfiles/rails60.gemfile index 0a02e49c15..e09741a5ea 100644 --- a/gemfiles/rails60.gemfile +++ b/gemfiles/rails60.gemfile @@ -28,6 +28,7 @@ group :development, :test do gem "factory_bot_rails" gem "i18n-tasks", "1.0.13" gem "pry" + gem "standard" gem "yard" end diff --git a/gemfiles/rails61.gemfile b/gemfiles/rails61.gemfile index 47f420fb61..fdfb7039f0 100644 --- a/gemfiles/rails61.gemfile +++ b/gemfiles/rails61.gemfile @@ -28,6 +28,7 @@ group :development, :test do gem "factory_bot_rails" gem "i18n-tasks", "1.0.13" gem "pry" + gem "standard" gem "yard" end diff --git a/gemfiles/rails70.gemfile b/gemfiles/rails70.gemfile index 168e26720a..308fb92117 100644 --- a/gemfiles/rails70.gemfile +++ b/gemfiles/rails70.gemfile @@ -28,6 +28,7 @@ group :development, :test do gem "factory_bot_rails" gem "i18n-tasks", "1.0.13" gem "pry" + gem "standard" gem "yard" end diff --git a/lib/administrate.rb b/lib/administrate.rb index 63b25615b1..4acfd97792 100644 --- a/lib/administrate.rb +++ b/lib/administrate.rb @@ -4,39 +4,39 @@ module Administrate def self.warn_of_missing_resource_class deprecator.warn( - "Calling Field::Base.permitted_attribute without the option " + - ":resource_class is deprecated. If you are seeing this " + - "message, you are probably using a custom field type that" + - "does this. Please make sure to update it to a version that " + - "does not use a deprecated API", + "Calling Field::Base.permitted_attribute without the option " \ + ":resource_class is deprecated. If you are seeing this " \ + "message, you are probably using a custom field type that" \ + "does this. Please make sure to update it to a version that " \ + "does not use a deprecated API" ) end def self.warn_of_deprecated_option(name) deprecator.warn( - "The option :#{name} is deprecated. " + - "Administrate should detect it automatically. " + - "Please file an issue at " + - "https://github.com/thoughtbot/administrate/issues " + - "if you think otherwise.", + "The option :#{name} is deprecated. " \ + "Administrate should detect it automatically. " \ + "Please file an issue at " \ + "https://github.com/thoughtbot/administrate/issues " \ + "if you think otherwise." ) end def self.warn_of_deprecated_method(klass, method) deprecator.warn( - "The method #{klass}##{method} is deprecated. " + - "If you are seeing this message you are probably " + - "using a dashboard that depends explicitly on it. " + - "Please make sure you update it to a version that " + - "does not use a deprecated API", + "The method #{klass}##{method} is deprecated. " \ + "If you are seeing this message you are probably " \ + "using a dashboard that depends explicitly on it. " \ + "Please make sure you update it to a version that " \ + "does not use a deprecated API" ) end def self.warn_of_deprecated_authorization_method(method) deprecator.warn( - "The method `#{method}` is deprecated. " + - "Please use `accessible_action?` instead, " + - "or see the documentation for other options.", + "The method `#{method}` is deprecated. " \ + "Please use `accessible_action?` instead, " \ + "or see the documentation for other options." ) end diff --git a/lib/administrate/base_dashboard.rb b/lib/administrate/base_dashboard.rb index 4b05404ce0..f9fa3556bd 100644 --- a/lib/administrate/base_dashboard.rb +++ b/lib/administrate/base_dashboard.rb @@ -79,7 +79,7 @@ def permitted_attributes(action = nil) attribute_types[attr].permitted_attribute( attr, resource_class: self.class.model, - action: action, + action: action ) end.uniq end @@ -118,10 +118,10 @@ def item_includes def item_associations attributes = if show_page_attributes.is_a?(Hash) - show_page_attributes.values.flatten - else - show_page_attributes - end + show_page_attributes.values.flatten + else + show_page_attributes + end attribute_associated attributes end diff --git a/lib/administrate/engine.rb b/lib/administrate/engine.rb index abb7092da0..75ca7e4e92 100644 --- a/lib/administrate/engine.rb +++ b/lib/administrate/engine.rb @@ -9,7 +9,6 @@ require "administrate/resource_resolver" require "administrate/search" require "administrate/namespace" -require "administrate/namespace/resource" module Administrate class Engine < ::Rails::Engine @@ -21,7 +20,7 @@ class Engine < ::Rails::Engine initializer "administrate.assets.precompile" do |app| app.config.assets.precompile += [ "administrate/application.js", - "administrate/application.css", + "administrate/application.css" ] end diff --git a/lib/administrate/field/associative.rb b/lib/administrate/field/associative.rb index 73d0434e81..ef81b33a62 100644 --- a/lib/administrate/field/associative.rb +++ b/lib/administrate/field/associative.rb @@ -41,7 +41,7 @@ def associated_class_name else self.class.associated_class_name( resource.class, - attribute, + attribute ) end end diff --git a/lib/administrate/field/base.rb b/lib/administrate/field/base.rb index beca439a78..a1e34bede2 100644 --- a/lib/administrate/field/base.rb +++ b/lib/administrate/field/base.rb @@ -56,13 +56,13 @@ def required? return false unless resource.class.respond_to?(:validators_on) resource.class.validators_on(attribute).any? do |v| - next false unless v.class == ActiveRecord::Validations::PresenceValidator + next false unless v.instance_of?(ActiveRecord::Validations::PresenceValidator) options = v.options next false if options.include?(:if) next false if options.include?(:unless) - if on_option = options[:on] + if (on_option = options[:on]) if on_option == :create && !resource.persisted? next true end diff --git a/lib/administrate/field/belongs_to.rb b/lib/administrate/field/belongs_to.rb index a867628058..c26a5affec 100644 --- a/lib/administrate/field/belongs_to.rb +++ b/lib/administrate/field/belongs_to.rb @@ -25,7 +25,7 @@ def associated_resource_options candidate_resources.map do |resource| [ display_candidate_resource(resource), - resource.send(association_primary_key), + resource.send(association_primary_key) ] end end diff --git a/lib/administrate/field/date.rb b/lib/administrate/field/date.rb index 04c89f93db..1d17b34d97 100644 --- a/lib/administrate/field/date.rb +++ b/lib/administrate/field/date.rb @@ -6,7 +6,7 @@ class Date < Base def date I18n.localize( data.to_date, - format: format, + format: format ) end diff --git a/lib/administrate/field/date_time.rb b/lib/administrate/field/date_time.rb index e7ce021d9d..2263af4d2a 100644 --- a/lib/administrate/field/date_time.rb +++ b/lib/administrate/field/date_time.rb @@ -6,7 +6,7 @@ class DateTime < Base def date I18n.localize( data.in_time_zone(timezone).to_date, - format: format, + format: format ) end @@ -14,7 +14,7 @@ def datetime I18n.localize( data.in_time_zone(timezone), format: format, - default: data, + default: data ) end diff --git a/lib/administrate/field/deferred.rb b/lib/administrate/field/deferred.rb index 88f7f23998..10609735af 100644 --- a/lib/administrate/field/deferred.rb +++ b/lib/administrate/field/deferred.rb @@ -35,7 +35,7 @@ def searchable? def searchable_field Administrate.deprecator.warn( - "searchable_field is deprecated, use searchable_fields instead", + "searchable_field is deprecated, use searchable_fields instead" ) options.fetch(:searchable_field) end diff --git a/lib/administrate/field/has_many.rb b/lib/administrate/field/has_many.rb index a5b7275603..8e14759cb9 100644 --- a/lib/administrate/field/has_many.rb +++ b/lib/administrate/field/has_many.rb @@ -18,14 +18,14 @@ def self.permitted_attribute(attr, _options = {}) # be `country_ids` instead. # # See https://github.com/rails/rails/blob/b30a23f53b52e59d31358f7b80385ee5c2ba3afe/activerecord/lib/active_record/associations/builder/collection_association.rb#L48 - { "#{attr.to_s.singularize}_ids".to_sym => [] } + {"#{attr.to_s.singularize}_ids": []} end def associated_collection(order = self.order) Administrate::Page::Collection.new( associated_dashboard, order: order, - collection_attributes: options[:collection_attributes], + collection_attributes: options[:collection_attributes] ) end @@ -37,7 +37,7 @@ def associated_resource_options candidate_resources.map do |associated_resource| [ display_candidate_resource(associated_resource), - associated_resource.send(association_primary_key), + associated_resource.send(association_primary_key) ] end end @@ -59,7 +59,7 @@ def paginate? def permitted_attribute self.class.permitted_attribute( attribute, - resource_class: resource.class, + resource_class: resource.class ) end @@ -82,7 +82,7 @@ def data def order_from_params(params) Administrate::Order.new( params.fetch(:order, sort_by), - params.fetch(:direction, direction), + params.fetch(:direction, direction) ) end diff --git a/lib/administrate/field/has_one.rb b/lib/administrate/field/has_one.rb index 760b5ad2d2..475685dd5b 100644 --- a/lib/administrate/field/has_one.rb +++ b/lib/administrate/field/has_one.rb @@ -20,10 +20,10 @@ def self.permitted_attribute(attr, options = {}) end end related_dashboard_attributes = - Administrate::ResourceResolver. - new("admin/#{final_associated_class_name}"). - dashboard_class.new.permitted_attributes + [:id] - { "#{attr}_attributes": related_dashboard_attributes } + Administrate::ResourceResolver + .new("admin/#{final_associated_class_name}") + .dashboard_class.new.permitted_attributes + [:id] + {"#{attr}_attributes": related_dashboard_attributes} end def self.eager_load? @@ -33,14 +33,14 @@ def self.eager_load? def nested_form @nested_form ||= Administrate::Page::Form.new( resolver.dashboard_class.new, - data || resolver.resource_class.new, + data || resolver.resource_class.new ) end def nested_show @nested_show ||= Administrate::Page::Show.new( resolver.dashboard_class.new, - data || resolver.resource_class.new, + data || resolver.resource_class.new ) end diff --git a/lib/administrate/field/number.rb b/lib/administrate/field/number.rb index 433795d12e..7c90b0f32f 100644 --- a/lib/administrate/field/number.rb +++ b/lib/administrate/field/number.rb @@ -38,8 +38,8 @@ def format(result) formatter = options[:format][:formatter] formatter_options = options[:format][:formatter_options].to_h - ActiveSupport::NumberHelper. - try(formatter, result, **formatter_options) || result + ActiveSupport::NumberHelper + .try(formatter, result, **formatter_options) || result end end end diff --git a/lib/administrate/field/polymorphic.rb b/lib/administrate/field/polymorphic.rb index aa0db6a0d8..420ad11c1d 100644 --- a/lib/administrate/field/polymorphic.rb +++ b/lib/administrate/field/polymorphic.rb @@ -4,7 +4,7 @@ module Administrate module Field class Polymorphic < BelongsTo def self.permitted_attribute(attr, _options = {}) - { attr => %i{type value} } + {attr => %i[type value]} end def associated_resource_grouped_options @@ -16,11 +16,11 @@ def associated_resource_grouped_options end def permitted_attribute - { attribute => %i{type value} } + {attribute => %i[type value]} end def selected_global_id - data ? data.to_global_id : nil + data&.to_global_id end private diff --git a/lib/administrate/generator_helpers.rb b/lib/administrate/generator_helpers.rb index e0f07a2c53..4ecd7fff3d 100644 --- a/lib/administrate/generator_helpers.rb +++ b/lib/administrate/generator_helpers.rb @@ -7,7 +7,7 @@ def call_generator(generator, *args) private def generator_options - { behavior: behavior } + {behavior: behavior} end end end diff --git a/lib/administrate/namespace/resource.rb b/lib/administrate/namespace/resource.rb index 19ab0213c7..cc1dd7e0fa 100644 --- a/lib/administrate/namespace/resource.rb +++ b/lib/administrate/namespace/resource.rb @@ -21,7 +21,7 @@ def name end def path - name.to_s.gsub("/", "_") + name.to_s.tr("/", "_") end end end diff --git a/lib/administrate/order.rb b/lib/administrate/order.rb index 8ac2ae5df3..f7d712a6f1 100644 --- a/lib/administrate/order.rb +++ b/lib/administrate/order.rb @@ -48,7 +48,7 @@ def reversed_direction_param_for(attr) end def opposite_direction - direction == :asc ? :desc : :asc + (direction == :asc) ? :desc : :asc end def order_by_association(relation) @@ -67,10 +67,10 @@ def order_by_association(relation) def order_by_count(relation) klass = reflect_association(relation).klass query = klass.arel_table[klass.primary_key].count.public_send(direction) - relation. - left_joins(attribute.to_sym). - group(:id). - reorder(query) + relation + .left_joins(attribute.to_sym) + .group(:id) + .reorder(query) end def order_by_belongs_to(relation) @@ -91,7 +91,7 @@ def order_by_has_one(relation) def order_by_attribute(relation) relation.joins( - attribute.to_sym, + attribute.to_sym ).reorder(order_by_attribute_query) end diff --git a/lib/administrate/page/base.rb b/lib/administrate/page/base.rb index f894898cb6..78fbf1a6bd 100644 --- a/lib/administrate/page/base.rb +++ b/lib/administrate/page/base.rb @@ -12,7 +12,7 @@ def resource_name end def resource_path - @resource_path ||= resource_name.gsub("/", "_") + @resource_path ||= resource_name.tr("/", "_") end def collection_includes diff --git a/lib/administrate/page/collection.rb b/lib/administrate/page/collection.rb index 60ad26ef79..9582c43365 100644 --- a/lib/administrate/page/collection.rb +++ b/lib/administrate/page/collection.rb @@ -5,7 +5,7 @@ module Page class Collection < Page::Base def attribute_names options.fetch(:collection_attributes, nil) || - dashboard.collection_attributes + dashboard.collection_attributes end def attributes_for(resource) @@ -25,7 +25,7 @@ def ordered_html_class(attr) delegate :ordered_by?, to: :order def order_params_for(attr, key: resource_name) - { key => order.order_params_for(attr) } + {key => order.order_params_for(attr)} end private diff --git a/lib/administrate/page/form.rb b/lib/administrate/page/form.rb index e7456d837d..4305a1f5e0 100644 --- a/lib/administrate/page/form.rb +++ b/lib/administrate/page/form.rb @@ -14,7 +14,7 @@ def attributes(action = nil) attributes = dashboard.form_attributes(action) if attributes.is_a? Array - attributes = { "" => attributes } + attributes = {"" => attributes} end attributes.transform_values do |attrs| diff --git a/lib/administrate/page/show.rb b/lib/administrate/page/show.rb index 22802465cb..569aab9607 100644 --- a/lib/administrate/page/show.rb +++ b/lib/administrate/page/show.rb @@ -18,7 +18,7 @@ def attributes attributes = dashboard.show_page_attributes if attributes.is_a? Array - attributes = { "" => attributes } + attributes = {"" => attributes} end attributes.transform_values do |attrs| diff --git a/lib/administrate/resource_resolver.rb b/lib/administrate/resource_resolver.rb index a3a24a7320..ed09472d3c 100644 --- a/lib/administrate/resource_resolver.rb +++ b/lib/administrate/resource_resolver.rb @@ -35,7 +35,7 @@ def model_path_parts end def controller_path_parts - path_parts = controller_path.split("/")[1..-1] + path_parts = controller_path.split("/")[1..] path_parts << path_parts.pop.singularize end diff --git a/lib/administrate/search.rb b/lib/administrate/search.rb index 304a84a8e1..ac04587c9f 100644 --- a/lib/administrate/search.rb +++ b/lib/administrate/search.rb @@ -59,8 +59,7 @@ def run @scoped_resource.all else results = search_results(@scoped_resource) - results = filter_results(results) - results + filter_results(results) end end @@ -112,9 +111,9 @@ def search_attributes end def search_results(resources) - resources. - left_joins(tables_to_join). - where(query_template, *query_values) + resources + .left_joins(tables_to_join) + .where(query_template, *query_values) end def valid_filters @@ -141,8 +140,8 @@ def query_table_name(attr) end ActiveRecord::Base.connection.quote_table_name(unquoted_table_name) else - ActiveRecord::Base.connection. - quote_table_name(@scoped_resource.table_name) + ActiveRecord::Base.connection + .quote_table_name(@scoped_resource.table_name) end end diff --git a/lib/administrate/view_generator.rb b/lib/administrate/view_generator.rb index 3591d2bf8e..2bbe887b6f 100644 --- a/lib/administrate/view_generator.rb +++ b/lib/administrate/view_generator.rb @@ -9,13 +9,13 @@ class ViewGenerator < Rails::Generators::Base :namespace, type: :string, desc: "Namespace where the admin dashboards live", - default: "admin", + default: "admin" ) def self.template_source_path File.expand_path( "../../../app/views/administrate/application", - __FILE__, + __FILE__ ) end @@ -30,7 +30,7 @@ def copy_resource_template(template_name) copy_file( template_file, - "app/views/#{namespace}/#{resource_path}/#{template_file}", + "app/views/#{namespace}/#{resource_path}/#{template_file}" ) end diff --git a/lib/generators/administrate/dashboard/dashboard_generator.rb b/lib/generators/administrate/dashboard/dashboard_generator.rb index 87513a3d4d..09ee0c0274 100644 --- a/lib/generators/administrate/dashboard/dashboard_generator.rb +++ b/lib/generators/administrate/dashboard/dashboard_generator.rb @@ -13,14 +13,14 @@ class DashboardGenerator < Rails::Generators::NamedBase time: "Field::Time", text: "Field::Text", string: "Field::String", - uuid: "Field::String", + uuid: "Field::String" } ATTRIBUTE_OPTIONS_MAPPING = { # procs must be defined in one line! - enum: { searchable: false, - collection: ->(field) { field.resource.class.send(field.attribute.to_s.pluralize).keys } }, - float: { decimals: 2 }, + enum: {searchable: false, + collection: ->(field) { field.resource.class.send(field.attribute.to_s.pluralize).keys }}, + float: {decimals: 2} } DEFAULT_FIELD_TYPE = "Field::String.with_options(searchable: false)" @@ -31,7 +31,7 @@ class DashboardGenerator < Rails::Generators::NamedBase :namespace, type: :string, desc: "Namespace where the admin dashboards live", - default: "admin", + default: "admin" ) source_root File.expand_path("../templates", __FILE__) @@ -39,13 +39,13 @@ class DashboardGenerator < Rails::Generators::NamedBase def create_dashboard_definition template( "dashboard.rb.erb", - Rails.root.join("app/dashboards/#{file_name}_dashboard.rb"), + Rails.root.join("app/dashboards/#{file_name}_dashboard.rb") ) end def create_resource_controller destination = Rails.root.join( - "app/controllers/#{namespace}/#{file_name.pluralize}_controller.rb", + "app/controllers/#{namespace}/#{file_name.pluralize}_controller.rb" ) template("controller.rb.erb", destination) @@ -72,7 +72,7 @@ def attributes primary_key, *attrs.sort, created_at, - updated_at, + updated_at ].compact end @@ -116,7 +116,7 @@ def column_type_for_attribute(attr) def enum_column?(attr) klass.respond_to?(:defined_enums) && - klass.defined_enums.keys.include?(attr) + klass.defined_enums.key?(attr) end def column_types(attr) diff --git a/lib/generators/administrate/field/field_generator.rb b/lib/generators/administrate/field/field_generator.rb index 577fe1efb3..5eb3821176 100644 --- a/lib/generators/administrate/field/field_generator.rb +++ b/lib/generators/administrate/field/field_generator.rb @@ -6,7 +6,7 @@ class FieldGenerator < Rails::Generators::NamedBase def template_field_object template( "field_object.rb.erb", - "app/fields/#{file_name}_field.rb", + "app/fields/#{file_name}_field.rb" ) end @@ -23,7 +23,7 @@ def copy_partial(partial_name) copy_file( partial, - "app/views/fields/#{file_name}_field/#{partial}", + "app/views/fields/#{file_name}_field/#{partial}" ) end end diff --git a/lib/generators/administrate/install/install_generator.rb b/lib/generators/administrate/install/install_generator.rb index 710799febd..1558382ef3 100644 --- a/lib/generators/administrate/install/install_generator.rb +++ b/lib/generators/administrate/install/install_generator.rb @@ -18,7 +18,7 @@ class InstallGenerator < Rails::Generators::Base :namespace, type: :string, desc: "Namespace where the admin dashboards will live", - default: "admin", + default: "admin" ) def run_routes_generator @@ -31,7 +31,7 @@ def run_routes_generator def create_dashboard_controller template( "application_controller.rb.erb", - "app/controllers/#{namespace}/application_controller.rb", + "app/controllers/#{namespace}/application_controller.rb" ) end diff --git a/lib/generators/administrate/routes/routes_generator.rb b/lib/generators/administrate/routes/routes_generator.rb index a92b236259..fe037f5af9 100644 --- a/lib/generators/administrate/routes/routes_generator.rb +++ b/lib/generators/administrate/routes/routes_generator.rb @@ -18,7 +18,7 @@ class RoutesGenerator < Rails::Generators::Base :namespace, type: :string, desc: "Namespace where the admin dashboards live", - default: "admin", + default: "admin" ) def insert_dashboard_routes @@ -61,10 +61,10 @@ def valid_dashboard_models end def database_models - ActiveRecord::Base.descendants. - reject(&:abstract_class?). - reject { |k| k < Administrate::Generators::TestRecord }. - sort_by(&:to_s) + ActiveRecord::Base.descendants + .reject(&:abstract_class?) + .reject { |k| k < Administrate::Generators::TestRecord } + .sort_by(&:to_s) end def invalid_dashboard_models diff --git a/lib/generators/administrate/views/field_generator.rb b/lib/generators/administrate/views/field_generator.rb index c883338d3a..91b8d0a745 100644 --- a/lib/generators/administrate/views/field_generator.rb +++ b/lib/generators/administrate/views/field_generator.rb @@ -7,7 +7,7 @@ class FieldGenerator < Administrate::ViewGenerator def self.template_source_path File.expand_path( "../../../../../app/views/fields/", - __FILE__, + __FILE__ ) end @@ -41,7 +41,7 @@ def copy_field_partial(resource_path, partial_name) copy_file( template_file, - "app/views/fields/#{template_file}", + "app/views/fields/#{template_file}" ) end end diff --git a/lib/generators/administrate/views/layout_generator.rb b/lib/generators/administrate/views/layout_generator.rb index 4936de5ac7..6f683ac728 100644 --- a/lib/generators/administrate/views/layout_generator.rb +++ b/lib/generators/administrate/views/layout_generator.rb @@ -9,7 +9,7 @@ class LayoutGenerator < Administrate::ViewGenerator def copy_template copy_file( "../../layouts/administrate/application.html.erb", - "app/views/layouts/admin/application.html.erb", + "app/views/layouts/admin/application.html.erb" ) call_generator("administrate:views:navigation") diff --git a/spec/administrate/views/fields/belongs_to/_index_spec.rb b/spec/administrate/views/fields/belongs_to/_index_spec.rb index 5ea69f7c61..edc245b2d2 100644 --- a/spec/administrate/views/fields/belongs_to/_index_spec.rb +++ b/spec/administrate/views/fields/belongs_to/_index_spec.rb @@ -10,7 +10,7 @@ "Administrate::Field::BelongsTo", associated_class: associated_class, display_associated_resource: product.name, - data: product, + data: product ) end @@ -19,7 +19,7 @@ instance_double( "Administrate::Field::BelongsTo", associated_class: associated_class, - data: nil, + data: nil ) end @@ -58,7 +58,7 @@ def render_belongs_to_index render( partial: "fields/belongs_to/index", - locals: { field: belongs_to, namespace: :admin }, + locals: {field: belongs_to, namespace: :admin} ) end end diff --git a/spec/administrate/views/fields/belongs_to/_show_spec.rb b/spec/administrate/views/fields/belongs_to/_show_spec.rb index f61a1ae416..b0b387fc59 100644 --- a/spec/administrate/views/fields/belongs_to/_show_spec.rb +++ b/spec/administrate/views/fields/belongs_to/_show_spec.rb @@ -10,7 +10,7 @@ "Administrate::Field::BelongsTo", associated_class: associated_class, display_associated_resource: product.name, - data: product, + data: product ) end @@ -43,7 +43,7 @@ def render_belongs_to_show render( partial: "fields/belongs_to/show", - locals: { field: belongs_to, namespace: :admin }, + locals: {field: belongs_to, namespace: :admin} ) end end diff --git a/spec/administrate/views/fields/date_time/_index_spec.rb b/spec/administrate/views/fields/date_time/_index_spec.rb index cd1f2c5c73..7cb7a306ff 100644 --- a/spec/administrate/views/fields/date_time/_index_spec.rb +++ b/spec/administrate/views/fields/date_time/_index_spec.rb @@ -8,12 +8,12 @@ format: #{Time::DATE_FORMATS[:default]} )", data: product, - datetime: product.created_at, + datetime: product.created_at ) render( partial: "fields/date_time/index", - locals: { field: date_time, namespace: :admin }, + locals: {field: date_time, namespace: :admin} ) end end diff --git a/spec/administrate/views/fields/has_many/_form_spec.rb b/spec/administrate/views/fields/has_many/_form_spec.rb index ccb473d865..4aafd90360 100644 --- a/spec/administrate/views/fields/has_many/_form_spec.rb +++ b/spec/administrate/views/fields/has_many/_form_spec.rb @@ -5,12 +5,12 @@ it "displays the association name" do has_many = double( attribute_key: :associated_object_ids, - attribute: :associated_objects, + attribute: :associated_objects ) render( partial: "fields/has_many/form", - locals: { f: fake_form_builder, field: has_many }, + locals: {f: fake_form_builder, field: has_many} ) expect(rendered).to include("Associated objects") diff --git a/spec/administrate/views/fields/has_many/_index_spec.rb b/spec/administrate/views/fields/has_many/_index_spec.rb index f36bc16c68..19d0c764a6 100644 --- a/spec/administrate/views/fields/has_many/_index_spec.rb +++ b/spec/administrate/views/fields/has_many/_index_spec.rb @@ -5,14 +5,14 @@ it "displays the pluralized attribute name" do has_many = double( data: double( - size: 0, + size: 0 ), - attribute: :teams, + attribute: :teams ) render( partial: "fields/has_many/index", - locals: { field: has_many }, + locals: {field: has_many} ) expect(rendered.strip).to eq("0 teams") @@ -23,14 +23,14 @@ it "displays the singularized attribute name" do has_many = double( data: double( - size: 1, + size: 1 ), - attribute: :teams, + attribute: :teams ) render( partial: "fields/has_many/index", - locals: { field: has_many }, + locals: {field: has_many} ) expect(rendered.strip).to eq("1 team") @@ -41,14 +41,14 @@ it "displays the pluralized attribute name" do has_many = double( data: double( - size: 2, + size: 2 ), - attribute: :teams, + attribute: :teams ) render( partial: "fields/has_many/index", - locals: { field: has_many }, + locals: {field: has_many} ) expect(rendered.strip).to eq("2 teams") diff --git a/spec/administrate/views/fields/has_many/_show_spec.rb b/spec/administrate/views/fields/has_many/_show_spec.rb index 12a09aa6c8..c3fe9aa0b9 100644 --- a/spec/administrate/views/fields/has_many/_show_spec.rb +++ b/spec/administrate/views/fields/has_many/_show_spec.rb @@ -7,7 +7,7 @@ render( partial: "fields/has_many/show", - locals: { field: has_many }, + locals: {field: has_many} ) expect(rendered.strip).to eq(t("administrate.fields.has_many.none")) diff --git a/spec/administrate/views/fields/has_one/_form_spec.rb b/spec/administrate/views/fields/has_one/_form_spec.rb index ee1a01a03e..fb7183e23e 100644 --- a/spec/administrate/views/fields/has_one/_form_spec.rb +++ b/spec/administrate/views/fields/has_one/_form_spec.rb @@ -8,12 +8,12 @@ attribute: "Meta", data: nil, nested_form: nested_form, - name: "product_tag", + name: "product_tag" ) render( partial: "fields/has_one/form", - locals: { field: has_one, f: form_builder }, + locals: {field: has_one, f: form_builder} ) expect(rendered.strip).to include("Product Tag") @@ -32,10 +32,10 @@ def nested_form instance_double( "Administrate::Page::Show", resource: double( - class: ProductMetaTag, + class: ProductMetaTag ), attributes: [], - resource_name: "Product Tag", + resource_name: "Product Tag" ) end end diff --git a/spec/administrate/views/fields/has_one/_index_spec.rb b/spec/administrate/views/fields/has_one/_index_spec.rb index 6093d745b2..e30074bb4b 100644 --- a/spec/administrate/views/fields/has_one/_index_spec.rb +++ b/spec/administrate/views/fields/has_one/_index_spec.rb @@ -9,7 +9,7 @@ "Administrate::Field::HasOne", data: product, linkable?: true, - display_associated_resource: product.name, + display_associated_resource: product.name ) end @@ -17,7 +17,7 @@ let(:has_one) do instance_double( "Administrate::Field::HasOne", - linkable?: false, + linkable?: false ) end @@ -57,7 +57,7 @@ def render_has_one_index render( partial: "fields/has_one/index", - locals: { field: has_one, namespace: :admin }, + locals: {field: has_one, namespace: :admin} ) end end diff --git a/spec/administrate/views/fields/has_one/_show_spec.rb b/spec/administrate/views/fields/has_one/_show_spec.rb index 6afefc0b23..5bc71c57b7 100644 --- a/spec/administrate/views/fields/has_one/_show_spec.rb +++ b/spec/administrate/views/fields/has_one/_show_spec.rb @@ -13,12 +13,12 @@ has_one = Administrate::Field::HasOne.new( :product_meta_tag, build(:product_meta_tag), - :show, + :show ) render( partial: "fields/has_one/show", - locals: { field: has_one }, + locals: {field: has_one} ) expect(rendered.strip).to eq("") @@ -35,17 +35,17 @@ name: "simple_string_field", truncate: "string value", html_class: "string", - to_partial_path: "fields/string/index", + to_partial_path: "fields/string/index" ) nested_show_page_for_has_one = instance_double( "Administrate::Page::Show", resource: double( - class: ProductMetaTag, + class: ProductMetaTag ), - attributes: { "" => [ - nested_simple_field, - ] }, + attributes: {"" => [ + nested_simple_field + ]} ) @has_one_field = instance_double( @@ -54,7 +54,7 @@ data: field_resource, linkable?: true, nested_show: nested_show_page_for_has_one, - associated_class_name: "NestedHasOne", + associated_class_name: "NestedHasOne" ) @page_double = instance_double("Administrate::Page::Show") @@ -66,8 +66,8 @@ def render_field locals: { field: @has_one_field, page: @page_double, - resource_name: "parent_resource", - }, + resource_name: "parent_resource" + } ) end @@ -76,10 +76,10 @@ def render_field helpers: { label: { nested_has_one: { - simple_string_field: "Just a Simple String", - }, - }, - }, + simple_string_field: "Just a Simple String" + } + } + } ) render_field @@ -123,15 +123,15 @@ def render_field data: nested_collection, html_class: "has-many", name: "payments", - to_partial_path: "fields/has_many/index", + to_partial_path: "fields/has_many/index" ) nested_show_page_for_nested_has_one = instance_double( "Administrate::Page::Show", resource: double( - class: ProductMetaTag, + class: ProductMetaTag ), - attributes: { "" => [] }, + attributes: {"" => []} ) nested_has_one = instance_double( @@ -143,12 +143,12 @@ def render_field html_class: "has-one", to_partial_path: "fields/has_one/show", display_associated_resource: "Resource Doubly Nested with HasOne", - name: "page", + name: "page" ) nested_show_page_for_top_has_one = instance_double( "Administrate::Page::Show", - attributes: { "" => [nested_has_one, nested_has_many] }, + attributes: {"" => [nested_has_one, nested_has_many]} ) has_one_field = instance_double( @@ -157,7 +157,7 @@ def render_field data: field_resource, linkable?: true, nested_show: nested_show_page_for_top_has_one, - associated_class_name: "NameOfAssociatedClass", + associated_class_name: "NameOfAssociatedClass" ) page_double = instance_double("Administrate::Page::Show") @@ -167,8 +167,8 @@ def render_field locals: { field: has_one_field, page: page_double, - resource_name: "product_meta_tag", - }, + resource_name: "product_meta_tag" + } ) expect(rendered.strip).to include("Resource Nested with HasOne") diff --git a/spec/administrate/views/fields/polymorphic/_form_spec.rb b/spec/administrate/views/fields/polymorphic/_form_spec.rb index 42be7b93b9..c546fac2ee 100644 --- a/spec/administrate/views/fields/polymorphic/_form_spec.rb +++ b/spec/administrate/views/fields/polymorphic/_form_spec.rb @@ -6,7 +6,7 @@ render( partial: "fields/polymorphic/form", - locals: { field: polymorphic, f: fake_form_builder }, + locals: {field: polymorphic, f: fake_form_builder} ) expect(rendered).to include("Parent") diff --git a/spec/administrate/views/fields/polymorphic/_index_spec.rb b/spec/administrate/views/fields/polymorphic/_index_spec.rb index f0c1d72218..406b8954d8 100644 --- a/spec/administrate/views/fields/polymorphic/_index_spec.rb +++ b/spec/administrate/views/fields/polymorphic/_index_spec.rb @@ -8,7 +8,7 @@ instance_double( "Administrate::Field::Polymorphic", data: product, - display_associated_resource: product.name, + display_associated_resource: product.name ) end @@ -16,7 +16,7 @@ let(:polymorphic) do instance_double( "Administrate::Field::Polymorphic", - data: nil, + data: nil ) end @@ -55,7 +55,7 @@ def render_polymorphic_index render( partial: "fields/polymorphic/index", - locals: { field: polymorphic, namespace: :admin }, + locals: {field: polymorphic, namespace: :admin} ) end end diff --git a/spec/administrate/views/fields/polymorphic/_show_spec.rb b/spec/administrate/views/fields/polymorphic/_show_spec.rb index 9e19f2d480..051e897fd6 100644 --- a/spec/administrate/views/fields/polymorphic/_show_spec.rb +++ b/spec/administrate/views/fields/polymorphic/_show_spec.rb @@ -8,12 +8,12 @@ polymorphic = instance_double( "Administrate::Field::Polymorphic", display_associated_resource: "", - data: nil, + data: nil ) render( partial: "fields/polymorphic/show", - locals: { field: polymorphic }, + locals: {field: polymorphic} ) expect(rendered.strip).to eq("") @@ -28,14 +28,14 @@ "Administrate::Field::Polymorphic", display_associated_resource: product.name, data: product, - attribute: "product", + attribute: "product" ) allow(view).to receive(:accessible_action?).and_return(true) render( partial: "fields/polymorphic/show", - locals: { field: polymorphic, namespace: :admin }, + locals: {field: polymorphic, namespace: :admin} ) expected = "#{product.name}" diff --git a/spec/administrate/views/fields/select/_edit_spec.rb b/spec/administrate/views/fields/select/_edit_spec.rb index 045d575f65..45447d7c3b 100644 --- a/spec/administrate/views/fields/select/_edit_spec.rb +++ b/spec/administrate/views/fields/select/_edit_spec.rb @@ -9,17 +9,17 @@ attribute: :email_subscriber, data: false, selectable_options: [true, false, nil], - include_blank_option: false, + include_blank_option: false ) render( partial: "fields/select/form", - locals: { field: select, f: form_builder(customer) }, + locals: {field: select, f: form_builder(customer)} ) expect(rendered).to have_css( - %{select[name="customer[email_subscriber]"] - option[value="false"][selected="selected"]}, + %(select[name="customer[email_subscriber]"] + option[value="false"][selected="selected"]) ) end @@ -30,17 +30,17 @@ attribute: :email_subscriber, data: "Yes", selectable_options: ["Yes", "No"], - include_blank_option: "Unknown", + include_blank_option: "Unknown" ) render( partial: "fields/select/form", - locals: { field: select, f: form_builder(customer) }, + locals: {field: select, f: form_builder(customer)} ) expect(rendered).to have_css( - %{select[name="customer[email_subscriber]"] option[value=""]}, - text: "Unknown", + %(select[name="customer[email_subscriber]"] option[value=""]), + text: "Unknown" ) end @@ -49,7 +49,7 @@ def form_builder(object) object.model_name.singular, object, build_template, - {}, + {} ) end diff --git a/spec/administrate/views/fields/time/_index_spec.rb b/spec/administrate/views/fields/time/_index_spec.rb index dd6ee9af4f..ff0b2ead04 100644 --- a/spec/administrate/views/fields/time/_index_spec.rb +++ b/spec/administrate/views/fields/time/_index_spec.rb @@ -7,7 +7,7 @@ render( partial: "fields/time/index", - locals: { field: time }, + locals: {field: time} ) expect(rendered.strip).to eq("") @@ -21,11 +21,11 @@ time = instance_double( "Administrate::Field::Time", data: customer.example_time, - time: "12:34PM", + time: "12:34PM" ) render( partial: "fields/time/index", - locals: { field: time, namespace: :admin }, + locals: {field: time, namespace: :admin} ) expect(rendered.strip).to eq("12:34PM") diff --git a/spec/administrate/views/fields/url/_form_spec.rb b/spec/administrate/views/fields/url/_form_spec.rb index 2c739a62a6..642a3e7aa5 100644 --- a/spec/administrate/views/fields/url/_form_spec.rb +++ b/spec/administrate/views/fields/url/_form_spec.rb @@ -7,15 +7,15 @@ url = instance_double( "Administrate::Field::Url", attribute: :image_url, - data: nil, + data: nil ) render( partial: "fields/url/form", - locals: { field: url, f: form_builder(product) }, + locals: {field: url, f: form_builder(product)} ) - expect(rendered).to have_css(%{input[type="url"][name="product[image_url]"]}) + expect(rendered).to have_css(%(input[type="url"][name="product[image_url]"])) end def form_builder(object) @@ -23,7 +23,7 @@ def form_builder(object) object.model_name.singular, object, build_template, - {}, + {} ) end diff --git a/spec/administrate/views/fields/url/_index_spec.rb b/spec/administrate/views/fields/url/_index_spec.rb index e5719ae215..d6fb1e809b 100644 --- a/spec/administrate/views/fields/url/_index_spec.rb +++ b/spec/administrate/views/fields/url/_index_spec.rb @@ -9,17 +9,17 @@ url = instance_double( "Administrate::Field::Url", data: product.image_url, - html_options: {}, + html_options: {} ) render( partial: "fields/url/index", - locals: { field: url, namespace: :admin }, + locals: {field: url, namespace: :admin} ) expect(rendered).to have_css( - %{a[href="#{product.image_url}"]}, - text: product.image_url, + %(a[href="#{product.image_url}"]), + text: product.image_url ) end @@ -27,17 +27,17 @@ url = instance_double( "Administrate::Field::Url", data: product.image_url, - html_options: { referrerpolicy: "no-referrer" }, + html_options: {referrerpolicy: "no-referrer"} ) render( partial: "fields/url/show", - locals: { field: url, namespace: :admin }, + locals: {field: url, namespace: :admin} ) expect(rendered).to have_css( - %{a[href="#{product.image_url}"][referrerpolicy="no-referrer"]}, - text: product.image_url, + %(a[href="#{product.image_url}"][referrerpolicy="no-referrer"]), + text: product.image_url ) end end diff --git a/spec/administrate/views/fields/url/_show_spec.rb b/spec/administrate/views/fields/url/_show_spec.rb index e4d0c16d6f..a12e733dc0 100644 --- a/spec/administrate/views/fields/url/_show_spec.rb +++ b/spec/administrate/views/fields/url/_show_spec.rb @@ -9,17 +9,17 @@ url = instance_double( "Administrate::Field::Url", data: product.image_url, - html_options: {}, + html_options: {} ) render( partial: "fields/url/show", - locals: { field: url, namespace: :admin }, + locals: {field: url, namespace: :admin} ) expect(rendered).to have_css( - %{a[href="#{product.image_url}"]}, - text: product.image_url, + %(a[href="#{product.image_url}"]), + text: product.image_url ) end @@ -27,17 +27,17 @@ url = instance_double( "Administrate::Field::Url", data: product.image_url, - html_options: { target: "_blank" }, + html_options: {target: "_blank"} ) render( partial: "fields/url/show", - locals: { field: url, namespace: :admin }, + locals: {field: url, namespace: :admin} ) expect(rendered).to have_css( - %{a[href="#{product.image_url}"][target="_blank"]}, - text: product.image_url, + %(a[href="#{product.image_url}"][target="_blank"]), + text: product.image_url ) end end diff --git a/spec/controllers/admin/application_controller_spec.rb b/spec/controllers/admin/application_controller_spec.rb index 82900a1e24..3aa2b46dde 100644 --- a/spec/controllers/admin/application_controller_spec.rb +++ b/spec/controllers/admin/application_controller_spec.rb @@ -4,7 +4,7 @@ describe "redirections after actions" do controller(Admin::OrdersController) do def after_resource_destroyed_path(_requested_resource) - { action: :index, controller: :customers } + {action: :index, controller: :customers} end def after_resource_created_path(requested_resource) @@ -19,7 +19,7 @@ def after_resource_updated_path(requested_resource) it "redirect to custom route after destroy" do order = create(:order) - delete :destroy, params: { id: order.to_param } + delete :destroy, params: {id: order.to_param} expect(response).to redirect_to(admin_customers_path) end @@ -30,18 +30,18 @@ def after_resource_updated_path(requested_resource) "id", "created_at", "updated_at", - "shipped_at", + "shipped_at" ) - post :create, params: { order: params } + post :create, params: {order: params} expect(response).to redirect_to(admin_customer_path(customer)) end it "redirect to custom route after update" do order = create(:order) - order_params = { address_line_one: order.address_line_one } + order_params = {address_line_one: order.address_line_one} - put :update, params: { id: order.to_param, order: order_params } + put :update, params: {id: order.to_param, order: order_params} expect(response).to redirect_to(admin_customer_path(order.customer)) end end @@ -64,10 +64,10 @@ def create "id", "created_at", "updated_at", - "shipped_at", + "shipped_at" ) - post :create, params: { order: params } + post :create, params: {order: params} expect(controller.resource).to be_a(Order) end @@ -90,14 +90,14 @@ def authorized_action?(resource, _action) it "authorizes allowed actions" do resource = FactoryBot.create(:order, address_zip: "666") - expect { get :show, params: { id: resource.id } }. - not_to raise_error + expect { get :show, params: {id: resource.id} } + .not_to raise_error end it "does not authorize disallowed actions" do resource = FactoryBot.create(:order, address_zip: "667") - expect { get :show, params: { id: resource.id } }. - to raise_error(Administrate::NotAuthorizedError) + expect { get :show, params: {id: resource.id} } + .to raise_error(Administrate::NotAuthorizedError) end end @@ -112,8 +112,8 @@ def index allow(Administrate.deprecator).to receive(:warn) get :index expect(Administrate.deprecator).to( - have_received(:warn). - with(/`show_action\?` is deprecated/), + have_received(:warn) + .with(/`show_action\?` is deprecated/) ) end end @@ -129,8 +129,8 @@ def index allow(Administrate.deprecator).to receive(:warn) get :index expect(Administrate.deprecator).to( - have_received(:warn). - with(/`valid_action\?` is deprecated/), + have_received(:warn) + .with(/`valid_action\?` is deprecated/) ) end end diff --git a/spec/controllers/admin/blog/posts_controller_spec.rb b/spec/controllers/admin/blog/posts_controller_spec.rb index 4c02019c0f..d628da56a0 100644 --- a/spec/controllers/admin/blog/posts_controller_spec.rb +++ b/spec/controllers/admin/blog/posts_controller_spec.rb @@ -11,7 +11,7 @@ it "passes the search term to the view" do locals = capture_view_locals do - get :index, params: { search: "foo" } + get :index, params: {search: "foo"} end expect(locals[:search_term]).to eq("foo") @@ -29,7 +29,7 @@ blog_post = create(:blog_post) locals = capture_view_locals do - get :show, params: { id: blog_post.to_param } + get :show, params: {id: blog_post.to_param} end page = locals[:page] @@ -51,7 +51,7 @@ blog_post = create(:blog_post) locals = capture_view_locals do - get :edit, params: { id: blog_post.to_param } + get :edit, params: {id: blog_post.to_param} end page = locals[:page] @@ -64,12 +64,12 @@ context "with valid params" do it "creates a new blog post" do expect do - post :create, params: { blog_post: attributes_for(:blog_post) } + post :create, params: {blog_post: attributes_for(:blog_post)} end.to change(Blog::Post, :count).by(1) end it "redirects to the created blog post" do - post :create, params: { blog_post: attributes_for(:blog_post) } + post :create, params: {blog_post: attributes_for(:blog_post)} expect(response).to redirect_to([:admin, Blog::Post.last]) end @@ -79,10 +79,10 @@ render_views it "passes a form page object to the view" do - invalid_attributes = { title: "" } + invalid_attributes = {title: ""} locals = capture_view_locals do - post :create, params: { blog_post: invalid_attributes } + post :create, params: {blog_post: invalid_attributes} end page = locals[:page] @@ -91,9 +91,9 @@ end it "re-renders the 'new' template" do - invalid_attributes = { title: "" } + invalid_attributes = {title: ""} - post :create, params: { blog_post: invalid_attributes } + post :create, params: {blog_post: invalid_attributes} expect(page.find("h1")).to have_content "New Blog Post" end @@ -104,11 +104,11 @@ context "with valid params" do it "updates the requested blog post" do blog_post = create(:blog_post, title: "old title") - new_attributes = { title: "new title" } + new_attributes = {title: "new title"} put( :update, - params: { id: blog_post.to_param, blog_post: new_attributes }, + params: {id: blog_post.to_param, blog_post: new_attributes} ) blog_post.reload @@ -121,7 +121,7 @@ put( :update, - params: { id: blog_post.to_param, blog_post: valid_attributes }, + params: {id: blog_post.to_param, blog_post: valid_attributes} ) blog_post.reload @@ -134,14 +134,14 @@ it "re-renders the 'edit' template" do blog_post = create(:blog_post) - invalid_attributes = { title: "" } + invalid_attributes = {title: ""} put( :update, params: { id: blog_post.to_param, - blog_post: invalid_attributes, - }, + blog_post: invalid_attributes + } ) expect(page.find("h1")).to have_content "Edit" @@ -149,15 +149,15 @@ it "passes a form page object to the view" do blog_post = create(:blog_post) - invalid_attributes = { title: "" } + invalid_attributes = {title: ""} locals = capture_view_locals do put( :update, params: { id: blog_post.to_param, - blog_post: invalid_attributes, - }, + blog_post: invalid_attributes + } ) end @@ -173,14 +173,14 @@ blog_post = create(:blog_post) expect do - delete :destroy, params: { id: blog_post.to_param } + delete :destroy, params: {id: blog_post.to_param} end.to change(Blog::Post, :count).by(-1) end it "redirects to the blog posts list" do blog_post = create(:blog_post) - delete :destroy, params: { id: blog_post.to_param } + delete :destroy, params: {id: blog_post.to_param} expect(response).to redirect_to(admin_blog_posts_path) end diff --git a/spec/controllers/admin/customers_controller_spec.rb b/spec/controllers/admin/customers_controller_spec.rb index 805df1f662..84e88d44c6 100644 --- a/spec/controllers/admin/customers_controller_spec.rb +++ b/spec/controllers/admin/customers_controller_spec.rb @@ -19,7 +19,7 @@ it "passes the search term to the view" do locals = capture_view_locals do - get :index, params: { search: "foo" } + get :index, params: {search: "foo"} end expect(locals[:search_term]).to eq("foo") @@ -32,7 +32,7 @@ end it "shows the search bar" do - customer = create(:customer) + create(:customer) locals = capture_view_locals { get :index } expect(locals[:show_search_bar]).to be_truthy @@ -73,7 +73,7 @@ def default_sorting_direction customer = create(:customer) locals = capture_view_locals do - get :show, params: { id: customer.to_param } + get :show, params: {id: customer.to_param} end page = locals[:page] @@ -95,7 +95,7 @@ def default_sorting_direction customer = create(:customer) locals = capture_view_locals do - get :edit, params: { id: customer.to_param } + get :edit, params: {id: customer.to_param} end page = locals[:page] @@ -108,12 +108,12 @@ def default_sorting_direction describe "with valid params" do it "creates a new Customer" do expect { - post :create, params: { customer: attributes_for(:customer) } + post :create, params: {customer: attributes_for(:customer)} }.to change(Customer, :count).by(1) end it "redirects to the created customer" do - post :create, params: { customer: attributes_for(:customer) } + post :create, params: {customer: attributes_for(:customer)} expect(response).to redirect_to([:admin, Customer.last]) end @@ -121,10 +121,10 @@ def default_sorting_direction describe "with invalid params" do it "passes a form page object to the view" do - invalid_attributes = { name: "" } + invalid_attributes = {name: ""} locals = capture_view_locals do - post :create, params: { customer: invalid_attributes } + post :create, params: {customer: invalid_attributes} end page = locals[:page] @@ -135,10 +135,10 @@ def default_sorting_direction describe "with empty string param" do it "sets empty string value to nil" do - empty_string_attributes = { country_code: "" } + empty_string_attributes = {country_code: ""} locals = capture_view_locals do - post :create, params: { customer: empty_string_attributes } + post :create, params: {customer: empty_string_attributes} end page = locals[:page] @@ -152,9 +152,9 @@ def default_sorting_direction it "updates the requested customer" do customer = create(:customer) new_name = "new name" - new_attributes = { name: new_name } + new_attributes = {name: new_name} - put :update, params: { id: customer.to_param, customer: new_attributes } + put :update, params: {id: customer.to_param, customer: new_attributes} customer.reload expect(customer.name).to eq new_name @@ -166,7 +166,7 @@ def default_sorting_direction put( :update, - params: { id: customer.to_param, customer: valid_attributes }, + params: {id: customer.to_param, customer: valid_attributes} ) expect(response).to redirect_to([:admin, customer]) @@ -176,12 +176,12 @@ def default_sorting_direction describe "with invalid params" do it "passes a form page object to the view" do customer = create(:customer) - invalid_attributes = { name: "" } + invalid_attributes = {name: ""} locals = capture_view_locals do put( :update, - params: { id: customer.to_param, customer: invalid_attributes }, + params: {id: customer.to_param, customer: invalid_attributes} ) end @@ -197,14 +197,14 @@ def default_sorting_direction customer = create(:customer) expect do - delete :destroy, params: { id: customer.to_param } + delete :destroy, params: {id: customer.to_param} end.to change(Customer, :count).by(-1) end it "redirects to the customers list" do customer = create(:customer) - delete :destroy, params: { id: customer.to_param } + delete :destroy, params: {id: customer.to_param} expect(response).to redirect_to(admin_customers_url) end diff --git a/spec/controllers/admin/log_entries_controller_spec.rb b/spec/controllers/admin/log_entries_controller_spec.rb index fba486fd00..c55467a210 100644 --- a/spec/controllers/admin/log_entries_controller_spec.rb +++ b/spec/controllers/admin/log_entries_controller_spec.rb @@ -7,10 +7,10 @@ def post_create(action: "create", logeable: create(:customer)) action: action, logeable: { type: "Administrate::Field::Polymorphic", - value: logeable.to_global_id.to_s, - }, + value: logeable.to_global_id.to_s + } ) - post :create, params: { log_entry: resource_params } + post :create, params: {log_entry: resource_params} end describe "with valid params" do @@ -36,15 +36,15 @@ def post_create(action: "create", logeable: create(:customer)) params: { logeable: { type: "Administrate::Field::Polymorphic", - value: customer.to_global_id.to_s, - }, - }, - }, - }, + value: customer.to_global_id.to_s + } + } + } + } ) allow_any_instance_of( - LogEntryDashboard, + LogEntryDashboard ).to receive(:permitted_attributes).and_return( [ arbitrarily: { @@ -52,23 +52,23 @@ def post_create(action: "create", logeable: create(:customer)) params: { logeable: [ :type, - :value, - ], - }, - }, - }, - ], + :value + ] + } + } + } + ] ) LogEntry.attr_accessor :arbitrarily - post :create, params: { log_entry: resource_params } + post :create, params: {log_entry: resource_params} logeable_in_params = subject.send(:resource_params).dig( :arbitrarily, :nested, :params, - :logeable, + :logeable ) expect(logeable_in_params).to eq(customer) end @@ -95,10 +95,10 @@ def put_update(original, action: "create", logeable: create(:customer)) action: action, logeable: { type: "Administrate::Field::Polymorphic", - value: logeable.to_global_id.to_s, - }, + value: logeable.to_global_id.to_s + } ) - put :update, params: { id: original.to_param, log_entry: resource_params } + put :update, params: {id: original.to_param, log_entry: resource_params} end describe "with valid params" do diff --git a/spec/controllers/admin/orders_controller_spec.rb b/spec/controllers/admin/orders_controller_spec.rb index da0a0f4728..f0fd4f43df 100644 --- a/spec/controllers/admin/orders_controller_spec.rb +++ b/spec/controllers/admin/orders_controller_spec.rb @@ -3,6 +3,7 @@ # Test Authorization by using the Pundit concern and an example policy, # which will test all the authorization functionality. +# standard:disable Lint/ConstantDefinitionInBlock describe Admin::OrdersController, type: :controller do context "with namespaced Punditize concern" do controller(Admin::OrdersController) do @@ -41,14 +42,14 @@ def pundit_user describe "GET edit" do it "allows me to edit my records" do order = create :order, customer: user - expect { get :edit, params: { id: order.id } }.not_to raise_error + expect { get :edit, params: {id: order.id} }.not_to raise_error end it "does not allow me to see other users' records" do other_user = create(:customer) order = create(:order, customer: other_user) - expect { get :show, params: { id: order.id } }. - to raise_error(ActiveRecord::RecordNotFound) + expect { get :show, params: {id: order.id} } + .to raise_error(ActiveRecord::RecordNotFound) end end @@ -58,8 +59,8 @@ def send_request(order:) :update, params: { id: order.id, - order: { address_line_one: "22 Acacia Avenue" }, - }, + order: {address_line_one: "22 Acacia Avenue"} + } ) end @@ -82,8 +83,8 @@ def send_request(order:) describe "DELETE destroy" do it "never allows me to delete a record" do o = create :order, customer: user, address_state: "AZ" - expect { delete :destroy, params: { id: o.id } }. - to raise_error(Pundit::NotAuthorizedError) + expect { delete :destroy, params: {id: o.id} } + .to raise_error(Pundit::NotAuthorizedError) end end @@ -147,8 +148,8 @@ def pundit_user locals = capture_view_locals { get :index } expect(locals[:resources]).to contain_exactly(order1, order3) - expect(Administrate.deprecator).to have_received(:warn). - with(/`resolve_admin` method is deprecated/) + expect(Administrate.deprecator).to have_received(:warn) + .with(/`resolve_admin` method is deprecated/) end end @@ -161,18 +162,18 @@ def pundit_user describe "GET edit" do it "allows me to edit my records" do order = create :order, customer: user - expect { get :edit, params: { id: order.id } }.not_to raise_error - expect(Administrate.deprecator).to have_received(:warn). - with(/`resolve_admin` method is deprecated/) + expect { get :edit, params: {id: order.id} }.not_to raise_error + expect(Administrate.deprecator).to have_received(:warn) + .with(/`resolve_admin` method is deprecated/) end it "does not allow me to see other users' records" do other_user = create(:customer) order = create(:order, customer: other_user) - expect { get :show, params: { id: order.id } }. - to raise_error(ActiveRecord::RecordNotFound) - expect(Administrate.deprecator).to have_received(:warn). - with(/`resolve_admin` method is deprecated/) + expect { get :show, params: {id: order.id} } + .to raise_error(ActiveRecord::RecordNotFound) + expect(Administrate.deprecator).to have_received(:warn) + .with(/`resolve_admin` method is deprecated/) end end @@ -182,8 +183,8 @@ def send_request(order:) :update, params: { id: order.id, - order: { address_line_one: "22 Acacia Avenue" }, - }, + order: {address_line_one: "22 Acacia Avenue"} + } ) end @@ -192,8 +193,8 @@ def send_request(order:) send_request(order: order) expect(response).to redirect_to([:admin, order]) expect(order.reload.address_line_one).to eq("22 Acacia Avenue") - expect(Administrate.deprecator).to have_received(:warn). - with(/`resolve_admin` method is deprecated/) + expect(Administrate.deprecator).to have_received(:warn) + .with(/`resolve_admin` method is deprecated/) end it "does not allow me to update other users' records" do @@ -202,16 +203,16 @@ def send_request(order:) expect do send_request(order: order) end.to raise_error(ActiveRecord::RecordNotFound) - expect(Administrate.deprecator).to have_received(:warn). - with(/`resolve_admin` method is deprecated/) + expect(Administrate.deprecator).to have_received(:warn) + .with(/`resolve_admin` method is deprecated/) end end describe "DELETE destroy" do it "never allows me to delete a record" do o = create :order, customer: user, address_state: "AZ" - expect { delete :destroy, params: { id: o.id } }. - to raise_error(Pundit::NotAuthorizedError) + expect { delete :destroy, params: {id: o.id} } + .to raise_error(Pundit::NotAuthorizedError) end end @@ -234,3 +235,4 @@ def send_request(order:) end end end +# standard:enable Lint/ConstantDefinitionInBlock diff --git a/spec/controllers/concerns/administrate/punditize_spec.rb b/spec/controllers/concerns/administrate/punditize_spec.rb index ae13983db1..7575cfa659 100644 --- a/spec/controllers/concerns/administrate/punditize_spec.rb +++ b/spec/controllers/concerns/administrate/punditize_spec.rb @@ -24,7 +24,7 @@ def unload_constants yield - Object.const_set("Pundit", original) + Object.const_set(:Pundit, original) end def reload_punditize @@ -36,7 +36,7 @@ def reload_punditize "controllers", "concerns", "administrate", - "punditize.rb", + "punditize.rb" ) end diff --git a/spec/dashboards/customer_dashboard_spec.rb b/spec/dashboards/customer_dashboard_spec.rb index a9350a1e0c..79cedf2a39 100644 --- a/spec/dashboards/customer_dashboard_spec.rb +++ b/spec/dashboards/customer_dashboard_spec.rb @@ -12,15 +12,15 @@ describe "#attribute_types" do it "maps each attribute to an attribute field" do - Field = Administrate::Field + stub_const("Field", Administrate::Field) dashboard = CustomerDashboard.new fields = dashboard.attribute_types expect(fields[:name]).to eq(Field::String) expect(fields[:email]).to eq(Field::Email) - expect(fields[:lifetime_value]). - to eq(Field::Number.with_options(prefix: "$", decimals: 2)) + expect(fields[:lifetime_value]) + .to eq(Field::Number.with_options(prefix: "$", decimals: 2)) end end @@ -40,8 +40,8 @@ def missing_attribute_message(attribute, dashboard_class) context "for a non-existent attribute" do it "raises an exception" do dashboard = CustomerDashboard.new - expect { dashboard.attribute_type_for(:foo) }. - to raise_error missing_attribute_message("foo", "CustomerDashboard") + expect { dashboard.attribute_type_for(:foo) } + .to raise_error missing_attribute_message("foo", "CustomerDashboard") end end end @@ -53,7 +53,7 @@ def missing_attribute_message(attribute, dashboard_class) fields = dashboard.attribute_types_for([:name, :email]) expect(fields).to match( name: Administrate::Field::String, - email: Administrate::Field::Email, + email: Administrate::Field::Email ) end end @@ -61,8 +61,8 @@ def missing_attribute_message(attribute, dashboard_class) context "for one non-existent attribute" do it "raises an exception" do dashboard = CustomerDashboard.new - expect { dashboard.attribute_types_for([:name, :foo]) }. - to raise_error missing_attribute_message("foo", "CustomerDashboard") + expect { dashboard.attribute_types_for([:name, :foo]) } + .to raise_error missing_attribute_message("foo", "CustomerDashboard") end end end diff --git a/spec/dashboards/line_item_dashboard_spec.rb b/spec/dashboards/line_item_dashboard_spec.rb index ee6778f89b..94f5d36a5b 100644 --- a/spec/dashboards/line_item_dashboard_spec.rb +++ b/spec/dashboards/line_item_dashboard_spec.rb @@ -16,7 +16,7 @@ product quantity unit_price - ], + ] ) end end @@ -29,7 +29,7 @@ %i[ order product - ], + ] ) end end @@ -43,7 +43,7 @@ order product quantity - ], + ] ) end end @@ -58,7 +58,7 @@ product quantity unit_price - ], + ] ) end end diff --git a/spec/example_app/app/controllers/admin/log_entries_controller.rb b/spec/example_app/app/controllers/admin/log_entries_controller.rb index ef95094213..ae1705956b 100644 --- a/spec/example_app/app/controllers/admin/log_entries_controller.rb +++ b/spec/example_app/app/controllers/admin/log_entries_controller.rb @@ -6,23 +6,23 @@ def filter_resources(resources, search_term:) customer_ids = Customer.where( [ "name ILIKE ?", - "%#{search_term}%", - ], + "%#{search_term}%" + ] ).pluck(:id) order_ids = Order.joins(:customer).where( [ "customers.name ILIKE ?", - "%#{search_term}%", - ], + "%#{search_term}%" + ] ).pluck(:id) customers_filter = resources.where( logeable_type: "Customer", - logeable_id: customer_ids, + logeable_id: customer_ids ) orders_filter = resources.where( logeable_type: "Order", - logeable_id: order_ids, + logeable_id: order_ids ) customers_filter.or(orders_filter) end diff --git a/spec/example_app/app/controllers/admin/stats_controller.rb b/spec/example_app/app/controllers/admin/stats_controller.rb index a790914606..7ab0a4150c 100644 --- a/spec/example_app/app/controllers/admin/stats_controller.rb +++ b/spec/example_app/app/controllers/admin/stats_controller.rb @@ -3,7 +3,7 @@ class StatsController < Admin::ApplicationController def index @stats = { customer_count: Customer.count, - order_count: Order.count, + order_count: Order.count } end end diff --git a/spec/example_app/app/controllers/docs_controller.rb b/spec/example_app/app/controllers/docs_controller.rb index 78a61d8201..3d7d48d9ce 100644 --- a/spec/example_app/app/controllers/docs_controller.rb +++ b/spec/example_app/app/controllers/docs_controller.rb @@ -21,7 +21,7 @@ def show def render_page(name, title = nil) page = DocPage.find(name) - title = title || page.title + title ||= page.title @page_title = [title, "Administrate"].compact.join(" - ") # rubocop:disable Rails/OutputSafety render layout: "docs", html: page.body.html_safe @@ -30,7 +30,7 @@ def render_page(name, title = nil) render( file: Rails.root.join("public", "404.html"), layout: false, - status: :not_found, + status: :not_found ) end end diff --git a/spec/example_app/app/dashboards/blog/post_dashboard.rb b/spec/example_app/app/dashboards/blog/post_dashboard.rb index 9afbb0e14c..c321299010 100644 --- a/spec/example_app/app/dashboards/blog/post_dashboard.rb +++ b/spec/example_app/app/dashboards/blog/post_dashboard.rb @@ -9,20 +9,20 @@ class PostDashboard < Administrate::BaseDashboard title: Field::String, published_at: Field::DateTime, body: Field::Text, - tags: Field::HasMany, + tags: Field::HasMany } READ_ONLY_ATTRIBUTES = [ :id, :created_at, - :updated_at, + :updated_at ] COLLECTION_ATTRIBUTES = [ :id, :title, :tags, - :published_at, + :published_at ] FORM_ATTRIBUTES = ATTRIBUTE_TYPES.keys - READ_ONLY_ATTRIBUTES diff --git a/spec/example_app/app/dashboards/blog/tag_dashboard.rb b/spec/example_app/app/dashboards/blog/tag_dashboard.rb index b0ce488f53..9dc178bf64 100644 --- a/spec/example_app/app/dashboards/blog/tag_dashboard.rb +++ b/spec/example_app/app/dashboards/blog/tag_dashboard.rb @@ -7,7 +7,7 @@ class TagDashboard < Administrate::BaseDashboard name: Field::String, created_at: Field::DateTime, updated_at: Field::DateTime, - posts: Field::HasMany, + posts: Field::HasMany }.freeze COLLECTION_ATTRIBUTES = %i[ diff --git a/spec/example_app/app/dashboards/country_dashboard.rb b/spec/example_app/app/dashboards/country_dashboard.rb index 1f5f872497..6b97213f05 100644 --- a/spec/example_app/app/dashboards/country_dashboard.rb +++ b/spec/example_app/app/dashboards/country_dashboard.rb @@ -1,13 +1,13 @@ require "administrate/base_dashboard" class CountryDashboard < Administrate::BaseDashboard - ATTRIBUTES = %i(code name).freeze + ATTRIBUTES = %i[code name].freeze ATTRIBUTE_TYPES = { created_at: Field::DateTime, updated_at: Field::DateTime, code: Field::String, - name: Field::String, + name: Field::String }.freeze COLLECTION_ATTRIBUTES = ATTRIBUTES diff --git a/spec/example_app/app/dashboards/customer_dashboard.rb b/spec/example_app/app/dashboards/customer_dashboard.rb index 483f115794..79786fa4f7 100644 --- a/spec/example_app/app/dashboards/customer_dashboard.rb +++ b/spec/example_app/app/dashboards/customer_dashboard.rb @@ -15,9 +15,9 @@ class CustomerDashboard < Administrate::BaseDashboard territory: Field::BelongsTo.with_options( searchable: true, searchable_fields: ["name"], - include_blank: true, + include_blank: true ), - password: Field::Password, + password: Field::Password } COLLECTION_ATTRIBUTES = ATTRIBUTE_TYPES.keys - %i[created_at updated_at] @@ -28,12 +28,12 @@ class CustomerDashboard < Administrate::BaseDashboard :email_subscriber, :kind, :territory, - :password, + :password ].freeze COLLECTION_FILTERS = { vip: ->(resources) { resources.where(kind: :vip) }, - kind: ->(resources, arg) { resources.where(kind: arg) }, + kind: ->(resources, arg) { resources.where(kind: arg) } }.freeze def display_resource(customer) diff --git a/spec/example_app/app/dashboards/line_item_dashboard.rb b/spec/example_app/app/dashboards/line_item_dashboard.rb index a57ff36b03..4a7c29402c 100644 --- a/spec/example_app/app/dashboards/line_item_dashboard.rb +++ b/spec/example_app/app/dashboards/line_item_dashboard.rb @@ -5,7 +5,7 @@ class LineItemDashboard < Administrate::BaseDashboard :order, :product, :quantity, - :unit_price, + :unit_price ] ATTRIBUTE_TYPES = { @@ -15,7 +15,7 @@ class LineItemDashboard < Administrate::BaseDashboard product: Field::BelongsTo, quantity: Field::Number, total_price: Field::Number.with_options(prefix: "$", decimals: 2), - unit_price: Field::Number.with_options(prefix: "$", decimals: 2), + unit_price: Field::Number.with_options(prefix: "$", decimals: 2) } COLLECTION_ATTRIBUTES = ATTRIBUTES + [:total_price] diff --git a/spec/example_app/app/dashboards/log_entry_dashboard.rb b/spec/example_app/app/dashboards/log_entry_dashboard.rb index 0a0502ba26..cf69369e68 100644 --- a/spec/example_app/app/dashboards/log_entry_dashboard.rb +++ b/spec/example_app/app/dashboards/log_entry_dashboard.rb @@ -1,12 +1,12 @@ require "administrate/base_dashboard" class LogEntryDashboard < Administrate::BaseDashboard - ATTRIBUTES = %i(action logeable).freeze + ATTRIBUTES = %i[action logeable].freeze ATTRIBUTE_TYPES = { id: Field::Number, action: Field::String, - logeable: Field::Polymorphic.with_options(classes: [Customer, ::Order]), + logeable: Field::Polymorphic.with_options(classes: [Customer, ::Order]) }.freeze COLLECTION_ATTRIBUTES = [:id] + ATTRIBUTES @@ -24,9 +24,9 @@ def safe_display_logeable(logeable) end def display_logeable(logeable) - (logeable.class.to_s + "Dashboard"). - constantize. - new. - display_resource(logeable) + (logeable.class.to_s + "Dashboard") + .constantize + .new + .display_resource(logeable) end end diff --git a/spec/example_app/app/dashboards/logged/order_dashboard.rb b/spec/example_app/app/dashboards/logged/order_dashboard.rb index a22ba98497..11c1a86b2b 100644 --- a/spec/example_app/app/dashboards/logged/order_dashboard.rb +++ b/spec/example_app/app/dashboards/logged/order_dashboard.rb @@ -14,14 +14,14 @@ class OrderDashboard < Administrate::BaseDashboard customer: Field::BelongsTo, line_items: Field::HasMany, total_price: Field::Number.with_options(prefix: "$", decimals: 2), - shipped_at: Field::DateTime, + shipped_at: Field::DateTime } READ_ONLY_ATTRIBUTES = [ :id, :total_price, :created_at, - :updated_at, + :updated_at ] COLLECTION_ATTRIBUTES = [ @@ -30,7 +30,7 @@ class OrderDashboard < Administrate::BaseDashboard :address_state, :total_price, :line_items, - :shipped_at, + :shipped_at ] FORM_ATTRIBUTES = ATTRIBUTE_TYPES.keys - READ_ONLY_ATTRIBUTES diff --git a/spec/example_app/app/dashboards/order_dashboard.rb b/spec/example_app/app/dashboards/order_dashboard.rb index 3aba480019..1e1407b52d 100644 --- a/spec/example_app/app/dashboards/order_dashboard.rb +++ b/spec/example_app/app/dashboards/order_dashboard.rb @@ -12,18 +12,18 @@ class OrderDashboard < Administrate::BaseDashboard address_zip: Field::String, customer: Field::BelongsTo.with_options(order: "name"), line_items: Field::HasMany.with_options( - collection_attributes: %i[product quantity unit_price total_price], + collection_attributes: %i[product quantity unit_price total_price] ), total_price: Field::Number.with_options(prefix: "$", decimals: 2), shipped_at: Field::DateTime, - payments: Field::HasMany, + payments: Field::HasMany } READ_ONLY_ATTRIBUTES = [ :id, :total_price, :created_at, - :updated_at, + :updated_at ] COLLECTION_ATTRIBUTES = [ @@ -32,7 +32,7 @@ class OrderDashboard < Administrate::BaseDashboard :address_state, :total_price, :line_items, - :shipped_at, + :shipped_at ] FORM_ATTRIBUTES = { @@ -48,10 +48,10 @@ class OrderDashboard < Administrate::BaseDashboard address_city address_state address_zip - ], + ] }.freeze SHOW_PAGE_ATTRIBUTES = FORM_ATTRIBUTES.merge( "" => %i[customer created_at updated_at], - "details" => %i[line_items total_price shipped_at payments], + "details" => %i[line_items total_price shipped_at payments] ).freeze end diff --git a/spec/example_app/app/dashboards/page_dashboard.rb b/spec/example_app/app/dashboards/page_dashboard.rb index 049fd0113a..aef7fe4b69 100644 --- a/spec/example_app/app/dashboards/page_dashboard.rb +++ b/spec/example_app/app/dashboards/page_dashboard.rb @@ -7,7 +7,7 @@ class PageDashboard < Administrate::BaseDashboard title: Field::String, body: Field::Text, created_at: Field::DateTime, - updated_at: Field::DateTime, + updated_at: Field::DateTime }.freeze COLLECTION_ATTRIBUTES = %i[ diff --git a/spec/example_app/app/dashboards/payment_dashboard.rb b/spec/example_app/app/dashboards/payment_dashboard.rb index b89d65f49e..2460311de2 100644 --- a/spec/example_app/app/dashboards/payment_dashboard.rb +++ b/spec/example_app/app/dashboards/payment_dashboard.rb @@ -5,11 +5,11 @@ class PaymentDashboard < Administrate::BaseDashboard id: Field::Number, created_at: Field::DateTime, updated_at: Field::DateTime, - order: Field::BelongsTo, + order: Field::BelongsTo } COLLECTION_ATTRIBUTES = [ - :id, + :id ] SHOW_PAGE_ATTRIBUTES = ATTRIBUTE_TYPES.keys diff --git a/spec/example_app/app/dashboards/product_dashboard.rb b/spec/example_app/app/dashboards/product_dashboard.rb index 95606f284e..88c96c638b 100644 --- a/spec/example_app/app/dashboards/product_dashboard.rb +++ b/spec/example_app/app/dashboards/product_dashboard.rb @@ -8,7 +8,7 @@ class ProductDashboard < Administrate::BaseDashboard :description, :image_url, :product_meta_tag, - :release_year, + :release_year ] ATTRIBUTE_TYPES = { @@ -21,8 +21,8 @@ class ProductDashboard < Administrate::BaseDashboard price: Field::Number.with_options(prefix: "$", decimals: 2), product_meta_tag: Field::HasOne.with_options(order: "meta_title"), release_year: Field::Select.with_options( - collection: -> { (Time.current.year - 10)..Time.current.year }, - ), + collection: -> { (Time.current.year - 10)..Time.current.year } + ) } COLLECTION_ATTRIBUTES = ATTRIBUTES diff --git a/spec/example_app/app/dashboards/product_meta_tag_dashboard.rb b/spec/example_app/app/dashboards/product_meta_tag_dashboard.rb index 42e4660e26..22647657f6 100644 --- a/spec/example_app/app/dashboards/product_meta_tag_dashboard.rb +++ b/spec/example_app/app/dashboards/product_meta_tag_dashboard.rb @@ -10,7 +10,7 @@ class ProductMetaTagDashboard < Administrate::BaseDashboard created_at: Field::DateTime, updated_at: Field::DateTime, meta_title: Field::String, - meta_description: Field::String, + meta_description: Field::String }.freeze COLLECTION_ATTRIBUTES = ATTRIBUTES diff --git a/spec/example_app/app/dashboards/series_dashboard.rb b/spec/example_app/app/dashboards/series_dashboard.rb index c2ab109f29..6665cee5e6 100644 --- a/spec/example_app/app/dashboards/series_dashboard.rb +++ b/spec/example_app/app/dashboards/series_dashboard.rb @@ -3,14 +3,14 @@ class SeriesDashboard < Administrate::BaseDashboard ATTRIBUTE_TYPES = { id: Field::Number, - name: Field::String, + name: Field::String }.freeze - COLLECTION_ATTRIBUTES = %i(id name).freeze + COLLECTION_ATTRIBUTES = %i[id name].freeze - SHOW_PAGE_ATTRIBUTES = %i(id name).freeze + SHOW_PAGE_ATTRIBUTES = %i[id name].freeze FORM_ATTRIBUTES = [ - :name, + :name ].freeze end diff --git a/spec/example_app/app/models/customer.rb b/spec/example_app/app/models/customer.rb index 6eaa28fb21..05e5ebc886 100644 --- a/spec/example_app/app/models/customer.rb +++ b/spec/example_app/app/models/customer.rb @@ -4,7 +4,7 @@ class Customer < ApplicationRecord :territory, class_name: "Country", foreign_key: :country_code, - primary_key: :code, + primary_key: :code ) has_many :log_entries, as: :logeable @@ -13,7 +13,7 @@ class Customer < ApplicationRecord KINDS = { "standard" => "kind:std", - "vip" => "kind:vip", + "vip" => "kind:vip" }.freeze enum kind: KINDS diff --git a/spec/example_app/app/models/doc_page.rb b/spec/example_app/app/models/doc_page.rb index deb3255ce1..866588fac6 100644 --- a/spec/example_app/app/models/doc_page.rb +++ b/spec/example_app/app/models/doc_page.rb @@ -32,7 +32,7 @@ def path_exists?(full_path) def doc_paths [ Dir.glob(Rails.root + "../../**/*.md"), - Dir.glob(Rails.root + "../../*.md"), + Dir.glob(Rails.root + "../../*.md") ].join end @@ -95,7 +95,7 @@ def title def redcarpet_config { fenced_code_blocks: true, - autolink: true, + autolink: true } end end diff --git a/spec/example_app/app/models/product.rb b/spec/example_app/app/models/product.rb index 7dc567611c..07d74101a2 100644 --- a/spec/example_app/app/models/product.rb +++ b/spec/example_app/app/models/product.rb @@ -18,10 +18,10 @@ def self.policy_class validates :name, presence: true validates :price, presence: true validates :release_year, - numericality: { - less_than_or_equal_to: ->(_product) { Time.current.year }, - }, - allow_blank: true + numericality: { + less_than_or_equal_to: ->(_product) { Time.current.year } + }, + allow_blank: true validates :slug, uniqueness: true validates :product_meta_tag, presence: true, on: :some_unclear_situation validate :valid_slug diff --git a/spec/example_app/config/application.rb b/spec/example_app/config/application.rb index a554edbdb0..d58ae76151 100644 --- a/spec/example_app/config/application.rb +++ b/spec/example_app/config/application.rb @@ -24,10 +24,10 @@ class Application < Rails::Application end config.action_controller.action_on_unpermitted_parameters = :raise - config.active_record.time_zone_aware_types = %i(datetime time) + config.active_record.time_zone_aware_types = %i[datetime time] # Opt-out of FLoC: https://amifloced.org/ - config.action_dispatch. - default_headers["Permissions-Policy"] = "interest-cohort=()" + config.action_dispatch + .default_headers["Permissions-Policy"] = "interest-cohort=()" end end diff --git a/spec/example_app/config/environments/production.rb b/spec/example_app/config/environments/production.rb index 1a81bdf00f..f3bc14236d 100644 --- a/spec/example_app/config/environments/production.rb +++ b/spec/example_app/config/environments/production.rb @@ -12,7 +12,7 @@ config.eager_load = true # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false + config.consider_all_requests_local = false config.action_controller.perform_caching = true # Ensures that a master key has been made available in either @@ -72,9 +72,9 @@ config.log_formatter = ::Logger::Formatter.new if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) + logger = ActiveSupport::Logger.new($stdout) logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) + config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. diff --git a/spec/example_app/config/environments/test.rb b/spec/example_app/config/environments/test.rb index 2518ef3511..0693c2b5a7 100644 --- a/spec/example_app/config/environments/test.rb +++ b/spec/example_app/config/environments/test.rb @@ -15,7 +15,7 @@ if config.respond_to?(:public_file_server) config.public_file_server.enabled = true config.public_file_server.headers = { - "Cache-Control" => "public, max-age=3600", + "Cache-Control" => "public, max-age=3600" } else config.serve_static_files = true @@ -23,7 +23,7 @@ end # Show full error reports and disable caching. - config.consider_all_requests_local = true + config.consider_all_requests_local = true config.action_controller.perform_caching = false config.cache_store = :null_store diff --git a/spec/example_app/config/initializers/assets.rb b/spec/example_app/config/initializers/assets.rb index f7f5f54423..3641828406 100644 --- a/spec/example_app/config/initializers/assets.rb +++ b/spec/example_app/config/initializers/assets.rb @@ -8,4 +8,4 @@ # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. -Rails.application.config.assets.precompile += %w( docs.css ) +Rails.application.config.assets.precompile += %w[docs.css] diff --git a/spec/example_app/config/initializers/inflections.rb b/spec/example_app/config/initializers/inflections.rb index d219604014..953b695f4b 100644 --- a/spec/example_app/config/initializers/inflections.rb +++ b/spec/example_app/config/initializers/inflections.rb @@ -4,10 +4,10 @@ # are locale specific, and you may define rules for as many different # locales as you wish. All of these examples are active by default: ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.plural /^(ox)$/i, '\1en' -# inflect.singular /^(ox)en/i, '\1' -# inflect.irregular 'person', 'people' - inflect.uncountable %w(series) + # inflect.plural /^(ox)$/i, '\1en' + # inflect.singular /^(ox)en/i, '\1' + # inflect.irregular 'person', 'people' + inflect.uncountable %w[series] end # These inflection rules are supported but not enabled by default: diff --git a/spec/example_app/config/initializers/session_store.rb b/spec/example_app/config/initializers/session_store.rb index e6a77f78e0..8641604737 100644 --- a/spec/example_app/config/initializers/session_store.rb +++ b/spec/example_app/config/initializers/session_store.rb @@ -1,3 +1,3 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.session_store :cookie_store, key: '_administrate-prototype_session' +Rails.application.config.session_store :cookie_store, key: "_administrate-prototype_session" diff --git a/spec/example_app/db/migrate/20150914175022_add_slug_to_products.rb b/spec/example_app/db/migrate/20150914175022_add_slug_to_products.rb index 11e36d306d..560a5c4455 100644 --- a/spec/example_app/db/migrate/20150914175022_add_slug_to_products.rb +++ b/spec/example_app/db/migrate/20150914175022_add_slug_to_products.rb @@ -6,8 +6,8 @@ def change products.each do |product| update(<<-SQL) UPDATE products - SET slug='#{product['name'].parameterize}' - WHERE id=#{product['id']} + SET slug='#{product["name"].parameterize}' + WHERE id=#{product["id"]} SQL end diff --git a/spec/example_app/db/migrate/20170510122301_create_countries.rb b/spec/example_app/db/migrate/20170510122301_create_countries.rb index 0bd23327b2..c8a8ba4319 100644 --- a/spec/example_app/db/migrate/20170510122301_create_countries.rb +++ b/spec/example_app/db/migrate/20170510122301_create_countries.rb @@ -1,7 +1,7 @@ class CreateCountries < ActiveRecord::Migration[4.2] def change create_table :countries do |t| - t.string :code, null: false, index: { unique: true } + t.string :code, null: false, index: {unique: true} t.string :name t.timestamps null: false diff --git a/spec/example_app/db/seeds.rb b/spec/example_app/db/seeds.rb index 56ac876bb9..599021f9b4 100644 --- a/spec/example_app/db/seeds.rb +++ b/spec/example_app/db/seeds.rb @@ -19,11 +19,11 @@ Page.destroy_all countries = Country.create! [ - { code: "US", name: "USA" }, - { code: "CA", name: "Canada" }, - { code: "CN", name: "China" }, - { code: "RU", name: "Russia" }, - { code: "AU", name: "Australia" }, + {code: "US", name: "USA"}, + {code: "CA", name: "Canada"}, + {code: "CN", name: "China"}, + {code: "RU", name: "Russia"}, + {code: "AU", name: "Australia"} ] customer_attributes = Array.new(100) do @@ -32,7 +32,7 @@ name: name, email: Faker::Internet.email(name: name), territory: countries.sample, - password: Faker::Internet.password, + password: Faker::Internet.password } end @@ -41,27 +41,27 @@ log_entry_attributes = customers.map do |c| { action: "create", - logeable: c, + logeable: c } end LogEntry.create!(log_entry_attributes) -product_attributes = YAML.load_file(Rails.root.join('db/seeds/products.yml')) +product_attributes = YAML.load_file(Rails.root.join("db/seeds/products.yml")) product_attributes.each do |attributes| attributes = attributes.merge product_meta_tag_attributes: { meta_title: Faker::Movies::LordOfTheRings.character, - meta_description: Faker::Movies::LordOfTheRings.location, + meta_description: Faker::Movies::LordOfTheRings.location } - Product.create! attributes.merge(price: 20 + rand(50)) + Product.create! attributes.merge(price: rand(20..69)) end Product.find_each do |p| Page.create!( title: "Rules of #{p.name}", body: Faker::Lorem.paragraph, - product: p, + product: p ) end @@ -72,12 +72,12 @@ Blog::Post.create!( title: "The secrets of #{p.name}", body: Faker::Lorem.paragraph, - tags: [tag_secrets], + tags: [tag_secrets] ) Blog::Post.create!( title: "If you liked #{p.name}, you will love these products", body: Faker::Lorem.paragraph, - tags: [tag_recommendations], + tags: [tag_recommendations] ) end @@ -89,11 +89,11 @@ def create_order(customer:, shipped_at: nil) address_city: Faker::Address.city, address_state: Faker::Address.state_abbr, address_zip: Faker::Address.zip, - shipped_at: shipped_at, + shipped_at: shipped_at ) LogEntry.create!( action: "create", - logeable: order, + logeable: order ) item_count = (1..3).to_a.sample @@ -102,7 +102,7 @@ def create_order(customer:, shipped_at: nil) order: order, product: product, unit_price: product.price, - quantity: (1..3).to_a.sample, + quantity: (1..3).to_a.sample ) end diff --git a/spec/example_app/spec/models/product_spec.rb b/spec/example_app/spec/models/product_spec.rb index 2818f24069..9bdbb2818b 100644 --- a/spec/example_app/spec/models/product_spec.rb +++ b/spec/example_app/spec/models/product_spec.rb @@ -11,7 +11,7 @@ it "is trimmed on save" do product = FactoryBot.create( :product, - image_url: "\n https://example.com/foo/bar \n", + image_url: "\n https://example.com/foo/bar \n" ) expect(product.image_url).to eq("https://example.com/foo/bar") end diff --git a/spec/factories.rb b/spec/factories.rb index d5c147d154..981f3daf01 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -2,7 +2,7 @@ factory :customer do association :territory, factory: :country sequence(:name) { |n| "Customer #{n}" } - email { name.downcase.gsub(" ", "_") + "@example.com" } + email { name.downcase.tr(" ", "_") + "@example.com" } transient do order_count { 3 } diff --git a/spec/features/authorization_spec.rb b/spec/features/authorization_spec.rb index 251268fb5f..81d531785d 100644 --- a/spec/features/authorization_spec.rb +++ b/spec/features/authorization_spec.rb @@ -1,5 +1,6 @@ require "rails_helper" +# standard:disable Lint/ConstantDefinitionInBlock describe "authorization" do before do class TestProductPolicy < ProductPolicy @@ -54,3 +55,4 @@ def become_user(customer) expect(page).to have_css(".js-table-row", count: 1) end end +# standard:enable Lint/ConstantDefinitionInBlock diff --git a/spec/features/documentation_spec.rb b/spec/features/documentation_spec.rb index f4bdcf0eba..df9f981079 100644 --- a/spec/features/documentation_spec.rb +++ b/spec/features/documentation_spec.rb @@ -12,7 +12,7 @@ expect(page).to have_css("div.main h1", text: "Administrate") expect(page).to have_content( - "A framework for creating flexible, powerful admin dashboards in Rails", + "A framework for creating flexible, powerful admin dashboards in Rails" ) end @@ -21,7 +21,7 @@ expect(page).to have_css("div.main h1", text: "Contributing Guide") expect(page).to have_content( - "We welcome pull requests from everyone.", + "We welcome pull requests from everyone." ) visit("/CONTRIBUTING.md") @@ -80,8 +80,8 @@ it "links to the GitHub repo" do visit root_path - expect(github_link[:href]). - to eq "https://github.com/thoughtbot/administrate" + expect(github_link[:href]) + .to eq "https://github.com/thoughtbot/administrate" end private @@ -91,8 +91,8 @@ def github_link end def internal_documentation_links - all(".sidebar a"). - map { |anchor| anchor[:href] }. - select { |href| URI.parse(href).relative? } + all(".sidebar a") + .map { |anchor| anchor[:href] } + .select { |href| URI.parse(href).relative? } end end diff --git a/spec/features/edit_page_spec.rb b/spec/features/edit_page_spec.rb index 556e56d67a..c451d417b8 100644 --- a/spec/features/edit_page_spec.rb +++ b/spec/features/edit_page_spec.rb @@ -52,7 +52,7 @@ visit edit_admin_customer_path(customer) expect(page).to have_css( ".selectize-input.items > [data-value]", - text: "vip", + text: "vip" ) end @@ -65,7 +65,7 @@ expect(page).to have_css( "#error_explanation ul li.flash-error", - text: "Name can't be blank", + text: "Name can't be blank" ) end @@ -77,9 +77,9 @@ translations = { activerecord: { models: { - customer: "Custom name", - }, - }, + customer: "Custom name" + } + } } with_translations(:en, translations) do diff --git a/spec/features/form_spec.rb b/spec/features/form_spec.rb index 2132c51752..9d87a8375e 100644 --- a/spec/features/form_spec.rb +++ b/spec/features/form_spec.rb @@ -16,10 +16,10 @@ helpers: { label: { customer: { - email_subscriber: custom_label, - }, - }, - }, + email_subscriber: custom_label + } + } + } } with_translations(:en, translations) do @@ -36,7 +36,7 @@ Product.human_attribute_name(:name), Product.human_attribute_name(:description), Product.human_attribute_name(:price), - Product.human_attribute_name(:image_url), + Product.human_attribute_name(:image_url) ] required_field_labels = find_all(".field-unit--required").map(&:text) @@ -114,10 +114,10 @@ administrate: { field_hints: { customer: { - kind: field_hint, - }, - }, - }, + kind: field_hint + } + } + } } with_translations(:en, translations) do diff --git a/spec/features/index_page_spec.rb b/spec/features/index_page_spec.rb index 276c386f77..e4c79296ac 100644 --- a/spec/features/index_page_spec.rb +++ b/spec/features/index_page_spec.rb @@ -1,7 +1,5 @@ require "rails_helper" -search_input_selector = ".search__input" - describe "customer index page" do it "displays customers' name and email" do customer = create(:customer) @@ -62,10 +60,10 @@ helpers: { label: { customer: { - email_subscriber: custom_label, - }, - }, - }, + email_subscriber: custom_label + } + } + } } with_translations(:en, translations) do diff --git a/spec/features/log_entries_form_spec.rb b/spec/features/log_entries_form_spec.rb index 7cb2ce8f57..e8d076182b 100644 --- a/spec/features/log_entries_form_spec.rb +++ b/spec/features/log_entries_form_spec.rb @@ -11,7 +11,7 @@ expect(page).to have_link(customer.name) expect(page).to have_flash( - t("administrate.controller.create.success", resource: "Log entry"), + t("administrate.controller.create.success", resource: "Log entry") ) end diff --git a/spec/features/log_entries_index_spec.rb b/spec/features/log_entries_index_spec.rb index 9802fe5cfd..922db71c39 100644 --- a/spec/features/log_entries_index_spec.rb +++ b/spec/features/log_entries_index_spec.rb @@ -56,7 +56,7 @@ click_on t("administrate.actions.destroy") end expect(page).to have_flash( - t("administrate.controller.destroy.success", resource: "Log entry"), + t("administrate.controller.destroy.success", resource: "Log entry") ) end end diff --git a/spec/features/navigation_spec.rb b/spec/features/navigation_spec.rb index e60ebe45b9..4962b4b3de 100644 --- a/spec/features/navigation_spec.rb +++ b/spec/features/navigation_spec.rb @@ -32,10 +32,10 @@ models: { customer: { one: "User", - other: "Users", - }, - }, - }, + other: "Users" + } + } + } } with_translations(:en, translations) do diff --git a/spec/features/orders_form_spec.rb b/spec/features/orders_form_spec.rb index 540dbdb1b1..75eedc5105 100644 --- a/spec/features/orders_form_spec.rb +++ b/spec/features/orders_form_spec.rb @@ -79,10 +79,10 @@ helpers: { label: { order: { - line_items: custom_label, - }, - }, - }, + line_items: custom_label + } + } + } } with_translations(:en, translations) do diff --git a/spec/features/products_form_spec.rb b/spec/features/products_form_spec.rb index 58a368be54..4eddddfb48 100644 --- a/spec/features/products_form_spec.rb +++ b/spec/features/products_form_spec.rb @@ -30,8 +30,8 @@ travel_to(1.year.ago) do visit new_admin_product_path - expect(page). - not_to have_select("Release year", with_options: [current_year]) + expect(page) + .not_to have_select("Release year", with_options: [current_year]) end end @@ -40,8 +40,8 @@ new_release_year = Administrate::Field::Select.with_options( collection: [ ["Last Year", 2019], - ["This Year", 2020], - ], + ["This Year", 2020] + ] ) ProductDashboard::ATTRIBUTE_TYPES[:release_year] = new_release_year @@ -75,10 +75,10 @@ helpers: { label: { product: { - product_meta_tag: custom_label, - }, - }, - }, + product_meta_tag: custom_label + } + } + } } with_translations(:en, translations) do diff --git a/spec/features/products_index_spec.rb b/spec/features/products_index_spec.rb index 523eb03e61..eb69b17958 100644 --- a/spec/features/products_index_spec.rb +++ b/spec/features/products_index_spec.rb @@ -41,15 +41,15 @@ scenario "product sorted by has_one association" do create( :product, - product_meta_tag: build(:product_meta_tag, meta_title: "Gamma"), + product_meta_tag: build(:product_meta_tag, meta_title: "Gamma") ) create( :product, - product_meta_tag: build(:product_meta_tag, meta_title: "Alpha"), + product_meta_tag: build(:product_meta_tag, meta_title: "Alpha") ) create( :product, - product_meta_tag: build(:product_meta_tag, meta_title: "Beta"), + product_meta_tag: build(:product_meta_tag, meta_title: "Beta") ) visit admin_products_path diff --git a/spec/features/search_spec.rb b/spec/features/search_spec.rb index 0878d7ffb6..fdae491026 100644 --- a/spec/features/search_spec.rb +++ b/spec/features/search_spec.rb @@ -16,7 +16,7 @@ def have_a_search_bar it "is hidden when nothing is searchable in the current dashboard" do CustomerDashboard::ATTRIBUTE_TYPES.each do |_name, field_class| allow(field_class).to( - receive(:searchable?).and_return(false), + receive(:searchable?).and_return(false) ) end @@ -122,7 +122,7 @@ def have_a_search_bar scenario "admin clears search" do query = "foo" mismatch = create(:customer, name: "someone") - visit admin_customers_path(search: query, customer: { order: :name }) + visit admin_customers_path(search: query, customer: {order: :name}) expect(page).not_to have_content(mismatch.email) clear_search diff --git a/spec/features/show_page_spec.rb b/spec/features/show_page_spec.rb index a069028bf6..786d57f291 100644 --- a/spec/features/show_page_spec.rb +++ b/spec/features/show_page_spec.rb @@ -48,15 +48,12 @@ end end - describe( - "when these are not a collection field" + - "and there's another paging association", - ) do + describe "when not a collection field and there's another paging association" do it "doesn't break" do orig_collection_attributes = CustomerDashboard::COLLECTION_ATTRIBUTES allow_any_instance_of(CustomerDashboard).to( - receive(:collection_attributes). - and_return(orig_collection_attributes - [:orders]), + receive(:collection_attributes) + .and_return(orig_collection_attributes - [:orders]) ) customer = create(:customer) @@ -117,8 +114,8 @@ end visit admin_customer_path(customer, orders: { - order: :id, direction: :desc - }) + order: :id, direction: :desc + }) order_ids = orders.sort_by(&:id).map(&:id).reverse @@ -127,8 +124,8 @@ end visit admin_customer_path(customer, orders: { - order: :id, direction: :desc, page: 2 - }) + order: :id, direction: :desc, page: 2 + }) within(table_for_attribute(:orders)) do expect(order_ids.last(2)).to eq(ids_in_table) @@ -146,8 +143,8 @@ visit admin_customer_path( customer, - orders: { order: :id, direction: :desc }, - log_entries: { order: :id, direction: :asc }, + orders: {order: :id, direction: :desc}, + log_entries: {order: :id, direction: :asc} ) order_ids = orders.sort_by(&:id).map(&:id).reverse @@ -166,8 +163,8 @@ orders: { order: :id, direction: :desc, - page: 2, - }, + page: 2 + } ) within(table_for_attribute(:orders)) do @@ -223,10 +220,10 @@ helpers: { label: { customer: { - email_subscriber: custom_label, - }, - }, - }, + email_subscriber: custom_label + } + } + } } with_translations(:en, translations) do @@ -246,16 +243,16 @@ actions: { edit: "Edit", destroy: "Destroy", - confirm: "Are you sure?", - }, + confirm: "Are you sure?" + } }, helpers: { label: { order: { - shipped_at: custom_label, - }, - }, - }, + shipped_at: custom_label + } + } + } } with_translations(:en, translations) do @@ -275,7 +272,7 @@ e[:class]&.split&.last&.split("--line_item_")&.last end expect(%w[product quantity unit_price total_price]).to( - eq(columns.first(4)), + eq(columns.first(4)) ) end end diff --git a/spec/generators/assets_generator_spec.rb b/spec/generators/assets_generator_spec.rb index 0c54bce19e..7d4b10cac2 100644 --- a/spec/generators/assets_generator_spec.rb +++ b/spec/generators/assets_generator_spec.rb @@ -10,8 +10,8 @@ run_generator [] %w[javascripts stylesheets].each do |asset| - expect(Rails::Generators). - to invoke_generator("administrate:assets:#{asset}") + expect(Rails::Generators) + .to invoke_generator("administrate:assets:#{asset}") end end end diff --git a/spec/generators/dashboard_generator_spec.rb b/spec/generators/dashboard_generator_spec.rb index 892cae33b3..5ead0ceb40 100644 --- a/spec/generators/dashboard_generator_spec.rb +++ b/spec/generators/dashboard_generator_spec.rb @@ -21,91 +21,83 @@ describe "#attribute_types" do it "includes standard model attributes" do - begin - ActiveRecord::Schema.define do - create_table(:foos) { |t| t.timestamps null: false } - end + ActiveRecord::Schema.define do + create_table(:foos) { |t| t.timestamps null: false } + end - class Foo < Administrate::Generators::TestRecord - reset_column_information - end + class Foo < Administrate::Generators::TestRecord + reset_column_information + end - run_generator ["foo"] - load file("app/dashboards/foo_dashboard.rb") - attrs = FooDashboard::ATTRIBUTE_TYPES + run_generator ["foo"] + load file("app/dashboards/foo_dashboard.rb") + attrs = FooDashboard::ATTRIBUTE_TYPES - expect(attrs[:id]).to eq(Administrate::Field::Number) - expect(attrs[:created_at]).to eq(Administrate::Field::DateTime) - expect(attrs[:updated_at]).to eq(Administrate::Field::DateTime) - ensure - remove_constants :Foo, :FooDashboard - end + expect(attrs[:id]).to eq(Administrate::Field::Number) + expect(attrs[:created_at]).to eq(Administrate::Field::DateTime) + expect(attrs[:updated_at]).to eq(Administrate::Field::DateTime) + ensure + remove_constants :Foo, :FooDashboard end it "includes user-defined database columns" do - begin - ActiveRecord::Schema.define do - create_table(:foos) { |t| t.string :name } - end + ActiveRecord::Schema.define do + create_table(:foos) { |t| t.string :name } + end - class Foo < Administrate::Generators::TestRecord - reset_column_information - end + class Foo < Administrate::Generators::TestRecord + reset_column_information + end - run_generator ["foo"] - load file("app/dashboards/foo_dashboard.rb") - attrs = FooDashboard::ATTRIBUTE_TYPES + run_generator ["foo"] + load file("app/dashboards/foo_dashboard.rb") + attrs = FooDashboard::ATTRIBUTE_TYPES - expect(attrs[:name]).to eq(Administrate::Field::String) - ensure - remove_constants :Foo, :FooDashboard - end + expect(attrs[:name]).to eq(Administrate::Field::String) + ensure + remove_constants :Foo, :FooDashboard end it "sorts the attributes" do - begin - ActiveRecord::Schema.define do - create_table(:foos, primary_key: :code) do |t| - t.string :col_2 - t.string :col_1 - t.string :col_3 - t.timestamps - end + ActiveRecord::Schema.define do + create_table(:foos, primary_key: :code) do |t| + t.string :col_2 + t.string :col_1 + t.string :col_3 + t.timestamps end + end - class Foo < Administrate::Generators::TestRecord - reset_column_information - end + class Foo < Administrate::Generators::TestRecord + reset_column_information + end - run_generator ["foo"] - load file("app/dashboards/foo_dashboard.rb") - attrs = FooDashboard::ATTRIBUTE_TYPES.keys + run_generator ["foo"] + load file("app/dashboards/foo_dashboard.rb") + attrs = FooDashboard::ATTRIBUTE_TYPES.keys - expect(attrs).to eq(%i[code col_1 col_2 col_3 created_at updated_at]) - ensure - remove_constants :Foo, :FooDashboard - end + expect(attrs).to eq(%i[code col_1 col_2 col_3 created_at updated_at]) + ensure + remove_constants :Foo, :FooDashboard end it "defaults to a string column that is not searchable" do - begin - ActiveRecord::Schema.define do - create_table(:foos) { |t| t.inet :ip_address } - end + ActiveRecord::Schema.define do + create_table(:foos) { |t| t.inet :ip_address } + end - class Foo < Administrate::Generators::TestRecord - reset_column_information - end + class Foo < Administrate::Generators::TestRecord + reset_column_information + end - run_generator ["foo"] - load file("app/dashboards/foo_dashboard.rb") - attrs = FooDashboard::ATTRIBUTE_TYPES + run_generator ["foo"] + load file("app/dashboards/foo_dashboard.rb") + attrs = FooDashboard::ATTRIBUTE_TYPES - expect(attrs[:ip_address]). - to eq(Administrate::Field::String.with_options(searchable: false)) - ensure - remove_constants :Foo, :FooDashboard - end + expect(attrs[:ip_address]) + .to eq(Administrate::Field::String.with_options(searchable: false)) + ensure + remove_constants :Foo, :FooDashboard end it "includes has_many relationships" do @@ -117,29 +109,27 @@ class Foo < Administrate::Generators::TestRecord end it "assigns numeric fields a type of `Number`" do - begin - ActiveRecord::Schema.define do - create_table :inventory_items do |t| - t.integer :quantity - t.float :price - end + ActiveRecord::Schema.define do + create_table :inventory_items do |t| + t.integer :quantity + t.float :price end + end - class InventoryItem < Administrate::Generators::TestRecord - reset_column_information - end + class InventoryItem < Administrate::Generators::TestRecord + reset_column_information + end - run_generator ["inventory_item"] - load file("app/dashboards/inventory_item_dashboard.rb") - attrs = InventoryItemDashboard::ATTRIBUTE_TYPES + run_generator ["inventory_item"] + load file("app/dashboards/inventory_item_dashboard.rb") + attrs = InventoryItemDashboard::ATTRIBUTE_TYPES - expect(attrs[:price]). - to eq(Administrate::Field::Number.with_options(decimals: 2)) - expect(attrs[:quantity]). - to eq(Administrate::Field::Number) - ensure - remove_constants :InventoryItem, :InventoryItemDashboard - end + expect(attrs[:price]) + .to eq(Administrate::Field::Number.with_options(decimals: 2)) + expect(attrs[:quantity]) + .to eq(Administrate::Field::Number) + ensure + remove_constants :InventoryItem, :InventoryItemDashboard end it "detects enum field as `Select`" do @@ -180,186 +170,172 @@ class Shipment < Administrate::Generators::TestRecord attrs = ShipmentDashboard::ATTRIBUTE_TYPES enum_collection_option = attrs[:status].options[:collection] select_field = Administrate::Field::Select.new(:status, - nil, - attrs[:status].options, - resource: Shipment.new) + nil, + attrs[:status].options, + resource: Shipment.new) - expect(enum_collection_option.call(select_field)). - to eq(Shipment.statuses.keys) + expect(enum_collection_option.call(select_field)) + .to eq(Shipment.statuses.keys) ensure remove_constants :Shipment, :ShipmentDashboard end it "detects boolean values" do - begin - ActiveRecord::Schema.define do - create_table(:users) { |t| t.boolean :active } - end + ActiveRecord::Schema.define do + create_table(:users) { |t| t.boolean :active } + end - class User < Administrate::Generators::TestRecord - reset_column_information - end + class User < Administrate::Generators::TestRecord + reset_column_information + end - run_generator ["user"] - load file("app/dashboards/user_dashboard.rb") - attrs = UserDashboard::ATTRIBUTE_TYPES + run_generator ["user"] + load file("app/dashboards/user_dashboard.rb") + attrs = UserDashboard::ATTRIBUTE_TYPES - expect(attrs[:active]).to eq(Administrate::Field::Boolean) - ensure - remove_constants :User, :UserDashboard - end + expect(attrs[:active]).to eq(Administrate::Field::Boolean) + ensure + remove_constants :User, :UserDashboard end it "assigns dates, times, and datetimes a type of `Date`, `DateTime` and `Time` respectively" do - begin - ActiveRecord::Schema.define do - create_table :events do |t| - t.date :start_date - t.time :start_time - t.datetime :ends_at - end + ActiveRecord::Schema.define do + create_table :events do |t| + t.date :start_date + t.time :start_time + t.datetime :ends_at end + end - class Event < Administrate::Generators::TestRecord - reset_column_information - end + class Event < Administrate::Generators::TestRecord + reset_column_information + end - run_generator ["event"] - load file("app/dashboards/event_dashboard.rb") - attrs = EventDashboard::ATTRIBUTE_TYPES + run_generator ["event"] + load file("app/dashboards/event_dashboard.rb") + attrs = EventDashboard::ATTRIBUTE_TYPES - expect(attrs[:start_date]).to eq(Administrate::Field::Date) - expect(attrs[:start_time]).to eq(Administrate::Field::Time) - expect(attrs[:ends_at]).to eq(Administrate::Field::DateTime) - ensure - remove_constants :Event, :EventDashboard - end + expect(attrs[:start_date]).to eq(Administrate::Field::Date) + expect(attrs[:start_time]).to eq(Administrate::Field::Time) + expect(attrs[:ends_at]).to eq(Administrate::Field::DateTime) + ensure + remove_constants :Event, :EventDashboard end it "detects belongs_to relationships" do - begin - ActiveRecord::Schema.define do - create_table(:comments) { |t| t.references :post } - end - class Comment < Administrate::Generators::TestRecord - belongs_to :post - end + ActiveRecord::Schema.define do + create_table(:comments) { |t| t.references :post } + end + class Comment < Administrate::Generators::TestRecord + belongs_to :post + end - run_generator ["comment"] - load file("app/dashboards/comment_dashboard.rb") - attrs = CommentDashboard::ATTRIBUTE_TYPES + run_generator ["comment"] + load file("app/dashboards/comment_dashboard.rb") + attrs = CommentDashboard::ATTRIBUTE_TYPES - expect(attrs[:post]).to eq(Administrate::Field::BelongsTo) - expect(attrs.keys).not_to include(:post_id) - ensure - remove_constants :Comment, :CommentDashboard - end + expect(attrs[:post]).to eq(Administrate::Field::BelongsTo) + expect(attrs.keys).not_to include(:post_id) + ensure + remove_constants :Comment, :CommentDashboard end it "detects polymorphic belongs_to relationships" do - begin - ActiveRecord::Schema.define do - create_table :comments do |t| - t.references :commentable, polymorphic: true - end - end - class Comment < Administrate::Generators::TestRecord - belongs_to :commentable, polymorphic: true + ActiveRecord::Schema.define do + create_table :comments do |t| + t.references :commentable, polymorphic: true end + end + class Comment < Administrate::Generators::TestRecord + belongs_to :commentable, polymorphic: true + end - run_generator ["comment"] - load file("app/dashboards/comment_dashboard.rb") - attrs = CommentDashboard::ATTRIBUTE_TYPES + run_generator ["comment"] + load file("app/dashboards/comment_dashboard.rb") + attrs = CommentDashboard::ATTRIBUTE_TYPES - expect(attrs[:commentable]).to eq(Administrate::Field::Polymorphic) - expect(attrs.keys).not_to include(:commentable_id) - expect(attrs.keys).not_to include(:commentable_type) - ensure - remove_constants :Comment, :CommentDashboard - end + expect(attrs[:commentable]).to eq(Administrate::Field::Polymorphic) + expect(attrs.keys).not_to include(:commentable_id) + expect(attrs.keys).not_to include(:commentable_type) + ensure + remove_constants :Comment, :CommentDashboard end it "detects has_one relationships" do - begin - ActiveRecord::Schema.define do - create_table :accounts + ActiveRecord::Schema.define do + create_table :accounts - create_table :profiles do |t| - t.references :account - end + create_table :profiles do |t| + t.references :account end + end - class Account < Administrate::Generators::TestRecord - reset_column_information - has_one :profile - end + class Account < Administrate::Generators::TestRecord + reset_column_information + has_one :profile + end - class Ticket < Administrate::Generators::TestRecord - reset_column_information - belongs_to :account - end + class Ticket < Administrate::Generators::TestRecord + reset_column_information + belongs_to :account + end - dashboard = file("app/dashboards/account_dashboard.rb") + dashboard = file("app/dashboards/account_dashboard.rb") - run_generator ["account"] + run_generator ["account"] - expect(dashboard).to contain("profile: Field::HasOne") - ensure - remove_constants :Account, :Ticket - end + expect(dashboard).to contain("profile: Field::HasOne") + ensure + remove_constants :Account, :Ticket end if ActiveRecord.version >= Gem::Version.new(5) it "skips temporary attributes" do - begin - ActiveRecord::Schema.define do - create_table :accounts - end + ActiveRecord::Schema.define do + create_table :accounts + end - class Account < Administrate::Generators::TestRecord - reset_column_information - attribute :tmp_attribute, :boolean - end + class Account < Administrate::Generators::TestRecord + reset_column_information + attribute :tmp_attribute, :boolean + end - dashboard = file("app/dashboards/account_dashboard.rb") + dashboard = file("app/dashboards/account_dashboard.rb") - run_generator ["account"] + run_generator ["account"] - expect(dashboard).not_to contain("tmp_attribute") - ensure - remove_constants :Account - end + expect(dashboard).not_to contain("tmp_attribute") + ensure + remove_constants :Account end end end describe "COLLECTION_ATTRIBUTES" do it "is limited to a reasonable number of items" do - begin - ActiveRecord::Schema.define do - create_table :foos do |t| - %i(a b c d e f g).each { |attr| t.string attr } - end - end - - class Foo < Administrate::Generators::TestRecord - reset_column_information + ActiveRecord::Schema.define do + create_table :foos do |t| + %i[a b c d e f g].each { |attr| t.string attr } end + end - run_generator ["foo"] - load file("app/dashboards/foo_dashboard.rb") - all_attrs = FooDashboard::ATTRIBUTE_TYPES.keys.sort - table_attrs = FooDashboard::COLLECTION_ATTRIBUTES - - expect(table_attrs).to contain_exactly( - :id, - *all_attrs.first(table_attribute_limit - 1), - ) - expect(table_attrs).not_to eq(all_attrs) - ensure - remove_constants :Foo, :FooDashboard + class Foo < Administrate::Generators::TestRecord + reset_column_information end + + run_generator ["foo"] + load file("app/dashboards/foo_dashboard.rb") + all_attrs = FooDashboard::ATTRIBUTE_TYPES.keys.sort + table_attrs = FooDashboard::COLLECTION_ATTRIBUTES + + expect(table_attrs).to contain_exactly( + :id, + *all_attrs.first(table_attribute_limit - 1) + ) + expect(table_attrs).not_to eq(all_attrs) + ensure + remove_constants :Foo, :FooDashboard end def table_attribute_limit @@ -369,33 +345,6 @@ def table_attribute_limit describe "FORM_ATTRIBUTES" do it "does not include read-only attributes" do - begin - ActiveRecord::Schema.define do - create_table :foos do |t| - t.string :name - t.timestamps null: true - end - end - - class Foo < Administrate::Generators::TestRecord - reset_column_information - end - - run_generator ["foo"] - load file("app/dashboards/foo_dashboard.rb") - attrs = FooDashboard::FORM_ATTRIBUTES - - expect(attrs).to match_array([:name]) - ensure - remove_constants :Foo, :FooDashboard - end - end - end - end - - describe "SHOW_PAGE_ATTRIBUTES" do - it "includes all attributes" do - begin ActiveRecord::Schema.define do create_table :foos do |t| t.string :name @@ -409,15 +358,38 @@ class Foo < Administrate::Generators::TestRecord run_generator ["foo"] load file("app/dashboards/foo_dashboard.rb") + attrs = FooDashboard::FORM_ATTRIBUTES - attrs = FooDashboard::SHOW_PAGE_ATTRIBUTES - expect(attrs).to match_array([:name, :id, :created_at, :updated_at]) + expect(attrs).to match_array([:name]) ensure remove_constants :Foo, :FooDashboard end end end + describe "SHOW_PAGE_ATTRIBUTES" do + it "includes all attributes" do + ActiveRecord::Schema.define do + create_table :foos do |t| + t.string :name + t.timestamps null: true + end + end + + class Foo < Administrate::Generators::TestRecord + reset_column_information + end + + run_generator ["foo"] + load file("app/dashboards/foo_dashboard.rb") + + attrs = FooDashboard::SHOW_PAGE_ATTRIBUTES + expect(attrs).to match_array([:name, :id, :created_at, :updated_at]) + ensure + remove_constants :Foo, :FooDashboard + end + end + describe "resource controller" do it "has valid syntax" do controller = file("app/controllers/admin/customers_controller.rb") @@ -429,38 +401,35 @@ class Foo < Administrate::Generators::TestRecord end it "subclasses Admin::ApplicationController by default" do - begin - ActiveRecord::Schema.define { create_table :foos } - class Foo < Administrate::Generators::TestRecord; end + ActiveRecord::Schema.define { create_table :foos } + class Foo < Administrate::Generators::TestRecord; end - run_generator ["foo"] - load file("app/controllers/admin/foos_controller.rb") + run_generator ["foo"] + load file("app/controllers/admin/foos_controller.rb") - expect(Admin::FoosController.ancestors). - to include(Admin::ApplicationController) - ensure - remove_constants :Foo - Admin.send(:remove_const, :FoosController) - end + expect(Admin::FoosController.ancestors) + .to include(Admin::ApplicationController) + ensure + remove_constants :Foo + Admin.send(:remove_const, :FoosController) end it "uses the given namespace to create controllers" do - begin - ActiveRecord::Schema.define { create_table :foos } - class Foo < Administrate::Generators::TestRecord; end - module Manager - class ApplicationController < Administrate::ApplicationController; end - end - - run_generator ["foo", "--namespace", "manager"] - load file("app/controllers/manager/foos_controller.rb") + ActiveRecord::Schema.define { create_table :foos } + class Foo < Administrate::Generators::TestRecord; end - expect(Manager::FoosController.ancestors). - to include(Manager::ApplicationController) - ensure - remove_constants :Foo - Manager.send(:remove_const, :FoosController) + module Manager + class ApplicationController < Administrate::ApplicationController; end end + + run_generator ["foo", "--namespace", "manager"] + load file("app/controllers/manager/foos_controller.rb") + + expect(Manager::FoosController.ancestors) + .to include(Manager::ApplicationController) + ensure + remove_constants :Foo + Manager.send(:remove_const, :FoosController) end end end diff --git a/spec/generators/field_generator_spec.rb b/spec/generators/field_generator_spec.rb index 7abdaaa171..f0fa1ec4ae 100644 --- a/spec/generators/field_generator_spec.rb +++ b/spec/generators/field_generator_spec.rb @@ -5,18 +5,16 @@ describe Administrate::Generators::FieldGenerator, :generator do describe "administrate:field field_name" do it "generates a field object" do - begin - run_generator ["foobar"] - - load file("app/fields/foobar_field.rb") - field = FoobarField.new(:attr_name, "value", "show") - - expect(field.name).to eq("attr_name") - expect(field.data).to eq("value") - expect(field.to_s).to eq("value") - ensure - remove_constants :FoobarField - end + run_generator ["foobar"] + + load file("app/fields/foobar_field.rb") + field = FoobarField.new(:attr_name, "value", "show") + + expect(field.name).to eq("attr_name") + expect(field.data).to eq("value") + expect(field.to_s).to eq("value") + ensure + remove_constants :FoobarField end it "generates a default `_index` partial" do diff --git a/spec/generators/install_generator_spec.rb b/spec/generators/install_generator_spec.rb index 549a349f6c..414125ca48 100644 --- a/spec/generators/install_generator_spec.rb +++ b/spec/generators/install_generator_spec.rb @@ -95,8 +95,8 @@ class ApplicationController < Administrate::ApplicationController run_generator %w[customer order product line_item].each do |resource| - expect(Rails::Generators). - to invoke_generator( + expect(Rails::Generators) + .to invoke_generator( "administrate:dashboard", [resource, "--namespace", "admin"] ) end @@ -107,7 +107,7 @@ def insert_generated_routes insert_into_file_after_line( 1, file("config/routes.rb"), - File.read("lib/generators/administrate/install/templates/routes.rb"), + File.read("lib/generators/administrate/install/templates/routes.rb") ) end diff --git a/spec/generators/routes_generator_spec.rb b/spec/generators/routes_generator_spec.rb index ef0b5fe019..18f29c47c0 100644 --- a/spec/generators/routes_generator_spec.rb +++ b/spec/generators/routes_generator_spec.rb @@ -51,18 +51,16 @@ end it "skips models that aren't backed by the database with a warning" do - begin - class ModelWithoutDBTable < ApplicationRecord; end - routes = file("config/routes.rb") + class ModelWithoutDBTable < ApplicationRecord; end + routes = file("config/routes.rb") - output = run_generator + output = run_generator - expect(routes).not_to contain("model_without_db_table") - expect(output).to include("WARNING: Unable to generate a dashboard " \ - "for ModelWithoutDBTable.") - ensure - remove_constants :ModelWithoutDBTable - end + expect(routes).not_to contain("model_without_db_table") + expect(output).to include("WARNING: Unable to generate a dashboard " \ + "for ModelWithoutDBTable.") + ensure + remove_constants :ModelWithoutDBTable end it "skips models that don't have a named constant" do @@ -93,7 +91,7 @@ class AbstractModel < ApplicationRecord output = run_generator expect(routes).not_to contain("abstract_model") - expect(output).not_to include("WARNING: Unable to generate a "\ + expect(output).not_to include("WARNING: Unable to generate a " \ "dashboard for AbstractModel") end end diff --git a/spec/generators/views/field_generator_spec.rb b/spec/generators/views/field_generator_spec.rb index 295e4e053f..5def814a5d 100644 --- a/spec/generators/views/field_generator_spec.rb +++ b/spec/generators/views/field_generator_spec.rb @@ -44,7 +44,7 @@ field_types.each do |field_type| expected_contents = contents_for_field_template(field_type, :show) contents = File.read( - file("app/views/fields/#{field_type}/_show.html.erb"), + file("app/views/fields/#{field_type}/_show.html.erb") ) expect(contents).to eq(expected_contents) @@ -57,7 +57,7 @@ field_types.each do |field_type| expected_contents = contents_for_field_template(field_type, :form) contents = File.read( - file("app/views/fields/#{field_type}/_form.html.erb"), + file("app/views/fields/#{field_type}/_form.html.erb") ) expect(contents).to eq(expected_contents) @@ -70,7 +70,7 @@ field_types.each do |field_type| expected_contents = contents_for_field_template(field_type, :index) contents = File.read( - file("app/views/fields/#{field_type}/_index.html.erb"), + file("app/views/fields/#{field_type}/_index.html.erb") ) expect(contents).to eq(expected_contents) @@ -81,7 +81,7 @@ def contents_for_field_template(field_name, partial_name) File.read( - "app/views/fields/#{field_name}/_#{partial_name}.html.erb", + "app/views/fields/#{field_name}/_#{partial_name}.html.erb" ) end end diff --git a/spec/generators/views/layout_generator_spec.rb b/spec/generators/views/layout_generator_spec.rb index 492dfce55f..c9fff9ca42 100644 --- a/spec/generators/views/layout_generator_spec.rb +++ b/spec/generators/views/layout_generator_spec.rb @@ -7,7 +7,7 @@ it "copies the layout template into the `admin/application` namespace" do allow(Rails::Generators).to receive(:invoke) expected_contents = File.read( - "app/views/layouts/administrate/application.html.erb", + "app/views/layouts/administrate/application.html.erb" ) run_generator [] @@ -32,8 +32,8 @@ run_generator [] - expect(Rails::Generators). - to invoke_generator("administrate:views:navigation") + expect(Rails::Generators) + .to invoke_generator("administrate:views:navigation") end it "copies the javascript partial into the `admin/application` namespace" do diff --git a/spec/generators/views_generator_spec.rb b/spec/generators/views_generator_spec.rb index 87e936e4f7..8854f10aae 100644 --- a/spec/generators/views_generator_spec.rb +++ b/spec/generators/views_generator_spec.rb @@ -11,10 +11,10 @@ run_generator [resource] %w[index show new edit].each do |generator| - expect(Rails::Generators). - to invoke_generator( + expect(Rails::Generators) + .to invoke_generator( "administrate:views:#{generator}", - [resource, "--namespace", "admin"], + [resource, "--namespace", "admin"] ) end end @@ -28,23 +28,23 @@ expect(Rails::Generators).to invoke_generator( "administrate:views:index", [resource, "--namespace", "admin"], - behavior: :revoke, + behavior: :revoke ) end context "when run without any arguments" do it "calls the sub-generators without any arguments" do application_resource_path = instance_double("BaseResourcePath") - allow(Administrate::ViewGenerator::BaseResourcePath).to receive(:new). - and_return(application_resource_path) + allow(Administrate::ViewGenerator::BaseResourcePath).to receive(:new) + .and_return(application_resource_path) allow(Rails::Generators).to receive(:invoke) run_generator %w[index show new edit].each do |generator| - expect(Rails::Generators). to invoke_generator( + expect(Rails::Generators).to invoke_generator( "administrate:views:#{generator}", - [application_resource_path, "--namespace", "admin"], + [application_resource_path, "--namespace", "admin"] ) end end @@ -59,10 +59,10 @@ run_generator [resource, "--namespace", namespace] %w[index show new edit].each do |generator| - expect(Rails::Generators). - to invoke_generator( + expect(Rails::Generators) + .to invoke_generator( "administrate:views:#{generator}", - [resource, "--namespace", namespace], + [resource, "--namespace", namespace] ) end end diff --git a/spec/helpers/administrate/application_helper_spec.rb b/spec/helpers/administrate/application_helper_spec.rb index f79abca99a..da782c2185 100644 --- a/spec/helpers/administrate/application_helper_spec.rb +++ b/spec/helpers/administrate/application_helper_spec.rb @@ -39,10 +39,10 @@ models: { customer: { one: "User", - other: "Users", - }, - }, - }, + other: "Users" + } + } + } } end @@ -114,10 +114,10 @@ class MyResource; end ctx.accessible_action?("my_resource", "foo") expect(ctx).to( - have_received(:existing_action?).with(:my_resource, "foo"), + have_received(:existing_action?).with(:my_resource, "foo") ) expect(ctx).to( - have_received(:authorized_action?).with(:my_resource, "foo"), + have_received(:authorized_action?).with(:my_resource, "foo") ) ensure remove_constants :MyResource @@ -133,10 +133,10 @@ class MyResource; end ctx.accessible_action?(:my_resource, "foo") expect(ctx).to( - have_received(:existing_action?).with(:my_resource, "foo"), + have_received(:existing_action?).with(:my_resource, "foo") ) expect(ctx).to( - have_received(:authorized_action?).with(:my_resource, "foo"), + have_received(:authorized_action?).with(:my_resource, "foo") ) ensure remove_constants :MyResource @@ -153,7 +153,7 @@ class MyResource; end expect(ctx).to have_received(:existing_action?).with(MyResource, "foo") expect(ctx).to( - have_received(:authorized_action?).with(MyResource, "foo"), + have_received(:authorized_action?).with(MyResource, "foo") ) ensure remove_constants :MyResource diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb index c1b7aeefc9..d820900301 100644 --- a/spec/i18n_spec.rb +++ b/spec/i18n_spec.rb @@ -1,17 +1,17 @@ -require 'spec_helper' -require 'i18n/tasks' +require "spec_helper" +require "i18n/tasks" -describe 'I18n' do +describe "I18n" do let(:i18n) { I18n::Tasks::BaseTask.new } let(:missing_keys) { i18n.missing_keys } let(:unused_keys) { i18n.unused_keys } - it 'does not have missing keys' do + it "does not have missing keys" do expect(missing_keys).to be_empty, "Missing #{missing_keys.leaves.count} i18n keys, run `i18n-tasks missing' to show them" end - it 'does not have unused keys' do + it "does not have unused keys" do expect(unused_keys).to be_empty, "#{unused_keys.leaves.count} unused i18n keys, run `i18n-tasks unused' to show them" end diff --git a/spec/lib/administrate/not_authorized_error_spec.rb b/spec/lib/administrate/not_authorized_error_spec.rb index a5196bf113..50d9d6840a 100644 --- a/spec/lib/administrate/not_authorized_error_spec.rb +++ b/spec/lib/administrate/not_authorized_error_spec.rb @@ -5,10 +5,10 @@ it "produces a message mentioning it directly" do error = described_class.new( resource: Administrate, - action: "foo", + action: "foo" ) expect(error.message).to eq( - %{Not allowed to perform "foo" on Administrate}, + %(Not allowed to perform "foo" on Administrate) ) end end @@ -17,9 +17,9 @@ it "produces a message mentioning it directly" do error = described_class.new( resource: "User", - action: "foo", + action: "foo" ) - expect(error.message).to eq(%{Not allowed to perform "foo" on "User"}) + expect(error.message).to eq(%(Not allowed to perform "foo" on "User")) end end @@ -27,9 +27,9 @@ it "produces a message mentioning it directly" do error = described_class.new( resource: :user, - action: "foo", + action: "foo" ) - expect(error.message).to eq(%{Not allowed to perform "foo" on :user}) + expect(error.message).to eq(%(Not allowed to perform "foo" on :user)) end end @@ -39,10 +39,10 @@ class TestStuff; end error = described_class.new( resource: TestStuff.new, - action: "foo", + action: "foo" ) expect(error.message).to eq( - %{Not allowed to perform "foo" on the given TestStuff}, + %(Not allowed to perform "foo" on the given TestStuff) ) ensure remove_constants :TestStuff diff --git a/spec/lib/administrate/order_spec.rb b/spec/lib/administrate/order_spec.rb index a1e4d87c19..343b86484a 100644 --- a/spec/lib/administrate/order_spec.rb +++ b/spec/lib/administrate/order_spec.rb @@ -38,7 +38,7 @@ ordered = order.apply(relation) expect(relation).to have_received(:reorder).with( - to_sql('"table_name"."name" ASC'), + to_sql('"table_name"."name" ASC') ) expect(ordered).to eq(relation) end @@ -51,7 +51,7 @@ ordered = order.apply(relation) expect(relation).to have_received(:reorder).with( - to_sql('"table_name"."name" DESC'), + to_sql('"table_name"."name" DESC') ) expect(ordered).to eq(relation) end @@ -64,7 +64,7 @@ ordered = order.apply(relation) expect(relation).to have_received(:reorder).with( - to_sql('"table_name"."name" ASC'), + to_sql('"table_name"."name" ASC') ) expect(ordered).to eq(relation) end @@ -78,8 +78,8 @@ klass: double( table_name: "users", arel_table: Arel::Table.new("users"), - primary_key: "uid", - ), + primary_key: "uid" + ) ) allow(relation).to receive(:reorder).and_return(relation) allow(relation).to receive(:left_joins).and_return(relation) @@ -90,7 +90,7 @@ expect(relation).to have_received(:left_joins).with(:name) expect(relation).to have_received(:group).with(:id) expect(relation).to have_received(:reorder).with( - to_sql('COUNT("users"."uid") ASC'), + to_sql('COUNT("users"."uid") ASC') ) expect(ordered).to eq(relation) end @@ -101,14 +101,14 @@ order = Administrate::Order.new relation = relation_with_association( :belongs_to, - foreign_key: "some_foreign_key", + foreign_key: "some_foreign_key" ) allow(relation).to receive(:reorder).and_return(relation) ordered = order.apply(relation) expect(relation).to have_received(:reorder).with( - to_sql('"table_name"."some_foreign_key" ASC'), + to_sql('"table_name"."some_foreign_key" ASC') ) expect(ordered).to eq(relation) end @@ -118,21 +118,21 @@ order = Administrate::Order.new( double(to_sym: :user, tableize: "users"), nil, - association_attribute: "name", + association_attribute: "name" ) relation = relation_with_association( :belongs_to, klass: double( table_name: "users", - columns_hash: { "name" => :value }, - ), + columns_hash: {"name" => :value} + ) ) allow(relation).to receive(:joins).and_return(relation) allow(relation).to receive(:reorder).and_return(relation) ordered = order.apply(relation) expect(relation).to have_received(:reorder).with( - to_sql('"users"."name" ASC'), + to_sql('"users"."name" ASC') ) expect(ordered).to eq(relation) end @@ -143,14 +143,14 @@ order = Administrate::Order.new( double(table_name: "users", to_sym: :user), nil, - association_attribute: "invalid_column_name", + association_attribute: "invalid_column_name" ) relation = relation_with_association( :belongs_to, klass: double( table_name: "users", - columns_hash: { name: :value }, - ), + columns_hash: {name: :value} + ) ) allow(relation).to receive(:joins).and_return(relation) allow(relation).to receive(:reorder).and_return(relation) @@ -158,7 +158,7 @@ ordered = order.apply(relation) expect(relation).to have_received(:reorder).with( - to_sql('"table_name"."belongs_to_id" ASC'), + to_sql('"table_name"."belongs_to_id" ASC') ) expect(ordered).to eq(relation) end @@ -168,7 +168,7 @@ context "when relation has has_one association" do it "orders by id" do order = Administrate::Order.new( - double(to_sym: :user, tableize: "users"), + double(to_sym: :user, tableize: "users") ) relation = relation_with_association(:has_one) allow(relation).to receive(:reorder).and_return(relation) @@ -176,7 +176,7 @@ ordered = order.apply(relation) expect(relation).to have_received(:reorder).with( - to_sql('"users"."id" ASC'), + to_sql('"users"."id" ASC') ) expect(ordered).to eq(relation) end @@ -186,21 +186,21 @@ order = Administrate::Order.new( double(to_sym: :user, tableize: "users"), nil, - association_attribute: "name", + association_attribute: "name" ) relation = relation_with_association( :has_one, klass: double( table_name: "users", - columns_hash: { "name" => :value }, - ), + columns_hash: {"name" => :value} + ) ) allow(relation).to receive(:joins).and_return(relation) allow(relation).to receive(:reorder).and_return(relation) ordered = order.apply(relation) expect(relation).to have_received(:reorder).with( - to_sql('"users"."name" ASC'), + to_sql('"users"."name" ASC') ) expect(ordered).to eq(relation) end @@ -211,14 +211,14 @@ order = Administrate::Order.new( double(to_sym: :user, tableize: "users"), nil, - association_attribute: "invalid_column_name", + association_attribute: "invalid_column_name" ) relation = relation_with_association( :has_one, klass: double( table_name: "users", - columns_hash: { name: :value }, - ), + columns_hash: {name: :value} + ) ) allow(relation).to receive(:joins).and_return(relation) allow(relation).to receive(:reorder).and_return(relation) @@ -226,7 +226,7 @@ ordered = order.apply(relation) expect(relation).to have_received(:reorder).with( - to_sql('"users"."id" ASC'), + to_sql('"users"."id" ASC') ) expect(ordered).to eq(relation) end @@ -321,9 +321,9 @@ def relation_with_column(column) double( klass: double(reflect_on_association: nil), - columns_hash: { column.to_s => :column_info }, + columns_hash: {column.to_s => :column_info}, table_name: "table_name", - arel_table: Arel::Table.new("table_name"), + arel_table: Arel::Table.new("table_name") ) end @@ -338,11 +338,11 @@ def relation_with_association( "#{association}_reflection", macro: association, foreign_key: foreign_key, - klass: klass, - ), + klass: klass + ) ), table_name: "table_name", - arel_table: Arel::Table.new("table_name"), + arel_table: Arel::Table.new("table_name") ) end end diff --git a/spec/lib/administrate/resource_resolver_spec.rb b/spec/lib/administrate/resource_resolver_spec.rb index 79c245c1d4..57a2595f2c 100644 --- a/spec/lib/administrate/resource_resolver_spec.rb +++ b/spec/lib/administrate/resource_resolver_spec.rb @@ -79,9 +79,9 @@ class Book < ApplicationRecord; self.abstract_class = true; end translations = { activerecord: { models: { - "library/book": "Library Book", - }, - }, + "library/book": "Library Book" + } + } } with_translations(:en, translations) do diff --git a/spec/lib/administrate/search_spec.rb b/spec/lib/administrate/search_spec.rb index dc3dffbc4e..9b01250efa 100644 --- a/spec/lib/administrate/search_spec.rb +++ b/spec/lib/administrate/search_spec.rb @@ -7,10 +7,10 @@ require "administrate/field/has_many" require "administrate/field/has_one" require "administrate/field/number" -require "administrate/field/string" require "administrate/base_dashboard" require "administrate/search" +# standard:disable Lint/ConstantDefinitionInBlock describe Administrate::Search do before :all do module Administrate @@ -22,14 +22,16 @@ def self.table_name end class Role < MockRecord; end + class Person < MockRecord; end + class Address < MockRecord; end class Foo < MockRecord belongs_to :role belongs_to( :author, - class_name: "Administrate::SearchSpecMocks::Person", + class_name: "Administrate::SearchSpecMocks::Person" ) has_one :address end @@ -39,12 +41,12 @@ class UserDashboard < Administrate::BaseDashboard id: Administrate::Field::Number.with_options(searchable: true), name: Administrate::Field::String, email: Administrate::Field::Email, - phone: Administrate::Field::Number, + phone: Administrate::Field::Number }.freeze COLLECTION_FILTERS = { vip: ->(resource) { resource.where(kind: :vip) }, - kind: ->(resource, param) { resource.where(kind: param) }, + kind: ->(resource, param) { resource.where(kind: param) } }.freeze end @@ -52,17 +54,17 @@ class FooDashboard < Administrate::BaseDashboard ATTRIBUTE_TYPES = { role: Administrate::Field::BelongsTo.with_options( searchable: true, - searchable_field: "name", + searchable_field: "name" ), author: Administrate::Field::BelongsTo.with_options( searchable: true, searchable_fields: ["first_name", "last_name"], - class_name: "Administrate::SearchSpecMocks::Person", + class_name: "Administrate::SearchSpecMocks::Person" ), address: Administrate::Field::HasOne.with_options( searchable: true, - searchable_fields: ["street"], - ), + searchable_fields: ["street"] + ) }.freeze end end @@ -83,7 +85,7 @@ class User < ApplicationRecord; end search = Administrate::Search.new( scoped_object, Administrate::SearchSpecMocks::UserDashboard.new, - nil, + nil ) expect(scoped_object).to receive(:all) @@ -98,7 +100,7 @@ class User < ApplicationRecord; end search = Administrate::Search.new( scoped_object, Administrate::SearchSpecMocks::UserDashboard.new, - " ", + " " ) expect(scoped_object).to receive(:all) @@ -113,17 +115,17 @@ class User < ApplicationRecord; end search = Administrate::Search.new( scoped_object, Administrate::SearchSpecMocks::UserDashboard.new, - "test", + "test" ) expected_query = [ [ 'LOWER(CAST("users"."id" AS CHAR(256))) LIKE ?', 'LOWER(CAST("users"."name" AS CHAR(256))) LIKE ?', - 'LOWER(CAST("users"."email" AS CHAR(256))) LIKE ?', + 'LOWER(CAST("users"."email" AS CHAR(256))) LIKE ?' ].join(" OR "), "%test%", "%test%", - "%test%", + "%test%" ] expect(scoped_object).to receive(:where).with(*expected_query) @@ -138,17 +140,17 @@ class User < ApplicationRecord; end search = Administrate::Search.new( scoped_object, Administrate::SearchSpecMocks::UserDashboard.new, - "Тест Test", + "Тест Test" ) expected_query = [ [ 'LOWER(CAST("users"."id" AS CHAR(256))) LIKE ?', 'LOWER(CAST("users"."name" AS CHAR(256))) LIKE ?', - 'LOWER(CAST("users"."email" AS CHAR(256))) LIKE ?', + 'LOWER(CAST("users"."email" AS CHAR(256))) LIKE ?' ].join(" OR "), "%тест test%", "%тест test%", - "%тест test%", + "%тест test%" ] expect(scoped_object).to receive(:where).with(*expected_query) @@ -168,20 +170,20 @@ class User < ApplicationRecord; end Administrate::Search.new( scoped_object, Administrate::SearchSpecMocks::FooDashboard.new, - "Тест Test", + "Тест Test" ) end let(:expected_query) do [ - 'LOWER(CAST("roles"."name" AS CHAR(256))) LIKE ?'\ - ' OR LOWER(CAST("people"."first_name" AS CHAR(256))) LIKE ?'\ - ' OR LOWER(CAST("people"."last_name" AS CHAR(256))) LIKE ?'\ + 'LOWER(CAST("roles"."name" AS CHAR(256))) LIKE ?' \ + ' OR LOWER(CAST("people"."first_name" AS CHAR(256))) LIKE ?' \ + ' OR LOWER(CAST("people"."last_name" AS CHAR(256))) LIKE ?' \ ' OR LOWER(CAST("addresses"."street" AS CHAR(256))) LIKE ?', "%тест test%", "%тест test%", "%тест test%", - "%тест test%", + "%тест test%" ] end @@ -192,7 +194,7 @@ class User < ApplicationRecord; end search.run expect(scoped_object).to( - have_received(:left_joins).with(%i(role author address)), + have_received(:left_joins).with(%i[role author address]) ) end @@ -203,22 +205,22 @@ class User < ApplicationRecord; end search.run expect(scoped_object).to( - have_received(:where).with(*expected_query), + have_received(:where).with(*expected_query) ) end it "triggers a deprecation warning" do allow(scoped_object).to receive(:where) allow(scoped_object).to( - receive(:left_joins). - with(%i(role author address)). - and_return(scoped_object), + receive(:left_joins) + .with(%i[role author address]) + .and_return(scoped_object) ) search.run - expect(Administrate.deprecator).to have_received(:warn). - with(/:class_name is deprecated/) + expect(Administrate.deprecator).to have_received(:warn) + .with(/:class_name is deprecated/) end end @@ -230,12 +232,12 @@ class User < ApplicationRecord search = Administrate::Search.new( scoped_object, Administrate::SearchSpecMocks::UserDashboard.new, - "vip:", + "vip:" ) expect(scoped_object).to \ - receive(:where). - with(kind: :vip). - and_return(scoped_object) + receive(:where) + .with(kind: :vip) + .and_return(scoped_object) expect(scoped_object).to receive(:where).and_return(scoped_object) search.run @@ -244,3 +246,4 @@ class User < ApplicationRecord end end end +# standard:enable Lint/ConstantDefinitionInBlock diff --git a/spec/lib/fields/base_spec.rb b/spec/lib/fields/base_spec.rb index f1d9a2cc94..43b71efc50 100644 --- a/spec/lib/fields/base_spec.rb +++ b/spec/lib/fields/base_spec.rb @@ -8,11 +8,11 @@ it "is false by default" do resource_class = class_double( "ActiveRecord::Base", - validators_on: [], + validators_on: [] ) resource = instance_double( "ActiveRecord::Base", - class: resource_class, + class: resource_class ) field = field_class.new(:attribute, :date, :page, resource: resource) @@ -22,15 +22,15 @@ it "is true on an unconditional requirement for a value" do validator = ActiveRecord::Validations::PresenceValidator.new( attributes: [:foo], - options: {}, + options: {} ) resource_class = class_double( "ActiveRecord::Base", - validators_on: [validator], + validators_on: [validator] ) resource = instance_double( "ActiveRecord::Base", - class: resource_class, + class: resource_class ) field = field_class.new(:attribute, :date, :page, resource: resource) @@ -40,15 +40,15 @@ it "is false on a conditional requirement for a value (with :if)" do validator = ActiveRecord::Validations::PresenceValidator.new( attributes: [:foo], - if: -> { true }, + if: -> { true } ) resource_class = class_double( "ActiveRecord::Base", - validators_on: [validator], + validators_on: [validator] ) resource = instance_double( "ActiveRecord::Base", - class: resource_class, + class: resource_class ) field = field_class.new(:attribute, :date, :page, resource: resource) @@ -58,15 +58,15 @@ it "is false on a conditional requirement for a value (with :unless)" do validator = ActiveRecord::Validations::PresenceValidator.new( attributes: [:foo], - unless: -> { true }, + unless: -> { true } ) resource_class = class_double( "ActiveRecord::Base", - validators_on: [validator], + validators_on: [validator] ) resource = instance_double( "ActiveRecord::Base", - class: resource_class, + class: resource_class ) field = field_class.new(:attribute, :date, :page, resource: resource) @@ -76,16 +76,16 @@ it "is true for an unpersisted record in only required on create" do validator = ActiveRecord::Validations::PresenceValidator.new( attributes: [:foo], - on: :create, + on: :create ) resource_class = class_double( "ActiveRecord::Base", - validators_on: [validator], + validators_on: [validator] ) resource = instance_double( "ActiveRecord::Base", class: resource_class, - persisted?: false, + persisted?: false ) field = field_class.new(:attribute, :date, :page, resource: resource) @@ -95,16 +95,16 @@ it "is false for a persisted record if only required on create" do validator = ActiveRecord::Validations::PresenceValidator.new( attributes: [:foo], - on: :create, + on: :create ) resource_class = class_double( "ActiveRecord::Base", - validators_on: [validator], + validators_on: [validator] ) resource = instance_double( "ActiveRecord::Base", class: resource_class, - persisted?: true, + persisted?: true ) field = field_class.new(:attribute, :date, :page, resource: resource) @@ -114,16 +114,16 @@ it "is true for a persisted record in only required on update" do validator = ActiveRecord::Validations::PresenceValidator.new( attributes: [:foo], - on: :update, + on: :update ) resource_class = class_double( "ActiveRecord::Base", - validators_on: [validator], + validators_on: [validator] ) resource = instance_double( "ActiveRecord::Base", class: resource_class, - persisted?: true, + persisted?: true ) field = field_class.new(:attribute, :date, :page, resource: resource) @@ -133,16 +133,16 @@ it "is false for a persisted record in only required on update" do validator = ActiveRecord::Validations::PresenceValidator.new( attributes: [:foo], - on: :update, + on: :update ) resource_class = class_double( "ActiveRecord::Base", - validators_on: [validator], + validators_on: [validator] ) resource = instance_double( "ActiveRecord::Base", class: resource_class, - persisted?: false, + persisted?: false ) field = field_class.new(:attribute, :date, :page, resource: resource) @@ -152,15 +152,15 @@ it "is false when required only on unstandard situations" do validator = ActiveRecord::Validations::PresenceValidator.new( attributes: [:foo], - on: :some_situation_or_the_other, + on: :some_situation_or_the_other ) resource_class = class_double( "ActiveRecord::Base", - validators_on: [validator], + validators_on: [validator] ) resource = instance_double( "ActiveRecord::Base", - class: resource_class, + class: resource_class ) field = field_class.new(:attribute, :date, :page, resource: resource) diff --git a/spec/lib/fields/belongs_to_spec.rb b/spec/lib/fields/belongs_to_spec.rb index 90148f986f..8b7c1839d5 100644 --- a/spec/lib/fields/belongs_to_spec.rb +++ b/spec/lib/fields/belongs_to_spec.rb @@ -10,7 +10,7 @@ should_permit_param( "country_code", on_model: Customer, - for_attribute: :territory, + for_attribute: :territory ) end @@ -33,7 +33,7 @@ :product, nil, :show, - resource: line_item, + resource: line_item ) expect(field.associated_class).to eq(Product) end @@ -44,7 +44,7 @@ :territory, nil, :show, - resource: customer, + resource: customer ) expect(field.associated_class).to eq(Country) end @@ -58,12 +58,12 @@ :product, line_item.product, :show, - resource: line_item, + resource: line_item ) allow_any_instance_of(ProductDashboard).to( receive(:display_resource) do |_, resource| "Mock #{resource.name}" - end, + end ) expect(field.display_associated_resource).to eq("Mock Associated Product") end @@ -75,12 +75,12 @@ :territory, country, :show, - resource: customer, + resource: customer ) allow_any_instance_of(CountryDashboard).to( receive(:display_resource) do |_, resource| "Mock #{resource.name}" - end, + end ) expect(field.display_associated_resource).to eq("Mock Associated Country") end @@ -94,13 +94,13 @@ it "determines the associated_class" do line_item = create(:line_item) field_class = Administrate::Field::BelongsTo.with_options( - class_name: "Customer", + class_name: "Customer" ) field = field_class.new( :product, line_item.product, :show, - resource: line_item, + resource: line_item ) expect(field.associated_class).to eq(Customer) end @@ -109,33 +109,33 @@ product = create(:product, name: "Associated Product") line_item = create(:line_item, product: product) field_class = Administrate::Field::BelongsTo.with_options( - class_name: "LineItem", + class_name: "LineItem" ) field = field_class.new( :product, line_item.product, :show, - resource: line_item, + resource: line_item ) expect(field.display_associated_resource).to match( - /^Line Item \#\d\d\d\d$/, + /^Line Item \#\d\d\d\d$/ ) end it "triggers a deprecation warning" do line_item = create(:line_item) field_class = Administrate::Field::BelongsTo.with_options( - class_name: "Customer", + class_name: "Customer" ) field = field_class.new( :product, line_item.product, :show, - resource: line_item, + resource: line_item ) field.associated_class - expect(Administrate.deprecator).to have_received(:warn). - with(/:class_name is deprecated/) + expect(Administrate.deprecator).to have_received(:warn) + .with(/:class_name is deprecated/) end end @@ -148,11 +148,11 @@ :territory, [], :edit, - resource: customer, + resource: customer ) candidates = field.associated_resource_options - expect(field.include_blank_option). to eq(true) + expect(field.include_blank_option).to eq(true) expect(candidates).to eq([]) end end @@ -161,17 +161,17 @@ it "determines if choices has blank option or not" do customer = create(:customer, territory: nil) association = Administrate::Field::BelongsTo.with_options( - include_blank: false, + include_blank: false ) field = association.new( :territory, [], :edit, - resource: customer, + resource: customer ) candidates = field.associated_resource_options - expect(field.include_blank_option). to eq(false) + expect(field.include_blank_option).to eq(false) expect(candidates).to eq([]) end end @@ -181,25 +181,21 @@ before do allow(Administrate.deprecator).to receive(:warn) - Foo = Class.new - FooDashboard = Class.new + stub_const("Foo", Class.new) + stub_const("FooDashboard", Class.new) uuid = SecureRandom.uuid allow(Foo).to receive(:all).and_return([Foo]) allow(Foo).to receive(:uuid).and_return(uuid) allow(Foo).to receive(:id).and_return(1) allow_any_instance_of(FooDashboard).to( - receive(:display_resource).and_return(uuid), + receive(:display_resource).and_return(uuid) ) end - after do - remove_constants :Foo, :FooDashboard - end - it "is the associated table key that matches our foreign key" do association = Administrate::Field::BelongsTo.with_options( - primary_key: "uuid", class_name: "Foo", + primary_key: "uuid", class_name: "Foo" ) field = association.new(:customers, [], :show) field.associated_resource_options @@ -212,13 +208,13 @@ it "triggers a deprecation warning" do association = Administrate::Field::BelongsTo.with_options( - primary_key: "uuid", + primary_key: "uuid" ) field = association.new(:foo, double(uuid: nil), :baz) field.selected_option - expect(Administrate.deprecator).to have_received(:warn). - with(/:primary_key is deprecated/) + expect(Administrate.deprecator).to have_received(:warn) + .with(/:primary_key is deprecated/) end end @@ -229,7 +225,7 @@ it "determines what foreign key is used on the relationship for the form" do association = Administrate::Field::BelongsTo.with_options( - foreign_key: "foo_uuid", class_name: "Foo", + foreign_key: "foo_uuid", class_name: "Foo" ) field = association.new(:customers, [], :show) permitted_attribute = field.permitted_attribute @@ -238,14 +234,14 @@ it "triggers a deprecation warning" do association = Administrate::Field::BelongsTo.with_options( - foreign_key: "foo_uuid", class_name: "Foo", + foreign_key: "foo_uuid", class_name: "Foo" ) field = association.new(:customers, [], :show) field.permitted_attribute - expect(Administrate.deprecator).to have_received(:warn). - with(/:foreign_key is deprecated/) + expect(Administrate.deprecator).to have_received(:warn) + .with(/:foreign_key is deprecated/) end end @@ -254,7 +250,7 @@ it "returns the resources in correct order" do order = create(:order) create_list(:customer, 5) - options = { order: "name" } + options = {order: "name"} association = Administrate::Field::BelongsTo.with_options(options) field = association.new(:customer, [], :show, resource: order) @@ -270,7 +266,7 @@ create_list(:customer, 3) options = { order: "name", - scope: -> { Customer.order(name: :desc) }, + scope: -> { Customer.order(name: :desc) } } association = Administrate::Field::BelongsTo.with_options(options) diff --git a/spec/lib/fields/boolean_spec.rb b/spec/lib/fields/boolean_spec.rb index fbf5b207a6..1ad81ae1b7 100644 --- a/spec/lib/fields/boolean_spec.rb +++ b/spec/lib/fields/boolean_spec.rb @@ -21,7 +21,7 @@ should_permit_param( "foo", on_model: Customer, - for_attribute: :foo, + for_attribute: :foo ) end diff --git a/spec/lib/fields/date_spec.rb b/spec/lib/fields/date_spec.rb index 36a8b9bb16..e4605365ba 100644 --- a/spec/lib/fields/date_spec.rb +++ b/spec/lib/fields/date_spec.rb @@ -6,29 +6,29 @@ let(:formats) do { date: { - formats: { default: "%m/%d/%Y", short: "%b %d" }, + formats: {default: "%m/%d/%Y", short: "%b %d"}, abbr_month_names: Array.new(13) { |i| "Dec" if i == 12 }, - abbr_day_names: Array.new(7) { |i| "Fri" if i == 5 }, + abbr_day_names: Array.new(7) { |i| "Fri" if i == 5 } }, time: { - formats: { default: "%a, %b %-d, %Y", short: "%d %b" }, - }, + formats: {default: "%a, %b %-d, %Y", short: "%d %b"} + } } end describe "#date" do it "displays the date" do with_translations(:en, formats) do - field = Administrate::Field::Date. - new(:start_date, start_date, :show) + field = Administrate::Field::Date + .new(:start_date, start_date, :show) expect(field.date).to eq("12/25/2015") end end context "with `prefix` option" do it "displays the date in the requested format" do - options_field = Administrate::Field::Date. - with_options(format: :short) + options_field = Administrate::Field::Date + .with_options(format: :short) field = options_field.new(:start_date, start_date, :show) with_translations(:en, formats) do @@ -37,8 +37,8 @@ end it "displays the date using a format string" do - options_field = Administrate::Field::Date. - with_options(format: "%Y") + options_field = Administrate::Field::Date + .with_options(format: "%Y") field = options_field.new(:start_date, start_date, :show) with_translations(:en, formats) do diff --git a/spec/lib/fields/date_time_spec.rb b/spec/lib/fields/date_time_spec.rb index fa1305b8d2..912732fe05 100644 --- a/spec/lib/fields/date_time_spec.rb +++ b/spec/lib/fields/date_time_spec.rb @@ -6,29 +6,29 @@ let(:formats) do { date: { - formats: { default: "%m/%d/%Y", short: "%b %d" }, + formats: {default: "%m/%d/%Y", short: "%b %d"}, abbr_month_names: Array.new(13) { |i| "Dec" if i == 12 }, - abbr_day_names: Array.new(7) { |i| "Fri" if i == 5 }, + abbr_day_names: Array.new(7) { |i| "Fri" if i == 5 } }, time: { - formats: { default: "%a, %b %-d, %Y at %r", short: "%d %b %H:%M" }, - }, + formats: {default: "%a, %b %-d, %Y at %r", short: "%d %b %H:%M"} + } } end describe "#date" do it "displays the date" do with_translations(:en, formats) do - field = Administrate::Field::DateTime. - new(:start_date, start_date, :show) + field = Administrate::Field::DateTime + .new(:start_date, start_date, :show) expect(field.date).to eq("12/25/2015") end end context "with `prefix` option" do it "displays the date in the requested format" do - options_field = Administrate::Field::DateTime. - with_options(format: :short) + options_field = Administrate::Field::DateTime + .with_options(format: :short) field = options_field.new(:start_date, start_date, :show) with_translations(:en, formats) do @@ -37,8 +37,8 @@ end it "displays the date using a format string" do - options_field = Administrate::Field::DateTime. - with_options(format: "%Y") + options_field = Administrate::Field::DateTime + .with_options(format: "%Y") field = options_field.new(:start_date, start_date, :show) with_translations(:en, formats) do @@ -50,8 +50,8 @@ context "with `timezone` option set to New York & early DateTime" do it "displays previous day because of the time difference" do start_date = DateTime.parse("2015-12-25 02:15:45") - options_field = Administrate::Field::DateTime. - with_options(format: :short, timezone: "America/New_York") + options_field = Administrate::Field::DateTime + .with_options(format: :short, timezone: "America/New_York") field = options_field.new(:start_date, start_date, :show) with_translations(:en, formats) do @@ -63,8 +63,8 @@ context "with default `timezone` set to New York & early DateTime" do it "displays previous day because of the time difference" do start_date = Time.zone.parse("2015-12-25 02:15:45") - options_field = Administrate::Field::DateTime. - with_options(format: :short) + options_field = Administrate::Field::DateTime + .with_options(format: :short) field = options_field.new(:start_date, start_date, :show) Time.use_zone("America/New_York") do @@ -76,8 +76,8 @@ it "displays the date with the timezone which is specified by options" do start_date = Time.zone.parse("2015-12-25 02:15:45") - options_field = Administrate::Field::DateTime. - with_options(format: :short, timezone: "Paris") + options_field = Administrate::Field::DateTime + .with_options(format: :short, timezone: "Paris") field = options_field.new(:start_date, start_date, :show) Time.use_zone("America/New_York") do @@ -100,8 +100,8 @@ context "with `prefix` option" do it "displays the datetime in the requested format" do - options_field = Administrate::Field::DateTime. - with_options(format: :short) + options_field = Administrate::Field::DateTime + .with_options(format: :short) field = options_field.new(:start_date, start_date, :show) with_translations(:en, formats) do @@ -110,8 +110,8 @@ end it "displays the datetime format string" do - options_field = Administrate::Field::DateTime. - with_options(format: "%H:%M") + options_field = Administrate::Field::DateTime + .with_options(format: "%H:%M") field = options_field.new(:start_date, start_date, :show) with_translations(:en, formats) do @@ -122,8 +122,8 @@ context "with `timezone` option" do it "displays the datetime for the specified timezone" do - options_field = Administrate::Field::DateTime. - with_options(format: "%H:%M", timezone: "America/New_York") + options_field = Administrate::Field::DateTime + .with_options(format: "%H:%M", timezone: "America/New_York") field = options_field.new(:start_date, start_date, :show) with_translations(:en, formats) do diff --git a/spec/lib/fields/deferred_spec.rb b/spec/lib/fields/deferred_spec.rb index 1d5eec25bc..c8b5514330 100644 --- a/spec/lib/fields/deferred_spec.rb +++ b/spec/lib/fields/deferred_spec.rb @@ -14,35 +14,35 @@ it "returns the value given" do deferred = Administrate::Field::Deferred.new( Administrate::Field::BelongsTo, - foreign_key: :bar, + foreign_key: :bar ) - expect(deferred.permitted_attribute(:foo, resource_class: LineItem)). - to eq(:bar) + expect(deferred.permitted_attribute(:foo, resource_class: LineItem)) + .to eq(:bar) end it "triggers a deprecation warning" do deferred = Administrate::Field::Deferred.new( Administrate::Field::BelongsTo, - foreign_key: :bar, + foreign_key: :bar ) deferred.permitted_attribute(:foo, resource_class: LineItem) - expect(Administrate.deprecator).to have_received(:warn). - with(/:foreign_key is deprecated/) + expect(Administrate.deprecator).to have_received(:warn) + .with(/:foreign_key is deprecated/) end end context "when not given a `foreign_key` option" do it "delegates to the backing class" do deferred = Administrate::Field::Deferred.new( - Administrate::Field::String, + Administrate::Field::String ) allow(Administrate::Field::String).to receive(:permitted_attribute) deferred.permitted_attribute(:foo, resource_class: LineItem) expect(Administrate::Field::String).to( - have_received(:permitted_attribute). - with(:foo, resource_class: LineItem), + have_received(:permitted_attribute) + .with(:foo, resource_class: LineItem) ) end end @@ -53,14 +53,14 @@ allow(field).to receive(:permitted_attribute) deferred = Administrate::Field::Deferred.new( field, - class_name: "Foo::Bar", + class_name: "Foo::Bar" ) deferred.permitted_attribute(:bars) expect(field).to( - have_received(:permitted_attribute). - with(:bars, class_name: "Foo::Bar"), + have_received(:permitted_attribute) + .with(:bars, class_name: "Foo::Bar") ) end end @@ -71,11 +71,11 @@ it "returns the value given" do searchable_deferred = Administrate::Field::Deferred.new( double(searchable?: false), - searchable: true, + searchable: true ) unsearchable_deferred = Administrate::Field::Deferred.new( double(searchable?: true), - searchable: false, + searchable: false ) expect(searchable_deferred.searchable?).to eq(true) @@ -86,10 +86,10 @@ context "when not given a `searchable` option" do it "falls back to the default of the deferred class" do searchable_deferred = Administrate::Field::Deferred.new( - double(searchable?: true), + double(searchable?: true) ) unsearchable_deferred = Administrate::Field::Deferred.new( - double(searchable?: false), + double(searchable?: false) ) expect(searchable_deferred.searchable?).to eq(true) diff --git a/spec/lib/fields/has_many_spec.rb b/spec/lib/fields/has_many_spec.rb index a7c07306b1..9ac5628240 100644 --- a/spec/lib/fields/has_many_spec.rb +++ b/spec/lib/fields/has_many_spec.rb @@ -23,7 +23,7 @@ :orders, Order.all, :show, - resource: customer, + resource: customer ) page = field.associated_collection @@ -38,17 +38,13 @@ before do allow(Administrate.deprecator).to receive(:warn) - FooDashboard = Class.new + stub_const("FooDashboard", Class.new) allow(FooDashboard).to receive(:new).and_return(dashboard_double) end - after do - remove_constants :FooDashboard - end - it "determines what dashboard is used to present the association" do - association = Administrate::Field::HasMany. - with_options(class_name: "Foo") + association = Administrate::Field::HasMany + .with_options(class_name: "Foo") field = association.new(:customers, [], :show) collection = field.associated_collection attributes = collection.attribute_names @@ -58,13 +54,13 @@ end it "triggers a deprecation warning" do - association = Administrate::Field::HasMany. - with_options(class_name: "Foo") + association = Administrate::Field::HasMany + .with_options(class_name: "Foo") field = association.new(:customers, [], :show) field.associated_collection - expect(Administrate.deprecator).to have_received(:warn). - with(/:class_name is deprecated/) + expect(Administrate.deprecator).to have_received(:warn) + .with(/:class_name is deprecated/) end end @@ -72,25 +68,21 @@ before do allow(Administrate.deprecator).to receive(:warn) - Foo = Class.new - FooDashboard = Class.new + stub_const("Foo", Class.new) + stub_const("FooDashboard", Class.new) uuid = SecureRandom.uuid allow(Foo).to receive(:all).and_return([Foo]) allow(Foo).to receive(:uuid).and_return(uuid) allow(Foo).to receive(:id).and_return(1) allow_any_instance_of(FooDashboard).to( - receive(:display_resource).and_return(uuid), + receive(:display_resource).and_return(uuid) ) end - after do - remove_constants :Foo, :FooDashboard - end - it "is the key matching the associated foreign key" do association = Administrate::Field::HasMany.with_options( - primary_key: "uuid", class_name: "Foo", + primary_key: "uuid", class_name: "Foo" ) field = association.new(:customers, [], :show) field.associated_resource_options @@ -103,13 +95,13 @@ it "triggers a deprecation warning" do association = Administrate::Field::HasMany.with_options( - primary_key: "uuid", class_name: "Foo", + primary_key: "uuid", class_name: "Foo" ) field = association.new(:customers, [], :show) field.associated_resource_options - expect(Administrate.deprecator).to have_received(:warn). - with(/:primary_key is deprecated/) + expect(Administrate.deprecator).to have_received(:warn) + .with(/:primary_key is deprecated/) end end @@ -143,7 +135,7 @@ :orders, value, :show, - resource: customer, + resource: customer ) expect(field.more_than_limit?).to eq(false) @@ -161,7 +153,7 @@ :orders, value, :show, - resource: customer, + resource: customer ) expect(field.resources.size).to eq(limit) @@ -176,7 +168,7 @@ :orders, value, :show, - resource: customer, + resource: customer ) expect(field.resources).to eq([]) @@ -198,13 +190,13 @@ context "with `sort_by` option" do it "returns the resources in correct order" do customer = create(:customer, :with_orders) - options = { sort_by: :address_line_two } + options = {sort_by: :address_line_two} association = Administrate::Field::HasMany.with_options(options) field = association.new( :orders, customer.orders, :show, - resource: customer, + resource: customer ) correct_order = customer.orders.sort_by(&:address_line_two).map(&:id) @@ -220,13 +212,13 @@ context "with `direction` option" do it "returns the resources in correct order" do customer = create(:customer, :with_orders) - options = { sort_by: :address_line_two, direction: :desc } + options = {sort_by: :address_line_two, direction: :desc} association = Administrate::Field::HasMany.with_options(options) field = association.new( :orders, customer.orders, :show, - resource: customer, + resource: customer ) reversed_order = customer.orders.sort_by(&:address_line_two).map(&:id) @@ -244,17 +236,17 @@ it "returns a collection of keys to use for the association" do associated_resource1 = double( "AssociatedResource1", - associated_resource_key: "associated-1", + associated_resource_key: "associated-1" ) associated_resource2 = double( "AssociatedResource2", - associated_resource_key: "associated-2", + associated_resource_key: "associated-2" ) attribute_value = MockRelation.new( [ associated_resource1, - associated_resource2, - ], + associated_resource2 + ] ) primary_resource = double( @@ -263,9 +255,9 @@ "ResourceClass", reflect_on_association: double( "ResourceReflection", - association_primary_key: "associated_resource_key", - ), - ), + association_primary_key: "associated_resource_key" + ) + ) ) association = Administrate::Field::HasMany @@ -273,7 +265,7 @@ :customers, attribute_value, :show, - resource: primary_resource, + resource: primary_resource ) expect(field.selected_options).to eq(["associated-1", "associated-2"]) @@ -288,7 +280,7 @@ :orders, value, :show, - resource: customer, + resource: customer ) expect(field.selected_options).to be_nil diff --git a/spec/lib/fields/has_one_spec.rb b/spec/lib/fields/has_one_spec.rb index 213ec21c4d..675eafa5ae 100644 --- a/spec/lib/fields/has_one_spec.rb +++ b/spec/lib/fields/has_one_spec.rb @@ -14,7 +14,7 @@ :product_meta_tag, value, :show, - resource: resource, + resource: resource ) form = field.nested_form @@ -31,7 +31,7 @@ :product_meta_tag, product_meta_tag, :show, - resource: product, + resource: product ) show = field.nested_show @@ -49,30 +49,30 @@ it "returns attributes from correct dashboard" do field = Administrate::Field::Deferred.new( Administrate::Field::HasOne, - class_name: :product_meta_tag, + class_name: :product_meta_tag ) field_name = "product_meta_tag" attributes = field.permitted_attribute( field_name, - resource_class: Product, + resource_class: Product ) - expect(attributes[:"#{field_name}_attributes"]). - to eq(%i(meta_title meta_description id)) + expect(attributes[:"#{field_name}_attributes"]) + .to eq(%i[meta_title meta_description id]) end it "triggers a deprecation warning" do field = Administrate::Field::Deferred.new( Administrate::Field::HasOne, - class_name: :product_meta_tag, + class_name: :product_meta_tag ) field_name = "product_meta_tag" field.permitted_attribute( field_name, - resource_class: Product, + resource_class: Product ) - expect(Administrate.deprecator).to have_received(:warn). - with(/:class_name is deprecated/) + expect(Administrate.deprecator).to have_received(:warn) + .with(/:class_name is deprecated/) end end end @@ -86,7 +86,7 @@ :product_meta_tag, value, page, - resource: resource, + resource: resource ) path = field.to_partial_path @@ -102,7 +102,7 @@ field = described_class.new( :product_meta_tag, product_meta_tag, - :show, + :show ) expect(field).to be_linkable @@ -115,7 +115,7 @@ field = described_class.new( :product_meta_tag, product_meta_tag, - :show, + :show ) expect(field).to_not be_linkable @@ -128,7 +128,7 @@ field = described_class.new( :product_meta_tag, product_meta_tag, - :show, + :show ) expect(field).not_to be_linkable diff --git a/spec/lib/fields/number_spec.rb b/spec/lib/fields/number_spec.rb index 9ce19b33cc..03202038ad 100644 --- a/spec/lib/fields/number_spec.rb +++ b/spec/lib/fields/number_spec.rb @@ -21,7 +21,7 @@ should_permit_param( "foo", on_model: Customer, - for_attribute: :foo, + for_attribute: :foo ) end @@ -87,21 +87,21 @@ context "when `formatter: :number_to_delimited`" do it "includes the delimiter for numbers greater than 999" do ninety_nine = number_with_options( - 999, format: { formatter: :number_to_delimited } + 999, format: {formatter: :number_to_delimited} ) thousand_default = number_with_options( - 1_000, format: { formatter: :number_to_delimited } + 1_000, format: {formatter: :number_to_delimited} ) thousand_explicit_comma = number_with_options( 1_000, format: { formatter: :number_to_delimited, - formatter_options: { delimiter: "," }, + formatter_options: {delimiter: ","} } ) million_explicit_space = number_with_options( 1_000_000, format: { formatter: :number_to_delimited, - formatter_options: { delimiter: " " }, + formatter_options: {delimiter: " "} } ) @@ -115,7 +115,7 @@ context "when `formatter: :number_to_currency`" do it "includes the currency" do with_currency = number_with_options( - 100, format: { formatter: :number_to_currency } + 100, format: {formatter: :number_to_currency} ) expect(with_currency.to_s).to eq("$100.00") end @@ -123,7 +123,7 @@ context "when passed incorrect `formatter`" do it "works" do - thousand = number_with_options(1_000, format: { formatter: :rubbish }) + thousand = number_with_options(1_000, format: {formatter: :rubbish}) expect(thousand.to_s).to eq("1000") end @@ -141,9 +141,9 @@ formatter: :number_to_delimited, formatter_options: { delimiter: " ", - separator: ",", - }, - }, + separator: "," + } + } } number = number_with_options(100, **options) diff --git a/spec/lib/fields/password_spec.rb b/spec/lib/fields/password_spec.rb index 249051fc27..06b7728427 100644 --- a/spec/lib/fields/password_spec.rb +++ b/spec/lib/fields/password_spec.rb @@ -20,7 +20,7 @@ should_permit_param( "foo", on_model: Customer, - for_attribute: :foo, + for_attribute: :foo ) end @@ -54,8 +54,8 @@ it "shortens to the given length & different to default character" do password = password_with_options(lorem(30), - truncate: 10, - character: "-") + truncate: 10, + character: "-") expect(password.truncate).to eq(lorem(10, "-")) end diff --git a/spec/lib/fields/polymorphic_spec.rb b/spec/lib/fields/polymorphic_spec.rb index e768a1c338..ac17c60cc4 100644 --- a/spec/lib/fields/polymorphic_spec.rb +++ b/spec/lib/fields/polymorphic_spec.rb @@ -20,29 +20,27 @@ it do should_permit_param( - { "foo" => %i{type value} }, + {"foo" => %i[type value]}, on_model: Customer, - for_attribute: :foo, + for_attribute: :foo ) end describe "#display_associated_resource" do it "displays through the dashboard based on the polymorphic class name" do - begin - Thing = Class.new - ThingDashboard = Class.new do - def display_resource(*) - :success - end + Thing = Class.new + ThingDashboard = Class.new do + def display_resource(*) + :success end + end - field = Administrate::Field::Polymorphic.new(:foo, Thing.new, :show) - display = field.display_associated_resource + field = Administrate::Field::Polymorphic.new(:foo, Thing.new, :show) + display = field.display_associated_resource - expect(display).to eq :success - ensure - remove_constants :Thing, :ThingDashboard - end + expect(display).to eq :success + ensure + remove_constants :Thing, :ThingDashboard end end diff --git a/spec/lib/fields/select_spec.rb b/spec/lib/fields/select_spec.rb index 36b9e63106..7acd2c4b8c 100644 --- a/spec/lib/fields/select_spec.rb +++ b/spec/lib/fields/select_spec.rb @@ -10,11 +10,11 @@ "yes", :_page_, resource: customer, - collection: ["no", "yes", "absolutely"], + collection: ["no", "yes", "absolutely"] ) expect(field.selectable_options).to eq( - ["no", "yes", "absolutely"], + ["no", "yes", "absolutely"] ) end @@ -28,14 +28,14 @@ collection: { "no" => "opt0", "yes" => "opt1", - "absolutely" => "opt2", - }, + "absolutely" => "opt2" + } ) expect(field.selectable_options).to eq( "no" => "opt0", "yes" => "opt1", - "absolutely" => "opt2", + "absolutely" => "opt2" ) end @@ -50,15 +50,15 @@ { "no" => "opt0", "yes" => "opt1", - "absolutely" => "opt2", + "absolutely" => "opt2" } - }, + } ) expect(field.selectable_options).to eq( "no" => "opt0", "yes" => "opt1", - "absolutely" => "opt2", + "absolutely" => "opt2" ) end @@ -74,15 +74,15 @@ { "no, #{person.name}" => "opt0", "yes, #{person.name}" => "opt1", - "absolutely, #{person.name}" => "opt2", + "absolutely, #{person.name}" => "opt2" } - }, + } ) expect(field.selectable_options).to eq( "no, Dave" => "opt0", "yes, Dave" => "opt1", - "absolutely, Dave" => "opt2", + "absolutely, Dave" => "opt2" ) end @@ -92,7 +92,7 @@ :kind, "vip", :_page_, - resource: customer, + resource: customer ) expect(field.selectable_options).to eq(["standard", "vip"]) @@ -105,7 +105,7 @@ "platinum", :_page_, resource: customer, - collection: ["gold", "platinum"], + collection: ["gold", "platinum"] ) expect(field.selectable_options).to eq(["gold", "platinum"]) @@ -117,7 +117,7 @@ :email_subscriber, "opt1", :_page_, - resource: customer, + resource: customer ) expect(field.selectable_options).to eq([]) diff --git a/spec/lib/fields/string_spec.rb b/spec/lib/fields/string_spec.rb index ed0c5087a3..3688aa1cfc 100644 --- a/spec/lib/fields/string_spec.rb +++ b/spec/lib/fields/string_spec.rb @@ -20,7 +20,7 @@ should_permit_param( "foo", on_model: Customer, - for_attribute: :foo, + for_attribute: :foo ) end diff --git a/spec/lib/fields/time_spec.rb b/spec/lib/fields/time_spec.rb index a65d7fba9c..bce4994696 100644 --- a/spec/lib/fields/time_spec.rb +++ b/spec/lib/fields/time_spec.rb @@ -19,8 +19,8 @@ time = DateTime.new(2021, 3, 26, 16, 38) formats = { time: { - formats: { short: "%H:%M" }, - }, + formats: {short: "%H:%M"} + } } options_field = Administrate::Field::Time.with_options(format: :short) diff --git a/spec/lib/fields/url_spec.rb b/spec/lib/fields/url_spec.rb index 1ae6546b95..dc3e94b526 100644 --- a/spec/lib/fields/url_spec.rb +++ b/spec/lib/fields/url_spec.rb @@ -43,7 +43,7 @@ :url, base_url + "a", :page, - truncate: base_url.length, + truncate: base_url.length ) truncated = url.truncate diff --git a/spec/lib/pages/form_spec.rb b/spec/lib/pages/form_spec.rb index 29d653e1f8..2faa5440fd 100644 --- a/spec/lib/pages/form_spec.rb +++ b/spec/lib/pages/form_spec.rb @@ -27,7 +27,7 @@ "" => %i[ order product - ], + ] ) end end @@ -40,7 +40,7 @@ "" => %i[ order product - ], + ] ) end end @@ -54,7 +54,7 @@ order product quantity - ], + ] ) end end diff --git a/spec/models/customer_spec.rb b/spec/models/customer_spec.rb index c520e30021..26e3e53262 100644 --- a/spec/models/customer_spec.rb +++ b/spec/models/customer_spec.rb @@ -1,6 +1,6 @@ -require 'rails_helper' +require "rails_helper" -RSpec.describe Customer, :type => :model do +RSpec.describe Customer, type: :model do it { should have_many :orders } it { should validate_presence_of(:name) } @@ -25,7 +25,7 @@ it "sums the total_price of all orders" do customer = Customer.new orders: [ order_stub(total_price: 20), - order_stub(total_price: 30), + order_stub(total_price: 30) ] expect(customer.lifetime_value).to eq 50 diff --git a/spec/models/doc_page_spec.rb b/spec/models/doc_page_spec.rb index a583988e66..890c90d80a 100644 --- a/spec/models/doc_page_spec.rb +++ b/spec/models/doc_page_spec.rb @@ -20,8 +20,8 @@ expect(page).to have_attributes( title: nil, body: a_string_matching( - /A framework for creating flexible, powerful admin dashboards/, - ), + /A framework for creating flexible, powerful admin dashboards/ + ) ) end @@ -32,8 +32,8 @@ title: "Getting Started", body: a_string_starting_with( "
Administrate is " \ - "released as a Ruby gem", - ), + "released as a Ruby gem" + ) ) end end diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb index 35de01b97a..b0245808ca 100644 --- a/spec/models/order_spec.rb +++ b/spec/models/order_spec.rb @@ -31,7 +31,7 @@ order.destroy expect(order.errors[:base]).to eq( - ["Cannot delete record because dependent payments exist"], + ["Cannot delete record because dependent payments exist"] ) end @@ -46,7 +46,7 @@ order = build(:order) order.line_items = [ line_item_stub(total_price: 20), - line_item_stub(total_price: 30), + line_item_stub(total_price: 30) ] expect(order.total_price).to eq 50 diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb index 9d3aba359a..af95d81d00 100644 --- a/spec/models/product_spec.rb +++ b/spec/models/product_spec.rb @@ -8,8 +8,8 @@ it { should validate_presence_of(:price) } it do - should validate_numericality_of(:release_year). - is_less_than_or_equal_to(Time.now.year) + should validate_numericality_of(:release_year) + .is_less_than_or_equal_to(Time.now.year) end it "should not allow names that produce empty slugs" do @@ -17,8 +17,8 @@ product.validate - expect(product.errors[:name]). - to include("must have letters or numbers for the URL") + expect(product.errors[:name]) + .to include("must have letters or numbers for the URL") end context "with other products in the database" do @@ -38,5 +38,4 @@ expect(Product.all).to be_empty end - end diff --git a/spec/support/constant_helpers.rb b/spec/support/constant_helpers.rb index 52774dc4e7..97f787b50e 100644 --- a/spec/support/constant_helpers.rb +++ b/spec/support/constant_helpers.rb @@ -2,7 +2,7 @@ module ConstantHelpers def remove_constants(*constants) constants.each { |const| Object.send(:remove_const, const) } rescue NameError => e - $stderr.puts "Warning from ConstantHelpers::remove_constants:\n\t#{e}" + warn "Warning from ConstantHelpers::remove_constants:\n\t#{e}" end end diff --git a/spec/support/dashboard_helpers.rb b/spec/support/dashboard_helpers.rb index 92d39617d6..897d9fae6e 100644 --- a/spec/support/dashboard_helpers.rb +++ b/spec/support/dashboard_helpers.rb @@ -1,8 +1,8 @@ module DashboardHelpers def displayed(resource) - (resource.class.to_s + "Dashboard"). - constantize. - new. - display_resource(resource) + (resource.class.to_s + "Dashboard") + .constantize + .new + .display_resource(resource) end end diff --git a/spec/support/field_matchers.rb b/spec/support/field_matchers.rb index b110c48ae8..afff818ec0 100644 --- a/spec/support/field_matchers.rb +++ b/spec/support/field_matchers.rb @@ -2,7 +2,7 @@ module FieldMatchers def should_permit_param(expected_param, for_attribute:, on_model:) permitted_param = described_class.permitted_attribute( for_attribute, - resource_class: on_model, + resource_class: on_model ) permitted_param = diff --git a/spec/support/generator_spec_helpers.rb b/spec/support/generator_spec_helpers.rb index 09bf175566..97d48db5df 100644 --- a/spec/support/generator_spec_helpers.rb +++ b/spec/support/generator_spec_helpers.rb @@ -17,11 +17,11 @@ def provide_existing_routes_file def contents_for_application_template(view_name) File.read( - "app/views/administrate/application/#{view_name}.html.erb", + "app/views/administrate/application/#{view_name}.html.erb" ) end - def invoke_generator(generator, args = [], options = { behavior: :invoke }) + def invoke_generator(generator, args = [], options = {behavior: :invoke}) have_received(:invoke).with(generator, args, options) end diff --git a/spec/support/table.rb b/spec/support/table.rb index 1ca63382a1..a9024abf63 100644 --- a/spec/support/table.rb +++ b/spec/support/table.rb @@ -29,7 +29,7 @@ def url_for(model) "/" + [ :admin, model.class.to_s.underscore.pluralize, - model.to_param, + model.to_param ].join("/") end end