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.
- checksums.yaml +4 -4
- data/CHANGELOG +39 -0
- data/{LICENSE → LICENSE.md} +1 -1
- data/README.md +27 -19
- data/app/assets/javascripts/active_scaffold.js.erb +1 -1
- data/app/assets/javascripts/jquery/active_scaffold.js +95 -43
- data/app/assets/javascripts/jquery/tiny_mce_bridge.js +30 -6
- data/app/assets/javascripts/prototype/tiny_mce_bridge.js +11 -1
- data/app/assets/stylesheets/active_scaffold_colors.scss +2 -2
- data/app/assets/stylesheets/active_scaffold_layout.css +36 -28
- data/app/views/active_scaffold_overrides/_base_form.html.erb +2 -3
- data/app/views/active_scaffold_overrides/_field_search.html.erb +8 -7
- data/app/views/active_scaffold_overrides/_form_association.html.erb +9 -9
- data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +6 -6
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +52 -50
- data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_human_conditions.html.erb +3 -1
- data/app/views/active_scaffold_overrides/_list_calculations.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_list_column_headings.html.erb +2 -0
- data/app/views/active_scaffold_overrides/_list_messages.html.erb +5 -3
- data/app/views/active_scaffold_overrides/_list_record.html.erb +3 -1
- data/app/views/active_scaffold_overrides/_list_with_header.html.erb +9 -9
- data/app/views/active_scaffold_overrides/_messages.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_refresh_list.js.erb +18 -10
- data/app/views/active_scaffold_overrides/_render_field.js.erb +3 -3
- data/app/views/active_scaffold_overrides/_search.html.erb +7 -6
- data/app/views/active_scaffold_overrides/_show_actions.html.erb +14 -0
- data/app/views/active_scaffold_overrides/_show_association.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_update_actions.html.erb +6 -2
- data/app/views/active_scaffold_overrides/_update_column.js.erb +1 -1
- data/app/views/active_scaffold_overrides/_update_form.html.erb +1 -1
- data/app/views/active_scaffold_overrides/destroy.js.erb +2 -3
- data/app/views/active_scaffold_overrides/edit_associated.js.erb +4 -3
- data/app/views/active_scaffold_overrides/on_action_update.js.erb +5 -3
- data/app/views/active_scaffold_overrides/on_create.js.erb +4 -4
- data/app/views/active_scaffold_overrides/on_update.js.erb +6 -6
- data/app/views/active_scaffold_overrides/show.html.erb +6 -0
- data/app/views/active_scaffold_overrides/update.html.erb +1 -1
- data/app/views/active_scaffold_overrides/update_column.js.erb +1 -1
- data/config/brakeman.ignore +26 -0
- data/config/brakeman.yml +3 -0
- data/config/i18n-tasks.yml +121 -0
- data/config/locales/de.yml +81 -70
- data/config/locales/en.yml +83 -74
- data/config/locales/es.yml +82 -73
- data/config/locales/fr.yml +86 -75
- data/config/locales/hu.yml +81 -70
- data/config/locales/ja.yml +71 -60
- data/config/locales/ru.yml +85 -74
- data/lib/active_scaffold.rb +3 -0
- data/lib/active_scaffold/actions/common_search.rb +11 -7
- data/lib/active_scaffold/actions/core.rb +119 -47
- data/lib/active_scaffold/actions/create.rb +1 -1
- data/lib/active_scaffold/actions/delete.rb +11 -8
- data/lib/active_scaffold/actions/field_search.rb +104 -6
- data/lib/active_scaffold/actions/list.rb +25 -21
- data/lib/active_scaffold/actions/mark.rb +12 -4
- data/lib/active_scaffold/actions/nested.rb +26 -26
- data/lib/active_scaffold/actions/search.rb +2 -2
- data/lib/active_scaffold/actions/show.rb +4 -5
- data/lib/active_scaffold/actions/subform.rb +9 -7
- data/lib/active_scaffold/actions/update.rb +20 -13
- data/lib/active_scaffold/active_record_permissions.rb +24 -5
- data/lib/active_scaffold/attribute_params.rb +68 -49
- data/lib/active_scaffold/bridges.rb +1 -1
- data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +15 -19
- data/lib/active_scaffold/bridges/bitfields.rb +1 -1
- data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +10 -14
- data/lib/active_scaffold/bridges/calendar_date_select.rb +0 -7
- data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +19 -22
- data/lib/active_scaffold/bridges/cancan.rb +4 -3
- data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +11 -21
- data/lib/active_scaffold/bridges/carrierwave.rb +2 -1
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +2 -6
- data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +6 -39
- data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +1 -1
- data/lib/active_scaffold/bridges/chosen.rb +4 -1
- data/lib/active_scaffold/bridges/chosen/helpers.rb +3 -2
- data/lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb +2 -2
- data/lib/active_scaffold/bridges/date_picker.rb +3 -0
- data/lib/active_scaffold/bridges/date_picker/ext.rb +43 -38
- data/lib/active_scaffold/bridges/date_picker/helper.rb +24 -23
- data/lib/active_scaffold/bridges/dragonfly.rb +1 -1
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +3 -7
- data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +3 -25
- data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +2 -2
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +6 -8
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +1 -1
- data/lib/active_scaffold/bridges/file_column/form_ui.rb +0 -2
- data/lib/active_scaffold/bridges/file_column/list_ui.rb +2 -1
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +1 -1
- data/lib/active_scaffold/bridges/paper_trail/actions.rb +1 -1
- data/lib/active_scaffold/bridges/paper_trail/helper.rb +1 -2
- data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +3 -7
- data/lib/active_scaffold/bridges/paperclip.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/form_ui.rb +3 -28
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +3 -7
- data/lib/active_scaffold/bridges/record_select.rb +2 -0
- data/lib/active_scaffold/bridges/record_select/helpers.rb +14 -18
- data/lib/active_scaffold/bridges/semantic_attributes/column.rb +4 -8
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +20 -20
- data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +7 -22
- data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +14 -14
- data/lib/active_scaffold/config/base.rb +9 -6
- data/lib/active_scaffold/config/core.rb +30 -21
- data/lib/active_scaffold/config/create.rb +2 -1
- data/lib/active_scaffold/config/delete.rb +2 -2
- data/lib/active_scaffold/config/field_search.rb +9 -3
- data/lib/active_scaffold/config/form.rb +4 -4
- data/lib/active_scaffold/config/list.rb +27 -23
- data/lib/active_scaffold/config/nested.rb +4 -4
- data/lib/active_scaffold/config/search.rb +6 -6
- data/lib/active_scaffold/config/show.rb +11 -1
- data/lib/active_scaffold/config/subform.rb +1 -1
- data/lib/active_scaffold/config/update.rb +4 -2
- data/lib/active_scaffold/constraints.rb +39 -36
- data/lib/active_scaffold/core.rb +36 -15
- data/lib/active_scaffold/data_structures/action_columns.rb +14 -9
- data/lib/active_scaffold/data_structures/action_link.rb +4 -5
- data/lib/active_scaffold/data_structures/action_links.rb +5 -4
- data/lib/active_scaffold/data_structures/actions.rb +2 -2
- data/lib/active_scaffold/data_structures/association.rb +8 -0
- data/lib/active_scaffold/data_structures/association/abstract.rb +147 -0
- data/lib/active_scaffold/data_structures/association/active_mongoid.rb +42 -0
- data/lib/active_scaffold/data_structures/association/active_record.rb +94 -0
- data/lib/active_scaffold/data_structures/association/mongoid.rb +45 -0
- data/lib/active_scaffold/data_structures/bridge.rb +3 -6
- data/lib/active_scaffold/data_structures/column.rb +100 -82
- data/lib/active_scaffold/data_structures/columns.rb +21 -3
- data/lib/active_scaffold/data_structures/nested_info.rb +22 -37
- data/lib/active_scaffold/data_structures/set.rb +4 -4
- data/lib/active_scaffold/data_structures/sorting.rb +29 -15
- data/lib/active_scaffold/engine.rb +3 -1
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +10 -5
- data/lib/active_scaffold/extensions/action_view_rendering.rb +65 -59
- data/lib/active_scaffold/extensions/left_outer_joins.rb +48 -53
- data/lib/active_scaffold/extensions/localize.rb +3 -4
- data/lib/active_scaffold/extensions/name_option_for_datetime.rb +7 -11
- data/lib/active_scaffold/extensions/paginator_extensions.rb +20 -18
- data/lib/active_scaffold/extensions/routing_mapper.rb +104 -40
- data/lib/active_scaffold/extensions/to_label.rb +1 -1
- data/lib/active_scaffold/extensions/unsaved_associated.rb +4 -13
- data/lib/active_scaffold/extensions/unsaved_record.rb +12 -1
- data/lib/active_scaffold/finder.rb +200 -134
- data/lib/active_scaffold/helpers/action_link_helpers.rb +398 -0
- data/lib/active_scaffold/helpers/association_helpers.rb +12 -30
- data/lib/active_scaffold/helpers/controller_helpers.rb +74 -24
- data/lib/active_scaffold/helpers/form_column_helpers.rb +205 -112
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +21 -11
- data/lib/active_scaffold/helpers/id_helpers.rb +1 -1
- data/lib/active_scaffold/helpers/list_column_helpers.rb +117 -39
- data/lib/active_scaffold/helpers/pagination_helpers.rb +11 -14
- data/lib/active_scaffold/helpers/search_column_helpers.rb +69 -32
- data/lib/active_scaffold/helpers/show_column_helpers.rb +9 -3
- data/lib/active_scaffold/helpers/view_helpers.rb +41 -426
- data/lib/active_scaffold/orm_checks.rb +109 -0
- data/lib/active_scaffold/paginator.rb +1 -1
- data/lib/active_scaffold/responds_to_parent.rb +12 -10
- data/lib/active_scaffold/tableless.rb +81 -43
- data/lib/active_scaffold/version.rb +2 -2
- data/lib/generators/active_scaffold/controller_generator.rb +49 -0
- data/lib/generators/active_scaffold/install_generator.rb +45 -0
- data/lib/generators/active_scaffold/resource_generator.rb +56 -0
- data/lib/generators/{active_scaffold_controller/templates → templates}/controller.rb +0 -0
- data/lib/generators/{active_scaffold_controller/templates → templates}/helper.rb +0 -0
- data/shoulda_macros/macros.rb +3 -3
- data/test/active_scaffold_config_mock.rb +33 -0
- data/test/bridges/bridge_test.rb +9 -9
- data/test/bridges/date_picker_test.rb +3 -1
- data/test/bridges/paper_trail_test.rb +2 -3
- data/test/bridges/paperclip_test.rb +21 -10
- data/test/bridges/tiny_mce_test.rb +20 -21
- data/test/class_with_finder.rb +42 -0
- data/test/company.rb +6 -4
- data/test/config/core_test.rb +1 -1
- data/test/config/create_test.rb +1 -1
- data/test/config/list_test.rb +3 -3
- data/test/config/update_test.rb +3 -3
- data/test/data_structures/action_columns_test.rb +3 -3
- data/test/data_structures/association_column_test.rb +5 -5
- data/test/data_structures/column_test.rb +14 -14
- data/test/data_structures/columns_test.rb +2 -2
- data/test/data_structures/set_test.rb +2 -2
- data/test/data_structures/sorting_test.rb +6 -4
- data/test/extensions/active_record_test.rb +1 -1
- data/test/extensions/routing_mapper_test.rb +64 -13
- data/test/helpers/form_column_helpers_test.rb +6 -6
- data/test/helpers/list_column_helpers_test.rb +9 -5
- data/test/helpers/pagination_helpers_test.rb +1 -0
- data/test/misc/active_record_permissions_test.rb +18 -1
- data/test/misc/attribute_params_test.rb +26 -17
- data/test/misc/calculation_test.rb +8 -31
- data/test/misc/configurable_test.rb +3 -2
- data/test/misc/constraints_test.rb +33 -22
- data/test/misc/convert_numbers_format_test.rb +28 -10
- data/test/misc/finder_test.rb +6 -29
- data/test/misc/parse_datetime_test.rb +160 -0
- data/test/misc/render_test.rb +1 -1
- data/test/misc/tableless_test.rb +24 -0
- data/test/mock_app/app/models/building.rb +2 -1
- data/test/mock_app/config.ru +1 -1
- data/test/mock_app/config/environments/test.rb +1 -1
- data/test/mock_app/config/routes.rb +11 -3
- data/test/model_stub.rb +11 -6
- data/test/run_all.rb +1 -1
- data/test/test_helper.rb +19 -4
- metadata +42 -23
- data/lib/active_scaffold/data_structures/error_message.rb +0 -22
- data/lib/active_scaffold/extensions/reverse_associations.rb +0 -119
- data/lib/generators/active_scaffold/USAGE +0 -29
- data/lib/generators/active_scaffold/active_scaffold_generator.rb +0 -21
- data/lib/generators/active_scaffold_controller/USAGE +0 -19
- data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +0 -29
- 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?(
|
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.
|
35
|
-
refute @association_column.
|
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.
|
39
|
-
refute plural_association_column.
|
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.
|
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
|
-
|
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
|
-
|
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
|
-
|
61
|
+
refute_equal columns, @column
|
62
62
|
|
63
63
|
# identity
|
64
|
-
|
64
|
+
assert_equal @column, @column
|
65
65
|
|
66
66
|
# string comparison
|
67
|
-
|
68
|
-
|
67
|
+
assert_equal @column, 'a'
|
68
|
+
refute_equal @column, 'fake'
|
69
69
|
|
70
70
|
# symbol comparison
|
71
|
-
|
72
|
-
|
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
|
-
|
76
|
+
refute_equal @column, column2
|
77
77
|
column2.name = 'a'
|
78
|
-
|
78
|
+
assert_equal @column, column2
|
79
79
|
|
80
80
|
# special comparisons
|
81
81
|
refute @column.nil?
|
82
|
-
|
83
|
-
|
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
|
-
|
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 [
|
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 [
|
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 [
|
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 [
|
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 << [
|
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.
|
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.
|
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
|
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', :
|
6
|
-
assert_routing 'addresses/1', :
|
7
|
-
assert_routing 'addresses/1/list', :
|
8
|
-
assert_routing 'addresses/1/edit', :
|
9
|
-
assert_routing({:
|
10
|
-
assert_routing({:
|
11
|
-
assert_routing({:
|
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', :
|
16
|
-
assert_routing({:
|
17
|
-
assert_routing({:
|
18
|
-
assert_routing '
|
19
|
-
assert_routing 'addresses/
|
20
|
-
assert_routing 'addresses/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] = [
|
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
|
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
|
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] = [[
|
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
|
27
|
-
@column.options[:options] = %w
|
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] = [
|
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
|
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
|
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] = [[
|
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,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
|
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 => '
|
38
|
-
assert_equal '
|
39
|
-
assert_equal Date.new(
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
-
|
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
|