active_scaffold 3.5.5 → 3.6.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +18 -2
  3. data/README.md +17 -7
  4. data/app/assets/javascripts/jquery/active_scaffold.js +28 -2
  5. data/app/views/active_scaffold_overrides/_base_form.html.erb +2 -2
  6. data/app/views/active_scaffold_overrides/_form.html.erb +1 -1
  7. data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +3 -2
  8. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +6 -6
  9. data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +1 -1
  10. data/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb +1 -1
  11. data/app/views/active_scaffold_overrides/_list.html.erb +2 -1
  12. data/app/views/active_scaffold_overrides/_list_messages.html.erb +1 -0
  13. data/app/views/active_scaffold_overrides/_messages.html.erb +1 -0
  14. data/app/views/active_scaffold_overrides/_render_field.js.erb +2 -1
  15. data/app/views/active_scaffold_overrides/_show_association_horizontal.html.erb +2 -1
  16. data/app/views/active_scaffold_overrides/_show_columns.html.erb +2 -2
  17. data/app/views/active_scaffold_overrides/_show_horizontal_record.html.erb +4 -4
  18. data/app/views/active_scaffold_overrides/_update_calculations.js.erb +1 -1
  19. data/app/views/active_scaffold_overrides/_update_column.js.erb +2 -2
  20. data/app/views/active_scaffold_overrides/action_confirmation.html.erb +2 -2
  21. data/app/views/active_scaffold_overrides/delete.html.erb +2 -2
  22. data/app/views/active_scaffold_overrides/on_action_update.js.erb +16 -6
  23. data/app/views/active_scaffold_overrides/on_update.js.erb +1 -1
  24. data/app/views/active_scaffold_overrides/row.js.erb +1 -1
  25. data/app/views/active_scaffold_overrides/update_column.js.erb +1 -1
  26. data/lib/active_scaffold.rb +11 -13
  27. data/lib/active_scaffold/actions/core.rb +25 -35
  28. data/lib/active_scaffold/actions/create.rb +1 -1
  29. data/lib/active_scaffold/actions/delete.rb +2 -2
  30. data/lib/active_scaffold/actions/field_search.rb +2 -2
  31. data/lib/active_scaffold/actions/list.rb +8 -7
  32. data/lib/active_scaffold/actions/nested.rb +9 -9
  33. data/lib/active_scaffold/actions/search.rb +1 -1
  34. data/lib/active_scaffold/actions/show.rb +1 -1
  35. data/lib/active_scaffold/actions/subform.rb +3 -1
  36. data/lib/active_scaffold/actions/update.rb +5 -4
  37. data/lib/active_scaffold/active_record_permissions.rb +2 -11
  38. data/lib/active_scaffold/attribute_params.rb +16 -23
  39. data/lib/active_scaffold/bridges.rb +8 -8
  40. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +1 -1
  41. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +1 -1
  42. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +3 -18
  43. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +1 -1
  44. data/lib/active_scaffold/bridges/chosen/helpers.rb +7 -6
  45. data/lib/active_scaffold/bridges/date_picker/ext.rb +0 -13
  46. data/lib/active_scaffold/bridges/date_picker/helper.rb +3 -3
  47. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +1 -1
  48. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +3 -3
  49. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +8 -7
  50. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +2 -4
  51. data/lib/active_scaffold/bridges/paper_trail.rb +1 -1
  52. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
  53. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +1 -1
  54. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +2 -2
  55. data/lib/active_scaffold/bridges/record_select/helpers.rb +9 -9
  56. data/lib/active_scaffold/bridges/shared/date_bridge.rb +3 -3
  57. data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +1 -1
  58. data/lib/active_scaffold/config/base.rb +89 -21
  59. data/lib/active_scaffold/config/core.rb +127 -18
  60. data/lib/active_scaffold/config/delete.rb +2 -0
  61. data/lib/active_scaffold/config/field_search.rb +7 -1
  62. data/lib/active_scaffold/config/form.rb +10 -1
  63. data/lib/active_scaffold/config/list.rb +27 -11
  64. data/lib/active_scaffold/config/mark.rb +3 -1
  65. data/lib/active_scaffold/config/nested.rb +16 -17
  66. data/lib/active_scaffold/config/search.rb +9 -0
  67. data/lib/active_scaffold/config/show.rb +4 -0
  68. data/lib/active_scaffold/config/update.rb +4 -0
  69. data/lib/active_scaffold/configurable.rb +11 -6
  70. data/lib/active_scaffold/constraints.rb +1 -1
  71. data/lib/active_scaffold/core.rb +46 -16
  72. data/lib/active_scaffold/data_structures/action_columns.rb +50 -59
  73. data/lib/active_scaffold/data_structures/action_link.rb +20 -8
  74. data/lib/active_scaffold/data_structures/action_links.rb +6 -2
  75. data/lib/active_scaffold/data_structures/association/abstract.rb +9 -5
  76. data/lib/active_scaffold/data_structures/association/active_record.rb +1 -1
  77. data/lib/active_scaffold/data_structures/column.rb +51 -33
  78. data/lib/active_scaffold/data_structures/nested_info.rb +1 -1
  79. data/lib/active_scaffold/data_structures/set.rb +8 -0
  80. data/lib/active_scaffold/data_structures/sorting.rb +5 -2
  81. data/lib/active_scaffold/delayed_setup.rb +2 -1
  82. data/lib/active_scaffold/extensions/action_controller_rendering.rb +2 -1
  83. data/lib/active_scaffold/extensions/action_view_rendering.rb +1 -1
  84. data/lib/active_scaffold/extensions/cow_proxy.rb +43 -0
  85. data/lib/active_scaffold/extensions/ice_nine.rb +36 -0
  86. data/lib/active_scaffold/extensions/left_outer_joins.rb +8 -33
  87. data/lib/active_scaffold/extensions/routing_mapper.rb +4 -43
  88. data/lib/active_scaffold/extensions/unsaved_record.rb +2 -4
  89. data/lib/active_scaffold/finder.rb +26 -30
  90. data/lib/active_scaffold/helpers/action_link_helpers.rb +16 -16
  91. data/lib/active_scaffold/helpers/association_helpers.rb +5 -5
  92. data/lib/active_scaffold/helpers/controller_helpers.rb +11 -1
  93. data/lib/active_scaffold/helpers/form_column_helpers.rb +25 -24
  94. data/lib/active_scaffold/helpers/id_helpers.rb +2 -2
  95. data/lib/active_scaffold/helpers/list_column_helpers.rb +8 -6
  96. data/lib/active_scaffold/helpers/search_column_helpers.rb +4 -4
  97. data/lib/active_scaffold/helpers/view_helpers.rb +7 -13
  98. data/lib/active_scaffold/marked_model.rb +2 -2
  99. data/lib/active_scaffold/orm_checks.rb +1 -5
  100. data/lib/active_scaffold/paginator.rb +6 -4
  101. data/lib/active_scaffold/registry.rb +22 -0
  102. data/lib/active_scaffold/responds_to_parent.rb +2 -6
  103. data/lib/active_scaffold/tableless.rb +63 -59
  104. data/lib/active_scaffold/version.rb +2 -2
  105. data/lib/generators/active_scaffold/controller_generator.rb +2 -2
  106. data/lib/generators/active_scaffold/install_generator.rb +1 -1
  107. data/lib/generators/active_scaffold/resource_generator.rb +2 -2
  108. data/test/bridges/date_picker_test.rb +1 -2
  109. data/test/bridges/paperclip_test.rb +5 -5
  110. data/test/class_with_finder.rb +2 -2
  111. data/test/company.rb +2 -2
  112. data/test/config/create_test.rb +4 -2
  113. data/test/config/nested_test.rb +1 -1
  114. data/test/config/show_test.rb +1 -1
  115. data/test/config/update_test.rb +7 -6
  116. data/test/data_structures/action_links_test.rb +1 -1
  117. data/test/data_structures/sorting_test.rb +7 -0
  118. data/test/misc/active_record_permissions_test.rb +1 -9
  119. data/test/misc/attribute_params_test.rb +8 -8
  120. data/test/misc/calculation_test.rb +1 -1
  121. data/test/misc/constraints_test.rb +2 -2
  122. data/test/misc/convert_numbers_format_test.rb +3 -3
  123. data/test/misc/lang_test.rb +1 -1
  124. data/test/misc/parse_datetime_test.rb +3 -4
  125. data/test/misc/tableless_test.rb +6 -0
  126. data/test/mock_app/Rakefile +1 -1
  127. data/test/mock_app/config/application.rb +1 -1
  128. data/test/mock_app/config/boot.rb +1 -1
  129. data/test/mock_app/config/environment.rb +2 -2
  130. data/test/test_helper.rb +8 -1
  131. metadata +38 -13
@@ -0,0 +1,22 @@
1
+ module ActiveScaffold
2
+ class Registry
3
+ extend ActiveSupport::PerThreadRegistry
4
+ attr_accessor :current_user_proc, :current_ability_proc, :marked_records
5
+
6
+ def user_settings
7
+ @user_settings ||= {}
8
+ end
9
+
10
+ def constraint_columns
11
+ @constraint_columns ||= Hash.new { |h, k| h[k] = [] }
12
+ end
13
+
14
+ def unauthorized_columns
15
+ @unauthorized_columns ||= Hash.new { |h, k| h[k] = [] }
16
+ end
17
+
18
+ def self.instance
19
+ RequestStore.store[@per_thread_registry_key] ||= new
20
+ end
21
+ end
22
+ end
@@ -34,12 +34,8 @@ module ActiveScaffold
34
34
  instance_variable_set(:@_response_body, nil)
35
35
  end
36
36
 
37
- # We're returning HTML instead of JS now
38
- if Rails.version < '4.1'
39
- render text: script, content_type: 'text/html' # remove when rails 4.0 is not supported
40
- else
41
- render html: script.html_safe, content_type: 'text/html' # rubocop:disable Rails/OutputSafety
42
- end
37
+ # We're returning HTML instead of JS now, content_type needed if not inside respond_to block
38
+ render html: script.html_safe, content_type: 'text/html' # rubocop:disable Rails/OutputSafety
43
39
  end
44
40
  alias respond_to_parent responds_to_parent
45
41
  end
@@ -1,10 +1,8 @@
1
1
  class ActiveScaffold::Tableless < ActiveRecord::Base
2
2
  class AssociationScope < ActiveRecord::Associations::AssociationScope
3
- if defined?(ActiveRecord::Associations::AssociationScope::INSTANCE) # rails >= 4.1
4
- INSTANCE = respond_to?(:create) ? create : new # create for rails >= 4.2
5
- def self.scope(association, connection)
6
- INSTANCE.scope association, connection
7
- end
3
+ INSTANCE = create
4
+ def self.scope(association, connection)
5
+ INSTANCE.scope association, connection
8
6
  end
9
7
 
10
8
  if Rails.version < '5.0.0'
@@ -19,11 +17,9 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
19
17
  end
20
18
  end
21
19
 
22
- if Rails.version >= '4.1'
23
- def add_constraints(scope, owner, assoc_klass, refl, tracker)
24
- tracker.instance_variable_set(:@assoc_klass, assoc_klass)
25
- super
26
- end
20
+ def add_constraints(scope, owner, assoc_klass, refl, tracker)
21
+ tracker.instance_variable_set(:@assoc_klass, assoc_klass)
22
+ super
27
23
  end
28
24
  end
29
25
  end
@@ -46,7 +42,7 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
46
42
  metadata = ActiveRecord::Base.connection.send :fetch_type_metadata, sql_type
47
43
  super(name, default, metadata, null)
48
44
  end
49
- elsif Rails.version >= '4.2.0'
45
+ else
50
46
  def initialize(name, default, sql_type = nil, null = true)
51
47
  cast_type = ActiveRecord::Base.connection.send :lookup_cast_type, sql_type
52
48
  super(name, default, cast_type, sql_type, null)
@@ -55,16 +51,18 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
55
51
  end
56
52
 
57
53
  module Tableless
58
- def association_scope
59
- @association_scope ||= overrided_association_scope if klass < ActiveScaffold::Tableless
60
- super
61
- end
54
+ if Rails.version < '5.2.0'
55
+ def skip_statement_cache?
56
+ klass < ActiveScaffold::Tableless ? true : super
57
+ end
62
58
 
63
- def overrided_association_scope
64
- if AssociationScope.respond_to?(:scope) # rails >= 4.1
65
- AssociationScope.scope(self, klass.connection)
66
- else # rails < 4.1
67
- AssociationScope.new(self).scope
59
+ def association_scope
60
+ @association_scope ||= AssociationScope.scope(self, klass.connection) if klass < ActiveScaffold::Tableless
61
+ super
62
+ end
63
+ else
64
+ def skip_statement_cache?(scope)
65
+ klass < ActiveScaffold::Tableless ? true : super
68
66
  end
69
67
  end
70
68
 
@@ -91,7 +89,7 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
91
89
 
92
90
  module CollectionAssociation
93
91
  def self.included(base)
94
- base.prepend TablelessCollectionAssociation if Rails.version >= '4.2'
92
+ base.prepend TablelessCollectionAssociation
95
93
  end
96
94
  end
97
95
 
@@ -110,20 +108,13 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
110
108
  module RelationExtension
111
109
  attr_reader :conditions
112
110
 
113
- if Rails.version >= '5.0'
114
- def initialize(klass, table, predicate_builder, values = {})
115
- super
116
- @conditions ||= []
117
- end
118
- else
119
- def initialize(klass, table)
120
- super
121
- @conditions ||= []
122
- end
111
+ def initialize(klass, *)
112
+ super
113
+ @conditions ||= []
123
114
  end
124
115
 
125
116
  def initialize_copy(other)
126
- @conditions = @conditions.try(:dup) || []
117
+ @conditions = @conditions&.dup || []
127
118
  super
128
119
  end
129
120
 
@@ -135,9 +126,9 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
135
126
  self
136
127
  end
137
128
 
138
- def merge(r)
129
+ def merge(rel)
139
130
  super.tap do |merged|
140
- merged.conditions.concat r.conditions unless r.nil? || r.is_a?(Array)
131
+ merged.conditions.concat rel.conditions unless rel.nil? || rel.is_a?(Array)
141
132
  end
142
133
  end
143
134
 
@@ -167,41 +158,56 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
167
158
  private
168
159
 
169
160
  def relation
170
- args = [self, arel_table]
171
- args << predicate_builder if Rails.version >= '5.0.0'
161
+ args = [self]
162
+ if Rails.version < '5.2.0'
163
+ args << arel_table
164
+ args << predicate_builder if Rails.version >= '5.0.0'
165
+ end
172
166
  ActiveScaffold::Tableless::Relation.new(*args)
173
167
  end
168
+
169
+ if Rails.version >= '5.2'
170
+ def cached_find_by_statement(key, &block)
171
+ StatementCache.new(key, self, &block)
172
+ end
173
+ end
174
174
  end
175
175
 
176
176
  class StatementCache
177
- def initialize(key)
177
+ def initialize(key, model = nil)
178
178
  @key = key
179
+ @model = model
179
180
  end
180
181
 
181
- def execute(values, model, connection)
182
- model.where(@key => values)
182
+ if Rails.version < '5.2' # 5.0 and 5.1
183
+ def execute(values, model, connection)
184
+ model.where(@key => values)
185
+ end
186
+ else
187
+ def execute(values, connection)
188
+ @model.where(@key => values)
189
+ end
183
190
  end
184
191
  end
185
192
 
186
- unless Rails.version < '4.2'
187
- def self.columns_hash
188
- if self < ActiveScaffold::Tableless
189
- @columns_hash ||= Hash[columns.map { |c| [c.name, c] }]
190
- else
191
- super
192
- end
193
- end
194
- if Rails.version >= '5.0'
195
- def self.initialize_find_by_cache
196
- @find_by_statement_cache = {
197
- true => Hash.new { |h, k| h[k] = StatementCache.new(k) },
198
- false => Hash.new { |h, k| h[k] = StatementCache.new(k) }
199
- }
200
- end
193
+ def self.columns_hash
194
+ if self < ActiveScaffold::Tableless
195
+ @columns_hash ||= Hash[columns.map { |c| [c.name, c] }]
201
196
  else
202
- def self.initialize_find_by_cache
203
- self.find_by_statement_cache = Hash.new { |h, k| h[k] = StatementCache.new(k) }
204
- end
197
+ super
198
+ end
199
+ end
200
+ if Rails.version < '5.0' # 4.2.x
201
+ def self.initialize_find_by_cache
202
+ # rubocop:disable Rails/DynamicFindBy
203
+ self.find_by_statement_cache = Hash.new { |h, k| h[k] = StatementCache.new(k) }
204
+ end
205
+ elsif Rails.version < '5.2' # 5.0 and 5.1
206
+ def self.initialize_find_by_cache
207
+ @find_by_statement_cache = {
208
+ true => Hash.new { |h, k| h[k] = StatementCache.new(k) },
209
+ false => Hash.new { |h, k| h[k] = StatementCache.new(k) }
210
+ }
205
211
  end
206
212
  end
207
213
 
@@ -250,10 +256,8 @@ class ActiveScaffold::Tableless < ActiveRecord::Base
250
256
  def _create_record #:nodoc:
251
257
  run_callbacks(:create) {}
252
258
  end
253
- alias create_record _create_record # for rails4 < 4.0.6, < 4.1.2
254
259
 
255
260
  def _update_record(*) #:nodoc:
256
261
  run_callbacks(:update) {}
257
262
  end
258
- alias update_record _update_record # for rails4 < 4.0.6, < 4.1.2
259
263
  end
@@ -1,8 +1,8 @@
1
1
  module ActiveScaffold
2
2
  module Version
3
3
  MAJOR = 3
4
- MINOR = 5
5
- PATCH = 5
4
+ MINOR = 6
5
+ PATCH = '0.pre'.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
 
@@ -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
@@ -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)
@@ -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')
@@ -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?
@@ -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)