active_scaffold 3.4.43 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (216) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +39 -0
  3. data/{LICENSE → LICENSE.md} +1 -1
  4. data/README.md +27 -19
  5. data/app/assets/javascripts/active_scaffold.js.erb +1 -1
  6. data/app/assets/javascripts/jquery/active_scaffold.js +95 -43
  7. data/app/assets/javascripts/jquery/tiny_mce_bridge.js +30 -6
  8. data/app/assets/javascripts/prototype/tiny_mce_bridge.js +11 -1
  9. data/app/assets/stylesheets/active_scaffold_colors.scss +2 -2
  10. data/app/assets/stylesheets/active_scaffold_layout.css +36 -28
  11. data/app/views/active_scaffold_overrides/_base_form.html.erb +2 -3
  12. data/app/views/active_scaffold_overrides/_field_search.html.erb +8 -7
  13. data/app/views/active_scaffold_overrides/_form_association.html.erb +9 -9
  14. data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +6 -6
  15. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +52 -50
  16. data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +1 -1
  17. data/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb +1 -1
  18. data/app/views/active_scaffold_overrides/_human_conditions.html.erb +3 -1
  19. data/app/views/active_scaffold_overrides/_list_calculations.html.erb +1 -1
  20. data/app/views/active_scaffold_overrides/_list_column_headings.html.erb +2 -0
  21. data/app/views/active_scaffold_overrides/_list_messages.html.erb +5 -3
  22. data/app/views/active_scaffold_overrides/_list_record.html.erb +3 -1
  23. data/app/views/active_scaffold_overrides/_list_with_header.html.erb +9 -9
  24. data/app/views/active_scaffold_overrides/_messages.html.erb +1 -1
  25. data/app/views/active_scaffold_overrides/_refresh_list.js.erb +18 -10
  26. data/app/views/active_scaffold_overrides/_render_field.js.erb +3 -3
  27. data/app/views/active_scaffold_overrides/_search.html.erb +7 -6
  28. data/app/views/active_scaffold_overrides/_show_actions.html.erb +14 -0
  29. data/app/views/active_scaffold_overrides/_show_association.html.erb +1 -1
  30. data/app/views/active_scaffold_overrides/_update_actions.html.erb +6 -2
  31. data/app/views/active_scaffold_overrides/_update_column.js.erb +1 -1
  32. data/app/views/active_scaffold_overrides/_update_form.html.erb +1 -1
  33. data/app/views/active_scaffold_overrides/destroy.js.erb +2 -3
  34. data/app/views/active_scaffold_overrides/edit_associated.js.erb +4 -3
  35. data/app/views/active_scaffold_overrides/on_action_update.js.erb +5 -3
  36. data/app/views/active_scaffold_overrides/on_create.js.erb +4 -4
  37. data/app/views/active_scaffold_overrides/on_update.js.erb +6 -6
  38. data/app/views/active_scaffold_overrides/show.html.erb +6 -0
  39. data/app/views/active_scaffold_overrides/update.html.erb +1 -1
  40. data/app/views/active_scaffold_overrides/update_column.js.erb +1 -1
  41. data/config/brakeman.ignore +26 -0
  42. data/config/brakeman.yml +3 -0
  43. data/config/i18n-tasks.yml +121 -0
  44. data/config/locales/de.yml +81 -70
  45. data/config/locales/en.yml +83 -74
  46. data/config/locales/es.yml +82 -73
  47. data/config/locales/fr.yml +86 -75
  48. data/config/locales/hu.yml +81 -70
  49. data/config/locales/ja.yml +71 -60
  50. data/config/locales/ru.yml +85 -74
  51. data/lib/active_scaffold.rb +3 -0
  52. data/lib/active_scaffold/actions/common_search.rb +11 -7
  53. data/lib/active_scaffold/actions/core.rb +119 -47
  54. data/lib/active_scaffold/actions/create.rb +1 -1
  55. data/lib/active_scaffold/actions/delete.rb +11 -8
  56. data/lib/active_scaffold/actions/field_search.rb +104 -6
  57. data/lib/active_scaffold/actions/list.rb +25 -21
  58. data/lib/active_scaffold/actions/mark.rb +12 -4
  59. data/lib/active_scaffold/actions/nested.rb +26 -26
  60. data/lib/active_scaffold/actions/search.rb +2 -2
  61. data/lib/active_scaffold/actions/show.rb +4 -5
  62. data/lib/active_scaffold/actions/subform.rb +9 -7
  63. data/lib/active_scaffold/actions/update.rb +20 -13
  64. data/lib/active_scaffold/active_record_permissions.rb +24 -5
  65. data/lib/active_scaffold/attribute_params.rb +68 -49
  66. data/lib/active_scaffold/bridges.rb +1 -1
  67. data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +15 -19
  68. data/lib/active_scaffold/bridges/bitfields.rb +1 -1
  69. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +10 -14
  70. data/lib/active_scaffold/bridges/calendar_date_select.rb +0 -7
  71. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +19 -22
  72. data/lib/active_scaffold/bridges/cancan.rb +4 -3
  73. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +11 -21
  74. data/lib/active_scaffold/bridges/carrierwave.rb +2 -1
  75. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +2 -6
  76. data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +6 -39
  77. data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +1 -1
  78. data/lib/active_scaffold/bridges/chosen.rb +4 -1
  79. data/lib/active_scaffold/bridges/chosen/helpers.rb +3 -2
  80. data/lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb +2 -2
  81. data/lib/active_scaffold/bridges/date_picker.rb +3 -0
  82. data/lib/active_scaffold/bridges/date_picker/ext.rb +43 -38
  83. data/lib/active_scaffold/bridges/date_picker/helper.rb +24 -23
  84. data/lib/active_scaffold/bridges/dragonfly.rb +1 -1
  85. data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +3 -7
  86. data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +3 -25
  87. data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +2 -2
  88. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +6 -8
  89. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +1 -1
  90. data/lib/active_scaffold/bridges/file_column/form_ui.rb +0 -2
  91. data/lib/active_scaffold/bridges/file_column/list_ui.rb +2 -1
  92. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +1 -1
  93. data/lib/active_scaffold/bridges/paper_trail/actions.rb +1 -1
  94. data/lib/active_scaffold/bridges/paper_trail/helper.rb +1 -2
  95. data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +3 -7
  96. data/lib/active_scaffold/bridges/paperclip.rb +1 -1
  97. data/lib/active_scaffold/bridges/paperclip/form_ui.rb +3 -28
  98. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
  99. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +3 -7
  100. data/lib/active_scaffold/bridges/record_select.rb +2 -0
  101. data/lib/active_scaffold/bridges/record_select/helpers.rb +14 -18
  102. data/lib/active_scaffold/bridges/semantic_attributes/column.rb +4 -8
  103. data/lib/active_scaffold/bridges/shared/date_bridge.rb +20 -20
  104. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +7 -22
  105. data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +14 -14
  106. data/lib/active_scaffold/config/base.rb +9 -6
  107. data/lib/active_scaffold/config/core.rb +30 -21
  108. data/lib/active_scaffold/config/create.rb +2 -1
  109. data/lib/active_scaffold/config/delete.rb +2 -2
  110. data/lib/active_scaffold/config/field_search.rb +9 -3
  111. data/lib/active_scaffold/config/form.rb +4 -4
  112. data/lib/active_scaffold/config/list.rb +27 -23
  113. data/lib/active_scaffold/config/nested.rb +4 -4
  114. data/lib/active_scaffold/config/search.rb +6 -6
  115. data/lib/active_scaffold/config/show.rb +11 -1
  116. data/lib/active_scaffold/config/subform.rb +1 -1
  117. data/lib/active_scaffold/config/update.rb +4 -2
  118. data/lib/active_scaffold/constraints.rb +39 -36
  119. data/lib/active_scaffold/core.rb +36 -15
  120. data/lib/active_scaffold/data_structures/action_columns.rb +14 -9
  121. data/lib/active_scaffold/data_structures/action_link.rb +4 -5
  122. data/lib/active_scaffold/data_structures/action_links.rb +5 -4
  123. data/lib/active_scaffold/data_structures/actions.rb +2 -2
  124. data/lib/active_scaffold/data_structures/association.rb +8 -0
  125. data/lib/active_scaffold/data_structures/association/abstract.rb +147 -0
  126. data/lib/active_scaffold/data_structures/association/active_mongoid.rb +42 -0
  127. data/lib/active_scaffold/data_structures/association/active_record.rb +94 -0
  128. data/lib/active_scaffold/data_structures/association/mongoid.rb +45 -0
  129. data/lib/active_scaffold/data_structures/bridge.rb +3 -6
  130. data/lib/active_scaffold/data_structures/column.rb +100 -82
  131. data/lib/active_scaffold/data_structures/columns.rb +21 -3
  132. data/lib/active_scaffold/data_structures/nested_info.rb +22 -37
  133. data/lib/active_scaffold/data_structures/set.rb +4 -4
  134. data/lib/active_scaffold/data_structures/sorting.rb +29 -15
  135. data/lib/active_scaffold/engine.rb +3 -1
  136. data/lib/active_scaffold/extensions/action_controller_rendering.rb +10 -5
  137. data/lib/active_scaffold/extensions/action_view_rendering.rb +65 -59
  138. data/lib/active_scaffold/extensions/left_outer_joins.rb +48 -53
  139. data/lib/active_scaffold/extensions/localize.rb +3 -4
  140. data/lib/active_scaffold/extensions/name_option_for_datetime.rb +7 -11
  141. data/lib/active_scaffold/extensions/paginator_extensions.rb +20 -18
  142. data/lib/active_scaffold/extensions/routing_mapper.rb +104 -40
  143. data/lib/active_scaffold/extensions/to_label.rb +1 -1
  144. data/lib/active_scaffold/extensions/unsaved_associated.rb +4 -13
  145. data/lib/active_scaffold/extensions/unsaved_record.rb +12 -1
  146. data/lib/active_scaffold/finder.rb +200 -134
  147. data/lib/active_scaffold/helpers/action_link_helpers.rb +398 -0
  148. data/lib/active_scaffold/helpers/association_helpers.rb +12 -30
  149. data/lib/active_scaffold/helpers/controller_helpers.rb +74 -24
  150. data/lib/active_scaffold/helpers/form_column_helpers.rb +205 -112
  151. data/lib/active_scaffold/helpers/human_condition_helpers.rb +21 -11
  152. data/lib/active_scaffold/helpers/id_helpers.rb +1 -1
  153. data/lib/active_scaffold/helpers/list_column_helpers.rb +117 -39
  154. data/lib/active_scaffold/helpers/pagination_helpers.rb +11 -14
  155. data/lib/active_scaffold/helpers/search_column_helpers.rb +69 -32
  156. data/lib/active_scaffold/helpers/show_column_helpers.rb +9 -3
  157. data/lib/active_scaffold/helpers/view_helpers.rb +41 -426
  158. data/lib/active_scaffold/orm_checks.rb +109 -0
  159. data/lib/active_scaffold/paginator.rb +1 -1
  160. data/lib/active_scaffold/responds_to_parent.rb +12 -10
  161. data/lib/active_scaffold/tableless.rb +81 -43
  162. data/lib/active_scaffold/version.rb +2 -2
  163. data/lib/generators/active_scaffold/controller_generator.rb +49 -0
  164. data/lib/generators/active_scaffold/install_generator.rb +45 -0
  165. data/lib/generators/active_scaffold/resource_generator.rb +56 -0
  166. data/lib/generators/{active_scaffold_controller/templates → templates}/controller.rb +0 -0
  167. data/lib/generators/{active_scaffold_controller/templates → templates}/helper.rb +0 -0
  168. data/shoulda_macros/macros.rb +3 -3
  169. data/test/active_scaffold_config_mock.rb +33 -0
  170. data/test/bridges/bridge_test.rb +9 -9
  171. data/test/bridges/date_picker_test.rb +3 -1
  172. data/test/bridges/paper_trail_test.rb +2 -3
  173. data/test/bridges/paperclip_test.rb +21 -10
  174. data/test/bridges/tiny_mce_test.rb +20 -21
  175. data/test/class_with_finder.rb +42 -0
  176. data/test/company.rb +6 -4
  177. data/test/config/core_test.rb +1 -1
  178. data/test/config/create_test.rb +1 -1
  179. data/test/config/list_test.rb +3 -3
  180. data/test/config/update_test.rb +3 -3
  181. data/test/data_structures/action_columns_test.rb +3 -3
  182. data/test/data_structures/association_column_test.rb +5 -5
  183. data/test/data_structures/column_test.rb +14 -14
  184. data/test/data_structures/columns_test.rb +2 -2
  185. data/test/data_structures/set_test.rb +2 -2
  186. data/test/data_structures/sorting_test.rb +6 -4
  187. data/test/extensions/active_record_test.rb +1 -1
  188. data/test/extensions/routing_mapper_test.rb +64 -13
  189. data/test/helpers/form_column_helpers_test.rb +6 -6
  190. data/test/helpers/list_column_helpers_test.rb +9 -5
  191. data/test/helpers/pagination_helpers_test.rb +1 -0
  192. data/test/misc/active_record_permissions_test.rb +18 -1
  193. data/test/misc/attribute_params_test.rb +26 -17
  194. data/test/misc/calculation_test.rb +8 -31
  195. data/test/misc/configurable_test.rb +3 -2
  196. data/test/misc/constraints_test.rb +33 -22
  197. data/test/misc/convert_numbers_format_test.rb +28 -10
  198. data/test/misc/finder_test.rb +6 -29
  199. data/test/misc/parse_datetime_test.rb +160 -0
  200. data/test/misc/render_test.rb +1 -1
  201. data/test/misc/tableless_test.rb +24 -0
  202. data/test/mock_app/app/models/building.rb +2 -1
  203. data/test/mock_app/config.ru +1 -1
  204. data/test/mock_app/config/environments/test.rb +1 -1
  205. data/test/mock_app/config/routes.rb +11 -3
  206. data/test/model_stub.rb +11 -6
  207. data/test/run_all.rb +1 -1
  208. data/test/test_helper.rb +19 -4
  209. metadata +42 -23
  210. data/lib/active_scaffold/data_structures/error_message.rb +0 -22
  211. data/lib/active_scaffold/extensions/reverse_associations.rb +0 -119
  212. data/lib/generators/active_scaffold/USAGE +0 -29
  213. data/lib/generators/active_scaffold/active_scaffold_generator.rb +0 -21
  214. data/lib/generators/active_scaffold_controller/USAGE +0 -19
  215. data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +0 -29
  216. data/test/data_structures/error_message_test.rb +0 -25
@@ -23,7 +23,7 @@ class AssociationColumnTest < MiniTest::Test
23
23
  end
24
24
 
25
25
  def test_association
26
- assert @association_column.association.is_a?(ActiveRecord::Reflection::AssociationReflection)
26
+ assert @association_column.association.is_a?(ActiveScaffold::DataStructures::Association::Abstract)
27
27
  end
28
28
 
29
29
  def test_includes
@@ -31,11 +31,11 @@ class AssociationColumnTest < MiniTest::Test
31
31
  end
32
32
 
33
33
  def test_plurality
34
- assert @association_column.singular_association?
35
- refute @association_column.plural_association?
34
+ assert @association_column.association.singular?
35
+ refute @association_column.association.collection?
36
36
 
37
37
  plural_association_column = ActiveScaffold::DataStructures::Column.new('other_models', ModelStub)
38
- assert plural_association_column.plural_association?
39
- refute plural_association_column.singular_association?
38
+ assert plural_association_column.association.collection?
39
+ refute plural_association_column.association.singular?
40
40
  end
41
41
  end
@@ -5,12 +5,12 @@ class ColumnTest < MiniTest::Test
5
5
  @column = ActiveScaffold::DataStructures::Column.new(:a, ModelStub)
6
6
  @association_col = ActiveScaffold::DataStructures::Column.new(:b, ModelStub)
7
7
  @association_col.stubs(:polymorphic_association?).returns(false)
8
- @association_col.instance_variable_set(:@association, true)
8
+ @association_col.stubs(association: stub(polymorphic?: false))
9
9
  end
10
10
 
11
11
  def test_column
12
12
  assert @column.column.is_a?(ActiveRecord::ConnectionAdapters::Column)
13
- assert @column.column.name == 'a'
13
+ assert_equal @column.column.name, 'a'
14
14
  end
15
15
 
16
16
  def test_basic_properties
@@ -54,33 +54,33 @@ class ColumnTest < MiniTest::Test
54
54
  def test_equality
55
55
  # create a separate columns object, and make sure it's not ==
56
56
  columns = ActiveScaffold::DataStructures::Columns.new(ModelStub, :a, :b)
57
- assert columns != @column
57
+ refute_equal columns, @column
58
58
 
59
59
  # create a separate action_columns object, and make sure it's not ==
60
60
  columns = ActiveScaffold::DataStructures::ActionColumns.new(:a, :b)
61
- assert columns != @column
61
+ refute_equal columns, @column
62
62
 
63
63
  # identity
64
- assert @column == @column # rubocop:disable Lint/UselessComparison
64
+ assert_equal @column, @column
65
65
 
66
66
  # string comparison
67
- assert @column == 'a'
68
- assert @column != 'fake'
67
+ assert_equal @column, 'a'
68
+ refute_equal @column, 'fake'
69
69
 
70
70
  # symbol comparison
71
- assert @column == :a
72
- assert @column != :fake
71
+ assert_equal @column, :a
72
+ refute_equal @column, :fake
73
73
 
74
74
  # comparison with different object of same type
75
75
  column2 = ActiveScaffold::DataStructures::Column.new(:fake, ModelStub)
76
- assert @column != column2
76
+ refute_equal @column, column2
77
77
  column2.name = 'a'
78
- assert @column == column2
78
+ assert_equal @column, column2
79
79
 
80
80
  # special comparisons
81
81
  refute @column.nil?
82
- assert @column != ''
83
- assert @column != 0
82
+ refute_equal @column, ''
83
+ refute_equal @column, 0
84
84
  end
85
85
 
86
86
  def test_ui
@@ -172,7 +172,7 @@ class ColumnTest < MiniTest::Test
172
172
  end
173
173
 
174
174
  def test_includes
175
- assert_equal nil, @column.includes
175
+ assert_nil @column.includes
176
176
 
177
177
  # make sure that when a non-array comes in, an array comes out
178
178
  @column.includes = :column_name
@@ -25,7 +25,7 @@ class ColumnsTest < MiniTest::Test
25
25
 
26
26
  # try adding an array of columns
27
27
  refute @columns.include?(:f)
28
- @columns.add [:f, :g]
28
+ @columns.add %i[f g]
29
29
  assert @columns.include?(:f)
30
30
  assert @columns.include?(:g)
31
31
  end
@@ -47,7 +47,7 @@ class ColumnsTest < MiniTest::Test
47
47
 
48
48
  def test_each
49
49
  @columns.each do |column|
50
- assert [:a, :b].include?(column.name)
50
+ assert %i[a b].include?(column.name)
51
51
  end
52
52
  end
53
53
 
@@ -26,7 +26,7 @@ class SetTest < MiniTest::Test
26
26
  def test_exclude_array
27
27
  # exclude with a symbol
28
28
  assert @items.include?(:b)
29
- @items.exclude [:a, :b]
29
+ @items.exclude %i[a b]
30
30
  refute @items.include?(:b)
31
31
  refute @items.include?(:a)
32
32
  end
@@ -55,7 +55,7 @@ class SetTest < MiniTest::Test
55
55
 
56
56
  # try adding an array of columns
57
57
  refute @items.include?(:f)
58
- @items.add [:f, :g]
58
+ @items.add %i[f g]
59
59
  assert @items.include?(:f)
60
60
  assert @items.include?(:g)
61
61
  end
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class SortingTest < MiniTest::Test
4
4
  def setup
5
5
  @columns = ActiveScaffold::DataStructures::Columns.new(ModelStub, :a, :b, :c, :d, :id)
6
- @sorting = ActiveScaffold::DataStructures::Sorting.new(@columns)
6
+ @sorting = ActiveScaffold::DataStructures::Sorting.new(@columns, ModelStub)
7
7
  end
8
8
 
9
9
  def test_add
@@ -25,7 +25,7 @@ class SortingTest < MiniTest::Test
25
25
  # test adding a lowercase string direction
26
26
  assert_equal 'DESC', @sorting.direction_of(:c)
27
27
 
28
- @sorting << [:d, :desc]
28
+ @sorting << %i[d desc]
29
29
  # testing adding with the alias
30
30
  assert @sorting.sorts_on?(:d)
31
31
  assert_equal 'DESC', @sorting.direction_of(:d)
@@ -119,7 +119,8 @@ class SortingTest < MiniTest::Test
119
119
  def test_set_default_sorting_with_simple_default_scope
120
120
  model_stub_with_default_scope = ModelStub.clone
121
121
  model_stub_with_default_scope.class_eval { default_scope -> { order('a') } }
122
- @sorting.set_default_sorting model_stub_with_default_scope
122
+ @sorting = ActiveScaffold::DataStructures::Sorting.new(@columns, model_stub_with_default_scope)
123
+ @sorting.set_default_sorting
123
124
 
124
125
  assert @sorting.sorts_on?(:a)
125
126
  assert_equal 'ASC', @sorting.direction_of(:a)
@@ -129,7 +130,8 @@ class SortingTest < MiniTest::Test
129
130
  def test_set_default_sorting_with_complex_default_scope
130
131
  model_stub_with_default_scope = ModelStub.clone
131
132
  model_stub_with_default_scope.class_eval { default_scope -> { order('a DESC, players.last_name ASC') } }
132
- @sorting.set_default_sorting model_stub_with_default_scope
133
+ @sorting = ActiveScaffold::DataStructures::Sorting.new(@columns, model_stub_with_default_scope)
134
+ @sorting.set_default_sorting
133
135
 
134
136
  assert @sorting.sorts_on?(:a)
135
137
  assert_equal 'DESC', @sorting.direction_of(:a)
@@ -7,7 +7,7 @@ class ActiveRecordTest < MiniTest::Test
7
7
 
8
8
  def test_to_label
9
9
  # without anything defined, it'll use the to_s method (e.g. #<ModelStub:0xb7379300>)
10
- assert_match /^#<[a-z]+:0x[0-9a-f]+>$/i, @record.to_label
10
+ assert_match(/^#<[a-z]+:0x[0-9a-f]+>$/i, @record.to_label)
11
11
 
12
12
  class << @record
13
13
  def to_s
@@ -2,21 +2,72 @@ require 'test_helper'
2
2
 
3
3
  class RoutingMapperTest < ActionController::TestCase
4
4
  test 'rails routes' do
5
- assert_routing 'addresses', :controller => 'addresses', :action => 'index'
6
- assert_routing 'addresses/1', :controller => 'addresses', :action => 'show', :id => '1'
7
- assert_routing 'addresses/1/list', :controller => 'addresses', :action => 'index', :id => '1'
8
- assert_routing 'addresses/1/edit', :controller => 'addresses', :action => 'edit', :id => '1'
9
- assert_routing({:method => :put, :path => 'addresses/1'}, {:controller => 'addresses', :action => 'update', :id => '1'})
10
- assert_routing({:method => :delete, :path => 'addresses/1'}, {:controller => 'addresses', :action => 'destroy', :id => '1'})
11
- assert_routing({:method => :post, :path => 'addresses'}, {:controller => 'addresses', :action => 'create'})
5
+ assert_routing 'addresses', controller: 'addresses', action: 'index'
6
+ assert_routing 'addresses/1', controller: 'addresses', action: 'show', id: '1'
7
+ assert_routing 'addresses/1/list', controller: 'addresses', action: 'index', id: '1'
8
+ assert_routing 'addresses/1/edit', controller: 'addresses', action: 'edit', id: '1'
9
+ assert_routing({method: :patch, path: 'addresses/1'}, {controller: 'addresses', action: 'update', id: '1'})
10
+ assert_routing({method: :delete, path: 'addresses/1'}, {controller: 'addresses', action: 'destroy', id: '1'})
11
+ assert_routing({method: :post, path: 'addresses'}, {controller: 'addresses', action: 'create'})
12
12
  end
13
13
 
14
14
  test 'active scaffold routes' do
15
- assert_routing 'addresses/show_search', :controller => 'addresses', :action => 'show_search'
16
- assert_routing({:method => 'post', :path => 'addresses/render_field'}, {:controller => 'addresses', :action => 'render_field'})
17
- assert_routing({:method => 'post', :path => 'addresses/2/render_field'}, {:controller => 'addresses', :action => 'render_field', :id => '2'})
18
- assert_routing 'addresses/2/render_field', :controller => 'addresses', :action => 'render_field', :id => '2'
19
- assert_routing 'addresses/edit_associated', :controller => 'addresses', :action => 'edit_associated'
20
- assert_routing 'addresses/2/edit_associated', :controller => 'addresses', :action => 'edit_associated', :id => '2'
15
+ assert_routing 'addresses/show_search', controller: 'addresses', action: 'show_search'
16
+ assert_routing({method: 'post', path: 'addresses/mark'}, {controller: 'addresses', action: 'mark'})
17
+ assert_routing({method: 'post', path: 'addresses/2/mark'}, {controller: 'addresses', action: 'mark', id: '2'})
18
+ assert_routing({method: 'post', path: 'addresses/render_field'}, {controller: 'addresses', action: 'render_field'})
19
+ assert_routing({method: 'post', path: 'addresses/2/render_field'}, {controller: 'addresses', action: 'render_field', id: '2'})
20
+ assert_routing({method: 'post', path: 'addresses/2/update_column'}, {controller: 'addresses', action: 'update_column', id: '2'})
21
+ assert_routing 'addresses/2/render_field', controller: 'addresses', action: 'render_field', id: '2'
22
+ assert_routing 'addresses/edit_associated', controller: 'addresses', action: 'edit_associated'
23
+ assert_routing 'addresses/2/edit_associated', controller: 'addresses', action: 'edit_associated', id: '2'
24
+ assert_routing 'addresses/new_existing', controller: 'addresses', action: 'new_existing'
25
+ assert_routing({method: 'post', path: 'addresses/add_existing'}, {controller: 'addresses', action: 'add_existing'})
26
+ assert_routing({method: 'delete', path: 'addresses/2/destroy_existing'}, {controller: 'addresses', action: 'destroy_existing', id: '2'})
27
+ end
28
+
29
+ test 'rails routes with except' do
30
+ assert_routing 'buildings/1', controller: 'buildings', action: 'show', id: '1'
31
+ assert_routing 'buildings/1/edit', controller: 'buildings', action: 'edit', id: '1'
32
+ assert_routing({method: :patch, path: 'buildings/1'}, {controller: 'buildings', action: 'update', id: '1'})
33
+ assert_routing({method: :delete, path: 'buildings/1'}, {controller: 'buildings', action: 'destroy', id: '1'})
34
+ assert_routing({method: :post, path: 'buildings'}, {controller: 'buildings', action: 'create'})
35
+
36
+ assert_raises(ActionController::RoutingError) { @routes.recognize_path '/buildings' }
37
+ assert_raises(ActionController::RoutingError) { @routes.recognize_path '/buildings/1/list' }
38
+ end
39
+
40
+ test 'active scaffold routes with except' do
41
+ assert_routing 'buildings/show_search', controller: 'buildings', action: 'show_search'
42
+ assert_routing({method: 'post', path: 'buildings/render_field'}, {controller: 'buildings', action: 'render_field'})
43
+ assert_routing({method: 'post', path: 'buildings/2/render_field'}, {controller: 'buildings', action: 'render_field', id: '2'})
44
+ assert_routing({method: 'post', path: 'buildings/2/update_column'}, {controller: 'buildings', action: 'update_column', id: '2'})
45
+ assert_routing 'buildings/2/render_field', controller: 'buildings', action: 'render_field', id: '2'
46
+ assert_routing 'buildings/edit_associated', controller: 'buildings', action: 'edit_associated'
47
+ assert_routing 'buildings/2/edit_associated', controller: 'buildings', action: 'edit_associated', id: '2'
48
+
49
+ assert_raises(ActionController::RoutingError) { @routes.recognize_path '/buildings/2/mark', method: :post }
50
+ assert_raises(ActionController::RoutingError) { @routes.recognize_path '/buildings/2/destroy_existing', method: :delete }
51
+ end
52
+
53
+ test 'rails routes with only' do
54
+ assert_routing 'cars/1/edit', controller: 'cars', action: 'edit', id: '1'
55
+ assert_routing({method: :patch, path: 'cars/1'}, {controller: 'cars', action: 'update', id: '1'})
56
+
57
+ assert_raises(ActionController::RoutingError) { @routes.recognize_path '/cars' }
58
+ assert_raises(ActionController::RoutingError) { @routes.recognize_path '/cars/1/list' }
59
+ assert_raises(ActionController::RoutingError) { @routes.recognize_path '/cars/1/destroy', method: :delete }
60
+ end
61
+
62
+ test 'active scaffold routes with only' do
63
+ assert_routing 'cars/show_search', controller: 'cars', action: 'show_search'
64
+ assert_routing({method: 'post', path: 'cars/render_field'}, {controller: 'cars', action: 'render_field'})
65
+ assert_routing({method: 'post', path: 'cars/2/render_field'}, {controller: 'cars', action: 'render_field', id: '2'})
66
+ assert_routing({method: 'post', path: 'cars/2/update_column'}, {controller: 'cars', action: 'update_column', id: '2'})
67
+ assert_routing 'cars/2/render_field', controller: 'cars', action: 'render_field', id: '2'
68
+
69
+ assert_raises(ActionController::RoutingError) { @routes.recognize_path '/cars/2/edit_associated' }
70
+ assert_raises(ActionController::RoutingError) { @routes.recognize_path '/cars/2/mark', method: :post }
71
+ assert_raises(ActionController::RoutingError) { @routes.recognize_path '/cars/2/destroy_existing', method: :delete }
21
72
  end
22
73
  end
@@ -9,22 +9,22 @@ class FormColumnHelpersTest < ActionView::TestCase
9
9
  end
10
10
 
11
11
  def test_choices_for_select_form_ui_for_simple_column
12
- @column.options[:options] = [:value_1, :value_2, :value_3]
12
+ @column.options[:options] = %i[value_1 value_2 value_3]
13
13
  assert_dom_equal "<select name=\"record[a]\" id=\"record_a\"><option value=\"value_1\">Value 1</option>\n<option value=\"value_2\">Value 2</option>\n<option value=\"value_3\">Value 3</option></select>", active_scaffold_input_select(@column, :object => @record)
14
14
 
15
- @column.options[:options] = %w(value_1 value_2 value_3)
15
+ @column.options[:options] = %w[value_1 value_2 value_3]
16
16
  assert_dom_equal "<select name=\"record[a]\" id=\"record_a\"><option value=\"value_1\">value_1</option>\n<option value=\"value_2\">value_2</option>\n<option value=\"value_3\">value_3</option></select>", active_scaffold_input_select(@column, :object => @record)
17
17
 
18
- @column.options[:options] = [%w(text_1 value_1), %w(text_2 value_2), %w(text_3 value_3)]
18
+ @column.options[:options] = [%w[text_1 value_1], %w[text_2 value_2], %w[text_3 value_3]]
19
19
  assert_dom_equal "<select name=\"record[a]\" id=\"record_a\"><option value=\"value_1\">text_1</option>\n<option value=\"value_2\">text_2</option>\n<option value=\"value_3\">text_3</option></select>", active_scaffold_input_select(@column, :object => @record)
20
20
 
21
- @column.options[:options] = [[:text_1, :value_1], [:text_2, :value_2], [:text_3, :value_3]]
21
+ @column.options[:options] = [%i[text_1 value_1], %i[text_2 value_2], %i[text_3 value_3]]
22
22
  assert_dom_equal "<select name=\"record[a]\" id=\"record_a\"><option value=\"value_1\">Text 1</option>\n<option value=\"value_2\">Text 2</option>\n<option value=\"value_3\">Text 3</option></select>", active_scaffold_input_select(@column, :object => @record)
23
23
  end
24
24
 
25
25
  def test_options_for_select_form_ui_for_simple_column
26
- @column.options = {:include_blank => 'None', :selected => 'value_2', :disabled => %w(value_1 value_3)}
27
- @column.options[:options] = %w(value_1 value_2 value_3)
26
+ @column.options = {:include_blank => 'None', :selected => 'value_2', :disabled => %w[value_1 value_3]}
27
+ @column.options[:options] = %w[value_1 value_2 value_3]
28
28
  @column.options[:html_options] = {:class => 'big'}
29
29
  assert_dom_equal "<select name=\"record[a]\" class=\"big\" id=\"record_a\"><option value=\"\">None</option>\n<option disabled=\"disabled\" value=\"value_1\">value_1</option>\n<option selected=\"selected\" value=\"value_2\">value_2</option>\n<option disabled=\"disabled\" value=\"value_3\">value_3</option></select>", active_scaffold_input_select(@column, :object => @record)
30
30
  end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  require 'test_helper'
3
2
 
4
3
  class ListColumnHelpersTest < ActionView::TestCase
@@ -16,21 +15,22 @@ class ListColumnHelpersTest < ActionView::TestCase
16
15
  end
17
16
 
18
17
  def test_options_for_select_list_ui_for_simple_column
19
- @column.options[:options] = [:value_1, :value_2, :value_3]
18
+ @column.options[:options] = %i[value_1 value_2 value_3]
20
19
  assert_equal 'Value 2', format_column_value(@record, @column)
21
20
 
22
- @column.options[:options] = %w(value_1 value_2 value_3)
21
+ @column.options[:options] = %w[value_1 value_2 value_3]
23
22
  assert_equal 'value_2', format_column_value(@record, @column)
24
23
 
25
- @column.options[:options] = [%w(text_1 value_1), %w(text_2 value_2), %w(text_3 value_3)]
24
+ @column.options[:options] = [%w[text_1 value_1], %w[text_2 value_2], %w[text_3 value_3]]
26
25
  assert_equal 'text_2', format_column_value(@record, @column)
27
26
 
28
- @column.options[:options] = [[:text_1, :value_1], [:text_2, :value_2], [:text_3, :value_3]]
27
+ @column.options[:options] = [%i[text_1 value_1], %i[text_2 value_2], %i[text_3 value_3]]
29
28
  assert_equal 'Text 2', format_column_value(@record, @column)
30
29
  end
31
30
 
32
31
  def test_association_join_text
33
32
  value = [1, 2, 3, 4].map(&:to_s)
33
+ value.stubs(loaded?: true)
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/>')
@@ -41,6 +41,10 @@ class ListColumnHelpersTest < ActionView::TestCase
41
41
 
42
42
  private
43
43
 
44
+ def grouped_search?
45
+ false
46
+ end
47
+
44
48
  def active_scaffold_config
45
49
  @config
46
50
  end
@@ -2,6 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class PaginationHelpersTest < MiniTest::Test
4
4
  include ActiveScaffold::Helpers::PaginationHelpers
5
+ include ActionView::Helpers::OutputSafetyHelper
5
6
 
6
7
  def active_scaffold_config
7
8
  @config ||= config_for('model_stub')
@@ -2,7 +2,18 @@ require 'test_helper'
2
2
 
3
3
  class PermissionModel < ActiveRecord::Base
4
4
  include ActiveScaffold::ActiveRecordPermissions::ModelUserAccess::Model
5
- def self.columns; @columns ||= [ColumnMock.new('id', '', 'int(11)')] + %w(a1 a2 a3 b1 b2 b3 c1 c2 c3).map { |c| ColumnMock.new(c, '', 'varchar(255)') }; end
5
+ def self.columns
6
+ @columns ||= [ColumnMock.new('id', '', 'int(11)')] +
7
+ %w[a1 a2 a3 b1 b2 b3 c1 c2 c3].map { |c| ColumnMock.new(c, '', 'varchar(255)') }
8
+ end
9
+
10
+ def self.columns_hash
11
+ @columns_hash ||= Hash[columns.map { |c| [c.name, c] }]
12
+ end
13
+
14
+ def self.schema_loaded?
15
+ true
16
+ end
6
17
 
7
18
  def authorized_for_read?; true; end
8
19
 
@@ -27,10 +38,12 @@ class PermissionModel < ActiveRecord::Base
27
38
  def a3_authorized_for_create?; true; end
28
39
 
29
40
  def b3_authorized_for_create?; false; end
41
+
30
42
  # def c3_authorized_for_create?; end
31
43
  def a2_authorized_for_create?; true; end
32
44
 
33
45
  def b2_authorized_for_create?; false; end
46
+
34
47
  # def c2_authorized_for_create?; end
35
48
  def a1_authorized_for_create?; true; end
36
49
 
@@ -40,10 +53,12 @@ class PermissionModel < ActiveRecord::Base
40
53
  def a3_authorized_for_read?; true; end
41
54
 
42
55
  def b3_authorized_for_read?; false; end
56
+
43
57
  # def c3_authorized_for_read?; end
44
58
  def a2_authorized_for_read?; true; end
45
59
 
46
60
  def b2_authorized_for_read?; false; end
61
+
47
62
  # def c2_authorized_for_read?; end
48
63
  def a1_authorized_for_read?; true; end
49
64
 
@@ -53,10 +68,12 @@ class PermissionModel < ActiveRecord::Base
53
68
  def a3_authorized_for_update?; true; end
54
69
 
55
70
  def b3_authorized_for_update?; false; end
71
+
56
72
  # def c3_authorized_for_update?; end
57
73
  def a2_authorized_for_update?; true; end
58
74
 
59
75
  def b2_authorized_for_update?; false; end
76
+
60
77
  # def c2_authorized_for_update?; end
61
78
  def a1_authorized_for_update?; true; end
62
79
 
@@ -34,13 +34,13 @@ class AttributeParamsTest < MiniTest::Test
34
34
  end
35
35
 
36
36
  def test_saving_multiparameter_attribute
37
- model = update_record_from_params(Contact.new, :update, :first_name, :birthday, :first_name => 'Christopher', :last_name => 'Columbus', 'birthday(1i)' => '1451', 'birthday(2i)' => '10', 'birthday(3i)' => '31')
38
- assert_equal 'Christopher', model.first_name
39
- assert_equal Date.new(1451, 10, 31), model.birthday
37
+ model = update_record_from_params(Contact.new, :update, :first_name, :birthday, :first_name => 'Diego', :last_name => 'Velazquez', 'birthday(1i)' => '1599', 'birthday(2i)' => '6', 'birthday(3i)' => '6')
38
+ assert_equal 'Diego', model.first_name
39
+ assert_equal Date.new(1599, 6, 6), model.birthday
40
40
  end
41
41
 
42
42
  def test_saving_has_many_select
43
- buildings = 2.times.map { Building.create }
43
+ buildings = Array.new(2) { Building.create }
44
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
@@ -160,45 +160,45 @@ class AttributeParamsTest < MiniTest::Test
160
160
  assert_equal 'Name', model.first_name
161
161
  assert model.home.present?
162
162
  assert model.floor.present?
163
- assert_equal [nil], building.floors(true).map(&:tenant_id), 'floor should not be saved yet'
163
+ assert_equal [nil], building.floors.reload.map(&:tenant_id), 'floor should not be saved yet'
164
164
  assert model.save
165
165
  assert_equal model.id, model.floor.tenant_id, 'tenant_id should be saved'
166
- assert_equal [nil, model.id], building.floors(true).map(&:tenant_id)
166
+ assert_equal [nil, model.id], building.floors.reload.map(&:tenant_id)
167
167
 
168
168
  model = update_record_from_params(model, :update, :first_name, :home, :first_name => 'First', :home => '') { raise ActiveRecord::Rollback }
169
169
  assert_equal 'First', model.first_name
170
- assert_equal [nil, model.id], building.floors(true).map(&:tenant_id), 'previous floor should not be deleted'
170
+ assert_equal [nil, model.id], building.floors.reload.map(&:tenant_id), 'previous floor should not be deleted'
171
171
  assert_nil model.home, 'home should be cleared'
172
172
 
173
173
  model.reload
174
174
  model = update_record_from_params(model, :update, :first_name, :home, :first_name => 'First', :home => '')
175
175
  assert_equal 'First', model.first_name
176
- assert_equal [nil], building.floors(true).map(&:tenant_id), 'previous floor should be deleted'
176
+ assert_equal [nil], building.floors.reload.map(&:tenant_id), 'previous floor should be deleted'
177
177
  assert_nil model.home, 'home should be cleared'
178
178
  assert model.save
179
179
  end
180
180
 
181
181
  def test_saving_has_many_through_select
182
- people = 2.times.map { Person.create }
182
+ people = Array.new(2) { Person.create }
183
183
  assert people.all?(&:persisted?)
184
184
 
185
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.respond_to?(:reload_floor) ? p.reload_floor : p.floor(true) }, 'floor should not be saved yet'
189
189
  assert model.save
190
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'
191
+ assert_equal [model.id] * 2, people.map { |p| (p.respond_to?(:reload_floor) ? p.reload_floor : 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.respond_to?(:reload_floor) ? p.reload_floor : 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.respond_to?(:reload_floor) ? p.reload_floor : 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
@@ -216,7 +216,7 @@ class AttributeParamsTest < MiniTest::Test
216
216
 
217
217
  def test_saving_has_many_crud_and_belongs_to_select
218
218
  floor = Floor.create
219
- people = 2.times.map { Person.create }
219
+ people = Array.new(2) { Person.create }
220
220
  key = Time.now.to_i.to_s
221
221
  floors = {'0' => '', floor.id.to_s => {:number => '1', :tenant => '', :id => floor.id.to_s}, key => {:number => '2', 'tenant' => people.first.id.to_s}, key.succ => {:number => '4', 'tenant' => people.last.id.to_s}, key.succ.succ => {:number => '', 'tenant' => ''}}
222
222
  model = update_record_from_params(Building.new, :create, :name, :floors, :name => 'First', :floors => floors)
@@ -358,7 +358,7 @@ class AttributeParamsTest < MiniTest::Test
358
358
  end
359
359
 
360
360
  def test_saving_has_many_polymorphic_select
361
- contacts = 2.times.map { Contact.create }
361
+ contacts = Array.new(2) { Contact.create }
362
362
 
363
363
  model = update_record_from_params(Person.new, :create, :first_name, :contacts, :first_name => 'Me', :contacts => ['', contacts.first.id.to_s])
364
364
  assert_equal 'Me', model.first_name
@@ -385,7 +385,7 @@ class AttributeParamsTest < MiniTest::Test
385
385
  end
386
386
 
387
387
  def test_saving_habtm_select
388
- roles = 2.times.map { Role.create }
388
+ roles = Array.new(2) { Role.create }
389
389
 
390
390
  model = update_record_from_params(Person.new, :create, :first_name, :roles, :first_name => 'Me', :roles => ['', roles.first.id.to_s])
391
391
  assert_equal 'Me', model.first_name
@@ -431,7 +431,8 @@ end
431
431
 
432
432
  class Controller
433
433
  def self.helper_method(*); end
434
- def self.before_filter(*); end
434
+
435
+ def self.before_action(*); end
435
436
 
436
437
  include ActiveScaffold::Core
437
438
  include ActiveScaffold::Helpers::ControllerHelpers
@@ -445,4 +446,12 @@ class Controller
445
446
  def flash
446
447
  @flash ||= ActionDispatch::Flash::FlashHash.new
447
448
  end
449
+
450
+ def params_hash?(v)
451
+ v.is_a? Hash
452
+ end
453
+
454
+ def params_hash(v)
455
+ v
456
+ end
448
457
  end