active_scaffold 3.5.3 → 3.6.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. checksums.yaml +4 -4
  2. data/{CHANGELOG → CHANGELOG.rdoc} +73 -0
  3. data/README.md +17 -7
  4. data/app/assets/javascripts/active_scaffold.js.erb +0 -1
  5. data/app/assets/javascripts/jquery/active_scaffold.js +97 -6
  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 +1 -0
  63. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +12 -15
  64. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +1 -1
  65. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +9 -12
  66. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +1 -1
  67. data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +2 -2
  68. data/lib/active_scaffold/bridges/chosen/helpers.rb +11 -9
  69. data/lib/active_scaffold/bridges/date_picker/ext.rb +0 -13
  70. data/lib/active_scaffold/bridges/date_picker/helper.rb +49 -44
  71. data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +1 -1
  72. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +1 -1
  73. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +3 -3
  74. data/lib/active_scaffold/bridges/file_column/form_ui.rb +3 -3
  75. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +10 -7
  76. data/lib/active_scaffold/bridges/paper_trail.rb +1 -1
  77. data/lib/active_scaffold/bridges/paper_trail/actions.rb +3 -1
  78. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
  79. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +1 -1
  80. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +2 -2
  81. data/lib/active_scaffold/bridges/record_select/helpers.rb +15 -17
  82. data/lib/active_scaffold/bridges/shared/date_bridge.rb +20 -19
  83. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -1
  84. data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +21 -4
  85. data/lib/active_scaffold/config/base.rb +133 -41
  86. data/lib/active_scaffold/config/core.rb +146 -18
  87. data/lib/active_scaffold/config/delete.rb +14 -1
  88. data/lib/active_scaffold/config/field_search.rb +7 -1
  89. data/lib/active_scaffold/config/form.rb +10 -1
  90. data/lib/active_scaffold/config/list.rb +39 -13
  91. data/lib/active_scaffold/config/mark.rb +4 -2
  92. data/lib/active_scaffold/config/nested.rb +16 -17
  93. data/lib/active_scaffold/config/search.rb +9 -0
  94. data/lib/active_scaffold/config/show.rb +4 -0
  95. data/lib/active_scaffold/config/update.rb +4 -0
  96. data/lib/active_scaffold/configurable.rb +14 -7
  97. data/lib/active_scaffold/constraints.rb +22 -20
  98. data/lib/active_scaffold/core.rb +67 -28
  99. data/lib/active_scaffold/data_structures/action_columns.rb +50 -59
  100. data/lib/active_scaffold/data_structures/action_link.rb +50 -20
  101. data/lib/active_scaffold/data_structures/action_links.rb +15 -13
  102. data/lib/active_scaffold/data_structures/association/abstract.rb +38 -15
  103. data/lib/active_scaffold/data_structures/association/active_mongoid.rb +2 -6
  104. data/lib/active_scaffold/data_structures/association/active_record.rb +6 -2
  105. data/lib/active_scaffold/data_structures/association/mongoid.rb +0 -3
  106. data/lib/active_scaffold/data_structures/column.rb +75 -66
  107. data/lib/active_scaffold/data_structures/columns.rb +3 -2
  108. data/lib/active_scaffold/data_structures/nested_info.rb +33 -19
  109. data/lib/active_scaffold/data_structures/set.rb +8 -0
  110. data/lib/active_scaffold/data_structures/sorting.rb +10 -2
  111. data/lib/active_scaffold/delayed_setup.rb +16 -5
  112. data/lib/active_scaffold/extensions/action_controller_rendering.rb +3 -2
  113. data/lib/active_scaffold/extensions/action_view_rendering.rb +34 -14
  114. data/lib/active_scaffold/extensions/cow_proxy.rb +95 -0
  115. data/lib/active_scaffold/extensions/ice_nine.rb +36 -0
  116. data/lib/active_scaffold/extensions/left_outer_joins.rb +8 -33
  117. data/lib/active_scaffold/extensions/localize.rb +3 -1
  118. data/lib/active_scaffold/extensions/routing_mapper.rb +6 -45
  119. data/lib/active_scaffold/extensions/to_label.rb +3 -2
  120. data/lib/active_scaffold/extensions/unsaved_record.rb +2 -4
  121. data/lib/active_scaffold/finder.rb +110 -77
  122. data/lib/active_scaffold/helpers/action_link_helpers.rb +62 -36
  123. data/lib/active_scaffold/helpers/association_helpers.rb +21 -19
  124. data/lib/active_scaffold/helpers/controller_helpers.rb +34 -10
  125. data/lib/active_scaffold/helpers/form_column_helpers.rb +196 -124
  126. data/lib/active_scaffold/helpers/human_condition_helpers.rb +1 -1
  127. data/lib/active_scaffold/helpers/id_helpers.rb +6 -2
  128. data/lib/active_scaffold/helpers/list_column_helpers.rb +86 -57
  129. data/lib/active_scaffold/helpers/pagination_helpers.rb +2 -2
  130. data/lib/active_scaffold/helpers/search_column_helpers.rb +29 -34
  131. data/lib/active_scaffold/helpers/show_column_helpers.rb +3 -5
  132. data/lib/active_scaffold/helpers/view_helpers.rb +38 -35
  133. data/lib/active_scaffold/marked_model.rb +2 -2
  134. data/lib/active_scaffold/orm_checks.rb +3 -7
  135. data/lib/active_scaffold/paginator.rb +7 -7
  136. data/lib/active_scaffold/registry.rb +33 -0
  137. data/lib/active_scaffold/responds_to_parent.rb +8 -11
  138. data/lib/active_scaffold/tableless.rb +67 -65
  139. data/lib/active_scaffold/version.rb +2 -2
  140. data/lib/generators/active_scaffold/controller_generator.rb +2 -2
  141. data/lib/generators/active_scaffold/install_generator.rb +1 -1
  142. data/lib/generators/active_scaffold/resource_generator.rb +2 -2
  143. data/shoulda_macros/macros.rb +3 -1
  144. data/test/bridges/date_picker_test.rb +1 -2
  145. data/test/bridges/paperclip_test.rb +6 -6
  146. data/test/class_with_finder.rb +2 -2
  147. data/test/company.rb +4 -4
  148. data/test/config/create_test.rb +4 -2
  149. data/test/config/nested_test.rb +1 -1
  150. data/test/config/show_test.rb +1 -1
  151. data/test/config/update_test.rb +7 -6
  152. data/test/data_structures/action_columns_test.rb +2 -2
  153. data/test/data_structures/action_links_test.rb +1 -1
  154. data/test/data_structures/column_test.rb +3 -6
  155. data/test/data_structures/columns_test.rb +2 -2
  156. data/test/data_structures/sorting_test.rb +7 -0
  157. data/test/extensions/active_record_test.rb +4 -4
  158. data/test/extensions/routing_mapper_test.rb +2 -2
  159. data/test/helpers/list_column_helpers_test.rb +3 -1
  160. data/test/misc/active_record_permissions_test.rb +3 -11
  161. data/test/misc/attribute_params_test.rb +12 -8
  162. data/test/misc/calculation_test.rb +1 -1
  163. data/test/misc/configurable_test.rb +10 -10
  164. data/test/misc/constraints_test.rb +2 -2
  165. data/test/misc/convert_numbers_format_test.rb +7 -3
  166. data/test/misc/lang_test.rb +1 -1
  167. data/test/misc/parse_datetime_test.rb +3 -4
  168. data/test/misc/tableless_test.rb +6 -0
  169. data/test/mock_app/Rakefile +1 -1
  170. data/test/mock_app/app/assets/config/manifest.js +0 -0
  171. data/test/mock_app/app/controllers/cars_controller.rb +1 -0
  172. data/test/mock_app/app/controllers/people_controller.rb +3 -1
  173. data/test/mock_app/config/application.rb +2 -1
  174. data/test/mock_app/config/boot.rb +1 -1
  175. data/test/mock_app/config/environment.rb +2 -2
  176. data/test/mock_app/config/routes.rb +4 -1
  177. data/test/mock_app/db/schema.rb +2 -0
  178. data/test/performance/list_cars_performance_test.rb +34 -0
  179. data/test/performance/list_people_performance_test.rb +31 -0
  180. data/test/performance_test_help.rb +3 -0
  181. data/test/test_helper.rb +10 -2
  182. metadata +55 -20
  183. data/app/assets/javascripts/prototype/rico_corner.js +0 -370
  184. 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 = 3
4
+ MINOR = 6
5
+ PATCH = '0.rc2'.freeze
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
@@ -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
@@ -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)
@@ -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
@@ -54,8 +54,8 @@ class RoutingMapperTest < ActionController::TestCase
54
54
  assert_routing 'cars/1/edit', controller: 'cars', action: 'edit', id: '1'
55
55
  assert_routing({method: :patch, path: 'cars/1'}, {controller: 'cars', action: 'update', id: '1'})
56
56
 
57
- assert_raises(ActionController::RoutingError) { @routes.recognize_path '/cars' }
58
- assert_raises(ActionController::RoutingError) { @routes.recognize_path '/cars/1/list' }
57
+ assert_raises(ActionController::RoutingError) { @routes.recognize_path '/cars', method: :post }
58
+ assert_raises(ActionController::RoutingError) { @routes.recognize_path '/cars/1' }
59
59
  assert_raises(ActionController::RoutingError) { @routes.recognize_path '/cars/1/destroy', method: :delete }
60
60
  end
61
61
 
@@ -34,8 +34,10 @@ class ListColumnHelpersTest < ActionView::TestCase
34
34
  value.each { |v| v.stubs(:to_label).returns(v) }
35
35
  assert_equal '1, 2, 3, … (4)', format_association_value(value, @association_column, value.size)
36
36
  @config.list.stubs(:association_join_text => ',<br/>')
37
+ remove_instance_variable :@_association_join_text
37
38
  assert_equal '1,&lt;br/&gt;2,&lt;br/&gt;3,&lt;br/&gt;… (4)', format_association_value(value, @association_column, value.size)
38
- @config.list.stubs(:association_join_text => ',<br/>'.html_safe)
39
+ @config.list.stubs(:association_join_text => ',<br/>'.html_safe) # rubocop:disable Rails/OutputSafety
40
+ remove_instance_variable :@_association_join_text
39
41
  assert_equal '1,<br/>2,<br/>3,<br/>… (4)', format_association_value(value, @association_column, value.size)
40
42
  end
41
43
 
@@ -91,7 +91,7 @@ class ActiveRecordPermissionsTest < MiniTest::Test
91
91
  # symbols are: is (a)bsent, returns (f)alse, returns (t)rue, or n/a (_)
92
92
  def test_method_combinations_with_default_true
93
93
  old_permission = nil
94
- ActiveScaffold.set_defaults do |config|
94
+ ActiveScaffold.defaults do |config|
95
95
  old_permission = config.security.default_permission
96
96
  config.security.default_permission = true
97
97
  end
@@ -134,17 +134,13 @@ class ActiveRecordPermissionsTest < MiniTest::Test
134
134
  miss(@model.authorized_for?(:crud_type => :read, :column => :b1), 'ttf')
135
135
  pass(@model.authorized_for?(:crud_type => :read, :column => :a1), 'ttt')
136
136
 
137
- ActiveScaffold.set_defaults do |config|
137
+ ActiveScaffold.defaults do |config|
138
138
  config.security.default_permission = old_permission
139
139
  end
140
140
  end
141
141
 
142
142
  def test_method_combinations_with_default_false
143
- old_permission = nil
144
- ActiveScaffold.set_defaults do |config|
145
- old_permission = config.security.default_permission
146
- config.security.default_permission = false
147
- end
143
+ ActiveScaffold::Config::Core.security.stubs(default_permission: false)
148
144
 
149
145
  miss(@model.authorized_for?(:column => :a3), '_a_')
150
146
  miss(@model.authorized_for?(:column => :a2), '_f_')
@@ -183,10 +179,6 @@ class ActiveRecordPermissionsTest < MiniTest::Test
183
179
  pass(@model.authorized_for?(:crud_type => :read, :column => :c1), 'tta')
184
180
  miss(@model.authorized_for?(:crud_type => :read, :column => :b1), 'ttf')
185
181
  pass(@model.authorized_for?(:crud_type => :read, :column => :a1), 'ttt')
186
-
187
- ActiveScaffold.set_defaults do |config|
188
- config.security.default_permission = old_permission
189
- end
190
182
  end
191
183
 
192
184
  private
@@ -46,6 +46,7 @@ class AttributeParamsTest < MiniTest::Test
46
46
  assert_nil model.last_name
47
47
  assert_equal buildings.map(&:id), model.building_ids
48
48
  assert_equal buildings.map(&:id), model.buildings.map(&:id)
49
+ assert_equal model, model.buildings[0].owner
49
50
  assert model.save
50
51
  assert_equal 2, model.reload.buildings_count
51
52
 
@@ -134,6 +135,7 @@ class AttributeParamsTest < MiniTest::Test
134
135
  assert_equal 'Name', model.first_name
135
136
  assert model.floor.present?
136
137
  assert_equal floor.id, model.floor.id
138
+ assert_equal model, model.floor.tenant
137
139
  assert_nil floor.reload.tenant_id, 'tenant_id should not be saved yet'
138
140
  assert model.save
139
141
  assert_equal model.id, floor.reload.tenant_id, 'tenant_id should be saved'
@@ -224,6 +226,7 @@ class AttributeParamsTest < MiniTest::Test
224
226
  assert_equal 3, model.floors.size
225
227
  assert_equal floor.id, model.floors.first.id
226
228
  assert_equal [nil, *people.map(&:id)], model.floors.map(&:tenant_id)
229
+ assert_equal model, model.floors[0].building
227
230
  assert model.save
228
231
  assert_equal [1, 1], people.map(&:reload).map(&:floors_count)
229
232
  assert_equal 3, model.reload.floors_count
@@ -299,6 +302,7 @@ class AttributeParamsTest < MiniTest::Test
299
302
  assert_equal 'First', model.first_name
300
303
  assert model.car.present?
301
304
  assert model.car.new_record?
305
+ assert_equal model, model.car.person
302
306
  assert model.save
303
307
  assert model.car.persisted?
304
308
 
@@ -417,15 +421,15 @@ class AttributeParamsTest < MiniTest::Test
417
421
  record = record.class.find(record.id) if record.persisted?
418
422
  new_record = @controller.update_record_from_params(record, build_action_columns(record, action, columns), params)
419
423
  yield if block_given?
420
- Thread.current[:constraint_columns] = nil
424
+ ActiveScaffold::Registry.constraint_columns.clear
421
425
  end
422
426
  new_record
423
427
  end
424
428
 
425
429
  def build_action_columns(record, action, *columns)
426
- controller = ActiveScaffold::Core.active_scaffold_controller_for record.class
427
- controller.active_scaffold_config.send(action).columns = columns
428
- controller.active_scaffold_config.send(action).columns
430
+ config = @controller.active_scaffold_config_for record.class
431
+ config.send(action).columns = columns
432
+ config.send(action).columns
429
433
  end
430
434
  end
431
435
 
@@ -447,11 +451,11 @@ class Controller
447
451
  @flash ||= ActionDispatch::Flash::FlashHash.new
448
452
  end
449
453
 
450
- def params_hash?(v)
451
- v.is_a? Hash
454
+ def params_hash?(value)
455
+ value.is_a? Hash
452
456
  end
453
457
 
454
- def params_hash(v)
455
- v
458
+ def params_hash(value)
459
+ value
456
460
  end
457
461
  end