active_scaffold 3.4.17 → 3.4.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +12 -1
  3. data/README.md +8 -4
  4. data/app/assets/javascripts/jquery/active_scaffold.js +82 -67
  5. data/app/assets/stylesheets/active_scaffold.scss +1 -1
  6. data/app/assets/stylesheets/active_scaffold_colors.scss +1 -1
  7. data/app/assets/stylesheets/blue-theme.css +1 -1
  8. data/app/views/active_scaffold_overrides/_form_association.html.erb +3 -3
  9. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +3 -3
  10. data/app/views/active_scaffold_overrides/_show_columns.html.erb +1 -1
  11. data/lib/active_scaffold.rb +16 -16
  12. data/lib/active_scaffold/actions/common_search.rb +13 -11
  13. data/lib/active_scaffold/actions/core.rb +85 -78
  14. data/lib/active_scaffold/actions/create.rb +29 -28
  15. data/lib/active_scaffold/actions/delete.rb +17 -17
  16. data/lib/active_scaffold/actions/field_search.rb +18 -19
  17. data/lib/active_scaffold/actions/list.rb +30 -22
  18. data/lib/active_scaffold/actions/mark.rb +1 -1
  19. data/lib/active_scaffold/actions/nested.rb +78 -65
  20. data/lib/active_scaffold/actions/search.rb +13 -10
  21. data/lib/active_scaffold/actions/show.rb +10 -6
  22. data/lib/active_scaffold/actions/subform.rb +1 -2
  23. data/lib/active_scaffold/actions/update.rb +39 -31
  24. data/lib/active_scaffold/active_record_permissions.rb +14 -15
  25. data/lib/active_scaffold/attribute_params.rb +42 -43
  26. data/lib/active_scaffold/bridges.rb +22 -12
  27. data/lib/active_scaffold/bridges/ancestry.rb +1 -1
  28. data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +6 -6
  29. data/lib/active_scaffold/bridges/bitfields.rb +1 -1
  30. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +12 -13
  31. data/lib/active_scaffold/bridges/calendar_date_select.rb +5 -5
  32. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +17 -20
  33. data/lib/active_scaffold/bridges/cancan.rb +1 -1
  34. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +8 -9
  35. data/lib/active_scaffold/bridges/carrierwave.rb +4 -4
  36. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +9 -8
  37. data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +11 -10
  38. data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +7 -6
  39. data/lib/active_scaffold/bridges/chosen.rb +1 -1
  40. data/lib/active_scaffold/bridges/chosen/helpers.rb +4 -4
  41. data/lib/active_scaffold/bridges/country_helper.rb +1 -1
  42. data/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb +259 -260
  43. data/lib/active_scaffold/bridges/date_picker.rb +2 -2
  44. data/lib/active_scaffold/bridges/date_picker/ext.rb +9 -11
  45. data/lib/active_scaffold/bridges/date_picker/helper.rb +61 -67
  46. data/lib/active_scaffold/bridges/dragonfly.rb +4 -4
  47. data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +9 -8
  48. data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +11 -10
  49. data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +6 -5
  50. data/lib/active_scaffold/bridges/file_column.rb +5 -5
  51. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +20 -23
  52. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +20 -23
  53. data/lib/active_scaffold/bridges/file_column/form_ui.rb +13 -14
  54. data/lib/active_scaffold/bridges/file_column/list_ui.rb +7 -8
  55. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +18 -22
  56. data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +5 -4
  57. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +2 -10
  58. data/lib/active_scaffold/bridges/paper_trail.rb +7 -5
  59. data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +4 -3
  60. data/lib/active_scaffold/bridges/paperclip.rb +5 -5
  61. data/lib/active_scaffold/bridges/paperclip/form_ui.rb +11 -10
  62. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +6 -5
  63. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +10 -9
  64. data/lib/active_scaffold/bridges/record_select.rb +1 -1
  65. data/lib/active_scaffold/bridges/record_select/helpers.rb +28 -28
  66. data/lib/active_scaffold/bridges/semantic_attributes.rb +1 -1
  67. data/lib/active_scaffold/bridges/semantic_attributes/column.rb +1 -1
  68. data/lib/active_scaffold/bridges/shared/date_bridge.rb +58 -52
  69. data/lib/active_scaffold/bridges/tiny_mce.rb +2 -2
  70. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -3
  71. data/lib/active_scaffold/config/base.rb +9 -10
  72. data/lib/active_scaffold/config/core.rb +24 -29
  73. data/lib/active_scaffold/config/create.rb +0 -1
  74. data/lib/active_scaffold/config/field_search.rb +8 -10
  75. data/lib/active_scaffold/config/form.rb +5 -5
  76. data/lib/active_scaffold/config/list.rb +21 -20
  77. data/lib/active_scaffold/config/mark.rb +3 -3
  78. data/lib/active_scaffold/config/nested.rb +11 -10
  79. data/lib/active_scaffold/config/search.rb +2 -3
  80. data/lib/active_scaffold/config/show.rb +1 -1
  81. data/lib/active_scaffold/config/update.rb +1 -2
  82. data/lib/active_scaffold/configurable.rb +9 -11
  83. data/lib/active_scaffold/constraints.rb +9 -8
  84. data/lib/active_scaffold/core.rb +72 -84
  85. data/lib/active_scaffold/data_structures/action_columns.rb +26 -25
  86. data/lib/active_scaffold/data_structures/action_link.rb +43 -43
  87. data/lib/active_scaffold/data_structures/action_links.rb +17 -15
  88. data/lib/active_scaffold/data_structures/actions.rb +5 -5
  89. data/lib/active_scaffold/data_structures/bridge.rb +6 -3
  90. data/lib/active_scaffold/data_structures/column.rb +110 -89
  91. data/lib/active_scaffold/data_structures/columns.rb +3 -3
  92. data/lib/active_scaffold/data_structures/error_message.rb +4 -6
  93. data/lib/active_scaffold/data_structures/nested_info.rb +43 -48
  94. data/lib/active_scaffold/data_structures/set.rb +7 -8
  95. data/lib/active_scaffold/data_structures/sorting.rb +38 -33
  96. data/lib/active_scaffold/delayed_setup.rb +5 -6
  97. data/lib/active_scaffold/engine.rb +4 -4
  98. data/lib/active_scaffold/extensions/action_controller_rendering.rb +3 -4
  99. data/lib/active_scaffold/extensions/action_controller_rescueing.rb +1 -1
  100. data/lib/active_scaffold/extensions/action_view_rendering.rb +5 -6
  101. data/lib/active_scaffold/extensions/left_outer_joins.rb +11 -11
  102. data/lib/active_scaffold/extensions/localize.rb +1 -1
  103. data/lib/active_scaffold/extensions/name_option_for_datetime.rb +1 -1
  104. data/lib/active_scaffold/extensions/paginator_extensions.rb +2 -5
  105. data/lib/active_scaffold/extensions/reverse_associations.rb +13 -13
  106. data/lib/active_scaffold/extensions/routing_mapper.rb +9 -9
  107. data/lib/active_scaffold/extensions/unsaved_associated.rb +9 -9
  108. data/lib/active_scaffold/finder.rb +90 -93
  109. data/lib/active_scaffold/helpers/association_helpers.rb +5 -5
  110. data/lib/active_scaffold/helpers/controller_helpers.rb +22 -19
  111. data/lib/active_scaffold/helpers/form_column_helpers.rb +115 -105
  112. data/lib/active_scaffold/helpers/human_condition_helpers.rb +62 -35
  113. data/lib/active_scaffold/helpers/id_helpers.rb +6 -6
  114. data/lib/active_scaffold/helpers/list_column_helpers.rb +89 -94
  115. data/lib/active_scaffold/helpers/pagination_helpers.rb +9 -9
  116. data/lib/active_scaffold/helpers/search_column_helpers.rb +47 -44
  117. data/lib/active_scaffold/helpers/show_column_helpers.rb +2 -2
  118. data/lib/active_scaffold/helpers/view_helpers.rb +86 -91
  119. data/lib/active_scaffold/marked_model.rb +10 -10
  120. data/lib/active_scaffold/paginator.rb +30 -34
  121. data/lib/active_scaffold/responds_to_parent.rb +27 -28
  122. data/lib/active_scaffold/tableless.rb +20 -15
  123. data/lib/active_scaffold/version.rb +1 -1
  124. data/lib/generators/active_scaffold/active_scaffold_generator.rb +8 -8
  125. data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +9 -9
  126. data/shoulda_macros/macros.rb +27 -22
  127. data/test/bridges/bridge_test.rb +38 -29
  128. data/test/bridges/date_picker_test.rb +1 -1
  129. data/test/bridges/paper_trail_test.rb +17 -0
  130. data/test/bridges/paperclip_test.rb +3 -2
  131. data/test/bridges/tiny_mce_test.rb +5 -2
  132. data/test/company.rb +25 -30
  133. data/test/config/base_test.rb +1 -1
  134. data/test/config/core_test.rb +9 -9
  135. data/test/config/create_test.rb +14 -8
  136. data/test/config/delete_test.rb +4 -4
  137. data/test/config/field_search_test.rb +6 -6
  138. data/test/config/list_test.rb +16 -16
  139. data/test/config/nested_test.rb +4 -4
  140. data/test/config/search_test.rb +8 -8
  141. data/test/config/show_test.rb +6 -6
  142. data/test/config/subform_test.rb +1 -1
  143. data/test/config/update_test.rb +5 -5
  144. data/test/const_mocker.rb +4 -4
  145. data/test/data_structures/action_columns_test.rb +4 -5
  146. data/test/data_structures/action_link_test.rb +1 -0
  147. data/test/data_structures/action_links_test.rb +5 -5
  148. data/test/data_structures/column_test.rb +9 -9
  149. data/test/data_structures/columns_test.rb +2 -2
  150. data/test/data_structures/error_message_test.rb +4 -5
  151. data/test/data_structures/set_test.rb +1 -2
  152. data/test/data_structures/sorting_test.rb +10 -10
  153. data/test/data_structures/validation_reflection_test.rb +8 -0
  154. data/test/extensions/routing_mapper_test.rb +2 -2
  155. data/test/helpers/list_column_helpers_test.rb +3 -2
  156. data/test/helpers/pagination_helpers_test.rb +5 -4
  157. data/test/helpers/search_column_helpers_test.rb +1 -1
  158. data/test/misc/active_record_permissions_test.rb +63 -50
  159. data/test/misc/attribute_params_test.rb +28 -26
  160. data/test/misc/calculation_test.rb +10 -3
  161. data/test/misc/configurable_test.rb +12 -13
  162. data/test/misc/constraints_test.rb +6 -6
  163. data/test/misc/convert_numbers_format_test.rb +7 -6
  164. data/test/misc/finder_test.rb +17 -12
  165. data/test/misc/lang_test.rb +3 -4
  166. data/test/misc/tableless_test.rb +2 -3
  167. data/test/mock_app/app/controllers/addresses_controller.rb +1 -1
  168. data/test/mock_app/app/controllers/buildings_controller.rb +1 -1
  169. data/test/mock_app/app/controllers/cars_controller.rb +1 -1
  170. data/test/mock_app/app/controllers/contacts_controller.rb +1 -1
  171. data/test/mock_app/app/controllers/people_controller.rb +1 -1
  172. data/test/mock_app/app/models/file_model.rb +2 -2
  173. data/test/mock_app/app/models/person.rb +1 -1
  174. data/test/mock_app/config/application.rb +3 -3
  175. data/test/mock_app/config/boot.rb +1 -1
  176. data/test/mock_app/config/environment.rb +1 -0
  177. data/test/mock_app/config/environments/development.rb +0 -1
  178. data/test/mock_app/config/environments/production.rb +1 -1
  179. data/test/mock_app/db/schema.rb +14 -15
  180. data/test/model_stub.rb +13 -16
  181. data/test/run_all.rb +5 -7
  182. data/test/test_helper.rb +12 -9
  183. metadata +19 -3
@@ -41,7 +41,7 @@ class AttributeParamsTest < MiniTest::Test
41
41
 
42
42
  def test_saving_has_many_select
43
43
  buildings = 2.times.map { Building.create }
44
- model = update_record_from_params(Person.new, :create, :first_name, :last_name, :buildings, :first_name => 'First', :last_name => '', :buildings => ['', *buildings.map{|b| b.id.to_s}]) # checkbox_list always add a hidden tag with empty value
44
+ model = update_record_from_params(Person.new, :create, :first_name, :last_name, :buildings, :first_name => 'First', :last_name => '', :buildings => ['', *buildings.map { |b| b.id.to_s }]) # checkbox_list always add a hidden tag with empty value
45
45
  assert_equal 'First', model.first_name
46
46
  assert_nil model.last_name
47
47
  assert_equal buildings.map(&:id), model.building_ids
@@ -52,7 +52,7 @@ class AttributeParamsTest < MiniTest::Test
52
52
  model = update_record_from_params(model, :update, :first_name, :last_name, :buildings, :first_name => 'Name', :last_name => 'Last', :buildings => ['']) { raise ActiveRecord::Rollback }
53
53
  assert_equal 'Name', model.first_name
54
54
  assert_equal 'Last', model.last_name
55
- assert_equal [model.id]*2, buildings.map{|b| b.reload.owner_id}, 'owners should not be saved'
55
+ assert_equal [model.id] * 2, buildings.map { |b| b.reload.owner_id }, 'owners should not be saved'
56
56
  assert model.building_ids.blank?, 'buildings should be cleared'
57
57
  assert model.buildings.blank?, 'buildings should be cleared'
58
58
  assert_equal 0, model.buildings.size
@@ -63,7 +63,7 @@ class AttributeParamsTest < MiniTest::Test
63
63
  assert_equal 'Last', model.last_name
64
64
  assert model.building_ids.blank?, 'buildings should be cleared'
65
65
  assert model.buildings.blank?, 'buildings should be cleared'
66
- assert_equal [nil]*2, buildings.map{|b| b.reload.owner_id}, 'buildings should be saved'
66
+ assert_equal [nil] * 2, buildings.map { |b| b.reload.owner_id }, 'buildings should be saved'
67
67
  assert model.save
68
68
  assert_equal 0, model.reload.buildings_count
69
69
  end
@@ -182,23 +182,23 @@ class AttributeParamsTest < MiniTest::Test
182
182
  people = 2.times.map { Person.create }
183
183
  assert people.all?(&:persisted?)
184
184
 
185
- model = update_record_from_params(Building.new, :create, :name, :tenants, :name => 'Tower', :tenants => ['', *people.map{|b| b.id.to_s}]) # checkbox_list always add a hidden tag with empty value
185
+ model = update_record_from_params(Building.new, :create, :name, :tenants, :name => 'Tower', :tenants => ['', *people.map { |b| b.id.to_s }]) # checkbox_list always add a hidden tag with empty value
186
186
  assert_equal 'Tower', model.name
187
187
  assert model.tenants.present?
188
- assert_equal [nil]*2, people.map {|p| p.floor(true)}, 'floor should not be saved yet'
188
+ assert_equal [nil] * 2, people.map { |p| p.floor(true) }, 'floor should not be saved yet'
189
189
  assert model.save
190
- assert_equal [model.id]*2, model.floors.map(&:building_id)
191
- assert_equal [model.id]*2, people.map {|p| p.floor(true).building_id}, 'floor should be saved'
190
+ assert_equal [model.id] * 2, model.floors.map(&:building_id)
191
+ assert_equal [model.id] * 2, people.map { |p| p.floor(true).building_id }, 'floor should be saved'
192
192
 
193
193
  model = update_record_from_params(model, :update, :name, :tenants, :name => 'Skyscrapper', :tenants => ['']) { raise ActiveRecord::Rollback }
194
194
  assert_equal 'Skyscrapper', model.name
195
- assert_equal [model.id]*2, people.map {|p| p.floor(true).building_id}, 'previous floor should not be deleted'
195
+ assert_equal [model.id] * 2, people.map { |p| p.floor(true).building_id }, 'previous floor should not be deleted'
196
196
  assert model.tenants.empty?, 'tenants should be cleared'
197
197
 
198
198
  model.reload
199
199
  model = update_record_from_params(model, :update, :name, :tenants, :name => 'Skyscrapper', :tenants => [''])
200
200
  assert_equal 'Skyscrapper', model.name
201
- assert_equal [nil]*2, people.map {|p| p.floor(true)}, 'previous floor should be deleted'
201
+ assert_equal [nil] * 2, people.map { |p| p.floor(true) }, 'previous floor should be deleted'
202
202
  assert model.tenants.empty?, 'tenants should be cleared'
203
203
  assert model.save
204
204
  end
@@ -346,7 +346,7 @@ class AttributeParamsTest < MiniTest::Test
346
346
 
347
347
  def test_saving_has_many_polymorphic_select
348
348
  contacts = 2.times.map { Contact.create }
349
-
349
+
350
350
  model = update_record_from_params(Person.new, :create, :first_name, :contacts, :first_name => 'Me', :contacts => ['', contacts.first.id.to_s])
351
351
  assert_equal 'Me', model.first_name
352
352
  assert model.contacts.present?
@@ -354,48 +354,49 @@ class AttributeParamsTest < MiniTest::Test
354
354
  assert_equal [model.id], model.contacts.map(&:contactable_id)
355
355
  assert_equal model.id, contacts.first.reload.contactable.id, 'contactable should be saved'
356
356
  assert_equal 1, model.reload.contacts_count
357
-
358
- model = update_record_from_params(model, :update, :first_name, :contacts, :first_name => 'Name', :contacts => ['', *contacts.map{|c| c.id.to_s}])
357
+
358
+ model = update_record_from_params(model, :update, :first_name, :contacts, :first_name => 'Name', :contacts => ['', *contacts.map { |c| c.id.to_s }])
359
359
  assert_equal 'Name', model.first_name
360
360
  assert model.contacts.present?
361
361
  assert model.save
362
- assert_equal [model.id]*2, model.contacts.map(&:contactable_id)
363
- assert_equal [model.id]*2, contacts.map {|c| c.reload.contactable.id}, 'contactable should be saved'
362
+ assert_equal [model.id] * 2, model.contacts.map(&:contactable_id)
363
+ assert_equal [model.id] * 2, contacts.map { |c| c.reload.contactable.id }, 'contactable should be saved'
364
364
  assert_equal 2, model.reload.contacts_count
365
-
365
+
366
366
  model = update_record_from_params(model, :update, :first_name, :contacts, :first_name => 'Name', :contacts => [''])
367
367
  assert_equal 'Name', model.first_name
368
368
  assert model.contacts.empty?
369
369
  assert model.save
370
- assert_equal [nil]*2, contacts.map {|c| c.reload.contactable}, 'contactable should be saved'
370
+ assert_equal [nil] * 2, contacts.map { |c| c.reload.contactable }, 'contactable should be saved'
371
371
  assert_equal 0, model.reload.contacts_count
372
372
  end
373
373
 
374
374
  def test_saving_habtm_select
375
375
  roles = 2.times.map { Role.create }
376
-
376
+
377
377
  model = update_record_from_params(Person.new, :create, :first_name, :roles, :first_name => 'Me', :roles => ['', roles.first.id.to_s])
378
378
  assert_equal 'Me', model.first_name
379
379
  assert model.roles.present?
380
380
  assert model.save
381
381
  assert_equal [[model.id]], model.roles.map(&:person_ids)
382
382
  assert_equal [model.id], roles.first.reload.person_ids, 'role should be saved'
383
-
384
- model = update_record_from_params(model, :update, :first_name, :roles, :first_name => 'Name', :roles => ['', *roles.map{|c| c.id.to_s}])
383
+
384
+ model = update_record_from_params(model, :update, :first_name, :roles, :first_name => 'Name', :roles => ['', *roles.map { |c| c.id.to_s }])
385
385
  assert_equal 'Name', model.first_name
386
386
  assert model.roles.present?
387
387
  assert model.save
388
- assert_equal [[model.id]]*2, model.roles.map(&:person_ids)
389
- assert_equal [[model.id]]*2, roles.map {|r| r.reload.person_ids}, 'roles should be saved'
390
-
388
+ assert_equal [[model.id]] * 2, model.roles.map(&:person_ids)
389
+ assert_equal [[model.id]] * 2, roles.map { |r| r.reload.person_ids }, 'roles should be saved'
390
+
391
391
  model = update_record_from_params(model, :update, :first_name, :roles, :first_name => 'Name', :roles => [''])
392
392
  assert_equal 'Name', model.first_name
393
393
  assert model.roles.empty?
394
394
  assert model.save
395
- assert roles.all? {|r| r.reload.people.empty?}, 'roles should be saved'
395
+ assert roles.all? { |r| r.reload.people.empty? }, 'roles should be saved'
396
396
  end
397
397
 
398
398
  protected
399
+
399
400
  def update_record_from_params(record, action, *columns, &block)
400
401
  params = columns.extract_options!.with_indifferent_access
401
402
  new_record = nil
@@ -416,9 +417,9 @@ class AttributeParamsTest < MiniTest::Test
416
417
  end
417
418
 
418
419
  class Controller
419
- def self.helper_method(*args); end
420
- def self.before_filter(*args); end
421
-
420
+ def self.helper_method(*); end
421
+ def self.before_filter(*); end
422
+
422
423
  include ActiveScaffold::Core
423
424
  include ActiveScaffold::Helpers::ControllerHelpers
424
425
  include ActiveScaffold::AttributeParams
@@ -427,6 +428,7 @@ class Controller
427
428
  def logger
428
429
  @logger ||= Logger.new(STDOUT)
429
430
  end
431
+
430
432
  def flash
431
433
  @flash ||= ActionDispatch::Flash::FlashHash.new
432
434
  end
@@ -3,31 +3,38 @@ require 'test_helper'
3
3
  class ClassWithFinder
4
4
  include ActiveScaffold::Finder
5
5
  def conditions_for_collection; end
6
+
6
7
  def conditions_from_params; end
8
+
7
9
  def conditions_from_constraints; end
10
+
8
11
  def joins_for_collection; end
12
+
9
13
  def custom_finder_options
10
14
  {}
11
15
  end
16
+
12
17
  def beginning_of_chain
13
18
  active_scaffold_config.model
14
19
  end
20
+
15
21
  def conditional_get_support?; end
22
+
16
23
  def params; {}; end
17
24
  end
18
25
 
19
26
  class CalculationTest < MiniTest::Test
20
27
  def setup
21
28
  @buildings = []
22
- @buildings << Building.create {|b| b.create_owner(:first_name => 'foo')}
29
+ @buildings << Building.create { |b| b.create_owner(:first_name => 'foo') }
23
30
  @buildings << Building.create(:name => 'foo bar')
24
31
  @buildings << Building.create
25
-
32
+
26
33
  @klass = ClassWithFinder.new
27
34
  @klass.stubs(:active_scaffold_config).returns(mock { stubs(:model).returns(Building) })
28
35
  @klass.stubs(:active_scaffold_session_storage).returns({})
29
36
  end
30
-
37
+
31
38
  def teardown
32
39
  @buildings.each(&:destroy).map(&:owner).compact.each(&:destroy)
33
40
  end
@@ -40,20 +40,19 @@ class ConfigurableTest < MiniTest::Test
40
40
  ## test normal block behaviors
41
41
  ##
42
42
  # functions
43
- assert_equal hello, configurable_class.configure {hello}
43
+ assert_equal hello, configurable_class.configure { hello }
44
44
  # variables
45
- assert_equal configurable_class, configurable_class.configure {configurable_class}
45
+ assert_equal configurable_class, configurable_class.configure { configurable_class }
46
46
  # constants
47
- assert_equal ConfigurableTest::HELLO, configurable_class.configure {ConfigurableTest::HELLO}
47
+ assert_equal ConfigurableTest::HELLO, configurable_class.configure { ConfigurableTest::HELLO }
48
48
 
49
49
  ##
50
50
  ## test extra "localized" block behavior
51
51
  ##
52
52
  # functions
53
- assert_equal configurable_class.foo, configurable_class.configure {foo}
53
+ assert_equal configurable_class.foo, configurable_class.configure { foo }
54
54
  # constants - not working
55
- # assert_equal configurable_class.FOO, configurable_class.configure {FOO}
56
-
55
+ # assert_equal configurable_class.FOO, configurable_class.configure {FOO}
57
56
  end
58
57
 
59
58
  def test_class_configuration
@@ -73,25 +72,25 @@ class ConfigurableTest < MiniTest::Test
73
72
  ## test normal block behaviors
74
73
  ##
75
74
  # functions
76
- assert_equal hello, ExtendedClass.configure {hello}
75
+ assert_equal hello, ExtendedClass.configure { hello }
77
76
  # variables
78
- assert_equal ExtendedClass, ExtendedClass.configure {ExtendedClass}
77
+ assert_equal ExtendedClass, ExtendedClass.configure { ExtendedClass }
79
78
  # constants
80
- assert_equal ConfigurableTest::HELLO, ExtendedClass.configure {ConfigurableTest::HELLO}
79
+ assert_equal ConfigurableTest::HELLO, ExtendedClass.configure { ConfigurableTest::HELLO }
81
80
 
82
81
  ##
83
82
  ## test extra "localized" block behavior
84
83
  ##
85
84
  # functions
86
- assert_equal ExtendedClass.foo, ExtendedClass.configure {foo}
85
+ assert_equal ExtendedClass.foo, ExtendedClass.configure { foo }
87
86
  # constants - not working
88
- # assert_equal ExtendedClass.FOO, ExtendedClass.configure {FOO}
87
+ # assert_equal ExtendedClass.FOO, ExtendedClass.configure {FOO}
89
88
  end
90
89
 
91
90
  def test_arity
92
91
  # this is the main style
93
- assert_equal 'foo', ExtendedClass.configure {'foo'}
92
+ assert_equal 'foo', ExtendedClass.configure { 'foo' }
94
93
  # but we want to let people accept the configurable class as the first argument, too
95
- assert_equal 'bar', ExtendedClass.configure {|a| a.foo}
94
+ assert_equal 'bar', ExtendedClass.configure { |a| a.foo } # rubocop:disable Style/SymbolProc
96
95
  end
97
96
  end
@@ -2,9 +2,9 @@ require 'test_helper'
2
2
 
3
3
  module ModelStubs
4
4
  class ModelStub < ActiveRecord::Base
5
- abstract_class = true
5
+ self.abstract_class = true
6
6
  def self.columns; @columns ||= [ColumnMock.new('foo', '')] end
7
- def self.columns_hash; @hash ||= Hash[@columns.map{|c| [c.name, c]}] end
7
+ def self.columns_hash; @hash ||= Hash[@columns.map { |c| [c.name, c] }] end
8
8
  def self.table_name
9
9
  @table_name || to_s.split('::').last.underscore.pluralize
10
10
  end
@@ -83,7 +83,7 @@ end
83
83
 
84
84
  class ConstraintsTestObject
85
85
  # stub out what the mixin expects to find ...
86
- def self.before_filter(*args); end
86
+ def self.before_filter(*); end
87
87
  def self.helper_method(*); end
88
88
  attr_accessor :active_scaffold_preload
89
89
  attr_accessor :active_scaffold_references
@@ -123,7 +123,7 @@ class ConstraintsTest < MiniTest::Test
123
123
  assert_constraint_condition({:address => 11}, [{'addresses.id' => 11}], 'find the user with address #11')
124
124
  # reverse of a has_many :through
125
125
  assert_constraint_condition({:subscription => {:service => 5}}, [{'services.id' => 5}], 'find all users subscribed to service #5')
126
- assert(@test_object.active_scaffold_references.include?({:subscription => :service}), 'multi-level association include')
126
+ assert(@test_object.active_scaffold_references.include?(:subscription => :service), 'multi-level association include')
127
127
 
128
128
  @test_object.active_scaffold_config = config_for('subscription')
129
129
  # belongs_to (vs has_one)
@@ -179,7 +179,7 @@ class ConstraintsTest < MiniTest::Test
179
179
 
180
180
  def test_constraint_conditions_for_associations_with_primary_key_option
181
181
  @test_object.active_scaffold_config = config_for('primary_key_location')
182
- #user = ModelStubs::PrimaryKeyUser.new(:id => 1, :name => 'User Name')
182
+ # user = ModelStubs::PrimaryKeyUser.new(:id => 1, :name => 'User Name')
183
183
  ModelStubs::PrimaryKeyUser.expects(:find).with(1).returns(stub(:id => 1, :name => 'User Name'))
184
184
  assert_constraint_condition({'user' => 1}, [{'primary_key_locations.username' => 'User Name'}], 'association with primary-key constraint')
185
185
  end
@@ -192,6 +192,6 @@ class ConstraintsTest < MiniTest::Test
192
192
  end
193
193
 
194
194
  def config_for(klass, namespace = nil)
195
- super(klass, "model_stubs/")
195
+ super(klass, 'model_stubs/')
196
196
  end
197
197
  end
@@ -6,7 +6,7 @@ class NumberModel < ActiveRecord::Base
6
6
  @columns ||= [ColumnMock.new('id', '', 'int(11)'), ColumnMock.new('number', '', 'double(10,2)')]
7
7
  end
8
8
  def self.columns_hash
9
- @hash ||= Hash[@columns.map{|c| [c.name, c]}]
9
+ @hash ||= Hash[@columns.map { |c| [c.name, c] }]
10
10
  end
11
11
  end
12
12
 
@@ -57,7 +57,7 @@ class ConvertNumbersFormatTest < MiniTest::Test
57
57
  assert_equal 1000, convert_number('1,000')
58
58
  assert_equal 1000, convert_number('+1,000')
59
59
  assert_equal -1000, convert_number('-1,000')
60
- assert_equal 1000000, convert_number('1,000,000')
60
+ assert_equal 1_000_000, convert_number('1,000,000')
61
61
  end
62
62
 
63
63
  def test_english_format_with_separator_and_delimiter_using_english_language
@@ -66,7 +66,7 @@ class ConvertNumbersFormatTest < MiniTest::Test
66
66
  assert_equal 1234.1, convert_number('1,234.100')
67
67
  assert_equal 1234.345, convert_number('+1,234.345')
68
68
  assert_equal -1234.345, convert_number('-1,234.345')
69
- assert_equal 1234000.1, convert_number('1,234,000.100')
69
+ assert_equal 1_234_000.1, convert_number('1,234,000.100')
70
70
  end
71
71
 
72
72
  def test_english_format_with_decimal_separator_using_spanish_language
@@ -97,7 +97,7 @@ class ConvertNumbersFormatTest < MiniTest::Test
97
97
  assert_equal 1000, convert_number('1.000')
98
98
  assert_equal 1000, convert_number('+1.000')
99
99
  assert_equal -1000, convert_number('-1.000')
100
- assert_equal 1000000, convert_number('1.000.000')
100
+ assert_equal 1_000_000, convert_number('1.000.000')
101
101
  end
102
102
 
103
103
  def test_spanish_format_with_separator_and_decimal_using_spanish_language
@@ -106,7 +106,7 @@ class ConvertNumbersFormatTest < MiniTest::Test
106
106
  assert_equal 1230.1, convert_number('1.230,100')
107
107
  assert_equal 1234.345, convert_number('+1.234,345')
108
108
  assert_equal -1234.345, convert_number('-1.234,345')
109
- assert_equal 1234000.1, convert_number('1.234.000,100')
109
+ assert_equal 1_234_000.1, convert_number('1.234.000,100')
110
110
  end
111
111
 
112
112
  def test_english_currency_format_with_decimal_separator_using_russian_language
@@ -139,10 +139,11 @@ class ConvertNumbersFormatTest < MiniTest::Test
139
139
  end
140
140
 
141
141
  private
142
+
142
143
  def convert_number(value, format = nil)
143
144
  record = NumberModel.new
144
145
  @config.columns[:number].options[:format] = format unless format.nil?
145
- update_record_from_params(record, @config.create.columns, HashWithIndifferentAccess.new({:number => value}))
146
+ update_record_from_params(record, @config.create.columns, HashWithIndifferentAccess.new(:number => value))
146
147
  record.number
147
148
  end
148
149
  end
@@ -3,16 +3,23 @@ require 'test_helper'
3
3
  class ClassWithFinder
4
4
  include ActiveScaffold::Finder
5
5
  def conditions_for_collection; end
6
+
6
7
  def conditions_from_params; end
8
+
7
9
  def conditions_from_constraints; end
10
+
8
11
  def joins_for_collection; end
12
+
9
13
  def custom_finder_options
10
14
  {}
11
15
  end
16
+
12
17
  def beginning_of_chain
13
18
  active_scaffold_config.model
14
19
  end
20
+
15
21
  def conditional_get_support?; end
22
+
16
23
  def params; {}; end
17
24
  end
18
25
 
@@ -28,14 +35,11 @@ class FinderTest < MiniTest::Test
28
35
  ActiveScaffold::DataStructures::Column.new(:a, ModelStub),
29
36
  ActiveScaffold::DataStructures::Column.new(:b, ModelStub)
30
37
  ]
31
- tokens = [
32
- 'foo',
33
- 'bar'
34
- ]
38
+ tokens = %w(foo bar)
35
39
 
36
40
  expected_conditions = [
37
- ['"model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?', '%foo%', '%foo%'],
38
- ['"model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?', '%bar%', '%bar%']
41
+ ['"model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?', '%foo%', '%foo%'],
42
+ ['"model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?', '%bar%', '%bar%']
39
43
  ]
40
44
  assert_equal expected_conditions, ClassWithFinder.create_conditions_for_columns(tokens, columns)
41
45
 
@@ -50,9 +54,9 @@ class FinderTest < MiniTest::Test
50
54
 
51
55
  def test_method_sorting
52
56
  column = ActiveScaffold::DataStructures::Column.new('a', ModelStub)
53
- column.sort_by :method => proc{self}
57
+ column.sort_by :method => proc { self }
54
58
 
55
- collection = [16000, 2853, 98765, 6188, 4]
59
+ collection = [16_000, 2853, 98_765, 6188, 4]
56
60
  assert_equal collection.sort, @klass.send(:sort_collection_by_column, collection, column, 'asc')
57
61
  assert_equal collection.sort.reverse, @klass.send(:sort_collection_by_column, collection, column, 'desc')
58
62
 
@@ -66,13 +70,13 @@ class FinderTest < MiniTest::Test
66
70
  end
67
71
 
68
72
  def test_count_with_group
69
- @klass.expects(:custom_finder_options).returns({:group => :a})
70
- relation_class.any_instance.expects(:count).returns({'foo' => 5, 'bar' => 4})
73
+ @klass.expects(:custom_finder_options).returns(:group => :a)
74
+ relation_class.any_instance.expects(:count).returns('foo' => 5, 'bar' => 4)
71
75
  relation_class.any_instance.expects(:limit).with(20).returns(ModelStub.where(nil))
72
76
  relation_class.any_instance.expects(:offset).with(0).returns(ModelStub.where(nil))
73
77
  page = @klass.send :find_page, :per_page => 20, :pagination => true
74
78
  page.items
75
-
79
+
76
80
  assert_kind_of Integer, page.pager.count
77
81
  assert_equal 2, page.pager.count
78
82
  assert_equal 1, page.pager.number_of_pages
@@ -89,7 +93,7 @@ class FinderTest < MiniTest::Test
89
93
 
90
94
  def test_infinite_pagination
91
95
  ModelStub.expects(:count).never
92
- page = @klass.send :find_page, :pagination => :infinite
96
+ @klass.send :find_page, :pagination => :infinite
93
97
  end
94
98
 
95
99
  def test_condition_for_column
@@ -98,6 +102,7 @@ class FinderTest < MiniTest::Test
98
102
  end
99
103
 
100
104
  private
105
+
101
106
  def relation_class
102
107
  @klass.active_scaffold_config.model.send(:relation).class
103
108
  end
@@ -1,11 +1,10 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class LocalizationTest < MiniTest::Test
4
-
5
4
  def test_localization
6
- assert_equal "Dutch", as_(:dutch)
7
- assert_equal "dutch", as_('dutch')
5
+ assert_equal 'Dutch', as_(:dutch)
6
+ assert_equal 'dutch', as_('dutch')
8
7
  I18n.backend.store_translations :en, :active_scaffold => {:create_model => 'Create %{model}'}
9
- assert_equal "Create Test", as_(:create_model, :model => 'Test')
8
+ assert_equal 'Create Test', as_(:create_model, :model => 'Test')
10
9
  end
11
10
  end