diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index a7b855ae..8b2f6679 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
- ruby-version: ['3.1', '3.2']
+ ruby-version: ['3.3', '3.4']
haml: [true, false]
steps:
- uses: actions/checkout@v4
@@ -34,7 +34,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
- ruby-version: 3.1
+ ruby-version: 3.3
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run rubocop
run: bundle exec rubocop
@@ -47,7 +47,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
- ruby-version: 3.1
+ ruby-version: 3.3
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- uses: paambaati/codeclimate-action@v5.0.0
env:
diff --git a/.rubocop.yml b/.rubocop.yml
index 29cdb992..34cac95f 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -1,112 +1 @@
-require:
- - rubocop-rails
-
-AllCops:
- DisplayCopNames: true
- NewCops: enable
- Exclude:
- # - test/test_app/**/*
- - rdoc/**/*
- - vendor/**/*
- # File generated by Rails
- - '**/test_helper.rb'
- - '**/spec_helper.rb'
- - '**/rails_helper.rb'
- - '**/schema.rb'
- - '**/seeds.rb'
- - '**/initializers/*.rb'
- - '**/environments/*.rb'
- - '**/config/puma.rb'
- - '**/config/routes.rb'
- - '**/config/spring.rb'
- - '**/db/migrate/*.rb'
- - '**/bin/*'
- - '**/boot.rb'
- - '**/config.ru'
- - '**/environment.rb'
- - '**/application.rb'
- - '**/application_helper.rb'
- - '**/application_controller.rb'
- - '**/application_job.rb'
- - '**/application_system_test_case.rb'
- - '**/channels/**/*.rb'
- - '**/rails'
- - '**/bundle'
- - '**/rake'
- - '**/Rakefile'
- - dry_crud.gemspec
- - '**/Gemfile'
- - '**/node_modules/**/*'
-
-Metrics/ClassLength:
- Max: 200
- Exclude:
- - '**/*_test.rb'
-
-Metrics/ModuleLength:
- Max: 150
-
-Metrics/MethodLength:
- Max: 18
-
-Metrics/CyclomaticComplexity:
- Max: 8
-
-Metrics/AbcSize:
- Max: 20
- Exclude:
- - '**/*_test.rb'
-
-Metrics/BlockLength:
- Exclude:
- - '**/*_spec.rb'
- - '**/*_test.rb'
- - '**/*_examples.rb'
-
-Layout/EmptyLinesAroundClassBody:
- Enabled: false
-
-Layout/EmptyLinesAroundModuleBody:
- Enabled: false
-
-Layout/EmptyLinesAroundBlockBody:
- Exclude:
- - '**/*_spec.rb'
-
-Rails/ActionControllerTestCase:
- Enabled: false
-
-Rails/I18nLocaleTexts:
- Exclude:
- - '**/test/support/*.rb'
-
-Rails/HelperInstanceVariable:
- Enabled: false
-
-Rails/LexicallyScopedActionFilter:
- Enabled: false
-
-Rails/OutputSafety:
- Exclude:
- - '**/*_test.rb'
- - '**/*_spec.rb'
-
-Style/ClassVars:
- Exclude:
- - '**/spec/**/*'
-
-# Rails does not, we do not
-Style/FrozenStringLiteralComment:
- Enabled: false
-
-Style/RegexpLiteral:
- Enabled: false
-
-Style/Attr:
- Enabled: false
-
-Style/IfUnlessModifier:
- Enabled: false
-
-Style/GuardClause:
- Enabled: false
+inherit_gem: { rubocop-rails-omakase: rubocop.yml }
diff --git a/Gemfile b/Gemfile
index f865a8d7..b5634666 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,46 +1,47 @@
-source 'https://rubygems.org'
+source "https://rubygems.org"
-gem 'rails', '~> 7.1.0'
+gem "rails", "~> 8.0.0"
-gem 'puma'
+gem "puma"
-gem 'rake'
-gem 'sdoc'
-gem 'rspec-rails'
+gem "rake"
-gem 'haml'
-gem 'jbuilder'
+gem "rspec-rails"
-gem 'kaminari'
+gem "haml"
+gem "jbuilder"
-gem "sprockets-rails"
+gem "kaminari"
+
+gem "propshaft"
gem "jsbundling-rails"
gem "cssbundling-rails"
gem "turbo-rails"
gem "stimulus-rails"
-gem 'bootsnap', require: false
+gem "bootsnap", require: false
-gem 'tzinfo-data', platforms: [:windows, :jruby]
+gem "tzinfo-data", platforms: [ :windows, :jruby ]
group :development do
- gem 'web-console'
- gem 'rubocop'
- gem 'rubocop-rails'
- gem 'spring'
+ gem "web-console"
+ gem "rubocop"
+ gem "rubocop-rails-omakase"
+ gem "sdoc"
+ gem "spring"
end
-gem 'simplecov', require: false
-gem 'debug', platforms: [:mri, :windows]
+gem "simplecov", require: false
+gem "debug", platforms: [ :mri, :windows ], require: "debug/prelude"
# platform specific gems
platforms :ruby do
- gem 'sqlite3'
+ gem "sqlite3"
end
platforms :jruby do
- gem 'jdbc-sqlite3'
- gem 'activerecord-jdbcsqlite3-adapter'
- gem 'jruby-openssl'
+ gem "jdbc-sqlite3"
+ gem "activerecord-jdbcsqlite3-adapter"
+ gem "jruby-openssl"
end
diff --git a/Rakefile b/Rakefile
index 2b578c02..f05c4eaf 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,114 +1,120 @@
# encoding: UTF-8
-#!/usr/bin/env rake
+
+# !/usr/bin/env rake
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 'rake/testtask'
-require 'rspec/core/rake_task'
-require 'sdoc'
-require 'rdoc/task'
+require "rake/testtask"
+require "rspec/core/rake_task"
+require "sdoc"
+require "rdoc/task"
TEST_APP_ROOT = File.join(File.dirname(__FILE__),
- 'test', 'test_app')
+ "test", "test_app")
GENERATOR_ROOT = File.join(File.dirname(__FILE__),
- 'lib', 'generators', 'dry_crud')
+ "lib", "generators", "dry_crud")
task default: :test
desc "Run all tests"
-task test: ['test:unit', 'test:spec']
+task test: [ "test:unit", "test:spec" ]
namespace :test do
-
desc "Run Test::Unit tests"
- Rake::TestTask.new(unit: 'test:app:init') do |test|
+ Rake::TestTask.new(unit: "test:app:init") do |test|
test.libs << "test/test_app/test"
test.test_files = FileList["test/test_app/test/**/*_test.rb"]
test.verbose = true
end
desc "Run RSpec tests"
- RSpec::Core::RakeTask.new(spec: 'test:app:init') do |t|
+ RSpec::Core::RakeTask.new(spec: "test:app:init") do |t|
t.ruby_opts = "-I test/test_app/spec"
t.pattern = "test/test_app/spec/**/*_spec.rb"
end
namespace :app do
-
desc "Initializes the test application with a couple of classes"
- task init: [:seed, :customize]
+ task init: [ :seed, :customize ]
desc "Customize some of the functionality provided by dry_crud"
- task customize: ['test:app:add_pagination',
- 'test:app:use_bootstrap',
- 'test:app:build_assets'
- ]
+ task customize: [ "test:app:add_pagination",
+ "test:app:use_bootstrap",
+ "test:app:build_assets" ]
desc "Create a rails test application"
task :create do
unless File.exist?(TEST_APP_ROOT)
sh "rails new #{TEST_APP_ROOT} --css=bootstrap --js esbuild"
- file_replace(File.join(TEST_APP_ROOT, 'Gemfile'),
+ file_replace(File.join(TEST_APP_ROOT, "Gemfile"),
/\z/,
File.read(File.join(File.dirname(__FILE__),
- 'test', 'templates', 'Gemfile.append')))
+ "test", "templates", "Gemfile.append")))
sh "cd #{TEST_APP_ROOT}; bundle install --local" # update Gemfile.lock
sh "cd #{TEST_APP_ROOT}; rails g rspec:install"
FileUtils.rm_f(File.join(TEST_APP_ROOT,
- 'test', 'performance', 'browsing_test.rb'))
- file_replace(File.join(TEST_APP_ROOT, 'test', 'test_helper.rb'),
+ "test", "performance", "browsing_test.rb"))
+ file_replace(File.join(TEST_APP_ROOT, "test", "test_helper.rb"),
/\A/,
- "require 'simplecov'\nSimpleCov.start do\n" +
- " coverage_dir 'coverage/test'\nend\n")
- file_replace(File.join(TEST_APP_ROOT, 'spec', 'spec_helper.rb'),
+ "require \"simplecov\"\nSimpleCov.start do\n" +
+ " coverage_dir \"coverage/test\"\nend\n")
+ file_replace(File.join(TEST_APP_ROOT, "test", "test_helper.rb"),
+ /module ActiveSupport/,
+ "Rails.root.glob(\"test/support/**/*.rb\").sort_by(&:to_s).each { |f| require f }\n\n" +
+ "module ActiveSupport")
+ file_replace(File.join(TEST_APP_ROOT, "spec", "spec_helper.rb"),
/\A/,
- "require 'simplecov'\nSimpleCov.start do\n" +
- " coverage_dir 'coverage/spec'\nend\n")
- file_replace(File.join(TEST_APP_ROOT, 'spec', 'rails_helper.rb'),
- "# Rails.root.glob('spec/support/**/*.rb').sort.each { |f| require f }",
- "Rails.root.glob('spec/support/**/*.rb').sort.each { |f| require f }")
+ "require \"simplecov\"\nSimpleCov.start do\n" +
+ " coverage_dir \"coverage/spec\"\nend\n")
+ file_replace(File.join(TEST_APP_ROOT, "spec", "rails_helper.rb"),
+ "# Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f }",
+ "Rails.root.glob(\"spec/support/**/*.rb\").sort_by(&:to_s).each { |f| require f }")
+
+ file_replace(File.join(TEST_APP_ROOT, "spec", "rails_helper.rb"),
+ "# config.infer_spec_type_from_file_location!",
+ "config.infer_spec_type_from_file_location!")
end
end
desc "Run the dry_crud generator for the test application"
- task generate_crud: [:create, :environment] do
- require File.join(GENERATOR_ROOT, 'dry_crud_generator_base')
- require File.join(GENERATOR_ROOT, 'dry_crud_generator')
+ task generate_crud: [ :create, :environment ] do
+ require File.join(GENERATOR_ROOT, "dry_crud_generator_base")
+ require File.join(GENERATOR_ROOT, "dry_crud_generator")
DryCrudGenerator.new([],
{ force: true,
- templates: %w[1 yes true].include?(ENV['HAML']) ? 'haml' : 'erb',
- tests: 'all' },
+ templates: %w[1 yes true].include?(ENV["HAML"]) ? "haml" : "erb",
+ tests: "all" },
destination_root: TEST_APP_ROOT).invoke_all
end
task :environment do
- ENV['RAILS_ROOT'] = TEST_APP_ROOT
- ENV['RAILS_ENV'] = 'test'
+ ENV["RAILS_ROOT"] = TEST_APP_ROOT
+ ENV["RAILS_ENV"] = "test"
- require(File.join(TEST_APP_ROOT, 'config', 'environment'))
+ require(File.join(TEST_APP_ROOT, "config", "environment"))
end
desc "Populates the test application with some models and controllers"
- task populate: [:generate_crud] do
+ task populate: [ :generate_crud ] do
# copy test app templates
FileUtils.cp_r(File.join(File.dirname(__FILE__),
- 'test', 'templates', '.'),
+ "test", "templates", "."),
TEST_APP_ROOT)
# copy shared fixtures
FileUtils.cp_r(File.join(File.dirname(__FILE__),
- 'test', 'templates', 'test', 'fixtures'),
- File.join(TEST_APP_ROOT, 'spec'))
+ "test", "templates", "test", "fixtures"),
+ File.join(TEST_APP_ROOT, "spec"))
# remove unused template type, erb or haml
- exclude = %w[1 yes true].include?(ENV['HAML']) ? 'erb' : 'haml'
+ exclude = %w[1 yes true].include?(ENV["HAML"]) ? "erb" : "haml"
Dir.glob(File.join(TEST_APP_ROOT,
- 'app', 'views', '**', "*.#{exclude}")).each do |f|
+ "app", "views", "**", "*.#{exclude}")).each do |f|
FileUtils.rm(f)
end
end
@@ -126,26 +132,26 @@ namespace :test do
desc "Adds pagination to the test app"
task :add_pagination do
list_ctrl = File.join(TEST_APP_ROOT,
- 'app', 'controllers', 'list_controller.rb')
+ "app", "controllers", "list_controller.rb")
file_replace(list_ctrl,
/def list_entries\n\s+(.+)\s*\n/,
"def list_entries\n" +
" list = \\1\n" +
" list.page(params[:page]).per(10)\n")
file_replace(File.join(TEST_APP_ROOT,
- 'app', 'views', 'list', 'index.html.erb'),
- "<%= render 'list' %>",
- "<%= paginate entries %>\n\n<%= render 'list' %>")
+ "app", "views", "list", "index.html.erb"),
+ "<%= render \"list\" %>",
+ "<%= paginate entries %>\n\n<%= render \"list\" %>")
file_replace(File.join(TEST_APP_ROOT,
- 'app', 'views', 'list', 'index.html.haml'),
- "= render 'list'",
- "= paginate entries\n\n= render 'list'")
+ "app", "views", "list", "index.html.haml"),
+ "= render \"list\"",
+ "= paginate entries\n\n= render \"list\"")
end
desc "Remove sample scss in the test app"
task :use_bootstrap do
FileUtils.rm_f(File.join(TEST_APP_ROOT,
- 'app', 'assets', 'stylesheets', 'sample.scss'))
+ "app", "assets", "stylesheets", "sample.scss"))
end
desc "Build javascript and css in the test app"
@@ -158,35 +164,35 @@ end
desc "Clean up all generated resources"
task :clobber do
FileUtils.rm_rf(TEST_APP_ROOT)
- FileUtils.rm_rf('pkg')
+ FileUtils.rm_rf("pkg")
end
Bundler::GemHelper.install_tasks
# :rdoc task
Rake::RDocTask.new do |rdoc|
- rdoc.title = 'dry_crud'
- rdoc.options << '--all' << '--line-numbers' << '--fmt' << 'sdoc'
+ rdoc.title = "dry_crud"
+ rdoc.options << "--all" << "--line-numbers" << "--fmt" << "sdoc"
rdoc.rdoc_files.include(
- *FileList.new('*') do |list|
+ *FileList.new("*") do |list|
list.exclude(/(^|[^.a-z])[a-z]+/)
- list.exclude('TODO')
+ list.exclude("TODO")
end.to_a)
- rdoc.rdoc_files.include('app/**/*.rb')
- rdoc.rdoc_files.include('lib/generators/dry_crud/templates/**/*.rb')
- rdoc.rdoc_files.exclude('lib/generators/dry_crud/templates/**/*_test.rb')
- rdoc.rdoc_files.exclude('lib/generators/dry_crud/templates/**/*_spec.rb')
- rdoc.rdoc_files.exclude('lib/generators/dry_crud/templates/**/*_examples.rb')
- rdoc.rdoc_files.exclude('TODO')
-
- rdoc.rdoc_dir = 'rdoc'
- rdoc.main = 'README.rdoc'
+ rdoc.rdoc_files.include("app/**/*.rb")
+ rdoc.rdoc_files.include("lib/generators/dry_crud/templates/**/*.rb")
+ rdoc.rdoc_files.exclude("lib/generators/dry_crud/templates/**/*_test.rb")
+ rdoc.rdoc_files.exclude("lib/generators/dry_crud/templates/**/*_spec.rb")
+ rdoc.rdoc_files.exclude("lib/generators/dry_crud/templates/**/*_examples.rb")
+ rdoc.rdoc_files.exclude("TODO")
+
+ rdoc.rdoc_dir = "rdoc"
+ rdoc.main = "README.rdoc"
end
desc "Deploy rdoc to website"
task site: :rdoc do
- if ENV['DEST']
- sh "rsync -rzv rdoc/ #{ENV['DEST']}"
+ if ENV["DEST"]
+ sh "rsync -rzv rdoc/ #{ENV["DEST"]}"
else
puts "Please specify a destination with DEST=user@server:/deploy/dir"
end
@@ -200,5 +206,5 @@ def file_replace(file, expression, replacement)
if text == replaced
puts "WARN: Nothing replaced in '#{file}' for '#{expression}'"
end
- File.open(file, 'w') { |f| f.puts replaced }
+ File.open(file, "w") { |f| f.puts replaced }
end
diff --git a/app/controllers/crud_controller.rb b/app/controllers/crud_controller.rb
index 8138dfbf..f48593b1 100644
--- a/app/controllers/crud_controller.rb
+++ b/app/controllers/crud_controller.rb
@@ -8,7 +8,6 @@
# With the help of additional callbacks, it is possible to hook into the
# action procedures without overriding the entire method.
class CrudController < ListController
-
class_attribute :permitted_attrs
# Defines before and after callback hooks for create, update, save and
@@ -139,7 +138,7 @@ def assign_attributes
# The form params for this model.
def model_params
- params.require(model_identifier).permit(permitted_attrs)
+ params.expect(model_identifier => permitted_attrs)
end
# Path of the index page to return to.
@@ -186,7 +185,7 @@ def redirect_on_success(**options)
# Perform a redirect after a failed operation and set a flash alert.
def redirect_on_failure(**options)
location = options[:location] ||
- request.env['HTTP_REFERER'].presence ||
+ request.env["HTTP_REFERER"].presence ||
index_path
flash[:alert] ||= error_messages.presence || flash_message(:failure)
redirect_to location
@@ -211,10 +210,10 @@ def render_failure_json
# or crud.{action_name}.flash.{state} as fallback.
def flash_message(state)
scope = "#{action_name}.flash.#{state}"
- keys = [:"#{controller_name}.#{scope}_html",
+ keys = [ :"#{controller_name}.#{scope}_html",
:"#{controller_name}.#{scope}",
:"crud.#{scope}_html",
- :"crud.#{scope}"]
+ :"crud.#{scope}" ]
I18n.t(keys.shift, model: full_entry_label, default: keys)
end
@@ -229,7 +228,7 @@ def full_entry_label
def error_messages
# rubocop:disable Rails/OutputSafety
escaped = entry.errors.full_messages.map { |m| ERB::Util.html_escape(m) }
- escaped.join('
').html_safe
+ escaped.join("
").html_safe
# rubocop:enable Rails/OutputSafety
end
@@ -242,5 +241,4 @@ def before_render_form(*methods)
before_render_edit(*methods)
end
end
-
end
diff --git a/app/controllers/dry_crud/generic_model.rb b/app/controllers/dry_crud/generic_model.rb
index f415720f..aa96ece6 100644
--- a/app/controllers/dry_crud/generic_model.rb
+++ b/app/controllers/dry_crud/generic_model.rb
@@ -1,5 +1,4 @@
module DryCrud
-
# Connects the including controller to the model whose name corrsponds to
# the controller's name.
#
@@ -7,13 +6,12 @@ module DryCrud
# Additional helper methods store and retrieve values in instance variables
# named after their class.
module GenericModel
-
extend ActiveSupport::Concern
included do
helper_method :model_class, :models_label, :path_args
- delegate :model_class, :models_label, :model_identifier, to: 'self.class'
+ delegate :model_class, :models_label, :model_identifier, to: "self.class"
end
# The scope where model entries will be listed and created.
@@ -43,11 +41,11 @@ def model_ivar_get(plural: false)
def model_ivar_set(value)
name = if value.respond_to?(:klass) # ActiveRecord::Relation
ivar_name(value.klass).pluralize
- elsif value.respond_to?(:each) # Array
+ elsif value.respond_to?(:each) # Array
ivar_name(value.first.class).pluralize
- else
+ else
ivar_name(value.class)
- end
+ end
instance_variable_set(:"@#{name}", value)
end
@@ -57,7 +55,6 @@ def ivar_name(klass)
# Class methods from GenericModel.
module ClassMethods
-
# The ActiveRecord class of the model.
def model_class
@model_class ||= controller_name.classify.constantize
@@ -77,7 +74,6 @@ def models_label(plural: true)
model_class.model_name.human(opts)
end
-
end
end
end
diff --git a/app/controllers/dry_crud/nestable.rb b/app/controllers/dry_crud/nestable.rb
index 97d4e120..3c62563f 100644
--- a/app/controllers/dry_crud/nestable.rb
+++ b/app/controllers/dry_crud/nestable.rb
@@ -1,5 +1,4 @@
module DryCrud
-
# Provides functionality to nest controllers/resources.
# If a controller is nested, the parent classes and namespaces
# may be defined as an array in the +nesting+ class attribute.
@@ -8,7 +7,6 @@ module DryCrud
# namespace, may define this attribute as follows:
# self.nesting = :admin, Country
module Nestable
-
# Adds the :nesting class attribute and parent helper methods
# to the including controller.
def self.prepended(klass)
@@ -45,7 +43,7 @@ def parent_entry(clazz)
# An array of objects used in url_for and related functions.
def path_args(last)
- parents + [last]
+ parents + [ last ]
end
# Uses the parent entry (if any) to constrain the model scope.
@@ -61,6 +59,5 @@ def model_scope
def parent_scope
parent.send(model_class.name.underscore.pluralize)
end
-
end
end
diff --git a/app/controllers/dry_crud/rememberable.rb b/app/controllers/dry_crud/rememberable.rb
index 7b12e91e..46b90d71 100644
--- a/app/controllers/dry_crud/rememberable.rb
+++ b/app/controllers/dry_crud/rememberable.rb
@@ -1,5 +1,4 @@
module DryCrud
-
# Remembers certain params of the index action in order to return
# to the same list after an entry was viewed or edited.
# If the index is called with a param :returning, the remembered params
@@ -11,14 +10,13 @@ module DryCrud
# The params are stored separately for each different +remember_key+, which
# defaults to the current request's path.
module Rememberable
-
extend ActiveSupport::Concern
included do
class_attribute :remember_params
self.remember_params = %w[q sort sort_dir page]
- before_action :handle_remember_params, only: [:index]
+ before_action :handle_remember_params, only: [ :index ]
end
private
@@ -61,6 +59,5 @@ def remembered_params
def remember_key
request.path
end
-
end
end
diff --git a/app/controllers/dry_crud/render_callbacks.rb b/app/controllers/dry_crud/render_callbacks.rb
index 36464783..e5aa3cd1 100644
--- a/app/controllers/dry_crud/render_callbacks.rb
+++ b/app/controllers/dry_crud/render_callbacks.rb
@@ -1,8 +1,6 @@
module DryCrud
-
# Provide +before_render+ callbacks.
module RenderCallbacks
-
extend ActiveSupport::Concern
included do
@@ -12,16 +10,14 @@ module RenderCallbacks
# Prepended methods for callbacks.
module Prepends
-
# Helper method to run +before_render+ callbacks and render the action.
# If a callback renders or redirects, the action is not rendered.
def render(...)
options = _normalize_render(...)
- callback = "render_#{options[:template]}"
-
+ callback = "render_#{options[:template] || options[:action] || action_name}"
run_callbacks(callback) if respond_to?(:"_#{callback}_callbacks", true)
- super(...) unless performed?
+ super unless performed?
end
private
@@ -33,12 +29,10 @@ def with_callbacks(*kinds, &block)
-> { run_callbacks(e, &a) }
end.call
end
-
end
# Class methods for callbacks.
module ClassMethods
-
# Defines before callbacks for the render actions.
def define_render_callbacks(*actions)
args = actions.map { |a| :"render_#{a}" }
@@ -58,8 +52,6 @@ def render_callback_terminator
terminate
end
end
-
end
-
end
end
diff --git a/app/controllers/dry_crud/searchable.rb b/app/controllers/dry_crud/searchable.rb
index 18aeef2a..52d9e0a8 100644
--- a/app/controllers/dry_crud/searchable.rb
+++ b/app/controllers/dry_crud/searchable.rb
@@ -1,10 +1,8 @@
module DryCrud
-
# The search functionality for the index table.
# Define an array of searchable string columns in your subclassing
# controllers using the class attribute +search_columns+.
module Searchable
-
extend ActiveSupport::Concern
included do
@@ -18,7 +16,6 @@ module Searchable
# Prepended methods for searching.
module Prepends
-
private
# Enhance the list entries with an optional search criteria
@@ -61,24 +58,20 @@ def search_column_condition(word)
def search_support?
search_columns.present?
end
-
end
# Class methods for Searchable.
module ClassMethods
-
# All search columns divided in table and field names.
def search_tables_and_fields
@search_tables_and_fields ||= search_columns.map do |f|
- if f.to_s.include?('.')
- f.split('.', 2)
+ if f.to_s.include?(".")
+ f.split(".", 2)
else
- [model_class.table_name, f]
+ [ model_class.table_name, f ]
end
end
end
-
end
-
end
end
diff --git a/app/controllers/dry_crud/sortable.rb b/app/controllers/dry_crud/sortable.rb
index e5284253..9a80cfe0 100644
--- a/app/controllers/dry_crud/sortable.rb
+++ b/app/controllers/dry_crud/sortable.rb
@@ -1,10 +1,8 @@
module DryCrud
-
# Sort functionality for the index table.
# Define a default sort expression that is always appended to the
# current sort params with the class attribute +default_sort+.
module Sortable
-
extend ActiveSupport::Concern
included do
@@ -20,7 +18,6 @@ module Sortable
# Class methods for sorting.
module ClassMethods
-
# Define a map of (virtual) attributes to SQL order expressions.
# May be used for sorting table columns that do not appear directly
# in the database table. E.g., map city_id: 'cities.name' to
@@ -29,20 +26,18 @@ def sort_mappings=(hash)
self.sort_mappings_with_indifferent_access =
hash.with_indifferent_access
end
-
end
# Prepended methods for sorting.
module Prepends
-
private
# Enhance the list entries with an optional sort order.
def list_entries
sortable = sortable?(params[:sort])
if sortable || default_sort
- clause = [sortable ? sort_expression : nil, default_sort]
- super.reorder(Arel.sql(clause.compact.join(', ')))
+ clause = [ sortable ? sort_expression : nil, default_sort ]
+ super.reorder(Arel.sql(clause.compact.join(", ")))
else
super
end
@@ -57,7 +52,7 @@ def sort_expression
# The sort direction, either 'asc' or 'desc'.
def sort_dir
- params[:sort_dir] == 'desc' ? 'DESC' : 'ASC'
+ params[:sort_dir] == "desc" ? "DESC" : "ASC"
end
# Returns true if the passed attribute is sortable.
@@ -66,8 +61,6 @@ def sortable?(attr)
model_class.column_names.include?(attr.to_s) ||
sort_mappings_with_indifferent_access.include?(attr))
end
-
end
-
end
end
diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb
index 91d0ec6f..efcdcfc3 100644
--- a/app/controllers/list_controller.rb
+++ b/app/controllers/list_controller.rb
@@ -7,7 +7,6 @@
# Furthermore, it remembers the last search and sort parameters after the
# user returns from a displayed or edited entry.
class ListController < ApplicationController
-
include DryCrud::GenericModel
prepend DryCrud::Nestable
include DryCrud::RenderCallbacks
@@ -48,5 +47,4 @@ def list_entries
# Include these modules after the #list_entries method is defined.
include DryCrud::Searchable
include DryCrud::Sortable
-
end
diff --git a/app/helpers/actions_helper.rb b/app/helpers/actions_helper.rb
index d0e4c8e0..fefcdd7b 100644
--- a/app/helpers/actions_helper.rb
+++ b/app/helpers/actions_helper.rb
@@ -3,19 +3,18 @@
# of action links, change the method #action_link, e.g. to generate a button.
# The common crud actions show, edit, destroy, index and add are provided here.
module ActionsHelper
-
# A generic helper method to create action links.
# These link could be styled to look like buttons, for example.
def action_link(label, icon = nil, url = {}, html_options = {})
- add_css_class html_options, 'action btn btn-light'
+ add_css_class html_options, "action btn btn-light"
link_to(icon ? action_icon(icon, label) : label,
url, html_options)
end
# Outputs an icon for an action with an optional label.
def action_icon(icon, label = nil)
- html = tag.i('', class: "bi-#{icon}")
- html << ' ' << label if label
+ html = tag.i("", class: "bi-#{icon}")
+ html << " " << label if label
html
end
@@ -23,7 +22,7 @@ def action_icon(icon, label = nil)
# Uses the current +entry+ if no path is given.
def show_action_link(path = nil)
path ||= path_args(entry)
- action_link(ti('link.show'), 'zoom-in', path)
+ action_link(ti("link.show"), "zoom-in", path)
end
# Standard edit action to given path.
@@ -31,14 +30,14 @@ def show_action_link(path = nil)
def edit_action_link(path = nil)
path ||= path_args(entry)
path = edit_polymorphic_path(path) unless path.is_a?(String)
- action_link(ti('link.edit'), 'pencil', path)
+ action_link(ti("link.edit"), "pencil", path)
end
# Standard destroy action to the given path.
# Uses the current +entry+ if no path is given.
def destroy_action_link(path = nil)
path ||= path_args(entry)
- action_link(ti('link.delete'), 'trash', path,
+ action_link(ti("link.delete"), "trash", path,
data: { 'turbo-confirm': ti(:confirm_delete),
'turbo-method': :delete })
end
@@ -48,7 +47,7 @@ def destroy_action_link(path = nil)
def index_action_link(path = nil, url_options = { returning: true })
path ||= path_args(model_class)
path = polymorphic_path(path, url_options) unless path.is_a?(String)
- action_link(ti('link.list'), 'list', path)
+ action_link(ti("link.list"), "list", path)
end
# Standard add action to given path.
@@ -56,7 +55,6 @@ def index_action_link(path = nil, url_options = { returning: true })
def add_action_link(path = nil, url_options = {})
path ||= path_args(model_class)
path = new_polymorphic_path(path, url_options) unless path.is_a?(String)
- action_link(ti('link.add'), 'plus', path)
+ action_link(ti("link.add"), "plus", path)
end
-
end
diff --git a/app/helpers/dry_crud/form/builder.rb b/app/helpers/dry_crud/form/builder.rb
index eeb9a2d0..79f64264 100644
--- a/app/helpers/dry_crud/form/builder.rb
+++ b/app/helpers/dry_crud/form/builder.rb
@@ -1,6 +1,5 @@
module DryCrud
module Form
-
# A form builder that automatically selects the corresponding input field
# for ActiveRecord column types. Convenience methods for each column type
# allow one to customize the different fields.
@@ -14,7 +13,6 @@ module Form
# See the Control class for how to customize the html rendered for a
# single input field.
class Builder < ActionView::Helpers::FormBuilder
-
class_attribute :control_class
self.control_class = Control
@@ -70,10 +68,10 @@ def string_field(attr, **html_options)
# Render a boolean field.
def boolean_field(attr, **html_options)
- tag.div(class: 'checkbox') do
+ tag.div(class: "checkbox") do
tag.label do
- detail = html_options.delete(:detail) || ' '.html_safe
- safe_join([check_box(attr, html_options), ' ', detail])
+ detail = html_options.delete(:detail) || " ".html_safe
+ safe_join([ check_box(attr, html_options), " ", detail ])
end
end
end
@@ -82,7 +80,7 @@ def boolean_field(attr, **html_options)
%w[text_field password_field email_field
number_field date_field time_field datetime_field].each do |method|
define_method(method) do |attr, **html_options|
- add_css_class(html_options, 'form-control')
+ add_css_class(html_options, "form-control")
super(attr, html_options)
end
end
@@ -93,7 +91,7 @@ def integer_field(attr, **html_options)
end
def float_field(attr, **html_options)
- html_options[:step] ||= 'any'
+ html_options[:step] ||= "any"
number_field(attr, **html_options)
end
@@ -105,9 +103,9 @@ def decimal_field(attr, **html_options)
# Customize the standard text area to have 5 rows by default.
def text_area(attr, **html_options)
- add_css_class(html_options, 'form-control')
+ add_css_class(html_options, "form-control")
html_options[:rows] ||= 5
- super(attr, **html_options)
+ super
end
# Render a select element for a :belongs_to association defined by attr.
@@ -118,7 +116,7 @@ def text_area(attr, **html_options)
def belongs_to_field(attr, **html_options)
list = association_entries(attr, **html_options).to_a
if list.present?
- add_css_class(html_options, 'form-control')
+ add_css_class(html_options, "form-control")
collection_select(attr, list, :id, :to_s,
select_options(attr, **html_options),
**html_options)
@@ -140,7 +138,7 @@ def belongs_to_field(attr, **html_options)
# association.
def has_many_field(attr, **html_options)
html_options[:multiple] = true
- add_css_class(html_options, 'multiselect')
+ add_css_class(html_options, "multiselect")
belongs_to_field(attr, **html_options)
end
# rubocop:enable Naming/PredicateName
@@ -149,46 +147,46 @@ def has_many_field(attr, **html_options)
# Render the error messages for the current form.
def error_messages
- @template.render('shared/error_messages',
+ @template.render("shared/error_messages",
errors: @object.errors,
object: @object)
end
# Renders the given content with an addon.
def with_addon(content, addon)
- tag.div(class: 'input-group') do
- content + tag.span(addon, class: 'input-group-text')
+ tag.div(class: "input-group") do
+ content + tag.span(addon, class: "input-group-text")
end
end
# Renders a static text where otherwise form inputs appear.
def static_text(text)
- tag.p(text, class: 'form-control-static')
+ tag.p(text, class: "form-control-static")
end
# Generates a help block for fields
def help_block(text)
- tag.p(text, class: 'help-block')
+ tag.p(text, class: "help-block")
end
# Render a submit button and a cancel link for this form.
- def standard_actions(submit_label = ti('button.save'), cancel_url = nil)
- tag.div(class: 'col-md-offset-2 col-md-8') do
- safe_join([submit_button(submit_label),
- cancel_link(cancel_url)],
- ' ')
+ def standard_actions(submit_label = ti("button.save"), cancel_url = nil)
+ tag.div(class: "col-md-offset-2 col-md-8") do
+ safe_join([ submit_button(submit_label),
+ cancel_link(cancel_url) ],
+ " ")
end
end
# Render a standard submit button with the given label.
- def submit_button(label = ti('button.save'))
- button(label, class: 'btn btn-primary', data: { disable_with: label })
+ def submit_button(label = ti("button.save"))
+ button(label, class: "btn btn-primary", data: { disable_with: label })
end
# Render a cancel link pointing to the given url.
def cancel_link(url = nil)
url ||= cancel_url
- link_to(ti('button.cancel'), url, class: 'cancel')
+ link_to(ti("button.cancel"), url, class: "cancel")
end
# Depending if the given attribute must be present, return
@@ -265,7 +263,7 @@ def respond_to_missing?(name, include_private = false)
# Checks if the passed name corresponds to a field method with a
# 'labeled_' prefix.
def labeled_field_method?(name)
- prefix = 'labeled_'
+ prefix = "labeled_"
if name.to_s.start_with?(prefix)
field_method = name.to_s[prefix.size..]
field_method if respond_to?(field_method)
@@ -321,7 +319,6 @@ def cancel_url
options[:cancel_url_edit] || options[:cancel_url]
end
end
-
end
end
end
diff --git a/app/helpers/dry_crud/form/control.rb b/app/helpers/dry_crud/form/control.rb
index 14eac3e9..389d49e5 100644
--- a/app/helpers/dry_crud/form/control.rb
+++ b/app/helpers/dry_crud/form/control.rb
@@ -1,18 +1,16 @@
module DryCrud
module Form
-
# Internal class to handle the rendering of a single form control,
# consisting of a label, input field, addon, help text or
# required mark.
class Control
-
attr_reader :builder, :attr, :args, :options, :addon, :help
delegate :tag, :object, :add_css_class,
to: :builder
# Html displayed to mark an input as required.
- REQUIRED_MARK = '*'.freeze
+ REQUIRED_MARK = "*".freeze
# Number of default input field span columns depending
# on the #field_method.
@@ -70,8 +68,8 @@ def render_labeled(content = nil)
# Create the HTML markup for any labeled content.
def labeled
- tag.div(class: 'row mb-3') do
- builder.label(attr, caption, class: 'col-md-2 col-form-label') +
+ tag.div(class: "row mb-3") do
+ builder.label(attr, caption, class: "col-md-2 col-form-label") +
tag.div(content, class: "col-md-#{span}")
end
end
@@ -98,8 +96,8 @@ def content
# depending on the attribute.
def input
@input ||= begin
- options[:required] = 'required' if required
- add_css_class(options, 'is-invalid') if errors?
+ options[:required] = "required" if required
+ add_css_class(options, "is-invalid") if errors?
builder.send(field_method, attr, *args, **options)
end
end
@@ -143,9 +141,9 @@ def detect_field_method
:belongs_to_field
elsif association_kind?(:has_and_belongs_to_many, :has_many)
:has_many_field
- elsif attr.to_s.include?('password')
+ elsif attr.to_s.include?("password")
:password_field
- elsif attr.to_s.include?('email')
+ elsif attr.to_s.include?("email")
:email_field
elsif builder.respond_to?(:"#{type}_field")
:"#{type}_field"
@@ -170,8 +168,6 @@ def association_kind?(*macros)
false
end
end
-
end
-
end
end
diff --git a/app/helpers/dry_crud/table/actions.rb b/app/helpers/dry_crud/table/actions.rb
index a812c88b..8ed7e342 100644
--- a/app/helpers/dry_crud/table/actions.rb
+++ b/app/helpers/dry_crud/table/actions.rb
@@ -1,12 +1,10 @@
module DryCrud
module Table
-
# Adds action columns to the table builder.
# Predefined actions are available for show, edit and destroy.
# Additionally, a special col type to define cells linked to the show page
# of the row entry is provided.
module Actions
-
extend ActiveSupport::Concern
included do
@@ -30,7 +28,7 @@ def show_action_col(**html_options, &block)
action_col do |entry|
path = action_path(entry, &block)
if path
- table_action_link('zoom-in',
+ table_action_link("zoom-in",
path,
**html_options.clone)
end
@@ -45,7 +43,7 @@ def edit_action_col(**html_options, &block)
path = action_path(entry, &block)
if path
path = edit_polymorphic_path(path) unless path.is_a?(String)
- table_action_link('pencil', path, **html_options.clone)
+ table_action_link("pencil", path, **html_options.clone)
end
end
end
@@ -57,12 +55,11 @@ def destroy_action_col(**html_options, &block)
action_col do |entry|
path = action_path(entry, &block)
if path
- table_action_link('trash',
+ table_action_link("trash",
path,
- **html_options.merge(
- data: { 'turbo-confirm': ti(:confirm_delete),
- 'turbo-method': :delete }
- ))
+ **html_options,
+ data: { 'turbo-confirm': ti(:confirm_delete),
+ 'turbo-method': :delete })
end
end
end
@@ -70,13 +67,13 @@ def destroy_action_col(**html_options, &block)
# Action column inside a table. No header.
# The cell content should be defined in the passed block.
def action_col(&block)
- col('', class: 'action', &block)
+ col("", class: "action", &block)
end
# Generic action link inside a table.
def table_action_link(icon, url, **html_options)
add_css_class(html_options, "bi-#{icon}")
- link_to('', url, html_options)
+ link_to("", url, html_options)
end
private
@@ -86,8 +83,6 @@ def table_action_link(icon, url, **html_options)
def action_path(entry)
block_given? ? yield(entry) : path_args(entry)
end
-
end
-
end
end
diff --git a/app/helpers/dry_crud/table/builder.rb b/app/helpers/dry_crud/table/builder.rb
index eda1643d..cb5ec127 100644
--- a/app/helpers/dry_crud/table/builder.rb
+++ b/app/helpers/dry_crud/table/builder.rb
@@ -1,6 +1,5 @@
module DryCrud
module Table
-
# A simple helper to easily define tables listing several rows of the same
# data type.
#
@@ -10,7 +9,6 @@ module Table
# t.attrs :name, :city
# end
class Builder
-
include Sorting
include Actions
@@ -39,7 +37,7 @@ def self.table(entries, template, **options)
# Define a column for the table with the given header, the html_options
# used for each td and a block rendering the contents of a cell for the
# current entry. The columns appear in the order they are defined.
- def col(header = '', **html_options, &block)
+ def col(header = "", **html_options, &block)
@cols << Col.new(header, html_options, @template, block)
end
@@ -76,9 +74,9 @@ def align_class(attr)
entry = entries.present? ? entry_class.new : nil
case column_type(entry, attr)
when :integer, :float, :decimal
- 'right' unless association(entry, attr, :belongs_to)
+ "right" unless association(entry, attr, :belongs_to)
when :boolean
- 'center'
+ "center"
end
end
@@ -110,7 +108,6 @@ def entry_class
entries.first.class
end
end
-
end
end
end
diff --git a/app/helpers/dry_crud/table/col.rb b/app/helpers/dry_crud/table/col.rb
index ddf21d5c..d6e12144 100644
--- a/app/helpers/dry_crud/table/col.rb
+++ b/app/helpers/dry_crud/table/col.rb
@@ -1,9 +1,7 @@
module DryCrud
module Table
-
# Helper class to store column information.
class Col # :nodoc:
-
delegate :tag, :capture, to: :template
attr_reader :header, :html_options, :template, :block
@@ -17,7 +15,7 @@ def initialize(header, html_options, template, block)
# Runs the Col block for the given entry.
def content(entry)
- entry.nil? ? '' : capture(entry, &block)
+ entry.nil? ? "" : capture(entry, &block)
end
# Renders the header cell of the Col.
@@ -29,7 +27,6 @@ def html_header
def html_cell(entry)
tag.td(content(entry), **html_options)
end
-
end
end
end
diff --git a/app/helpers/dry_crud/table/sorting.rb b/app/helpers/dry_crud/table/sorting.rb
index 033e1101..dc8737cc 100644
--- a/app/helpers/dry_crud/table/sorting.rb
+++ b/app/helpers/dry_crud/table/sorting.rb
@@ -1,11 +1,9 @@
module DryCrud
module Table
-
# Provides headers with sort links. Expects a method :sortable?(attr)
# in the template/controller to tell if an attribute is sortable or not.
# Extracted into an own module for convenience.
module Sorting
-
# Create a header with sort links and a mark for the current sort
# direction.
def sort_header(attr, label = nil)
@@ -40,10 +38,10 @@ def sort_params(attr)
def current_mark(attr)
if current_sort?(attr)
# rubocop:disable Rails/OutputSafety
- (sort_dir(attr) == 'asc' ? ' ↑' : ' ↓').html_safe
+ (sort_dir(attr) == "asc" ? " ↑" : " ↓").html_safe
# rubocop:enable Rails/OutputSafety
else
- ''
+ ""
end
end
@@ -54,14 +52,13 @@ def current_sort?(attr)
# The sort direction to use in the sort link for the given attribute.
def sort_dir(attr)
- current_sort?(attr) && params[:sort_dir] == 'asc' ? 'desc' : 'asc'
+ current_sort?(attr) && params[:sort_dir] == "asc" ? "desc" : "asc"
end
# Delegate to template.
def params
template.params
end
-
end
end
end
diff --git a/app/helpers/form_helper.rb b/app/helpers/form_helper.rb
index 7736a547..78a231fa 100644
--- a/app/helpers/form_helper.rb
+++ b/app/helpers/form_helper.rb
@@ -6,12 +6,11 @@
# * #crud_form - A #standard_form for the current +entry+, with the given
# attributes or default.
module FormHelper
-
# Renders a form using Crud::FormBuilder.
def plain_form(object, **options, &block)
options[:html] ||= {}
- add_css_class(options[:html], 'form-horizontal')
- options[:html][:role] ||= 'form'
+ add_css_class(options[:html], "form-horizontal")
+ options[:html][:role] ||= "form"
options[:builder] ||= DryCrud::Form::Builder
options[:cancel_url] ||= polymorphic_path(object, returning: true)
@@ -25,13 +24,13 @@ def plain_form(object, **options, &block)
# if present. An options hash may be given as the last argument.
def standard_form(object, *attrs, **options, &block)
plain_form(object, **options) do |form|
- content = [form.error_messages]
+ content = [ form.error_messages ]
content << if block_given?
capture(form, &block)
- else
+ else
form.labeled_input_fields(*attrs)
- end
+ end
content << form.standard_actions
safe_join(content)
@@ -45,5 +44,4 @@ def crud_form(*attrs, **options, &block)
attrs = default_crud_attrs - %i[created_at updated_at] if attrs.blank?
standard_form(path_args(entry), *attrs, **options, &block)
end
-
end
diff --git a/app/helpers/format_helper.rb b/app/helpers/format_helper.rb
index 299b9645..660d0020 100644
--- a/app/helpers/format_helper.rb
+++ b/app/helpers/format_helper.rb
@@ -6,19 +6,18 @@
# Futher helpers standartize the layout of multiple attributes (#render_attrs),
# values with labels (#labeled) and simple lists.
module FormatHelper
-
# Formats a basic value based on its Ruby class.
def f(value)
case value
when Float, BigDecimal
- number_with_precision(value, precision: t('number.format.precision'),
- delimiter: t('number.format.delimiter'))
+ number_with_precision(value, precision: t("number.format.precision"),
+ delimiter: t("number.format.delimiter"))
when Integer
- number_with_delimiter(value, delimiter: t('number.format.delimiter'))
+ number_with_delimiter(value, delimiter: t("number.format.delimiter"))
when Date then l(value)
when Time then "#{l(value.to_date)} #{l(value, format: :time)}"
- when true then t('global.yes')
- when false then t('global.no')
+ when true then t("global.yes")
+ when false then t("global.no")
when nil then UtilityHelper::EMPTY_STRING
else value.to_s
end
@@ -47,7 +46,7 @@ def simple_list(items, **ul_options)
# Renders a list of attributes with label and value for a given object.
# Optionally surrounded with a div.
def render_attrs(obj, *attrs)
- content_tag_nested(:dl, attrs, class: 'dl-horizontal') do |a|
+ content_tag_nested(:dl, attrs, class: "dl-horizontal") do |a|
labeled_attr(obj, a)
end
end
@@ -61,14 +60,14 @@ def labeled_attr(obj, attr)
# presentation.
def labeled(label, content = nil, &block)
content = capture(&block) if block_given?
- render('shared/labeled', label: label, content: content)
+ render("shared/labeled", label: label, content: content)
end
# Transform the given text into a form as used by labels or table headers.
def captionize(text, clazz = nil)
text = text.to_s
if clazz.respond_to?(:human_attribute_name)
- text_without_id = text.end_with?('_ids') ? text[0..-5].pluralize : text
+ text_without_id = text.end_with?("_ids") ? text[0..-5].pluralize : text
clazz.human_attribute_name(text_without_id)
else
text.humanize.titleize
@@ -80,7 +79,7 @@ def captionize(text, clazz = nil)
# Checks whether a format_{class}_{attr} or format_{attr} helper method is
# defined and calls it if is.
def format_with_helper(obj, attr)
- class_name = obj.class.name.underscore.tr('/', '_')
+ class_name = obj.class.name.underscore.tr("/", "_")
format_type_attr_method = :"format_#{class_name}_#{attr}"
format_attr_method = :"format_#{attr}"
@@ -123,7 +122,7 @@ def format_type(obj, attr)
when :decimal
number_with_precision(val.to_s.to_f,
precision: column_property(obj, attr, :scale),
- delimiter: t('number.format.delimiter'))
+ delimiter: t("number.format.delimiter"))
else f(val)
end
end
@@ -161,5 +160,4 @@ def assoc_link(assoc, val)
def assoc_link?(_assoc, val)
respond_to?(:"#{val.class.model_name.singular_route_key}_path")
end
-
end
diff --git a/app/helpers/i18n_helper.rb b/app/helpers/i18n_helper.rb
index 7f28253b..ae87c573 100644
--- a/app/helpers/i18n_helper.rb
+++ b/app/helpers/i18n_helper.rb
@@ -1,7 +1,6 @@
# Translation helpers extending the Rails +translate+ helper to support
# translation inheritance over the controller class hierarchy.
module I18nHelper
-
# Translates the passed key by looking it up over the controller hierarchy.
# The key is searched in the following order:
# - {controller}.{current_partial}.{key}
@@ -13,7 +12,7 @@ module I18nHelper
# - ...
# - global.{key}
def translate_inheritable(key, **variables)
- partial = defined?(@virtual_path) ? @virtual_path.gsub(/.*\/_?/, '') : nil
+ partial = defined?(@virtual_path) ? @virtual_path.gsub(/.*\/_?/, "") : nil
defaults = inheritable_translation_defaults(key, partial)
variables[:default] ||= defaults
t(defaults.shift, **variables)
@@ -30,8 +29,8 @@ def translate_inheritable(key, **variables)
# - global.associations.{key}
def translate_association(key, assoc = nil, **variables)
if assoc && assoc.options[:polymorphic].nil?
- variables[:default] ||= [association_klass_key(assoc, key).to_sym,
- :"global.associations.#{key}"]
+ variables[:default] ||= [ association_klass_key(assoc, key).to_sym,
+ :"global.associations.#{key}" ]
t(association_owner_key(assoc, key), **variables)
else
t("global.associations.#{key}", **variables)
@@ -44,20 +43,20 @@ def translate_association(key, assoc = nil, **variables)
# General translation key based on the klass of the association.
def association_klass_key(assoc, key)
- k = 'activerecord.associations.'
+ k = "activerecord.associations."
k << assoc.klass.model_name.singular
- k << '.'
+ k << "."
k << key.to_s
end
# Specific translation key based on the owner model and the name
# of the association.
def association_owner_key(assoc, key)
- k = 'activerecord.associations.models.'
+ k = "activerecord.associations.models."
k << assoc.active_record.model_name.singular
- k << '.'
+ k << "."
k << assoc.name.to_s
- k << '.'
+ k << "."
k << key.to_s
end
@@ -79,5 +78,4 @@ def append_controller_translation_keys(defaults, folder, partial, key)
defaults << :"#{folder}.#{action_name}.#{key}"
defaults << :"#{folder}.global.#{key}"
end
-
end
diff --git a/app/helpers/table_helper.rb b/app/helpers/table_helper.rb
index 25c369ba..7d39411e 100644
--- a/app/helpers/table_helper.rb
+++ b/app/helpers/table_helper.rb
@@ -7,14 +7,13 @@
# * #crud_table - A sortable #plain_table for the current +entries+, with the
# given attributes or default and the standard crud action links.
module TableHelper
-
# Renders a table for the given entries. One column is rendered for each
# attribute passed. If a block is given, the columns defined therein are
# appended to the attribute columns.
# If entries is empty, an appropriate message is rendered.
# An options hash may be given as the last argument.
def plain_table(entries, *attrs, **options)
- add_css_class(options, 'table table-striped table-hover')
+ add_css_class(options, "table table-striped table-hover")
builder = options.delete(:builder) || DryCrud::Table::Builder
builder.table(entries, self, **options) do |t|
t.attrs(*attrs)
@@ -29,7 +28,7 @@ def plain_table_or_message(entries, *attrs, **options, &block)
if entries.present?
plain_table(entries, *attrs, **options, &block)
else
- tag.div(ti(:no_list_entries), class: 'table')
+ tag.div(ti(:no_list_entries), class: "table")
end
end
@@ -77,5 +76,4 @@ def attrs_or_default(attrs)
attrs
end
end
-
end
diff --git a/app/helpers/utility_helper.rb b/app/helpers/utility_helper.rb
index b6d52c36..5be2ffa6 100644
--- a/app/helpers/utility_helper.rb
+++ b/app/helpers/utility_helper.rb
@@ -1,10 +1,9 @@
-require 'English'
+require "English"
# View helpers for basic functions used in various other helpers.
module UtilityHelper
-
# non-breaking space asserts better css.
- EMPTY_STRING = ' '.html_safe.freeze
+ EMPTY_STRING = " ".html_safe.freeze
# Render a content tag with the collected contents rendered
# by &block for each item in collection.
@@ -21,8 +20,8 @@ def safe_join(array, sep = $OUTPUT_FIELD_SEPARATOR, &block)
# Returns the css class for the given flash level.
def flash_class(level)
case level
- when :notice then 'success'
- when :alert then 'error'
+ when :notice then "success"
+ when :alert then "error"
else level.to_s
end
end
@@ -72,13 +71,12 @@ def association(obj, attr, *macros)
# Returns the name of the attr and it's corresponding field
def assoc_and_id_attr(attr)
attr = attr.to_s
- if attr.end_with?('_id')
- [attr[0..-4], attr]
- elsif attr.end_with?('_ids')
- [attr[0..-5].pluralize, attr]
+ if attr.end_with?("_id")
+ [ attr[0..-4], attr ]
+ elsif attr.end_with?("_ids")
+ [ attr[0..-5].pluralize, attr ]
else
- [attr, "#{attr}_id"]
+ [ attr, "#{attr}_id" ]
end
end
-
end
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 5bd95d65..bb485b43 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -10,7 +10,7 @@
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', 'data-turbo-track': 'reload' %>
- <%= javascript_include_tag 'application', 'data-turbo-track': 'reload', defer: true %>
+ <%= javascript_include_tag 'application', 'data-turbo-track': 'reload', type: 'module', defer: true %>
<%= yield :head %>
diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml
index 64c6acb2..a9a85bb2 100644
--- a/app/views/layouts/application.html.haml
+++ b/app/views/layouts/application.html.haml
@@ -12,7 +12,7 @@
= csp_meta_tag
= stylesheet_link_tag 'application', 'data-turbo-track': 'reload'
- = javascript_include_tag 'application', 'data-turbo-track': 'reload', defer: true
+ = javascript_include_tag 'application', 'data-turbo-track': 'reload', type: 'module', defer: true
= yield :head
diff --git a/dry_crud.gemspec b/dry_crud.gemspec
index ffa92b5f..366629f9 100644
--- a/dry_crud.gemspec
+++ b/dry_crud.gemspec
@@ -1,4 +1,5 @@
# encoding: UTF-8
+
require 'rubygems'
require 'rake'
require 'date'
diff --git a/lib/dry_crud.rb b/lib/dry_crud.rb
index 0b1fa926..eea5f9a3 100644
--- a/lib/dry_crud.rb
+++ b/lib/dry_crud.rb
@@ -1,4 +1,4 @@
-require 'dry_crud/engine'
+require "dry_crud/engine"
# Base namespace
module DryCrud
diff --git a/lib/dry_crud/engine.rb b/lib/dry_crud/engine.rb
index b56509c2..8d0bfcd7 100644
--- a/lib/dry_crud/engine.rb
+++ b/lib/dry_crud/engine.rb
@@ -1,10 +1,9 @@
module DryCrud
# Dry Crud Rails engine
class Engine < Rails::Engine
-
# Fields with errors are directly styled in DryCrud::FormBuilder.
# Rails should just output the plain html tag.
- initializer 'dry_crud.field_error_proc' do |_app|
+ initializer "dry_crud.field_error_proc" do |_app|
ActionView::Base.field_error_proc =
proc { |html_tag, _instance| html_tag }
end
@@ -21,6 +20,5 @@ class Engine < Rails::Engine
paths.prepend(dry_crud_helpers)
end
end
-
end
end
diff --git a/lib/generators/dry_crud/dry_crud_generator.rb b/lib/generators/dry_crud/dry_crud_generator.rb
index 73a0d8b7..3e33c398 100644
--- a/lib/generators/dry_crud/dry_crud_generator.rb
+++ b/lib/generators/dry_crud/dry_crud_generator.rb
@@ -1,15 +1,15 @@
begin
- require 'generators/dry_crud/dry_crud_generator_base'
+ require "generators/dry_crud/dry_crud_generator_base"
rescue LoadError => _e
# ok, we are in the rake task
end
# Copies all dry_crud files to the rails application.
class DryCrudGenerator < DryCrudGeneratorBase
- desc 'Copy all dry_crud files to the application.'
+ desc "Copy all dry_crud files to the application."
- class_options %w[templates -t] => 'erb'
- class_options %w[tests] => 'testunit'
+ class_options %w[templates -t] => "erb"
+ class_options %w[tests] => "testunit"
# copy everything to application
def install_dry_crud
@@ -19,7 +19,7 @@ def install_dry_crud
copy_crud_test_model
end
- readme 'INSTALL'
+ readme "INSTALL"
end
private
@@ -27,29 +27,29 @@ def install_dry_crud
def should_copy?(file_source)
!file_source.end_with?(exclude_template) &&
!file_source.start_with?(exclude_test_dir) &&
- file_source != 'INSTALL'
+ file_source != "INSTALL"
end
def copy_crud_test_model
- unless exclude_test_dir == 'spec'
- template(File.join('test', 'support', 'crud_test_model.rb'),
- File.join('spec', 'support', 'crud_test_model.rb'))
- template(File.join('test', 'support', 'crud_test_models_controller.rb'),
- File.join('spec', 'support', 'crud_test_models_controller.rb'))
- template(File.join('test', 'support', 'crud_test_helper.rb'),
- File.join('spec', 'support', 'crud_test_helper.rb'))
+ unless exclude_test_dir == "spec"
+ template(File.join("test", "support", "crud_test_model.rb"),
+ File.join("spec", "support", "crud_test_model.rb"))
+ template(File.join("test", "support", "crud_test_models_controller.rb"),
+ File.join("spec", "support", "crud_test_models_controller.rb"))
+ template(File.join("test", "support", "crud_test_helper.rb"),
+ File.join("spec", "support", "crud_test_helper.rb"))
end
end
def exclude_template
- options[:templates].casecmp('haml').zero? ? '.erb' : '.haml'
+ options[:templates].casecmp("haml").zero? ? ".erb" : ".haml"
end
def exclude_test_dir
case options[:tests].downcase
- when 'rspec' then 'test'
- when 'all' then 'exclude_nothing'
- else 'spec'
+ when "rspec" then "test"
+ when "all" then "exclude_nothing"
+ else "spec"
end
end
end
diff --git a/lib/generators/dry_crud/dry_crud_generator_base.rb b/lib/generators/dry_crud/dry_crud_generator_base.rb
index 8fcb052b..9f2560ce 100644
--- a/lib/generators/dry_crud/dry_crud_generator_base.rb
+++ b/lib/generators/dry_crud/dry_crud_generator_base.rb
@@ -1,31 +1,31 @@
-require 'rails/generators'
+require "rails/generators"
# Generates all dry crud files
class DryCrudGeneratorBase < Rails::Generators::Base
def self.template_root
- File.join(File.dirname(__FILE__), 'templates')
+ File.join(File.dirname(__FILE__), "templates")
end
def self.gem_root
- File.join(File.dirname(__FILE__), '..', '..', '..')
+ File.join(File.dirname(__FILE__), "..", "..", "..")
end
def self.source_paths
- [gem_root,
- template_root]
+ [ gem_root,
+ template_root ]
end
private
def all_template_files
{ self.class.gem_root =>
- template_files(self.class.gem_root, 'app', 'config'),
+ template_files(self.class.gem_root, "app", "config"),
self.class.template_root =>
template_files(self.class.template_root) }
end
def template_files(root, *folders)
- pattern = File.join('**', '**')
+ pattern = File.join("**", "**")
pattern = File.join("{#{folders.join(',')}}", pattern) if folders.present?
Dir.chdir(root) do
Dir.glob(pattern).sort.reject { |f| File.directory?(f) }
@@ -47,7 +47,7 @@ def should_copy?(_file_source)
end
def copy_file_source(file_source)
- if file_source.end_with?('.erb')
+ if file_source.end_with?(".erb")
copy_file(file_source)
else
template(file_source)
diff --git a/lib/generators/dry_crud/file_generator.rb b/lib/generators/dry_crud/file_generator.rb
index 0a6e2b66..2c774e57 100644
--- a/lib/generators/dry_crud/file_generator.rb
+++ b/lib/generators/dry_crud/file_generator.rb
@@ -1,16 +1,16 @@
-require 'generators/dry_crud/dry_crud_generator_base'
+require "generators/dry_crud/dry_crud_generator_base"
module DryCrud
# Copies one file of dry_crud to the rails application.
class FileGenerator < ::DryCrudGeneratorBase
desc "Copy one file from dry_crud to the application.\n" \
- 'FILENAME is a part of the name of the file to copy. ' \
- 'Must match exactly one file.'
+ "FILENAME is a part of the name of the file to copy. " \
+ "Must match exactly one file."
argument :filename,
type: :string,
- desc: 'Name or part of the filename to copy. ' \
- 'Must match exactly one file.'
+ desc: "Name or part of the filename to copy. " \
+ "Must match exactly one file."
# rubocop:disable Rails/Output
def copy_matching_file
@@ -21,7 +21,7 @@ def copy_matching_file
when 0
puts "No file containing '#{filename}' found in dry_crud."
else
- puts 'Please be more specific. ' \
+ puts "Please be more specific. " \
"All the following files match '#{filename}':"
files.each do |f|
puts " * #{f}"
diff --git a/lib/generators/dry_crud/templates/config/initializers/field_error_proc.rb b/lib/generators/dry_crud/templates/config/initializers/field_error_proc.rb
index bdf5728b..3bfd70a4 100644
--- a/lib/generators/dry_crud/templates/config/initializers/field_error_proc.rb
+++ b/lib/generators/dry_crud/templates/config/initializers/field_error_proc.rb
@@ -2,4 +2,4 @@
# Fields with errors are directly styled in Crud::FormBuilder.
# Rails should just output the plain html tag.
-ActionView::Base.field_error_proc = proc { |html_tag, instance| html_tag }
\ No newline at end of file
+ActionView::Base.field_error_proc = proc { |html_tag, instance| html_tag }
diff --git a/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb b/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb
index 0b8c438e..72c414f4 100644
--- a/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb
+++ b/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb
@@ -1,4 +1,4 @@
-require 'rails_helper'
+require "rails_helper"
# Tests all actions of the CrudController based on a dummy model
# (CrudTestModel). This is useful to test the general behavior
@@ -17,201 +17,201 @@
before { special_routing }
- include_examples 'crud controller', {}
+ include_examples "crud controller", {}
let(:test_entry) { crud_test_models(:AAAAA) }
let(:new_entry_attrs) do
- { name: 'foo',
+ { name: "foo",
children: 42,
companion_id: 3,
rating: 8.5,
income: 2.42,
- birthdate: '31-12-1999'.to_date,
+ birthdate: "31-12-1999".to_date,
human: true,
remarks: "some custom\n\tremarks" }
end
let(:edit_entry_attrs) do
- { name: 'foo',
+ { name: "foo",
children: 42,
rating: 8.5,
income: 2.42,
- birthdate: '31-12-1999'.to_date,
+ birthdate: "31-12-1999".to_date,
human: true,
remarks: "some custom\n\tremarks" }
end
- describe 'setup' do
- it 'model count is correct' do
+ describe "setup" do
+ it "model count is correct" do
expect(CrudTestModel.count).to eq(6)
end
- it 'has models_label' do
- expect(controller.models_label).to eq('Crud Test Models')
+ it "has models_label" do
+ expect(controller.models_label).to eq("Crud Test Models")
end
- it 'has models_label singular' do
- expect(controller.models_label(plural: false)).to eq('Crud Test Model')
+ it "has models_label singular" do
+ expect(controller.models_label(plural: false)).to eq("Crud Test Model")
end
end
describe_action :get, :index do
- context '.html', format: :html do
- context 'plain', combine: 'ihp' do
- it 'contains all entries' do
+ context ".html", format: :html do
+ context "plain", combine: "ihp" do
+ it "contains all entries" do
expect(entries.size).to eq(6)
end
- it 'session has empty list_params' do
+ it "session has empty list_params" do
expect(session[:list_params]).to eq({})
end
- it 'provides entries helper method' do
+ it "provides entries helper method" do
expect(entries).to be(controller.send(:entries))
end
end
- context 'search' do
+ context "search" do
let(:params) { { q: search_value } }
- context 'regular', combine: 'ihse' do
- it 'entries only contain test_entry' do
- expect(entries).to eq([test_entry])
+ context "regular", combine: "ihse" do
+ it "entries only contain test_entry" do
+ expect(entries).to eq([ test_entry ])
end
- it 'session has query list param' do
- expect(session[:list_params]['/crud_test_models.html'])
- .to eq('q' => 'AAAA')
+ it "session has query list param" do
+ expect(session[:list_params]["/crud_test_models.html"])
+ .to eq("q" => "AAAA")
end
end
- context 'with custom options', combine: 'ihsec' do
- let(:params) { { q: 'DDD', filter: true } }
+ context "with custom options", combine: "ihsec" do
+ let(:params) { { q: "DDD", filter: true } }
it_is_expected_to_respond
- it 'entries have one item' do
- expect(entries).to eq([CrudTestModel.find_by(name: 'BBBBB')])
+ it "entries have one item" do
+ expect(entries).to eq([ CrudTestModel.find_by(name: "BBBBB") ])
end
- it 'session has query list param' do
- expect(session[:list_params]['/crud_test_models.html'])
- .to eq('q' => 'DDD')
+ it "session has query list param" do
+ expect(session[:list_params]["/crud_test_models.html"])
+ .to eq("q" => "DDD")
end
end
end
- context 'sort' do
- context 'for given column', combine: 'ihsog' do
- let(:params) { { sort: 'children', sort_dir: 'asc' } }
+ context "sort" do
+ context "for given column", combine: "ihsog" do
+ let(:params) { { sort: "children", sort_dir: "asc" } }
it_is_expected_to_respond
- it 'entries are in correct order' do
+ it "entries are in correct order" do
expect(entries).to eq(CrudTestModel.all.sort_by(&:children))
end
- it 'session has sort list param' do
- expect(session[:list_params]['/crud_test_models.html']).to eq(
- 'sort' => 'children', 'sort_dir' => 'asc'
+ it "session has sort list param" do
+ expect(session[:list_params]["/crud_test_models.html"]).to eq(
+ "sort" => "children", "sort_dir" => "asc"
)
end
end
- context 'for virtual column', combine: 'ihsov' do
- let(:params) { { sort: 'chatty', sort_dir: 'desc' } }
+ context "for virtual column", combine: "ihsov" do
+ let(:params) { { sort: "chatty", sort_dir: "desc" } }
it_is_expected_to_respond
- it 'entries are in correct order' do
+ it "entries are in correct order" do
names = entries.map(&:name)
- assert names.index('BBBBB') < names.index('AAAAA')
- assert names.index('BBBBB') < names.index('DDDDD')
- assert names.index('EEEEE') < names.index('AAAAA')
- assert names.index('EEEEE') < names.index('DDDDD')
- assert names.index('AAAAA') < names.index('CCCCC')
- assert names.index('DDDDD') < names.index('CCCCC')
+ assert names.index("BBBBB") < names.index("AAAAA")
+ assert names.index("BBBBB") < names.index("DDDDD")
+ assert names.index("EEEEE") < names.index("AAAAA")
+ assert names.index("EEEEE") < names.index("DDDDD")
+ assert names.index("AAAAA") < names.index("CCCCC")
+ assert names.index("DDDDD") < names.index("CCCCC")
end
- it 'session has sort list param' do
- expect(session[:list_params]['/crud_test_models.html']).to eq(
- 'sort' => 'chatty', 'sort_dir' => 'desc'
+ it "session has sort list param" do
+ expect(session[:list_params]["/crud_test_models.html"]).to eq(
+ "sort" => "chatty", "sort_dir" => "desc"
)
end
end
- context 'with search', combine: 'ihsose' do
+ context "with search", combine: "ihsose" do
let(:params) do
- { q: 'DDD', sort: 'chatty', sort_dir: 'asc' }
+ { q: "DDD", sort: "chatty", sort_dir: "asc" }
end
it_is_expected_to_respond
- it 'entries are in correct order' do
+ it "entries are in correct order" do
expect(entries.map(&:name)).to eq(%w[CCCCC DDDDD BBBBB])
end
- it 'session has sort list param' do
- expect(session[:list_params]['/crud_test_models.html']).to eq(
- 'q' => 'DDD', 'sort' => 'chatty', 'sort_dir' => 'asc'
+ it "session has sort list param" do
+ expect(session[:list_params]["/crud_test_models.html"]).to eq(
+ "q" => "DDD", "sort" => "chatty", "sort_dir" => "asc"
)
end
end
end
- context 'with custom options', combine: 'ihsoco' do
+ context "with custom options", combine: "ihsoco" do
let(:params) { { filter: true } }
it_is_expected_to_respond
- context 'entries' do
+ context "entries" do
subject { entries }
it { expect(subject.size).to eq(2) }
it { is_expected.to eq(entries.sort_by(&:children).reverse) }
end
end
- context 'returning', perform_request: false do
+ context "returning", perform_request: false do
before do
session[:list_params] = {}
- session[:list_params]['/crud_test_models'] =
- { 'q' => 'DDD', 'sort' => 'chatty', 'sort_dir' => 'desc' }
+ session[:list_params]["/crud_test_models"] =
+ { "q" => "DDD", "sort" => "chatty", "sort_dir" => "desc" }
get :index, params: { returning: true }
end
it_is_expected_to_respond
- it 'entries are in correct order' do
+ it "entries are in correct order" do
expect(entries.map(&:name)).to eq(%w[BBBBB DDDDD CCCCC])
end
- it 'params are set' do
- expect(controller.params[:q]).to eq('DDD')
- expect(controller.params[:sort]).to eq('chatty')
- expect(controller.params[:sort_dir]).to eq('desc')
+ it "params are set" do
+ expect(controller.params[:q]).to eq("DDD")
+ expect(controller.params[:sort]).to eq("chatty")
+ expect(controller.params[:sort_dir]).to eq("desc")
end
end
end
- context '.js', format: :js, combine: 'ijs' do
+ context ".js", format: :js, combine: "ijs" do
it_is_expected_to_respond
- it { expect(response.body).to eq('index js') }
+ it { expect(response.body).to eq("index js") }
end
end
describe_action :get, :new do
- context 'plain', combine: 'new' do
- it 'assigns companions' do
+ context "plain", combine: "new" do
+ it "assigns companions" do
expect(ivar(:companions)).to be_present
end
- it 'calls two render callbacks' do
+ it "calls two render callbacks" do
expect(controller.called_callbacks).to eq(
%i[before_render_new before_render_form]
)
end
end
- context 'with before_render callback redirect',
+ context "with before_render callback redirect",
perform_request: false do
before do
controller.should_redirect = true
@@ -220,7 +220,7 @@
it { is_expected.to redirect_to(crud_test_models_path) }
- it 'does not set companions' do
+ it "does not set companions" do
expect(ivar(:companions)).to be_nil
end
end
@@ -229,44 +229,44 @@
describe_action :post, :create do
let(:params) { { model_identifier => new_entry_attrs } }
- it 'calls the correct callbacks' do
+ it "calls the correct callbacks" do
expect(controller.called_callbacks).to eq(
%i[before_create before_save after_save after_create]
)
end
- context 'with before callback' do
+ context "with before callback" do
let(:params) do
- { crud_test_model: { name: 'illegal', children: 2 } }
+ { crud_test_model: { name: "illegal", children: 2 } }
end
- it 'does not create entry', perform_request: false do
+ it "does not create entry", perform_request: false do
expect { perform_request }.to change { CrudTestModel.count }.by(0)
end
- context 'plain', combine: 'chcp' do
+ context "plain", combine: "chcp" do
it_is_expected_to_respond
it_is_expected_to_persist_entry(persist: false)
it_is_expected_to_have_flash(:alert)
- it 'sets entry name' do
- expect(entry.name).to eq('illegal')
+ it "sets entry name" do
+ expect(entry.name).to eq("illegal")
end
- it 'assigns companions' do
+ it "assigns companions" do
expect(ivar(:companions)).to be_present
end
- it 'calls the correct callbacks' do
+ it "calls the correct callbacks" do
expect(controller.called_callbacks).to eq(
%i[before_render_new before_render_form]
)
end
end
- context 'redirect', perform_request: false do
+ context "redirect", perform_request: false do
before { controller.should_redirect = true }
- it 'does not create entry' do
+ it "does not create entry" do
expect { perform_request }.to change { CrudTestModel.count }.by(0)
end
@@ -275,32 +275,32 @@
is_expected.to redirect_to(crud_test_models_path)
end
- it 'calls no callbacks' do
+ it "calls no callbacks" do
perform_request
expect(controller.called_callbacks).to be_nil
end
end
end
- context 'with invalid params' do
+ context "with invalid params" do
let(:params) { { crud_test_model: { children: 2 } } }
- context '.html' do
- it 'does not create entry', perform_request: false do
+ context ".html" do
+ it "does not create entry", perform_request: false do
expect { perform_request }.to change { CrudTestModel.count }.by(0)
end
- context 'plain', combine: 'chip' do
+ context "plain", combine: "chip" do
it_is_expected_to_respond
it_is_expected_to_persist_entry(persist: false)
it_is_expected_to_not_have_flash(:notice)
it_is_expected_to_not_have_flash(:alert)
- it 'assigns companions' do
+ it "assigns companions" do
expect(ivar(:companions)).to be_present
end
- it 'calls the correct callbacks' do
+ it "calls the correct callbacks" do
expect(controller.called_callbacks).to eq(
%i[before_create before_save
before_render_new before_render_form]
@@ -309,23 +309,23 @@
end
end
- context '.json', format: :json do
- it 'does not create entry', perform_request: false do
+ context ".json", format: :json do
+ it "does not create entry", perform_request: false do
expect { perform_request }.to change { CrudTestModel.count }.by(0)
end
- context 'plain', combine: 'cjcb' do
+ context "plain", combine: "cjcb" do
it_is_expected_to_respond(422)
it_is_expected_to_persist_entry(persist: false)
it_is_expected_to_not_have_flash(:notice)
it_is_expected_to_not_have_flash(:alert)
it_is_expected_to_render_json
- it 'does not assign companions' do
+ it "does not assign companions" do
expect(ivar(:companions)).to be_nil
end
- it 'calls the correct callbacks' do
+ it "calls the correct callbacks" do
expect(controller.called_callbacks).to eq(
%i[before_create before_save]
)
@@ -336,7 +336,7 @@
end
describe_action :get, :edit, id: true do
- it 'calls the correct callbacks' do
+ it "calls the correct callbacks" do
expect(controller.called_callbacks).to eq(
%i[before_render_edit before_render_form]
)
@@ -346,52 +346,52 @@
describe_action :put, :update, id: true do
let(:params) { { model_identifier => edit_entry_attrs } }
- it 'calls the correct callbacks' do
+ it "calls the correct callbacks" do
expect(controller.called_callbacks).to eq(
%i[before_update before_save after_save after_update]
)
end
- context 'with invalid params' do
+ context "with invalid params" do
let(:params) do
{
crud_test_model: {
rating: 20,
- other_ids: [OtherCrudTestModel.first.id]
+ other_ids: [ OtherCrudTestModel.first.id ]
}
}
end
- context '.html', combine: 'uhivp' do
+ context ".html", combine: "uhivp" do
it_is_expected_to_respond
it_is_expected_to_not_have_flash(:notice)
- it 'changes entry' do
+ it "changes entry" do
expect(entry).to be_changed
end
- it 'sets entry rating' do
+ it "sets entry rating" do
expect(entry.rating).to eq(20)
end
- it 'calls the correct callbacks' do
+ it "calls the correct callbacks" do
expect(controller.called_callbacks).to eq(
%i[before_update before_save
before_render_edit before_render_form]
)
end
- it 'does not update has_many ids' do
+ it "does not update has_many ids" do
expect(test_entry.reload.other_ids).to eq([])
end
end
- context '.json', format: :json, combine: 'ujivp' do
+ context ".json", format: :json, combine: "ujivp" do
it_is_expected_to_respond(422)
it_is_expected_to_not_have_flash(:notice)
it_is_expected_to_render_json
- it 'calls the correct callbacks' do
+ it "calls the correct callbacks" do
expect(controller.called_callbacks).to eq(
%i[before_update before_save]
)
@@ -401,23 +401,23 @@
end
describe_action :delete, :destroy, id: true do
- it 'calls the correct callbacks' do
+ it "calls the correct callbacks" do
expect(controller.called_callbacks).to eq(
%i[before_destroy after_destroy]
)
end
- context 'with failure' do
+ context "with failure" do
let(:test_entry) { crud_test_models(:BBBBB) }
- context '.html' do
- it 'does not delete entry from database',
+ context ".html" do
+ it "does not delete entry from database",
perform_request: false do
expect { perform_request }.not_to(change { CrudTestModel.count })
end
- it 'redirects to referer',
+ it "redirects to referer",
perform_request: false do
- ref = @request.env['HTTP_REFERER'] = crud_test_model_url(test_entry)
+ ref = @request.env["HTTP_REFERER"] = crud_test_model_url(test_entry)
perform_request
is_expected.to redirect_to(ref)
end
@@ -426,29 +426,29 @@
it_is_expected_to_not_have_flash(:notice)
end
- context '.json', format: :json, combine: 'djf' do
+ context ".json", format: :json, combine: "djf" do
it_is_expected_to_respond(422)
it_is_expected_to_not_have_flash(:notice)
it_is_expected_to_render_json
end
- context 'callback', perform_request: false do
+ context "callback", perform_request: false do
before do
# rubocop:disable Rails/SkipsModelValidations
- test_entry.update_attribute(:name, 'illegal')
+ test_entry.update_attribute(:name, "illegal")
# rubocop:enable Rails/SkipsModelValidations
end
- it 'does not delete entry from database' do
+ it "does not delete entry from database" do
expect { perform_request }.not_to(change { CrudTestModel.count })
end
- it 'redirects to index' do
+ it "redirects to index" do
perform_request
is_expected.to redirect_to(crud_test_models_path(returning: true))
end
- it 'has flash alert' do
+ it "has flash alert" do
perform_request
expect(flash[:alert]).to match(/illegal name/)
end
diff --git a/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb b/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb
index e494b21c..3719d60b 100644
--- a/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb
+++ b/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb
@@ -1,7 +1,6 @@
-require 'rails_helper'
-
-describe 'DryCrud::Form::Builder' do
+require "rails_helper"
+describe "DryCrud::Form::Builder" do
include FormatHelper
include FormHelper
include UtilityHelper
@@ -19,12 +18,11 @@
let(:entry) { CrudTestModel.first }
let(:form) { DryCrud::Form::Builder.new(:entry, entry, self, {}) }
- describe '#input_field' do
-
- it 'dispatches name attr to string field' do
+ describe "#input_field" do
+ it "dispatches name attr to string field" do
expect(form).to receive(:string_field)
- .with(:name, required: 'required')
- .and_return('')
+ .with(:name, required: "required")
+ .and_return("")
form.input_field(:name)
end
@@ -48,134 +46,132 @@
it { expect(form.input_field(attr)).to be_html_safe }
end
-
end
- describe '#labeled_input_fields' do
+ describe "#labeled_input_fields" do
subject { form.labeled_input_fields(:name, :remarks, :children) }
it { is_expected.to be_html_safe }
- it { is_expected.to include(form.input_field(:name, required: 'required')) }
+ it { is_expected.to include(form.input_field(:name, required: "required")) }
it { is_expected.to include(form.input_field(:remarks)) }
it { is_expected.to include(form.input_field(:children)) }
end
- describe '#labeled_input_field' do
- context 'when required' do
+ describe "#labeled_input_field" do
+ context "when required" do
subject { form.labeled_input_field(:name) }
- it { is_expected.to include('input-group-text') }
+ it { is_expected.to include("input-group-text") }
end
- context 'when not required' do
+ context "when not required" do
subject { form.labeled_input_field(:remarks) }
- it { is_expected.not_to include('input-group-text') }
+ it { is_expected.not_to include("input-group-text") }
end
- context 'with help text' do
- subject { form.labeled_input_field(:name, help: 'Some Help') }
- it { is_expected.to include(form.help_block('Some Help')) }
+ context "with help text" do
+ subject { form.labeled_input_field(:name, help: "Some Help") }
+ it { is_expected.to include(form.help_block("Some Help")) }
end
end
- describe '#belongs_to_field' do
- it 'has all options by default' do
+ describe "#belongs_to_field" do
+ it "has all options by default" do
f = form.belongs_to_field(:companion_id)
expect_n_options(f, 7)
end
- it 'with has options from :list option' do
+ it "with has options from :list option" do
list = CrudTestModel.all
f = form.belongs_to_field(:companion_id,
- list: [list.first, list.second])
+ list: [ list.first, list.second ])
expect_n_options(f, 3)
end
- it 'with empty instance list has no select' do
+ it "with empty instance list has no select" do
assign(:companions, [])
@companions = []
f = form.belongs_to_field(:companion_id)
- expect(f).to match t('global.associations.none_available')
+ expect(f).to match t("global.associations.none_available")
expect_n_options(f, 0)
end
end
- describe '#has_and_belongs_to_many_field' do
+ describe "#has_and_belongs_to_many_field" do
let(:others) { OtherCrudTestModel.all[0..1] }
- it 'has all options by default' do
+ it "has all options by default" do
f = form.has_many_field(:other_ids)
expect_n_options(f, 6)
end
- it 'uses options from :list option if given' do
+ it "uses options from :list option if given" do
f = form.has_many_field(:other_ids, list: others)
expect_n_options(f, 2)
end
- it 'uses options form instance variable if given' do
+ it "uses options form instance variable if given" do
assign(:others, others)
@others = others
f = form.has_many_field(:other_ids)
expect_n_options(f, 2)
end
- it 'displays a message for an empty list' do
+ it "displays a message for an empty list" do
@others = []
f = form.has_many_field(:other_ids)
- expect(f).to match t('global.associations.none_available')
+ expect(f).to match t("global.associations.none_available")
expect_n_options(f, 0)
end
end
- describe '#string_field' do
- it 'sets maxlength if attr has a limit' do
+ describe "#string_field" do
+ it "sets maxlength if attr has a limit" do
expect(form.string_field(:name)).to match(/maxlength="50"/)
end
end
- describe '#label' do
- context 'only with attr' do
+ describe "#label" do
+ context "only with attr" do
subject { form.label(:gugus_dada) }
it { is_expected.to be_html_safe }
- it 'provides the same interface as rails' do
+ it "provides the same interface as rails" do
is_expected.to match(/label [^>]*for.+Gugus dada/)
end
end
- context 'with attr and text' do
- subject { form.label(:gugus_dada, 'hoho') }
+ context "with attr and text" do
+ subject { form.label(:gugus_dada, "hoho") }
it { is_expected.to be_html_safe }
- it 'provides the same interface as rails' do
+ it "provides the same interface as rails" do
is_expected.to match(/label [^>]*for.+hoho/)
end
end
-
end
- describe '#labeled' do
- context 'in labeled_ method' do
+ describe "#labeled" do
+ context "in labeled_ method" do
subject { form.labeled_string_field(:name) }
it { is_expected.to be_html_safe }
- it 'provides the same interface as rails' do
+ it "provides the same interface as rails" do
is_expected.to match(/label [^>]*for.+input/m)
end
end
- context 'with custom content in argument' do
+ context "with custom content in argument" do
subject do
- form.labeled('gugus', "".html_safe)
+ form.labeled("gugus", "".html_safe)
end
it { is_expected.to be_html_safe }
it { is_expected.to match(/label [^>]*for.+".html_safe
end
end
@@ -184,20 +180,20 @@
it { is_expected.to match(/label [^>]*for.+".html_safe,
- caption: 'Caption')
+ caption: "Caption")
end
it { is_expected.to be_html_safe }
it { is_expected.to match(/label [^>]*for.+>Caption<\/label>.*".html_safe
end
end
@@ -207,26 +203,25 @@
end
end
- it 'handles missing methods' do
+ it "handles missing methods" do
expect { form.blabla }.to raise_error(NoMethodError)
end
- context '#respond_to?' do
- it 'returns false for non existing methods' do
+ context "#respond_to?" do
+ it "returns false for non existing methods" do
expect(form.respond_to?(:blabla)).to be false
end
- it 'returns true for existing methods' do
+ it "returns true for existing methods" do
expect(form.respond_to?(:text_field)).to be true
end
- it 'returns true for labeled_ methods' do
+ it "returns true for labeled_ methods" do
expect(form.respond_to?(:labeled_text_field)).to be true
end
end
def expect_n_options(form, count)
- expect(form.scan('').size).to eq(count)
+ expect(form.scan("").size).to eq(count)
end
-
end
diff --git a/lib/generators/dry_crud/templates/spec/helpers/dry_crud/table/builder_spec.rb b/lib/generators/dry_crud/templates/spec/helpers/dry_crud/table/builder_spec.rb
index 19115b2f..a92e5a3c 100644
--- a/lib/generators/dry_crud/templates/spec/helpers/dry_crud/table/builder_spec.rb
+++ b/lib/generators/dry_crud/templates/spec/helpers/dry_crud/table/builder_spec.rb
@@ -1,7 +1,6 @@
-require 'rails_helper'
-
-describe 'DryCrud::Table::Builder' do
+require "rails_helper"
+describe "DryCrud::Table::Builder" do
include FormatHelper
include UtilityHelper
@@ -12,43 +11,43 @@ def format_size(obj) # :nodoc:
"#{obj.size} chars"
end
- specify '#html_header' do
+ specify "#html_header" do
table.attrs :upcase, :size
- dom = '
<unsecure>bla
') + expect(string).to eq("<unsecure>bla
") end - it 'formats empty texts' do - model.remarks = ' ' + it "formats empty texts" do + model.remarks = " " string = format_type(model, :remarks) expect(string).to be_html_safe expect(string).to eq(UtilityHelper::EMPTY_STRING) end end - describe '#captionize' do - it 'handles symbols' do - expect(captionize(:camel_case)).to eq('Camel Case') + describe "#captionize" do + it "handles symbols" do + expect(captionize(:camel_case)).to eq("Camel Case") end - it 'renders all upper case' do - expect(captionize('all upper case')).to eq('All Upper Case') + it "renders all upper case" do + expect(captionize("all upper case")).to eq("All Upper Case") end - it 'renders human attribute name' do - expect(captionize(:gets_up_at, CrudTestModel)).to eq('Gets up at') + it "renders human attribute name" do + expect(captionize(:gets_up_at, CrudTestModel)).to eq("Gets up at") end end - end diff --git a/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb b/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb index 91af5a0e..a664f97c 100644 --- a/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb +++ b/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb @@ -1,101 +1,100 @@ -require 'rails_helper' +require "rails_helper" describe I18nHelper do - include CrudTestHelper - describe '#translate_inheritable' do + describe "#translate_inheritable" do before { @controller = CrudTestModelsController.new } before do I18n.backend.store_translations( I18n.locale, global: { - test_key: 'global' + test_key: "global" } ) end subject { ti(:test_key) } - it { is_expected.to eq('global') } + it { is_expected.to eq("global") } - context 'with list key' do + context "with list key" do before do I18n.backend.store_translations( I18n.locale, list: { global: { - test_key: 'list global' + test_key: "list global" } } ) end - it { is_expected.to eq('list global') } + it { is_expected.to eq("list global") } - context 'and list action key' do + context "and list action key" do before do I18n.backend.store_translations( I18n.locale, list: { index: { - test_key: 'list index' + test_key: "list index" } } ) end - it { is_expected.to eq('list index') } + it { is_expected.to eq("list index") } - context 'and crud global key' do + context "and crud global key" do before do I18n.backend.store_translations( I18n.locale, crud: { global: { - test_key: 'crud global' + test_key: "crud global" } } ) end - it { is_expected.to eq('crud global') } + it { is_expected.to eq("crud global") } - context 'and crud action key' do + context "and crud action key" do before do I18n.backend.store_translations( I18n.locale, crud: { index: { - test_key: 'crud index' + test_key: "crud index" } } ) end - it { is_expected.to eq('crud index') } + it { is_expected.to eq("crud index") } - context 'and controller global key' do + context "and controller global key" do before do I18n.backend.store_translations( I18n.locale, crud_test_models: { global: { - test_key: 'test global' + test_key: "test global" } } ) end - it { is_expected.to eq('test global') } + it { is_expected.to eq("test global") } - context 'and controller action key' do + context "and controller action key" do before do I18n.backend.store_translations( I18n.locale, crud_test_models: { index: { - test_key: 'test index' + test_key: "test index" } } ) end - it { is_expected.to eq('test index') } + it { is_expected.to eq("test index") } end end end @@ -104,7 +103,7 @@ end end - describe '#translate_association' do + describe "#translate_association" do let(:assoc) { CrudTestModel.reflect_on_association(:companion) } subject { ta(:test_key, assoc) } @@ -113,30 +112,30 @@ I18n.locale, global: { associations: { - test_key: 'global' + test_key: "global" } } ) end - it { is_expected.to eq('global') } + it { is_expected.to eq("global") } - context 'with model key' do + context "with model key" do before do I18n.backend.store_translations( I18n.locale, activerecord: { associations: { crud_test_model: { - test_key: 'model' + test_key: "model" } } } ) end - it { is_expected.to eq('model') } + it { is_expected.to eq("model") } - context 'and assoc key' do + context "and assoc key" do before do I18n.backend.store_translations( I18n.locale, @@ -145,7 +144,7 @@ models: { crud_test_model: { companion: { - test_key: 'companion' + test_key: "companion" } } } @@ -154,9 +153,9 @@ ) end - it { is_expected.to eq('companion') } - it 'uses global without assoc' do - expect(ta(:test_key)).to eq('global') + it { is_expected.to eq("companion") } + it "uses global without assoc" do + expect(ta(:test_key)).to eq("global") end end end diff --git a/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb b/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb index ef00b621..fa56b258 100644 --- a/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +++ b/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb @@ -1,7 +1,6 @@ -require 'rails_helper' +require "rails_helper" describe TableHelper do - include FormatHelper include UtilityHelper include I18nHelper @@ -15,171 +14,171 @@ after(:all) { reset_db } - describe '#plain_table' do + describe "#plain_table" do subject { plain_table(%w[foo bar], :size) { |t| t.attrs :upcase } } - it 'contains attrs' do + it "contains attrs" do is_expected.to match(/AAAAA BBBBB CCCCC\n
AAAAA BBBBB CCCCC\n