active_scaffold 3.6.0.rc1 → 3.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.rdoc +26 -0
  3. data/README.md +10 -9
  4. data/app/assets/javascripts/jquery/active_scaffold.js +48 -14
  5. data/app/assets/stylesheets/active_scaffold_layout.css +1 -1
  6. data/app/views/active_scaffold_overrides/_form_association.html.erb +2 -1
  7. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +22 -6
  8. data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +3 -3
  9. data/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb +2 -1
  10. data/app/views/active_scaffold_overrides/_vertical_subform.html.erb +2 -2
  11. data/app/views/active_scaffold_overrides/update_column.js.erb +1 -1
  12. data/lib/active_scaffold/actions/core.rb +5 -2
  13. data/lib/active_scaffold/actions/list.rb +1 -1
  14. data/lib/active_scaffold/actions/nested.rb +1 -1
  15. data/lib/active_scaffold/actions/subform.rb +12 -6
  16. data/lib/active_scaffold/attribute_params.rb +6 -16
  17. data/lib/active_scaffold/bridges/active_storage/active_storage_bridge.rb +1 -0
  18. data/lib/active_scaffold/bridges/active_storage/list_ui.rb +4 -4
  19. data/lib/active_scaffold/bridges/bitfields.rb +1 -1
  20. data/lib/active_scaffold/bridges/bitfields/list_ui.rb +19 -0
  21. data/lib/active_scaffold/bridges/paper_trail/actions.rb +3 -1
  22. data/lib/active_scaffold/bridges/record_select/helpers.rb +3 -1
  23. data/lib/active_scaffold/config/list.rb +1 -1
  24. data/lib/active_scaffold/data_structures/action_columns.rb +1 -1
  25. data/lib/active_scaffold/data_structures/association/abstract.rb +1 -4
  26. data/lib/active_scaffold/data_structures/nested_info.rb +14 -2
  27. data/lib/active_scaffold/extensions/action_view_rendering.rb +66 -25
  28. data/lib/active_scaffold/extensions/localize.rb +1 -1
  29. data/lib/active_scaffold/finder.rb +7 -5
  30. data/lib/active_scaffold/helpers/controller_helpers.rb +11 -0
  31. data/lib/active_scaffold/helpers/form_column_helpers.rb +52 -15
  32. data/lib/active_scaffold/helpers/list_column_helpers.rb +10 -6
  33. data/lib/active_scaffold/helpers/search_column_helpers.rb +14 -7
  34. data/lib/active_scaffold/helpers/view_helpers.rb +1 -1
  35. data/lib/active_scaffold/tableless.rb +16 -2
  36. data/lib/active_scaffold/version.rb +1 -1
  37. data/lib/generators/active_scaffold/install_generator.rb +51 -3
  38. data/test/data_structures/action_columns_test.rb +1 -1
  39. data/test/extensions/action_view_rendering_test.rb +20 -0
  40. data/test/misc/constraints_test.rb +1 -1
  41. data/test/misc/tableless_test.rb +8 -0
  42. data/test/mock_app/app/controllers/people_controller.rb +2 -0
  43. data/test/mock_app/app/controllers/roles_controller.rb +4 -0
  44. data/test/mock_app/app/views/active_scaffold_overrides/_form.html.erb +2 -0
  45. data/test/mock_app/app/views/active_scaffold_overrides/list.html.erb +2 -0
  46. data/test/mock_app/app/views/people/_first_name_form_column.html.erb +2 -0
  47. data/test/mock_app/app/views/people/_form.html.erb +2 -0
  48. data/test/mock_app/app/views/people/list.html.erb +2 -0
  49. data/test/test_helper.rb +2 -2
  50. metadata +25 -4
@@ -245,16 +245,23 @@ module ActiveScaffold
245
245
  options = column.options.merge(options)
246
246
  type = "#{'date' unless options[:discard_date]}#{'time' unless options[:discard_time]}"
247
247
  use_select = options.delete(:use_select)
248
- helper = use_select ? "select_#{type}" : "#{type}#{'_local' if type == 'datetime'}_field"
248
+ from_name = "#{options[:name]}[from]"
249
+ to_name = "#{options[:name]}[to]"
249
250
  if use_select
250
- default_from_options = {include_blank: true, prefix: "#{options[:name]}[from]"}
251
- default_to_options = {include_blank: true, prefix: "#{options[:name]}[to]"}
251
+ helper = "select_#{type}"
252
+ fields = [
253
+ send(helper, field_search_datetime_value(from_value), options.reverse_merge(include_blank: true, prefix: from_name)),
254
+ send(helper, field_search_datetime_value(to_value), options.reverse_merge(include_blank: true, prefix: to_name))
255
+ ]
256
+ else
257
+ helper = "#{type}#{'_local' if type == 'datetime'}_field_tag"
258
+ fields = [
259
+ send(helper, from_name, field_search_datetime_value(from_value), options.except(:name, :object).merge(id: "#{options[:id]}_from")),
260
+ send(helper, to_name, field_search_datetime_value(to_value), options.except(:name, :object).merge(id: "#{options[:id]}_to"))
261
+ ]
252
262
  end
253
263
 
254
- safe_join [
255
- send(helper, field_search_datetime_value(from_value), options.reverse_merge(default_from_options || {})),
256
- send(helper, field_search_datetime_value(to_value), options.reverse_merge(default_to_options || {}))
257
- ], ' - '
264
+ safe_join fields, ' - '
258
265
  end
259
266
 
260
267
  def active_scaffold_search_date(column, options)
@@ -41,7 +41,7 @@ module ActiveScaffold
41
41
  restore_view_paths = lookup_context.view_paths
42
42
  lookup_context.view_paths = @_view_paths
43
43
  end
44
- lookup_context.exists?(template_name, '', partial).tap do
44
+ (@_lookup_context || lookup_context).exists?(template_name, '', partial).tap do
45
45
  lookup_context.view_paths = restore_view_paths if @_view_paths
46
46
  end
47
47
  end
@@ -34,11 +34,17 @@ class ActiveScaffold::Tableless < ActiveRecord::Base # rubocop:disable Rails/App
34
34
  def columns(table_name)
35
35
  klass.columns
36
36
  end
37
+
38
+ if Rails.version >= '6.0.0'
39
+ def data_sources
40
+ klass ? [klass.table_name] : []
41
+ end
42
+ end
37
43
  end
38
44
 
39
45
  class Column < ActiveRecord::ConnectionAdapters::Column
40
46
  if Rails.version >= '5.0.0'
41
- def initialize(name, default, sql_type = nil, null = true)
47
+ def initialize(name, default, sql_type = nil, null = true, **)
42
48
  metadata = ActiveRecord::Base.connection.send :fetch_type_metadata, sql_type
43
49
  super(name, default, metadata, null)
44
50
  end
@@ -149,9 +155,17 @@ class ActiveScaffold::Tableless < ActiveRecord::Base # rubocop:disable Rails/App
149
155
  def execute_simple_calculation(operation, column_name, distinct)
150
156
  @klass.execute_simple_calculation(self, operation, column_name, distinct)
151
157
  end
158
+
159
+ def implicit_order_column
160
+ @klass.implicit_order_column
161
+ end
162
+
163
+ def exists?
164
+ limit(1).to_a.present?
165
+ end
152
166
  end
153
167
 
154
- class Relation < ActiveRecord::Relation
168
+ class Relation < ::ActiveRecord::Relation
155
169
  include RelationExtension
156
170
  end
157
171
  class << self
@@ -2,7 +2,7 @@ module ActiveScaffold
2
2
  module Version
3
3
  MAJOR = 3
4
4
  MINOR = 6
5
- PATCH = '0.rc1'.freeze
5
+ PATCH = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
@@ -14,18 +14,23 @@ module ActiveScaffold
14
14
  def add_to_javascript_manifest
15
15
  file = 'app/assets/javascripts/application.js'
16
16
  unless File.exist?(file)
17
+ if Rails.version >= '6.0'
18
+ create_javascript_manifest file
19
+ return
20
+ end
17
21
  say_status :missing, file, :red
18
22
  return if options[:pretend]
19
23
  raise Thor::Error, "JS file #{file} is required for ActiveScaffold"
20
24
  end
21
25
  original_js = File.binread(file)
22
26
  if original_js.include?('require active_scaffold')
23
- say_status('skipped', 'insert into app/assets/javascripts/application.js', :yellow)
27
+ say_status('skipped', "insert into #{file}", :yellow)
24
28
  else
25
- insert_into_file 'app/assets/javascripts/application.js', :after => %r{//= require +.*ujs['"]?\n} do
29
+ insert_into_file file, after: %r{//= require +.*ujs['"]?\n} do
26
30
  "//= require active_scaffold\n"
27
31
  end
28
32
  end
33
+ setup_jquery file, original_js
29
34
  end
30
35
 
31
36
  def add_to_stylesheet_manifest
@@ -35,11 +40,54 @@ module ActiveScaffold
35
40
  if original_css =~ /require active_scaffold$/
36
41
  say_status('skipped', 'insert into app/assets/stylesheets/application.css', :yellow)
37
42
  else
38
- insert_into_file 'app/assets/stylesheets/application.css', :before => %r{[ ]*\*/} do
43
+ insert_into_file 'app/assets/stylesheets/application.css', before: %r{[ ]*\*/} do
39
44
  " *= require active_scaffold\n"
40
45
  end
41
46
  end
42
47
  end
48
+
49
+ protected
50
+
51
+ def create_javascript_manifest(file)
52
+ FileUtils.mkdir_p File.dirname(file)
53
+ File.open(file, 'w') do |f|
54
+ f << "// This is a manifest file that'll be compiled into application.js, which will include all the files
55
+ // listed below.
56
+ //
57
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
58
+ // vendor/assets/javascripts directory can be referenced here using a relative path.
59
+ //
60
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
61
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
62
+ //
63
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
64
+ // about supported directives.
65
+ //
66
+ //= require active_scaffold
67
+ "
68
+ say_status('create', file)
69
+ end
70
+ insert_into_file 'app/views/layouts/application.html.erb', after: /javascript_pack_tag 'application'.*\n/ do
71
+ " <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>\n"
72
+ end
73
+ append_to_file 'config/initializers/assets.rb' do
74
+ "Rails.application.config.assets.precompile += %w( application.js )\n"
75
+ end
76
+ setup_jquery file, where: 'active_scaffold'
77
+ end
78
+
79
+ def setup_jquery(file, original_js = nil, where: 'ujs')
80
+ original_js ||= File.binread(file)
81
+ if ActiveScaffold.js_framework == :jquery
82
+ unless original_js.include?('require jquery')
83
+ insert_into_file file, before: %r{//= require +.*#{where}['"]?\n} do
84
+ "//= require jquery\n"
85
+ end
86
+ end
87
+ else
88
+ say_status('missing', 'no jquery-rails gem, load jquery in your layout, or add jquery-rails to Gemfile and add //= require jquery to application.js', :red)
89
+ end
90
+ end
43
91
  end
44
92
  end
45
93
  end
@@ -5,7 +5,7 @@ require 'test_helper'
5
5
  class ActionColumnsTest < MiniTest::Test
6
6
  def setup
7
7
  @columns = ActiveScaffold::DataStructures::ActionColumns.new(%i[a b])
8
- @columns.action = stub(:core => stub(:model_id => 'model_stub'))
8
+ @columns.action = stub(core: stub(model_id: 'model_stub'), user_settings_key: :"model_stub_active_scaffold/config/test")
9
9
  end
10
10
 
11
11
  def test_label
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ class ActionViewRenderingTest < ActionController::TestCase
4
+ setup do
5
+ @controller = PeopleController.new
6
+ end
7
+
8
+ test 'render :super twice' do
9
+ get :index
10
+ assert_select '#controller', 1
11
+ assert_select '#app', 1
12
+ end
13
+
14
+ test 'render partial override with render :super twice' do
15
+ get :new
16
+ assert_select '#first_name_field', 1
17
+ assert_select '#controller_form', 1
18
+ assert_select '#app_form', 1
19
+ end
20
+ end
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  module ModelStubs
4
4
  class ModelStub < ActiveRecord::Base
5
5
  self.abstract_class = true
6
- def self.columns; @columns ||= [ColumnMock.new('foo', '')] end
6
+ def self.columns; @columns ||= [ColumnMock.new('foo', '', 'string')] end
7
7
 
8
8
  def self.columns_hash; @hash ||= Hash[@columns.map { |c| [c.name, c] }] end
9
9
 
@@ -25,6 +25,10 @@ class TablelessTest < MiniTest::Test
25
25
 
26
26
  def test_find_with_association
27
27
  assert Person.new.files.empty?
28
+ @person = Person.new
29
+ @person.save(validate: false)
30
+ assert @person.files.empty?
31
+ assert_equal [], @person.files.to_a
28
32
  end
29
33
 
30
34
  def test_tableless_assoc_with_dependent
@@ -35,6 +39,10 @@ class TablelessTest < MiniTest::Test
35
39
 
36
40
  def test_find_with_through_association
37
41
  assert Building.new.files.empty?
42
+ @building = Building.new
43
+ @building.save(validate: false)
44
+ assert @building.files.empty?
45
+ assert_equal [], @building.files.to_a
38
46
  end
39
47
 
40
48
  def test_new
@@ -1,6 +1,8 @@
1
1
  class PeopleController < ApplicationController
2
2
  active_scaffold do |conf|
3
+ conf.columns.exclude :files
3
4
  conf.columns[:buildings].includes = nil
4
5
  conf.columns[:buildings].associated_limit = 0
6
+ conf.create.columns.exclude :address
5
7
  end
6
8
  end
@@ -0,0 +1,4 @@
1
+ class RolesController < ApplicationController
2
+ active_scaffold do
3
+ end
4
+ end
@@ -0,0 +1,2 @@
1
+ <div id="app_form"></div>
2
+ <%= render :super %>
@@ -0,0 +1,2 @@
1
+ <div id="app"></div>
2
+ <%= render :super %>
@@ -0,0 +1,2 @@
1
+ <span id="first_name_field"></span>
2
+ <%= form_attribute(column, record, scope, only_value, col_class) %>
@@ -0,0 +1,2 @@
1
+ <div id="controller_form"></div>
2
+ <%= render :super %>
@@ -0,0 +1,2 @@
1
+ <div id="controller"></div>
2
+ <%= render :super %>
data/test/test_helper.rb CHANGED
@@ -1,10 +1,10 @@
1
- require 'simplecov' if RUBY_ENGINE == 'ruby'
1
+ require 'simplecov' if ENV['COVERAGE']
2
2
 
3
3
  ENV['RAILS_ENV'] = 'test'
4
4
  require 'mock_app/config/environment'
5
5
  require 'rails/test_help'
6
6
  require 'minitest/autorun'
7
- require 'mocha/setup'
7
+ require 'mocha/minitest'
8
8
  require 'cow_proxy'
9
9
 
10
10
  require 'minitest/reporters'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0.rc1
4
+ version: 3.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Many, see README
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-09 00:00:00.000000000 Z
11
+ date: 2021-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 4.2.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.2'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 4.2.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.2'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: cow_proxy
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -224,6 +230,7 @@ files:
224
230
  - lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
225
231
  - lib/active_scaffold/bridges/bitfields.rb
226
232
  - lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
233
+ - lib/active_scaffold/bridges/bitfields/list_ui.rb
227
234
  - lib/active_scaffold/bridges/calendar_date_select.rb
228
235
  - lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb
229
236
  - lib/active_scaffold/bridges/cancan.rb
@@ -377,6 +384,7 @@ files:
377
384
  - test/data_structures/standard_column_test.rb
378
385
  - test/data_structures/validation_reflection_test.rb
379
386
  - test/data_structures/virtual_column_test.rb
387
+ - test/extensions/action_view_rendering_test.rb
380
388
  - test/extensions/active_record_test.rb
381
389
  - test/extensions/routing_mapper_test.rb
382
390
  - test/helpers/form_column_helpers_test.rb
@@ -404,6 +412,7 @@ files:
404
412
  - test/mock_app/app/controllers/contacts_controller.rb
405
413
  - test/mock_app/app/controllers/floors_controller.rb
406
414
  - test/mock_app/app/controllers/people_controller.rb
415
+ - test/mock_app/app/controllers/roles_controller.rb
407
416
  - test/mock_app/app/helpers/application_helper.rb
408
417
  - test/mock_app/app/models/address.rb
409
418
  - test/mock_app/app/models/building.rb
@@ -413,6 +422,11 @@ files:
413
422
  - test/mock_app/app/models/floor.rb
414
423
  - test/mock_app/app/models/person.rb
415
424
  - test/mock_app/app/models/role.rb
425
+ - test/mock_app/app/views/active_scaffold_overrides/_form.html.erb
426
+ - test/mock_app/app/views/active_scaffold_overrides/list.html.erb
427
+ - test/mock_app/app/views/people/_first_name_form_column.html.erb
428
+ - test/mock_app/app/views/people/_form.html.erb
429
+ - test/mock_app/app/views/people/list.html.erb
416
430
  - test/mock_app/config.ru
417
431
  - test/mock_app/config/application.rb
418
432
  - test/mock_app/config/boot.rb
@@ -457,9 +471,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
457
471
  version: '2.3'
458
472
  required_rubygems_version: !ruby/object:Gem::Requirement
459
473
  requirements:
460
- - - ">"
474
+ - - ">="
461
475
  - !ruby/object:Gem::Version
462
- version: 1.3.1
476
+ version: '0'
463
477
  requirements: []
464
478
  rubygems_version: 3.0.8
465
479
  signing_key:
@@ -498,6 +512,7 @@ test_files:
498
512
  - test/data_structures/standard_column_test.rb
499
513
  - test/data_structures/validation_reflection_test.rb
500
514
  - test/data_structures/virtual_column_test.rb
515
+ - test/extensions/action_view_rendering_test.rb
501
516
  - test/extensions/active_record_test.rb
502
517
  - test/extensions/routing_mapper_test.rb
503
518
  - test/helpers/form_column_helpers_test.rb
@@ -525,6 +540,7 @@ test_files:
525
540
  - test/mock_app/app/controllers/contacts_controller.rb
526
541
  - test/mock_app/app/controllers/floors_controller.rb
527
542
  - test/mock_app/app/controllers/people_controller.rb
543
+ - test/mock_app/app/controllers/roles_controller.rb
528
544
  - test/mock_app/app/helpers/application_helper.rb
529
545
  - test/mock_app/app/models/address.rb
530
546
  - test/mock_app/app/models/building.rb
@@ -534,6 +550,11 @@ test_files:
534
550
  - test/mock_app/app/models/floor.rb
535
551
  - test/mock_app/app/models/person.rb
536
552
  - test/mock_app/app/models/role.rb
553
+ - test/mock_app/app/views/active_scaffold_overrides/_form.html.erb
554
+ - test/mock_app/app/views/active_scaffold_overrides/list.html.erb
555
+ - test/mock_app/app/views/people/_first_name_form_column.html.erb
556
+ - test/mock_app/app/views/people/_form.html.erb
557
+ - test/mock_app/app/views/people/list.html.erb
537
558
  - test/mock_app/config.ru
538
559
  - test/mock_app/config/application.rb
539
560
  - test/mock_app/config/boot.rb