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.
- checksums.yaml +4 -4
- data/CHANGELOG +12 -1
- data/README.md +8 -4
- data/app/assets/javascripts/jquery/active_scaffold.js +82 -67
- data/app/assets/stylesheets/active_scaffold.scss +1 -1
- data/app/assets/stylesheets/active_scaffold_colors.scss +1 -1
- data/app/assets/stylesheets/blue-theme.css +1 -1
- data/app/views/active_scaffold_overrides/_form_association.html.erb +3 -3
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +3 -3
- data/app/views/active_scaffold_overrides/_show_columns.html.erb +1 -1
- data/lib/active_scaffold.rb +16 -16
- data/lib/active_scaffold/actions/common_search.rb +13 -11
- data/lib/active_scaffold/actions/core.rb +85 -78
- data/lib/active_scaffold/actions/create.rb +29 -28
- data/lib/active_scaffold/actions/delete.rb +17 -17
- data/lib/active_scaffold/actions/field_search.rb +18 -19
- data/lib/active_scaffold/actions/list.rb +30 -22
- data/lib/active_scaffold/actions/mark.rb +1 -1
- data/lib/active_scaffold/actions/nested.rb +78 -65
- data/lib/active_scaffold/actions/search.rb +13 -10
- data/lib/active_scaffold/actions/show.rb +10 -6
- data/lib/active_scaffold/actions/subform.rb +1 -2
- data/lib/active_scaffold/actions/update.rb +39 -31
- data/lib/active_scaffold/active_record_permissions.rb +14 -15
- data/lib/active_scaffold/attribute_params.rb +42 -43
- data/lib/active_scaffold/bridges.rb +22 -12
- data/lib/active_scaffold/bridges/ancestry.rb +1 -1
- data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +6 -6
- data/lib/active_scaffold/bridges/bitfields.rb +1 -1
- data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +12 -13
- data/lib/active_scaffold/bridges/calendar_date_select.rb +5 -5
- data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +17 -20
- data/lib/active_scaffold/bridges/cancan.rb +1 -1
- data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +8 -9
- data/lib/active_scaffold/bridges/carrierwave.rb +4 -4
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +9 -8
- data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +11 -10
- data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +7 -6
- data/lib/active_scaffold/bridges/chosen.rb +1 -1
- data/lib/active_scaffold/bridges/chosen/helpers.rb +4 -4
- data/lib/active_scaffold/bridges/country_helper.rb +1 -1
- data/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb +259 -260
- data/lib/active_scaffold/bridges/date_picker.rb +2 -2
- data/lib/active_scaffold/bridges/date_picker/ext.rb +9 -11
- data/lib/active_scaffold/bridges/date_picker/helper.rb +61 -67
- data/lib/active_scaffold/bridges/dragonfly.rb +4 -4
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +9 -8
- data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +11 -10
- data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +6 -5
- data/lib/active_scaffold/bridges/file_column.rb +5 -5
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +20 -23
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +20 -23
- data/lib/active_scaffold/bridges/file_column/form_ui.rb +13 -14
- data/lib/active_scaffold/bridges/file_column/list_ui.rb +7 -8
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +18 -22
- data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +5 -4
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +2 -10
- data/lib/active_scaffold/bridges/paper_trail.rb +7 -5
- data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +4 -3
- data/lib/active_scaffold/bridges/paperclip.rb +5 -5
- data/lib/active_scaffold/bridges/paperclip/form_ui.rb +11 -10
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +6 -5
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +10 -9
- data/lib/active_scaffold/bridges/record_select.rb +1 -1
- data/lib/active_scaffold/bridges/record_select/helpers.rb +28 -28
- data/lib/active_scaffold/bridges/semantic_attributes.rb +1 -1
- data/lib/active_scaffold/bridges/semantic_attributes/column.rb +1 -1
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +58 -52
- data/lib/active_scaffold/bridges/tiny_mce.rb +2 -2
- data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -3
- data/lib/active_scaffold/config/base.rb +9 -10
- data/lib/active_scaffold/config/core.rb +24 -29
- data/lib/active_scaffold/config/create.rb +0 -1
- data/lib/active_scaffold/config/field_search.rb +8 -10
- data/lib/active_scaffold/config/form.rb +5 -5
- data/lib/active_scaffold/config/list.rb +21 -20
- data/lib/active_scaffold/config/mark.rb +3 -3
- data/lib/active_scaffold/config/nested.rb +11 -10
- data/lib/active_scaffold/config/search.rb +2 -3
- data/lib/active_scaffold/config/show.rb +1 -1
- data/lib/active_scaffold/config/update.rb +1 -2
- data/lib/active_scaffold/configurable.rb +9 -11
- data/lib/active_scaffold/constraints.rb +9 -8
- data/lib/active_scaffold/core.rb +72 -84
- data/lib/active_scaffold/data_structures/action_columns.rb +26 -25
- data/lib/active_scaffold/data_structures/action_link.rb +43 -43
- data/lib/active_scaffold/data_structures/action_links.rb +17 -15
- data/lib/active_scaffold/data_structures/actions.rb +5 -5
- data/lib/active_scaffold/data_structures/bridge.rb +6 -3
- data/lib/active_scaffold/data_structures/column.rb +110 -89
- data/lib/active_scaffold/data_structures/columns.rb +3 -3
- data/lib/active_scaffold/data_structures/error_message.rb +4 -6
- data/lib/active_scaffold/data_structures/nested_info.rb +43 -48
- data/lib/active_scaffold/data_structures/set.rb +7 -8
- data/lib/active_scaffold/data_structures/sorting.rb +38 -33
- data/lib/active_scaffold/delayed_setup.rb +5 -6
- data/lib/active_scaffold/engine.rb +4 -4
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +3 -4
- data/lib/active_scaffold/extensions/action_controller_rescueing.rb +1 -1
- data/lib/active_scaffold/extensions/action_view_rendering.rb +5 -6
- data/lib/active_scaffold/extensions/left_outer_joins.rb +11 -11
- data/lib/active_scaffold/extensions/localize.rb +1 -1
- data/lib/active_scaffold/extensions/name_option_for_datetime.rb +1 -1
- data/lib/active_scaffold/extensions/paginator_extensions.rb +2 -5
- data/lib/active_scaffold/extensions/reverse_associations.rb +13 -13
- data/lib/active_scaffold/extensions/routing_mapper.rb +9 -9
- data/lib/active_scaffold/extensions/unsaved_associated.rb +9 -9
- data/lib/active_scaffold/finder.rb +90 -93
- data/lib/active_scaffold/helpers/association_helpers.rb +5 -5
- data/lib/active_scaffold/helpers/controller_helpers.rb +22 -19
- data/lib/active_scaffold/helpers/form_column_helpers.rb +115 -105
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +62 -35
- data/lib/active_scaffold/helpers/id_helpers.rb +6 -6
- data/lib/active_scaffold/helpers/list_column_helpers.rb +89 -94
- data/lib/active_scaffold/helpers/pagination_helpers.rb +9 -9
- data/lib/active_scaffold/helpers/search_column_helpers.rb +47 -44
- data/lib/active_scaffold/helpers/show_column_helpers.rb +2 -2
- data/lib/active_scaffold/helpers/view_helpers.rb +86 -91
- data/lib/active_scaffold/marked_model.rb +10 -10
- data/lib/active_scaffold/paginator.rb +30 -34
- data/lib/active_scaffold/responds_to_parent.rb +27 -28
- data/lib/active_scaffold/tableless.rb +20 -15
- data/lib/active_scaffold/version.rb +1 -1
- data/lib/generators/active_scaffold/active_scaffold_generator.rb +8 -8
- data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +9 -9
- data/shoulda_macros/macros.rb +27 -22
- data/test/bridges/bridge_test.rb +38 -29
- data/test/bridges/date_picker_test.rb +1 -1
- data/test/bridges/paper_trail_test.rb +17 -0
- data/test/bridges/paperclip_test.rb +3 -2
- data/test/bridges/tiny_mce_test.rb +5 -2
- data/test/company.rb +25 -30
- data/test/config/base_test.rb +1 -1
- data/test/config/core_test.rb +9 -9
- data/test/config/create_test.rb +14 -8
- data/test/config/delete_test.rb +4 -4
- data/test/config/field_search_test.rb +6 -6
- data/test/config/list_test.rb +16 -16
- data/test/config/nested_test.rb +4 -4
- data/test/config/search_test.rb +8 -8
- data/test/config/show_test.rb +6 -6
- data/test/config/subform_test.rb +1 -1
- data/test/config/update_test.rb +5 -5
- data/test/const_mocker.rb +4 -4
- data/test/data_structures/action_columns_test.rb +4 -5
- data/test/data_structures/action_link_test.rb +1 -0
- data/test/data_structures/action_links_test.rb +5 -5
- data/test/data_structures/column_test.rb +9 -9
- data/test/data_structures/columns_test.rb +2 -2
- data/test/data_structures/error_message_test.rb +4 -5
- data/test/data_structures/set_test.rb +1 -2
- data/test/data_structures/sorting_test.rb +10 -10
- data/test/data_structures/validation_reflection_test.rb +8 -0
- data/test/extensions/routing_mapper_test.rb +2 -2
- data/test/helpers/list_column_helpers_test.rb +3 -2
- data/test/helpers/pagination_helpers_test.rb +5 -4
- data/test/helpers/search_column_helpers_test.rb +1 -1
- data/test/misc/active_record_permissions_test.rb +63 -50
- data/test/misc/attribute_params_test.rb +28 -26
- data/test/misc/calculation_test.rb +10 -3
- data/test/misc/configurable_test.rb +12 -13
- data/test/misc/constraints_test.rb +6 -6
- data/test/misc/convert_numbers_format_test.rb +7 -6
- data/test/misc/finder_test.rb +17 -12
- data/test/misc/lang_test.rb +3 -4
- data/test/misc/tableless_test.rb +2 -3
- data/test/mock_app/app/controllers/addresses_controller.rb +1 -1
- data/test/mock_app/app/controllers/buildings_controller.rb +1 -1
- data/test/mock_app/app/controllers/cars_controller.rb +1 -1
- data/test/mock_app/app/controllers/contacts_controller.rb +1 -1
- data/test/mock_app/app/controllers/people_controller.rb +1 -1
- data/test/mock_app/app/models/file_model.rb +2 -2
- data/test/mock_app/app/models/person.rb +1 -1
- data/test/mock_app/config/application.rb +3 -3
- data/test/mock_app/config/boot.rb +1 -1
- data/test/mock_app/config/environment.rb +1 -0
- data/test/mock_app/config/environments/development.rb +0 -1
- data/test/mock_app/config/environments/production.rb +1 -1
- data/test/mock_app/db/schema.rb +14 -15
- data/test/model_stub.rb +13 -16
- data/test/run_all.rb +5 -7
- data/test/test_helper.rb +12 -9
- metadata +19 -3
@@ -9,19 +9,19 @@ class ActionLinksTest < MiniTest::Test
|
|
9
9
|
# test adding with a shortcut
|
10
10
|
@links.add 'foo/bar'
|
11
11
|
|
12
|
-
assert_equal 1, @links.find_all{true}.size
|
13
|
-
assert_equal 'foo/bar', @links.find_all{true}[0].action
|
12
|
+
assert_equal 1, @links.find_all { true }.size
|
13
|
+
assert_equal 'foo/bar', @links.find_all { true }[0].action
|
14
14
|
assert_equal 'foo/bar', @links['foo/bar'].action
|
15
15
|
|
16
16
|
# test adding an ActionLink object directly
|
17
17
|
@links.add ActiveScaffold::DataStructures::ActionLink.new('hello/world')
|
18
18
|
|
19
|
-
assert_equal 2, @links.find_all{true}.size
|
19
|
+
assert_equal 2, @links.find_all { true }.size
|
20
20
|
|
21
21
|
# test the << alias
|
22
22
|
@links << 'a/b'
|
23
23
|
|
24
|
-
assert_equal 3, @links.find_all{true}.size
|
24
|
+
assert_equal 3, @links.find_all { true }.size
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_array_access
|
@@ -60,7 +60,7 @@ class ActionLinksTest < MiniTest::Test
|
|
60
60
|
assert_equal 'bar', link.action
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
def test_delete
|
65
65
|
@links.add 'foo'
|
66
66
|
@links.add 'bar'
|
@@ -61,7 +61,7 @@ class ColumnTest < MiniTest::Test
|
|
61
61
|
assert columns != @column
|
62
62
|
|
63
63
|
# identity
|
64
|
-
assert @column == @column
|
64
|
+
assert @column == @column # rubocop:disable Lint/UselessComparison
|
65
65
|
|
66
66
|
# string comparison
|
67
67
|
assert @column == 'a'
|
@@ -78,7 +78,7 @@ class ColumnTest < MiniTest::Test
|
|
78
78
|
assert @column == column2
|
79
79
|
|
80
80
|
# special comparisons
|
81
|
-
|
81
|
+
refute @column.nil?
|
82
82
|
assert @column != ''
|
83
83
|
assert @column != 0
|
84
84
|
end
|
@@ -135,7 +135,7 @@ class ColumnTest < MiniTest::Test
|
|
135
135
|
hash = {:sql => 'foobar'}
|
136
136
|
assert_equal hash, @column.sort
|
137
137
|
|
138
|
-
some_proc = proc {'foobar'}
|
138
|
+
some_proc = proc { 'foobar' }
|
139
139
|
@column.sort_by :method => some_proc
|
140
140
|
hash = {:method => some_proc}
|
141
141
|
assert_equal hash, @column.sort
|
@@ -143,12 +143,12 @@ class ColumnTest < MiniTest::Test
|
|
143
143
|
end
|
144
144
|
|
145
145
|
def test_custom_sort__should_assert_keys
|
146
|
-
assert_raises(ArgumentError) { @column.sort_by :proc =>
|
147
|
-
assert_raises(ArgumentError) { @column.sort={:proc =>
|
148
|
-
assert_equal({:method =>
|
149
|
-
assert_equal({:sql =>
|
146
|
+
assert_raises(ArgumentError) { @column.sort_by :proc => 'invalid config' }
|
147
|
+
assert_raises(ArgumentError) { @column.sort = {:proc => 'invalid config'} }
|
148
|
+
assert_equal({:method => 'method'}, @column.sort_by(:method => 'method'))
|
149
|
+
assert_equal({:sql => 'method'}, @column.sort_by(:sql => 'method'))
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
def test_config_block
|
153
153
|
@column.configure do |config|
|
154
154
|
# we can use the config object
|
@@ -173,7 +173,7 @@ class ColumnTest < MiniTest::Test
|
|
173
173
|
|
174
174
|
def test_includes
|
175
175
|
assert_equal 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
|
179
179
|
assert_equal([:column_name], @column.includes)
|
@@ -41,8 +41,8 @@ class ColumnsTest < MiniTest::Test
|
|
41
41
|
|
42
42
|
# test the collection finders
|
43
43
|
found = @columns.find_by_names(:a, :b)
|
44
|
-
assert found.any? {|c| c.name == :a}
|
45
|
-
assert found.any? {|c| c.name == :b}
|
44
|
+
assert found.any? { |c| c.name == :a }
|
45
|
+
assert found.any? { |c| c.name == :b }
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_each
|
@@ -6,21 +6,20 @@ class ErrorMessageTest < MiniTest::Test
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def test_attributes
|
9
|
-
assert @error.public_attributes.
|
9
|
+
assert @error.public_attributes.key?(:error)
|
10
10
|
assert_equal 'foo', @error.public_attributes[:error]
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_xml
|
14
14
|
xml = Hash.from_xml(@error.to_xml)
|
15
|
-
assert xml.
|
16
|
-
assert xml['errors'].
|
15
|
+
assert xml.key?('errors')
|
16
|
+
assert xml['errors'].key?('error')
|
17
17
|
assert_equal 'foo', xml['errors']['error']
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_yaml
|
21
|
-
yml = nil
|
22
21
|
yml = YAML.load(@error.to_yaml)
|
23
|
-
assert yml.
|
22
|
+
assert yml.key?(:error)
|
24
23
|
assert_equal 'foo', yml[:error]
|
25
24
|
end
|
26
25
|
end
|
@@ -50,7 +50,7 @@ class SetTest < MiniTest::Test
|
|
50
50
|
|
51
51
|
# test that << also adds
|
52
52
|
refute @items.include?(:e)
|
53
|
-
@items <<
|
53
|
+
@items << 'e'
|
54
54
|
assert @items.include?(:e)
|
55
55
|
|
56
56
|
# try adding an array of columns
|
@@ -58,7 +58,6 @@ class SetTest < MiniTest::Test
|
|
58
58
|
@items.add [:f, :g]
|
59
59
|
assert @items.include?(:f)
|
60
60
|
assert @items.include?(:g)
|
61
|
-
|
62
61
|
end
|
63
62
|
|
64
63
|
def test_length
|
@@ -90,18 +90,18 @@ class SortingTest < MiniTest::Test
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def test_sorts_by_method
|
93
|
-
@columns[:a].sort_by :method => proc{0}
|
93
|
+
@columns[:a].sort_by :method => proc { 0 }
|
94
94
|
|
95
|
-
#test pure method sorting: true
|
95
|
+
# test pure method sorting: true
|
96
96
|
@sorting.add :a
|
97
97
|
assert @sorting.sorts_by_method?
|
98
98
|
|
99
|
-
#test mixed sql/method sorting: raise error
|
99
|
+
# test mixed sql/method sorting: raise error
|
100
100
|
assert_raises ArgumentError do
|
101
101
|
@sorting.add :b
|
102
102
|
end
|
103
|
-
|
104
|
-
#test pure sql sorting: false
|
103
|
+
|
104
|
+
# test pure sql sorting: false
|
105
105
|
@sorting.clear
|
106
106
|
@sorting.add :b
|
107
107
|
refute @sorting.sorts_by_method?
|
@@ -115,12 +115,12 @@ class SortingTest < MiniTest::Test
|
|
115
115
|
|
116
116
|
assert_equal '"model_stubs"."a" DESC, "model_stubs"."b" ASC', @sorting.clause.join(', ')
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
def test_set_default_sorting_with_simple_default_scope
|
120
120
|
model_stub_with_default_scope = ModelStub.clone
|
121
|
-
model_stub_with_default_scope.class_eval { default_scope
|
121
|
+
model_stub_with_default_scope.class_eval { default_scope -> { order('a') } }
|
122
122
|
@sorting.set_default_sorting model_stub_with_default_scope
|
123
|
-
|
123
|
+
|
124
124
|
assert @sorting.sorts_on?(:a)
|
125
125
|
assert_equal 'ASC', @sorting.direction_of(:a)
|
126
126
|
assert_nil @sorting.clause
|
@@ -128,9 +128,9 @@ class SortingTest < MiniTest::Test
|
|
128
128
|
|
129
129
|
def test_set_default_sorting_with_complex_default_scope
|
130
130
|
model_stub_with_default_scope = ModelStub.clone
|
131
|
-
model_stub_with_default_scope.class_eval { default_scope
|
131
|
+
model_stub_with_default_scope.class_eval { default_scope -> { order('a DESC, players.last_name ASC') } }
|
132
132
|
@sorting.set_default_sorting model_stub_with_default_scope
|
133
|
-
|
133
|
+
|
134
134
|
assert @sorting.sorts_on?(:a)
|
135
135
|
assert_equal 'DESC', @sorting.direction_of(:a)
|
136
136
|
assert_equal 1, @sorting.instance_variable_get(:@clauses).size
|
@@ -48,4 +48,12 @@ class ValidationReflectionTest < MiniTest::Test
|
|
48
48
|
column = ActiveScaffold::DataStructures::Column.new(:main_company, Company)
|
49
49
|
refute column.required?
|
50
50
|
end
|
51
|
+
|
52
|
+
def test_override_required
|
53
|
+
Company.expects(:validators_on).with(:name).returns([ActiveModel::Validations::PresenceValidator.new(:attributes => :name)])
|
54
|
+
column = ActiveScaffold::DataStructures::Column.new(:name, Company)
|
55
|
+
assert column.required?
|
56
|
+
column.required = false
|
57
|
+
refute column.required?
|
58
|
+
end
|
51
59
|
end
|
@@ -13,8 +13,8 @@ class RoutingMapperTest < ActionController::TestCase
|
|
13
13
|
|
14
14
|
test 'active scaffold routes' do
|
15
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')
|
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
18
|
assert_routing 'addresses/2/render_field', :controller => 'addresses', :action => 'render_field', :id => '2'
|
19
19
|
assert_routing 'addresses/edit_associated', :controller => 'addresses', :action => 'edit_associated'
|
20
20
|
assert_routing 'addresses/2/edit_associated', :controller => 'addresses', :action => 'edit_associated', :id => '2'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#encoding: utf-8
|
1
|
+
# encoding: utf-8
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
4
|
class ListColumnHelpersTest < ActionView::TestCase
|
@@ -31,7 +31,7 @@ class ListColumnHelpersTest < ActionView::TestCase
|
|
31
31
|
|
32
32
|
def test_association_join_text
|
33
33
|
value = [1, 2, 3, 4].map(&:to_s)
|
34
|
-
value.each {|v| v.stubs(:to_label).returns(v)}
|
34
|
+
value.each { |v| v.stubs(:to_label).returns(v) }
|
35
35
|
assert_equal '1, 2, 3, … (4)', format_association_value(value, @association_column, value.size)
|
36
36
|
@config.list.stubs(:association_join_text => ',<br/>')
|
37
37
|
assert_equal '1,<br/>2,<br/>3,<br/>… (4)', format_association_value(value, @association_column, value.size)
|
@@ -40,6 +40,7 @@ class ListColumnHelpersTest < ActionView::TestCase
|
|
40
40
|
end
|
41
41
|
|
42
42
|
private
|
43
|
+
|
43
44
|
def active_scaffold_config
|
44
45
|
@config
|
45
46
|
end
|
@@ -8,7 +8,7 @@ class PaginationHelpersTest < MiniTest::Test
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_links
|
11
|
-
|
11
|
+
stubs(:pagination_ajax_link).returns('l')
|
12
12
|
|
13
13
|
assert_equal '1', links(1, 1)
|
14
14
|
assert_equal '1 l', links(1, 2)
|
@@ -31,7 +31,7 @@ class PaginationHelpersTest < MiniTest::Test
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_links_with_infinite_pagination
|
34
|
-
|
34
|
+
stubs(:pagination_ajax_link).returns('l')
|
35
35
|
|
36
36
|
assert_equal '1 l l .. l .. l', links(1, nil, 2, true)
|
37
37
|
assert_equal 'l 2 l l .. l .. l', links(2, nil, 2, true)
|
@@ -51,13 +51,14 @@ class PaginationHelpersTest < MiniTest::Test
|
|
51
51
|
end
|
52
52
|
|
53
53
|
private
|
54
|
+
|
54
55
|
def links(current, last_page, window_size = 2, infinite = false)
|
55
|
-
paginator = stub(:last =>
|
56
|
+
paginator = stub(:last => stub(:number => last_page), :infinite? => infinite)
|
56
57
|
current_page = stub(:number => current, :pager => paginator)
|
57
58
|
pagination_ajax_links(current_page, {}, {}, window_size, 0)
|
58
59
|
end
|
59
60
|
|
60
|
-
def content_tag(tag, text, *
|
61
|
+
def content_tag(tag, text, *)
|
61
62
|
text
|
62
63
|
end
|
63
64
|
end
|
@@ -9,6 +9,6 @@ class SearchColumnHelpersTest < ActionView::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_choices_for_boolean_search_ui
|
12
|
-
assert_dom_equal "<select name=\"search[adult]\"><option value=\"\">- select -</option>\n<option value=\"true\">True</option>\n<option value=\"false\" selected=\"selected\">False</option></select>", active_scaffold_search_boolean(@column, :object => @record, :name =>
|
12
|
+
assert_dom_equal "<select name=\"search[adult]\"><option value=\"\">- select -</option>\n<option value=\"true\">True</option>\n<option value=\"false\" selected=\"selected\">False</option></select>", active_scaffold_search_boolean(@column, :object => @record, :name => 'search[adult]', :value => '0')
|
13
13
|
end
|
14
14
|
end
|
@@ -2,53 +2,66 @@ 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; @columns ||= [ColumnMock.new('id', '', 'int(11)')] + %w(a1 a2 a3 b1 b2 b3 c1 c2 c3).map { |c| ColumnMock.new(c, '', 'varchar(255)') }; end
|
6
6
|
|
7
7
|
def authorized_for_read?; true; end
|
8
|
+
|
8
9
|
def authorized_for_update?; false; end
|
9
|
-
#def authorized_for_create?; end
|
10
|
+
# def authorized_for_create?; end
|
10
11
|
|
11
12
|
def a1_authorized?; true; end
|
13
|
+
|
12
14
|
def a2_authorized?; false; end
|
13
|
-
#def a3_authorized?; end
|
15
|
+
# def a3_authorized?; end
|
14
16
|
|
15
17
|
def b1_authorized?; true; end
|
18
|
+
|
16
19
|
def b2_authorized?; false; end
|
17
|
-
#def b3_authorized?; end
|
20
|
+
# def b3_authorized?; end
|
18
21
|
|
19
22
|
def c1_authorized?; true; end
|
23
|
+
|
20
24
|
def c2_authorized?; false; end
|
21
|
-
#def c3_authorized?; end
|
25
|
+
# def c3_authorized?; end
|
22
26
|
|
23
27
|
def a3_authorized_for_create?; true; end
|
28
|
+
|
24
29
|
def b3_authorized_for_create?; false; end
|
25
|
-
#def c3_authorized_for_create?; end
|
30
|
+
# def c3_authorized_for_create?; end
|
26
31
|
def a2_authorized_for_create?; true; end
|
32
|
+
|
27
33
|
def b2_authorized_for_create?; false; end
|
28
|
-
#def c2_authorized_for_create?; end
|
34
|
+
# def c2_authorized_for_create?; end
|
29
35
|
def a1_authorized_for_create?; true; end
|
36
|
+
|
30
37
|
def b1_authorized_for_create?; false; end
|
31
|
-
#def c1_authorized_for_create?; end
|
38
|
+
# def c1_authorized_for_create?; end
|
32
39
|
|
33
40
|
def a3_authorized_for_read?; true; end
|
41
|
+
|
34
42
|
def b3_authorized_for_read?; false; end
|
35
|
-
#def c3_authorized_for_read?; end
|
43
|
+
# def c3_authorized_for_read?; end
|
36
44
|
def a2_authorized_for_read?; true; end
|
45
|
+
|
37
46
|
def b2_authorized_for_read?; false; end
|
38
|
-
#def c2_authorized_for_read?; end
|
47
|
+
# def c2_authorized_for_read?; end
|
39
48
|
def a1_authorized_for_read?; true; end
|
49
|
+
|
40
50
|
def b1_authorized_for_read?; false; end
|
41
|
-
#def c1_authorized_for_read?; end
|
51
|
+
# def c1_authorized_for_read?; end
|
42
52
|
|
43
53
|
def a3_authorized_for_update?; true; end
|
54
|
+
|
44
55
|
def b3_authorized_for_update?; false; end
|
45
|
-
#def c3_authorized_for_update?; end
|
56
|
+
# def c3_authorized_for_update?; end
|
46
57
|
def a2_authorized_for_update?; true; end
|
58
|
+
|
47
59
|
def b2_authorized_for_update?; false; end
|
48
|
-
#def c2_authorized_for_update?; end
|
60
|
+
# def c2_authorized_for_update?; end
|
49
61
|
def a1_authorized_for_update?; true; end
|
62
|
+
|
50
63
|
def b1_authorized_for_update?; false; end
|
51
|
-
#def c1_authorized_for_update?; end
|
64
|
+
# def c1_authorized_for_update?; end
|
52
65
|
end
|
53
66
|
|
54
67
|
class ActiveRecordPermissionsTest < MiniTest::Test
|
@@ -67,41 +80,41 @@ class ActiveRecordPermissionsTest < MiniTest::Test
|
|
67
80
|
end
|
68
81
|
|
69
82
|
pass(@model.authorized_for?(:column => :a3), '_a_')
|
70
|
-
|
83
|
+
miss(@model.authorized_for?(:column => :a2), '_f_')
|
71
84
|
pass(@model.authorized_for?(:column => :a1), '_t_')
|
72
85
|
|
73
86
|
pass(@model.authorized_for?(:crud_type => :create), 'a__')
|
74
|
-
|
87
|
+
miss(@model.authorized_for?(:crud_type => :update), 'f__')
|
75
88
|
pass(@model.authorized_for?(:crud_type => :read), 't__')
|
76
89
|
|
77
90
|
pass(@model.authorized_for?(:crud_type => :create, :column => :c3), 'aaa')
|
78
|
-
|
91
|
+
miss(@model.authorized_for?(:crud_type => :create, :column => :b3), 'aaf')
|
79
92
|
pass(@model.authorized_for?(:crud_type => :create, :column => :a3), 'aat')
|
80
|
-
|
81
|
-
|
93
|
+
miss(@model.authorized_for?(:crud_type => :create, :column => :c2), 'afa')
|
94
|
+
miss(@model.authorized_for?(:crud_type => :create, :column => :b2), 'aff')
|
82
95
|
pass(@model.authorized_for?(:crud_type => :create, :column => :a2), 'aft')
|
83
96
|
pass(@model.authorized_for?(:crud_type => :create, :column => :c1), 'ata')
|
84
|
-
|
97
|
+
miss(@model.authorized_for?(:crud_type => :create, :column => :b1), 'atf')
|
85
98
|
pass(@model.authorized_for?(:crud_type => :create, :column => :a1), 'att')
|
86
99
|
|
87
|
-
|
88
|
-
|
100
|
+
miss(@model.authorized_for?(:crud_type => :update, :column => :c3), 'faa')
|
101
|
+
miss(@model.authorized_for?(:crud_type => :update, :column => :b3), 'faf')
|
89
102
|
pass(@model.authorized_for?(:crud_type => :update, :column => :a3), 'fat')
|
90
|
-
|
91
|
-
|
103
|
+
miss(@model.authorized_for?(:crud_type => :update, :column => :c2), 'ffa')
|
104
|
+
miss(@model.authorized_for?(:crud_type => :update, :column => :b2), 'fff')
|
92
105
|
pass(@model.authorized_for?(:crud_type => :update, :column => :a2), 'fft')
|
93
|
-
|
94
|
-
|
106
|
+
miss(@model.authorized_for?(:crud_type => :update, :column => :c1), 'fta')
|
107
|
+
miss(@model.authorized_for?(:crud_type => :update, :column => :b1), 'ftf')
|
95
108
|
pass(@model.authorized_for?(:crud_type => :update, :column => :a1), 'ftt')
|
96
109
|
|
97
110
|
pass(@model.authorized_for?(:crud_type => :read, :column => :c3), 'taa')
|
98
|
-
|
111
|
+
miss(@model.authorized_for?(:crud_type => :read, :column => :b3), 'taf')
|
99
112
|
pass(@model.authorized_for?(:crud_type => :read, :column => :a3), 'tat')
|
100
|
-
|
101
|
-
|
113
|
+
miss(@model.authorized_for?(:crud_type => :read, :column => :c2), 'tfa')
|
114
|
+
miss(@model.authorized_for?(:crud_type => :read, :column => :b2), 'tff')
|
102
115
|
pass(@model.authorized_for?(:crud_type => :read, :column => :a2), 'tft')
|
103
116
|
pass(@model.authorized_for?(:crud_type => :read, :column => :c1), 'tta')
|
104
|
-
|
117
|
+
miss(@model.authorized_for?(:crud_type => :read, :column => :b1), 'ttf')
|
105
118
|
pass(@model.authorized_for?(:crud_type => :read, :column => :a1), 'ttt')
|
106
119
|
|
107
120
|
ActiveScaffold.set_defaults do |config|
|
@@ -116,42 +129,42 @@ class ActiveRecordPermissionsTest < MiniTest::Test
|
|
116
129
|
config.security.default_permission = false
|
117
130
|
end
|
118
131
|
|
119
|
-
|
120
|
-
|
132
|
+
miss(@model.authorized_for?(:column => :a3), '_a_')
|
133
|
+
miss(@model.authorized_for?(:column => :a2), '_f_')
|
121
134
|
pass(@model.authorized_for?(:column => :a1), '_t_')
|
122
135
|
|
123
|
-
|
124
|
-
|
136
|
+
miss(@model.authorized_for?(:crud_type => :create), 'a__')
|
137
|
+
miss(@model.authorized_for?(:crud_type => :update), 'f__')
|
125
138
|
pass(@model.authorized_for?(:crud_type => :read), 't__')
|
126
139
|
|
127
|
-
|
128
|
-
|
140
|
+
miss(@model.authorized_for?(:crud_type => :create, :column => :c3), 'aaa')
|
141
|
+
miss(@model.authorized_for?(:crud_type => :create, :column => :b3), 'aaf')
|
129
142
|
pass(@model.authorized_for?(:crud_type => :create, :column => :a3), 'aat')
|
130
|
-
|
131
|
-
|
143
|
+
miss(@model.authorized_for?(:crud_type => :create, :column => :c2), 'afa')
|
144
|
+
miss(@model.authorized_for?(:crud_type => :create, :column => :b2), 'aff')
|
132
145
|
pass(@model.authorized_for?(:crud_type => :create, :column => :a2), 'aft')
|
133
146
|
pass(@model.authorized_for?(:crud_type => :create, :column => :c1), 'ata')
|
134
|
-
|
147
|
+
miss(@model.authorized_for?(:crud_type => :create, :column => :b1), 'atf')
|
135
148
|
pass(@model.authorized_for?(:crud_type => :create, :column => :a1), 'att')
|
136
149
|
|
137
|
-
|
138
|
-
|
150
|
+
miss(@model.authorized_for?(:crud_type => :update, :column => :c3), 'faa')
|
151
|
+
miss(@model.authorized_for?(:crud_type => :update, :column => :b3), 'faf')
|
139
152
|
pass(@model.authorized_for?(:crud_type => :update, :column => :a3), 'fat')
|
140
|
-
|
141
|
-
|
153
|
+
miss(@model.authorized_for?(:crud_type => :update, :column => :c2), 'ffa')
|
154
|
+
miss(@model.authorized_for?(:crud_type => :update, :column => :b2), 'fff')
|
142
155
|
pass(@model.authorized_for?(:crud_type => :update, :column => :a2), 'fft')
|
143
|
-
|
144
|
-
|
156
|
+
miss(@model.authorized_for?(:crud_type => :update, :column => :c1), 'fta')
|
157
|
+
miss(@model.authorized_for?(:crud_type => :update, :column => :b1), 'ftf')
|
145
158
|
pass(@model.authorized_for?(:crud_type => :update, :column => :a1), 'ftt')
|
146
159
|
|
147
160
|
pass(@model.authorized_for?(:crud_type => :read, :column => :c3), 'taa')
|
148
|
-
|
161
|
+
miss(@model.authorized_for?(:crud_type => :read, :column => :b3), 'taf')
|
149
162
|
pass(@model.authorized_for?(:crud_type => :read, :column => :a3), 'tat')
|
150
|
-
|
151
|
-
|
163
|
+
miss(@model.authorized_for?(:crud_type => :read, :column => :c2), 'tfa')
|
164
|
+
miss(@model.authorized_for?(:crud_type => :read, :column => :b2), 'tff')
|
152
165
|
pass(@model.authorized_for?(:crud_type => :read, :column => :a2), 'tft')
|
153
166
|
pass(@model.authorized_for?(:crud_type => :read, :column => :c1), 'tta')
|
154
|
-
|
167
|
+
miss(@model.authorized_for?(:crud_type => :read, :column => :b1), 'ttf')
|
155
168
|
pass(@model.authorized_for?(:crud_type => :read, :column => :a1), 'ttt')
|
156
169
|
|
157
170
|
ActiveScaffold.set_defaults do |config|
|
@@ -165,7 +178,7 @@ class ActiveRecordPermissionsTest < MiniTest::Test
|
|
165
178
|
assert value, "#{message} should pass"
|
166
179
|
end
|
167
180
|
|
168
|
-
def
|
181
|
+
def miss(value, message = nil)
|
169
182
|
refute value, "#{message} should fail"
|
170
183
|
end
|
171
184
|
end
|