active_scaffold 3.5.4 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/{CHANGELOG → CHANGELOG.rdoc} +72 -0
  3. data/README.md +20 -8
  4. data/app/assets/javascripts/active_scaffold.js.erb +0 -1
  5. data/app/assets/javascripts/jquery/active_scaffold.js +98 -7
  6. data/app/assets/stylesheets/active_scaffold_colors.scss +1 -1
  7. data/app/assets/stylesheets/active_scaffold_layout.css +52 -29
  8. data/app/views/active_scaffold_overrides/_base_form.html.erb +2 -2
  9. data/app/views/active_scaffold_overrides/_form.html.erb +1 -1
  10. data/app/views/active_scaffold_overrides/_form_association.html.erb +2 -1
  11. data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +3 -2
  12. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +9 -7
  13. data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +4 -4
  14. data/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb +2 -1
  15. data/app/views/active_scaffold_overrides/_list.html.erb +2 -1
  16. data/app/views/active_scaffold_overrides/_list_header.html.erb +5 -7
  17. data/app/views/active_scaffold_overrides/_list_messages.html.erb +1 -0
  18. data/app/views/active_scaffold_overrides/_list_record.html.erb +4 -5
  19. data/app/views/active_scaffold_overrides/_list_with_header.html.erb +1 -1
  20. data/app/views/active_scaffold_overrides/_messages.html.erb +1 -0
  21. data/app/views/active_scaffold_overrides/_refresh_list.js.erb +4 -0
  22. data/app/views/active_scaffold_overrides/_render_field.js.erb +2 -1
  23. data/app/views/active_scaffold_overrides/_show_association_horizontal.html.erb +2 -1
  24. data/app/views/active_scaffold_overrides/_show_columns.html.erb +2 -2
  25. data/app/views/active_scaffold_overrides/_show_horizontal_record.html.erb +4 -4
  26. data/app/views/active_scaffold_overrides/_update_calculations.js.erb +1 -1
  27. data/app/views/active_scaffold_overrides/_update_column.js.erb +2 -2
  28. data/app/views/active_scaffold_overrides/_vertical_subform.html.erb +2 -2
  29. data/app/views/active_scaffold_overrides/action_confirmation.html.erb +2 -2
  30. data/app/views/active_scaffold_overrides/delete.html.erb +2 -2
  31. data/app/views/active_scaffold_overrides/on_action_update.js.erb +16 -6
  32. data/app/views/active_scaffold_overrides/on_update.js.erb +1 -1
  33. data/app/views/active_scaffold_overrides/row.js.erb +1 -1
  34. data/app/views/active_scaffold_overrides/update_column.js.erb +2 -2
  35. data/config/locales/de.yml +2 -1
  36. data/config/locales/en.yml +1 -0
  37. data/config/locales/es.yml +1 -0
  38. data/config/locales/fr.yml +2 -1
  39. data/config/locales/hu.yml +1 -0
  40. data/config/locales/ja.yml +1 -0
  41. data/config/locales/ru.yml +1 -0
  42. data/lib/active_scaffold.rb +19 -16
  43. data/lib/active_scaffold/actions/common_search.rb +11 -8
  44. data/lib/active_scaffold/actions/core.rb +91 -70
  45. data/lib/active_scaffold/actions/create.rb +28 -28
  46. data/lib/active_scaffold/actions/delete.rb +3 -3
  47. data/lib/active_scaffold/actions/field_search.rb +53 -43
  48. data/lib/active_scaffold/actions/list.rb +111 -27
  49. data/lib/active_scaffold/actions/nested.rb +65 -48
  50. data/lib/active_scaffold/actions/search.rb +1 -1
  51. data/lib/active_scaffold/actions/show.rb +4 -4
  52. data/lib/active_scaffold/actions/subform.rb +23 -22
  53. data/lib/active_scaffold/actions/update.rb +96 -77
  54. data/lib/active_scaffold/active_record_permissions.rb +2 -11
  55. data/lib/active_scaffold/attribute_params.rb +102 -94
  56. data/lib/active_scaffold/bridges.rb +8 -8
  57. data/lib/active_scaffold/bridges/active_storage.rb +6 -0
  58. data/lib/active_scaffold/bridges/active_storage/active_storage_bridge.rb +34 -0
  59. data/lib/active_scaffold/bridges/active_storage/active_storage_helpers.rb +54 -0
  60. data/lib/active_scaffold/bridges/active_storage/form_ui.rb +22 -0
  61. data/lib/active_scaffold/bridges/active_storage/list_ui.rb +36 -0
  62. data/lib/active_scaffold/bridges/bitfields.rb +2 -1
  63. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +12 -15
  64. data/lib/active_scaffold/bridges/bitfields/list_ui.rb +19 -0
  65. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +1 -1
  66. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +9 -12
  67. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +1 -1
  68. data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +2 -2
  69. data/lib/active_scaffold/bridges/chosen/helpers.rb +7 -6
  70. data/lib/active_scaffold/bridges/date_picker/ext.rb +0 -13
  71. data/lib/active_scaffold/bridges/date_picker/helper.rb +49 -44
  72. data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +1 -1
  73. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +1 -1
  74. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +3 -3
  75. data/lib/active_scaffold/bridges/file_column/form_ui.rb +3 -3
  76. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +10 -7
  77. data/lib/active_scaffold/bridges/paper_trail.rb +1 -1
  78. data/lib/active_scaffold/bridges/paper_trail/actions.rb +3 -1
  79. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
  80. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +1 -1
  81. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +2 -2
  82. data/lib/active_scaffold/bridges/record_select/helpers.rb +15 -17
  83. data/lib/active_scaffold/bridges/shared/date_bridge.rb +20 -19
  84. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -1
  85. data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +21 -4
  86. data/lib/active_scaffold/config/base.rb +133 -41
  87. data/lib/active_scaffold/config/core.rb +146 -18
  88. data/lib/active_scaffold/config/delete.rb +14 -1
  89. data/lib/active_scaffold/config/field_search.rb +7 -1
  90. data/lib/active_scaffold/config/form.rb +10 -1
  91. data/lib/active_scaffold/config/list.rb +39 -13
  92. data/lib/active_scaffold/config/mark.rb +4 -2
  93. data/lib/active_scaffold/config/nested.rb +16 -17
  94. data/lib/active_scaffold/config/search.rb +9 -0
  95. data/lib/active_scaffold/config/show.rb +4 -0
  96. data/lib/active_scaffold/config/update.rb +4 -0
  97. data/lib/active_scaffold/configurable.rb +14 -7
  98. data/lib/active_scaffold/constraints.rb +22 -20
  99. data/lib/active_scaffold/core.rb +67 -28
  100. data/lib/active_scaffold/data_structures/action_columns.rb +50 -59
  101. data/lib/active_scaffold/data_structures/action_link.rb +50 -20
  102. data/lib/active_scaffold/data_structures/action_links.rb +15 -13
  103. data/lib/active_scaffold/data_structures/association/abstract.rb +38 -15
  104. data/lib/active_scaffold/data_structures/association/active_mongoid.rb +2 -6
  105. data/lib/active_scaffold/data_structures/association/active_record.rb +6 -2
  106. data/lib/active_scaffold/data_structures/association/mongoid.rb +0 -3
  107. data/lib/active_scaffold/data_structures/column.rb +75 -66
  108. data/lib/active_scaffold/data_structures/columns.rb +3 -2
  109. data/lib/active_scaffold/data_structures/nested_info.rb +33 -19
  110. data/lib/active_scaffold/data_structures/set.rb +8 -0
  111. data/lib/active_scaffold/data_structures/sorting.rb +10 -2
  112. data/lib/active_scaffold/delayed_setup.rb +16 -5
  113. data/lib/active_scaffold/extensions/action_controller_rendering.rb +3 -2
  114. data/lib/active_scaffold/extensions/action_view_rendering.rb +93 -32
  115. data/lib/active_scaffold/extensions/cow_proxy.rb +95 -0
  116. data/lib/active_scaffold/extensions/ice_nine.rb +36 -0
  117. data/lib/active_scaffold/extensions/left_outer_joins.rb +8 -33
  118. data/lib/active_scaffold/extensions/localize.rb +3 -1
  119. data/lib/active_scaffold/extensions/routing_mapper.rb +6 -45
  120. data/lib/active_scaffold/extensions/to_label.rb +3 -2
  121. data/lib/active_scaffold/extensions/unsaved_record.rb +2 -4
  122. data/lib/active_scaffold/finder.rb +110 -77
  123. data/lib/active_scaffold/helpers/action_link_helpers.rb +62 -36
  124. data/lib/active_scaffold/helpers/association_helpers.rb +18 -16
  125. data/lib/active_scaffold/helpers/controller_helpers.rb +34 -10
  126. data/lib/active_scaffold/helpers/form_column_helpers.rb +196 -124
  127. data/lib/active_scaffold/helpers/human_condition_helpers.rb +1 -1
  128. data/lib/active_scaffold/helpers/id_helpers.rb +6 -2
  129. data/lib/active_scaffold/helpers/list_column_helpers.rb +90 -57
  130. data/lib/active_scaffold/helpers/pagination_helpers.rb +2 -2
  131. data/lib/active_scaffold/helpers/search_column_helpers.rb +29 -34
  132. data/lib/active_scaffold/helpers/show_column_helpers.rb +3 -5
  133. data/lib/active_scaffold/helpers/view_helpers.rb +39 -36
  134. data/lib/active_scaffold/marked_model.rb +2 -2
  135. data/lib/active_scaffold/orm_checks.rb +3 -7
  136. data/lib/active_scaffold/paginator.rb +7 -7
  137. data/lib/active_scaffold/registry.rb +33 -0
  138. data/lib/active_scaffold/responds_to_parent.rb +8 -11
  139. data/lib/active_scaffold/tableless.rb +82 -66
  140. data/lib/active_scaffold/version.rb +2 -2
  141. data/lib/generators/active_scaffold/controller_generator.rb +2 -2
  142. data/lib/generators/active_scaffold/install_generator.rb +52 -4
  143. data/lib/generators/active_scaffold/resource_generator.rb +2 -2
  144. data/shoulda_macros/macros.rb +3 -1
  145. data/test/bridges/date_picker_test.rb +1 -2
  146. data/test/bridges/paperclip_test.rb +6 -6
  147. data/test/class_with_finder.rb +2 -2
  148. data/test/company.rb +4 -4
  149. data/test/config/create_test.rb +4 -2
  150. data/test/config/nested_test.rb +1 -1
  151. data/test/config/show_test.rb +1 -1
  152. data/test/config/update_test.rb +7 -6
  153. data/test/data_structures/action_columns_test.rb +2 -2
  154. data/test/data_structures/action_links_test.rb +1 -1
  155. data/test/data_structures/column_test.rb +3 -6
  156. data/test/data_structures/columns_test.rb +2 -2
  157. data/test/data_structures/sorting_test.rb +7 -0
  158. data/test/extensions/action_view_rendering_test.rb +20 -0
  159. data/test/extensions/active_record_test.rb +4 -4
  160. data/test/extensions/routing_mapper_test.rb +2 -2
  161. data/test/helpers/list_column_helpers_test.rb +3 -1
  162. data/test/misc/active_record_permissions_test.rb +3 -11
  163. data/test/misc/attribute_params_test.rb +12 -8
  164. data/test/misc/calculation_test.rb +1 -1
  165. data/test/misc/configurable_test.rb +10 -10
  166. data/test/misc/constraints_test.rb +2 -2
  167. data/test/misc/convert_numbers_format_test.rb +7 -3
  168. data/test/misc/lang_test.rb +1 -1
  169. data/test/misc/parse_datetime_test.rb +3 -4
  170. data/test/misc/tableless_test.rb +14 -0
  171. data/test/mock_app/Rakefile +1 -1
  172. data/test/mock_app/app/assets/config/manifest.js +0 -0
  173. data/test/mock_app/app/controllers/cars_controller.rb +1 -0
  174. data/test/mock_app/app/controllers/people_controller.rb +5 -1
  175. data/test/mock_app/app/controllers/roles_controller.rb +4 -0
  176. data/test/mock_app/app/views/active_scaffold_overrides/_form.html.erb +2 -0
  177. data/test/mock_app/app/views/active_scaffold_overrides/list.html.erb +2 -0
  178. data/test/mock_app/app/views/people/_first_name_form_column.html.erb +2 -0
  179. data/test/mock_app/app/views/people/_form.html.erb +2 -0
  180. data/test/mock_app/app/views/people/list.html.erb +2 -0
  181. data/test/mock_app/config/application.rb +2 -1
  182. data/test/mock_app/config/boot.rb +1 -1
  183. data/test/mock_app/config/environment.rb +2 -2
  184. data/test/mock_app/config/routes.rb +4 -1
  185. data/test/mock_app/db/schema.rb +2 -0
  186. data/test/performance/list_cars_performance_test.rb +34 -0
  187. data/test/performance/list_people_performance_test.rb +31 -0
  188. data/test/performance_test_help.rb +3 -0
  189. data/test/test_helper.rb +12 -4
  190. metadata +69 -18
  191. data/app/assets/javascripts/prototype/rico_corner.js +0 -370
  192. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +0 -7
@@ -1,8 +1,8 @@
1
1
  module ActiveScaffold
2
2
  module Version
3
3
  MAJOR = 3
4
- MINOR = 5
5
- PATCH = 4
4
+ MINOR = 6
5
+ PATCH = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
@@ -2,10 +2,10 @@
2
2
 
3
3
  module ActiveScaffold
4
4
  module Generators
5
- class ControllerGenerator < Rails::Generators::NamedBase # metagenerator
5
+ class ControllerGenerator < Rails::Generators::NamedBase
6
6
  include Rails::Generators::ResourceHelpers
7
7
 
8
- source_root File.expand_path('../../templates', __FILE__)
8
+ source_root File.expand_path('../templates', __dir__)
9
9
 
10
10
  check_class_collision :suffix => 'Controller'
11
11
 
@@ -3,7 +3,7 @@ require 'rails/generators/base'
3
3
 
4
4
  module ActiveScaffold
5
5
  module Generators
6
- class InstallGenerator < Rails::Generators::Base # metagenerator
6
+ class InstallGenerator < Rails::Generators::Base
7
7
  desc 'Add concerns to routes and require lines to assets manifest files'
8
8
 
9
9
  def add_concern_routes
@@ -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
@@ -3,7 +3,7 @@ require 'rails/generators/rails/resource/resource_generator'
3
3
 
4
4
  module ActiveScaffold
5
5
  module Generators
6
- class ResourceGenerator < Rails::Generators::ResourceGenerator # metagenerator
6
+ class ResourceGenerator < Rails::Generators::ResourceGenerator
7
7
  remove_hook_for :resource_controller
8
8
  remove_hook_for :resource_route
9
9
  remove_class_option :actions
@@ -46,7 +46,7 @@ module ActiveScaffold
46
46
  routing_code << ' end' * class_path.size
47
47
  log :route, routing_code
48
48
  in_root do
49
- inject_into_file 'config/routes.rb', " #{routing_code}\n", {after: /^[ ]*concern :active_scaffold,.*\n/, verbose: false, force: true}
49
+ inject_into_file 'config/routes.rb', " #{routing_code}\n", after: /^[ ]*concern :active_scaffold,.*\n/, verbose: false, force: true
50
50
  end
51
51
  end
52
52
 
@@ -127,7 +127,9 @@ class ActiveSupport::TestCase
127
127
  script = script.gsub('\n', '\\\\\\n')
128
128
  .gsub(/['"]/, '\\\\\\\\\&')
129
129
  .gsub('</script>', '</scr"+"ipt>')
130
- assert_select 'script[type=text/javascript]', Regexp.new('.*' + Regexp.quote("with(window.parent) { setTimeout(function() { window.eval('") + script + Regexp.quote("'); if (typeof(loc) !== 'undefined') loc.replace('about:blank'); }, 1) };") + '.*')
130
+ pre_regex = Regexp.quote("with(window.parent) { setTimeout(function() { window.eval('")
131
+ post_regex = Regexp.quote("'); if (typeof(loc) !== 'undefined') loc.replace('about:blank'); }, 1) };")
132
+ assert_select 'script[type=text/javascript]', Regexp.new('.*' + pre_regex + script + post_regex + '.*')
131
133
  end
132
134
  end
133
135
 
@@ -1,7 +1,6 @@
1
1
  require 'test_helper'
2
2
  require 'active_scaffold_config_mock'
3
- require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/bridges/date_picker/ext')
4
- # require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/bridges/date_picker/helper')
3
+ require File.expand_path('../../lib/active_scaffold/bridges/date_picker/ext', __dir__)
5
4
 
6
5
  class DatePickerTest < ActionView::TestCase
7
6
  include ActiveScaffold::Helpers::ViewHelpers
@@ -1,8 +1,8 @@
1
1
  require 'test_helper'
2
- require File.expand_path('../../../lib/active_scaffold/bridges/paperclip/paperclip_bridge', __FILE__)
3
- require File.expand_path('../../../lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers', __FILE__)
4
- require File.expand_path('../../../lib/active_scaffold/bridges/paperclip/form_ui', __FILE__)
5
- require File.expand_path('../../../lib/active_scaffold/bridges/paperclip/list_ui', __FILE__)
2
+ require File.expand_path('../../lib/active_scaffold/bridges/paperclip/paperclip_bridge', __dir__)
3
+ require File.expand_path('../../lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers', __dir__)
4
+ require File.expand_path('../../lib/active_scaffold/bridges/paperclip/form_ui', __dir__)
5
+ require File.expand_path('../../lib/active_scaffold/bridges/paperclip/list_ui', __dir__)
6
6
 
7
7
  class PaperclipCore < ActiveScaffold::Config::Core
8
8
  include ActiveScaffold::Bridges::Paperclip::PaperclipBridge
@@ -16,7 +16,7 @@ class PaperclipTest < ActionView::TestCase
16
16
  config = PaperclipCore.new(:company)
17
17
  refute config.create.multipart?
18
18
  refute config.update.multipart?
19
- refute config.columns.any? { |column| column.form_ui == :paperclip }
19
+ refute(config.columns.any? { |column| column.form_ui == :paperclip })
20
20
  end
21
21
 
22
22
  def test_initialization
@@ -51,7 +51,7 @@ class PaperclipTest < ActionView::TestCase
51
51
  assert_dom_equal '<a href="/system/file" target="_blank">file</a>', active_scaffold_column_paperclip(company, config.columns[:logo])
52
52
 
53
53
  company.stubs(:logo).returns(stub(:file? => true, :original_filename => 'file', :url => '/system/file', :styles => {:thumbnail => '40x40'}))
54
- assert_dom_equal '<a href="/system/file" target="_blank"><img src="/system/file" border="0" alt="File"/></a>', active_scaffold_column_paperclip(company, config.columns[:logo])
54
+ assert_dom_equal '<a href="/system/file" target="_blank"><img src="/system/file" border="0"/></a>', active_scaffold_column_paperclip(company, config.columns[:logo])
55
55
  end
56
56
 
57
57
  def test_form_ui
@@ -18,8 +18,8 @@ class ClassWithFinder
18
18
  {}
19
19
  end
20
20
 
21
- def params_hash(v)
22
- v
21
+ def params_hash(value)
22
+ value
23
23
  end
24
24
 
25
25
  def joins_for_collection; end
data/test/company.rb CHANGED
@@ -37,8 +37,8 @@ class Company < ActiveRecord::Base
37
37
  end
38
38
 
39
39
  # not the real signature of the method, but forgive me
40
- def self.before_destroy(s = nil)
41
- @@before = s
40
+ def self.before_destroy(string = nil)
41
+ @@before = string
42
42
  end
43
43
 
44
44
  if respond_to?(:create_reflection)
@@ -53,11 +53,11 @@ class Company < ActiveRecord::Base
53
53
  end
54
54
  end
55
55
 
56
- def self.has_many(association_id, options = {})
56
+ def self.has_many(association_id, options = {}) # rubocop:disable Naming/PredicateName
57
57
  create_reflection(:has_many, association_id, nil, options, self)
58
58
  end
59
59
 
60
- def self.has_one(association_id, options = {})
60
+ def self.has_one(association_id, options = {}) # rubocop:disable Naming/PredicateName
61
61
  create_reflection(:has_one, association_id, nil, options, self)
62
62
  end
63
63
 
@@ -2,6 +2,8 @@ require 'test_helper'
2
2
 
3
3
  module Config
4
4
  class CreateTest < MiniTest::Test
5
+ include ActiveScaffold::Helpers::ControllerHelpers
6
+
5
7
  def setup
6
8
  @config = ActiveScaffold::Config::Core.new :model_stub
7
9
  @default_link = @config.create.link
@@ -12,7 +14,7 @@ module Config
12
14
  end
13
15
 
14
16
  def test_default_columns
15
- assert_equal %i[a d other_model other_models], @config.create.columns.names
17
+ assert_equal %i[a d other_model other_models], @config.create.columns.visible_columns_names
16
18
  end
17
19
 
18
20
  def test_default_options
@@ -52,7 +54,7 @@ module Config
52
54
  label = 'create new monkeys'
53
55
  @config.create.label = label
54
56
  assert_equal label, @config.create.label
55
- I18n.backend.store_translations :en, :active_scaffold => {:create_new_model => 'Create new %{model}'}
57
+ I18n.backend.store_translations :en, :active_scaffold => {:create_new_model => 'Create new %<model>s'}
56
58
  @config.create.label = :create_new_model
57
59
  assert_equal 'Create new Model stub', @config.create.label
58
60
  end
@@ -20,7 +20,7 @@ module Config
20
20
  label = 'nested monkeys'
21
21
  @config.nested.label = label
22
22
  assert_equal label, @config.nested.label
23
- I18n.backend.store_translations :en, :active_scaffold => {:test_create_model => 'Add new %{model}'}
23
+ I18n.backend.store_translations :en, :active_scaffold => {:test_create_model => 'Add new %<model>s'}
24
24
  @config.nested.label = :test_create_model
25
25
  assert_equal 'Add new Model stub', @config.nested.label
26
26
  end
@@ -36,7 +36,7 @@ module Config
36
36
  label = 'show monkeys'
37
37
  @config.show.label = label
38
38
  assert_equal label, @config.show.label
39
- I18n.backend.store_translations :en, :active_scaffold => {:view_model => 'View %{model}'}
39
+ I18n.backend.store_translations :en, :active_scaffold => {:view_model => 'View %<model>s'}
40
40
  @config.show.label = :view_model
41
41
  assert_equal 'View Model stub', @config.show.label
42
42
  assert_equal 'View record', @config.show.label('record')
@@ -2,20 +2,20 @@ require 'test_helper'
2
2
 
3
3
  module Config
4
4
  class UpdateTest < MiniTest::Test
5
+ include ActiveScaffold::Helpers::ControllerHelpers
6
+
5
7
  def setup
6
8
  @config = ActiveScaffold::Config::Core.new :model_stub
7
9
  end
8
10
 
9
11
  def test_copy_columns_from_create
10
12
  @config.create.columns = %i[a c d]
11
- assert_equal %i[a d], @config.create.columns.names
13
+ assert_equal %i[a d], @config.create.columns.visible_columns_names
12
14
  @config.update.columns = @config.create.columns
13
- @config._load_action_columns
14
- assert_equal %i[a c d], @config.update.columns.names
15
+ assert_equal %i[a c d], @config.update.columns.visible_columns_names
15
16
  end
16
17
 
17
18
  def test__params_for_columns__returns_all_params
18
- @config._load_action_columns
19
19
  @config.columns[:a].params.add :keep_a, :a_temp
20
20
  assert @config.columns[:a].params.include?(:keep_a)
21
21
  assert @config.columns[:a].params.include?(:a_temp)
@@ -33,7 +33,8 @@ module Config
33
33
  end
34
34
 
35
35
  def test_nested_links
36
- old, @config.update.nested_links = @config.update.nested_links, true
36
+ old = @config.update.nested_links
37
+ @config.update.nested_links = true
37
38
  assert @config.update.nested_links
38
39
  @config.update.nested_links = old
39
40
  end
@@ -42,7 +43,7 @@ module Config
42
43
  label = 'update new monkeys'
43
44
  @config.update.label = label
44
45
  assert_equal label, @config.update.label
45
- I18n.backend.store_translations :en, :active_scaffold => {:change_model => 'Change %{model}'}
46
+ I18n.backend.store_translations :en, :active_scaffold => {:change_model => 'Change %<model>s'}
46
47
  @config.update.label = :change_model
47
48
  assert_equal 'Change Model stub', @config.update.label
48
49
  assert_equal 'Change record', @config.update.label('record')
@@ -71,12 +71,12 @@ class ActionColumnsTest < MiniTest::Test
71
71
  # first, use @columns.add directly
72
72
  @c2 = ActiveScaffold::DataStructures::ActionColumns.new
73
73
  @columns.add @c2
74
- assert @columns.any? { |c| c == @c2 }
74
+ assert(@columns.any? { |c| c == @c2 })
75
75
 
76
76
  # then use the shortcut
77
77
  @columns.add_subgroup 'foo' do
78
78
  end
79
- assert @columns.any? { |c| c.respond_to?(:label) && c.label == 'foo' }
79
+ assert(@columns.any? { |c| c.respond_to?(:label) && c.label == 'foo' })
80
80
  end
81
81
 
82
82
  def test_block_config
@@ -70,7 +70,7 @@ class ActionLinksTest < MiniTest::Test
70
70
  begin
71
71
  @links.delete :foo
72
72
  @links.delete 'foo'
73
- rescue
73
+ rescue StandardError
74
74
  assert false, "deleting from action links when item doesn't exist should not throw an error"
75
75
  end
76
76
  refute @links['bar'].nil?
@@ -16,9 +16,6 @@ class ColumnTest < MiniTest::Test
16
16
  def test_basic_properties
17
17
  # test that it was set during initialization
18
18
  assert_equal @column.name, :a
19
- # test that we can change it
20
- @column.name = :b
21
- assert_equal @column.name, :b
22
19
 
23
20
  # label
24
21
  @column.label = 'foo'
@@ -74,7 +71,7 @@ class ColumnTest < MiniTest::Test
74
71
  # comparison with different object of same type
75
72
  column2 = ActiveScaffold::DataStructures::Column.new(:fake, ModelStub)
76
73
  refute_equal @column, column2
77
- column2.name = 'a'
74
+ column2 = ActiveScaffold::DataStructures::Column.new(:a, ModelStub)
78
75
  assert_equal @column, column2
79
76
 
80
77
  # special comparisons
@@ -152,12 +149,12 @@ class ColumnTest < MiniTest::Test
152
149
  def test_config_block
153
150
  @column.configure do |config|
154
151
  # we can use the config object
155
- config.name = 'foo'
152
+ config.form_ui = :select
156
153
  # or not
157
154
  self.label = 'hello'
158
155
  end
159
156
 
160
- assert_equal 'foo', @column.name
157
+ assert_equal :select, @column.form_ui
161
158
  assert_equal 'hello', @column.label
162
159
  end
163
160
 
@@ -41,8 +41,8 @@ class ColumnsTest < MiniTest::Test
41
41
 
42
42
  # test the collection finders
43
43
  found = @columns.find_by_names(:a, :b)
44
- assert found.any? { |c| c.name == :a }
45
- assert found.any? { |c| c.name == :b }
44
+ assert(found.any? { |c| c.name == :a })
45
+ assert(found.any? { |c| c.name == :b })
46
46
  end
47
47
 
48
48
  def test_each
@@ -64,6 +64,13 @@ class SortingTest < MiniTest::Test
64
64
  assert @sorting.sorts_on?(:b)
65
65
  assert_equal 'ASC', @sorting.direction_of(:b)
66
66
 
67
+ @sorting.set({a: 'DESC'}, {b: 'ASC'})
68
+ assert @sorting.instance_variable_get('@clauses').size == 2
69
+ assert @sorting.sorts_on?(:a)
70
+ assert_equal 'DESC', @sorting.direction_of(:a)
71
+ assert @sorting.sorts_on?(:b)
72
+ assert_equal 'ASC', @sorting.direction_of(:b)
73
+
67
74
  @sorting.set [:a, 'DESC'], [:b, 'ASC']
68
75
  assert @sorting.instance_variable_get('@clauses').size == 2
69
76
  assert @sorting.sorts_on?(:a)
@@ -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
@@ -14,7 +14,7 @@ class ActiveRecordTest < MiniTest::Test
14
14
  'to_s'
15
15
  end
16
16
  end
17
-
17
+ RequestStore.clear!
18
18
  assert_equal 'to_s', @record.to_label
19
19
 
20
20
  class << @record
@@ -22,7 +22,7 @@ class ActiveRecordTest < MiniTest::Test
22
22
  'title'
23
23
  end
24
24
  end
25
-
25
+ RequestStore.clear!
26
26
  assert_equal 'title', @record.to_label
27
27
 
28
28
  class << @record
@@ -30,7 +30,7 @@ class ActiveRecordTest < MiniTest::Test
30
30
  'label'
31
31
  end
32
32
  end
33
-
33
+ RequestStore.clear!
34
34
  assert_equal 'label', @record.to_label
35
35
 
36
36
  class << @record
@@ -38,7 +38,7 @@ class ActiveRecordTest < MiniTest::Test
38
38
  'name'
39
39
  end
40
40
  end
41
-
41
+ RequestStore.clear!
42
42
  assert_equal 'name', @record.to_label
43
43
  end
44
44
  end