active_scaffold 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +27 -0
- data/CHANGELOG +152 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README +51 -0
- data/Rakefile +24 -0
- data/active_scaffold.gemspec +24 -0
- data/environment.rb +22 -0
- data/frontends/default/images/add.gif +0 -0
- data/frontends/default/images/arrow_down.gif +0 -0
- data/frontends/default/images/arrow_up.gif +0 -0
- data/frontends/default/images/close.gif +0 -0
- data/frontends/default/images/cross.png +0 -0
- data/frontends/default/images/indicator-small.gif +0 -0
- data/frontends/default/images/indicator.gif +0 -0
- data/frontends/default/images/magnifier.png +0 -0
- data/frontends/default/javascripts/jquery/active_scaffold.js +957 -0
- data/frontends/default/javascripts/jquery/jquery.editinplace.js +726 -0
- data/frontends/default/javascripts/prototype/active_scaffold.js +954 -0
- data/frontends/default/javascripts/prototype/dhtml_history.js +867 -0
- data/frontends/default/javascripts/prototype/form_enhancements.js +117 -0
- data/frontends/default/javascripts/prototype/rico_corner.js +370 -0
- data/frontends/default/stylesheets/stylesheet-ie.css +35 -0
- data/frontends/default/stylesheets/stylesheet.css +858 -0
- data/frontends/default/views/_add_existing_form.html.erb +30 -0
- data/frontends/default/views/_base_form.html.erb +41 -0
- data/frontends/default/views/_create_form.html.erb +6 -0
- data/frontends/default/views/_create_form_on_list.html.erb +5 -0
- data/frontends/default/views/_field_search.html.erb +32 -0
- data/frontends/default/views/_form.html.erb +24 -0
- data/frontends/default/views/_form_association.html.erb +14 -0
- data/frontends/default/views/_form_association_footer.html.erb +40 -0
- data/frontends/default/views/_form_attribute.html.erb +15 -0
- data/frontends/default/views/_form_hidden_attribute.html.erb +2 -0
- data/frontends/default/views/_form_messages.html.erb +5 -0
- data/frontends/default/views/_horizontal_subform.html.erb +19 -0
- data/frontends/default/views/_horizontal_subform_header.html.erb +10 -0
- data/frontends/default/views/_horizontal_subform_record.html.erb +37 -0
- data/frontends/default/views/_human_conditions.html.erb +1 -0
- data/frontends/default/views/_list.html.erb +18 -0
- data/frontends/default/views/_list_actions.html.erb +16 -0
- data/frontends/default/views/_list_calculations.html.erb +16 -0
- data/frontends/default/views/_list_column_headings.html.erb +12 -0
- data/frontends/default/views/_list_header.html.erb +12 -0
- data/frontends/default/views/_list_inline_adapter.html.erb +10 -0
- data/frontends/default/views/_list_messages.html.erb +32 -0
- data/frontends/default/views/_list_pagination.html.erb +11 -0
- data/frontends/default/views/_list_pagination_links.html.erb +9 -0
- data/frontends/default/views/_list_record.html.erb +14 -0
- data/frontends/default/views/_list_record_columns.html.erb +8 -0
- data/frontends/default/views/_list_with_header.html.erb +32 -0
- data/frontends/default/views/_messages.html.erb +10 -0
- data/frontends/default/views/_render_field.js.rjs +13 -0
- data/frontends/default/views/_row.html.erb +12 -0
- data/frontends/default/views/_search.html.erb +34 -0
- data/frontends/default/views/_search_attribute.html.erb +10 -0
- data/frontends/default/views/_show.html.erb +8 -0
- data/frontends/default/views/_show_columns.html.erb +12 -0
- data/frontends/default/views/_update_actions.html.erb +9 -0
- data/frontends/default/views/_update_form.html.erb +5 -0
- data/frontends/default/views/_vertical_subform.html.erb +12 -0
- data/frontends/default/views/_vertical_subform_record.html.erb +38 -0
- data/frontends/default/views/add_existing.js.rjs +17 -0
- data/frontends/default/views/add_existing_form.html.erb +5 -0
- data/frontends/default/views/create.html.erb +5 -0
- data/frontends/default/views/delete.html.erb +13 -0
- data/frontends/default/views/destroy.js.rjs +5 -0
- data/frontends/default/views/edit_associated.js.rjs +11 -0
- data/frontends/default/views/field_search.html.erb +5 -0
- data/frontends/default/views/form_messages.js.rjs +1 -0
- data/frontends/default/views/list.html.erb +1 -0
- data/frontends/default/views/list.js.rjs +1 -0
- data/frontends/default/views/on_action_update.js.rjs +8 -0
- data/frontends/default/views/on_create.js.rjs +24 -0
- data/frontends/default/views/on_update.js.rjs +15 -0
- data/frontends/default/views/search.html.erb +5 -0
- data/frontends/default/views/show.html.erb +5 -0
- data/frontends/default/views/update.html.erb +8 -0
- data/frontends/default/views/update_column.js.rjs +13 -0
- data/frontends/default/views/update_row.js.rjs +1 -0
- data/init.rb +1 -0
- data/install_assets.rb +44 -0
- data/lib/active_record_permissions.rb +134 -0
- data/lib/active_scaffold.rb +279 -0
- data/lib/active_scaffold/actions/common_search.rb +22 -0
- data/lib/active_scaffold/actions/core.rb +150 -0
- data/lib/active_scaffold/actions/create.rb +152 -0
- data/lib/active_scaffold/actions/delete.rb +72 -0
- data/lib/active_scaffold/actions/field_search.rb +82 -0
- data/lib/active_scaffold/actions/list.rb +128 -0
- data/lib/active_scaffold/actions/mark.rb +50 -0
- data/lib/active_scaffold/actions/nested.rb +241 -0
- data/lib/active_scaffold/actions/search.rb +47 -0
- data/lib/active_scaffold/actions/show.rb +54 -0
- data/lib/active_scaffold/actions/subform.rb +17 -0
- data/lib/active_scaffold/actions/update.rb +134 -0
- data/lib/active_scaffold/attribute_params.rb +207 -0
- data/lib/active_scaffold/bridges/ancestry/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb +38 -0
- data/lib/active_scaffold/bridges/bridge.rb +52 -0
- data/lib/active_scaffold/bridges/calendar_date_select/bridge.rb +16 -0
- data/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +79 -0
- data/lib/active_scaffold/bridges/carrierwave/bridge.rb +7 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +38 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +26 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +35 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb +17 -0
- data/lib/active_scaffold/bridges/date_picker/bridge.rb +22 -0
- data/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +225 -0
- data/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js +22 -0
- data/lib/active_scaffold/bridges/file_column/bridge.rb +11 -0
- data/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb +46 -0
- data/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb +59 -0
- data/lib/active_scaffold/bridges/file_column/lib/form_ui.rb +37 -0
- data/lib/active_scaffold/bridges/file_column/lib/list_ui.rb +26 -0
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +43 -0
- data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +9 -0
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +15 -0
- data/lib/active_scaffold/bridges/paperclip/bridge.rb +12 -0
- data/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb +27 -0
- data/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb +16 -0
- data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb +38 -0
- data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +26 -0
- data/lib/active_scaffold/bridges/semantic_attributes/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb +20 -0
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +187 -0
- data/lib/active_scaffold/bridges/tiny_mce/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb +45 -0
- data/lib/active_scaffold/bridges/validation_reflection/bridge.rb +8 -0
- data/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb +21 -0
- data/lib/active_scaffold/config/base.rb +54 -0
- data/lib/active_scaffold/config/core.rb +229 -0
- data/lib/active_scaffold/config/create.rb +43 -0
- data/lib/active_scaffold/config/delete.rb +25 -0
- data/lib/active_scaffold/config/field_search.rb +74 -0
- data/lib/active_scaffold/config/form.rb +46 -0
- data/lib/active_scaffold/config/list.rb +174 -0
- data/lib/active_scaffold/config/mark.rb +22 -0
- data/lib/active_scaffold/config/nested.rb +43 -0
- data/lib/active_scaffold/config/search.rb +68 -0
- data/lib/active_scaffold/config/show.rb +34 -0
- data/lib/active_scaffold/config/subform.rb +35 -0
- data/lib/active_scaffold/config/update.rb +38 -0
- data/lib/active_scaffold/configurable.rb +29 -0
- data/lib/active_scaffold/constraints.rb +179 -0
- data/lib/active_scaffold/data_structures/action_columns.rb +133 -0
- data/lib/active_scaffold/data_structures/action_link.rb +162 -0
- data/lib/active_scaffold/data_structures/action_links.rb +59 -0
- data/lib/active_scaffold/data_structures/actions.rb +45 -0
- data/lib/active_scaffold/data_structures/column.rb +348 -0
- data/lib/active_scaffold/data_structures/columns.rb +75 -0
- data/lib/active_scaffold/data_structures/error_message.rb +24 -0
- data/lib/active_scaffold/data_structures/nested_info.rb +108 -0
- data/lib/active_scaffold/data_structures/set.rb +62 -0
- data/lib/active_scaffold/data_structures/sorting.rb +168 -0
- data/lib/active_scaffold/finder.rb +333 -0
- data/lib/active_scaffold/helpers/association_helpers.rb +40 -0
- data/lib/active_scaffold/helpers/controller_helpers.rb +40 -0
- data/lib/active_scaffold/helpers/country_helpers.rb +352 -0
- data/lib/active_scaffold/helpers/form_column_helpers.rb +343 -0
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +59 -0
- data/lib/active_scaffold/helpers/id_helpers.rb +131 -0
- data/lib/active_scaffold/helpers/list_column_helpers.rb +363 -0
- data/lib/active_scaffold/helpers/pagination_helpers.rb +55 -0
- data/lib/active_scaffold/helpers/search_column_helpers.rb +238 -0
- data/lib/active_scaffold/helpers/show_column_helpers.rb +46 -0
- data/lib/active_scaffold/helpers/view_helpers.rb +315 -0
- data/lib/active_scaffold/locale/de.rb +113 -0
- data/lib/active_scaffold/locale/en.rb +118 -0
- data/lib/active_scaffold/locale/es.yml +112 -0
- data/lib/active_scaffold/locale/fr.rb +113 -0
- data/lib/active_scaffold/locale/hu.yml +63 -0
- data/lib/active_scaffold/locale/ja.yml +64 -0
- data/lib/active_scaffold/locale/ru.yml +62 -0
- data/lib/active_scaffold/marked_model.rb +38 -0
- data/lib/dhtml_confirm.rb +54 -0
- data/lib/extensions/action_controller_rendering.rb +20 -0
- data/lib/extensions/action_view_rendering.rb +113 -0
- data/lib/extensions/action_view_resolver.rb +7 -0
- data/lib/extensions/active_record_offset.rb +12 -0
- data/lib/extensions/array.rb +7 -0
- data/lib/extensions/localize.rb +10 -0
- data/lib/extensions/name_option_for_datetime.rb +12 -0
- data/lib/extensions/nil_id_in_url_params.rb +7 -0
- data/lib/extensions/paginator_extensions.rb +26 -0
- data/lib/extensions/reverse_associations.rb +62 -0
- data/lib/extensions/routing_mapper.rb +34 -0
- data/lib/extensions/to_label.rb +8 -0
- data/lib/extensions/unsaved_associated.rb +61 -0
- data/lib/extensions/unsaved_record.rb +20 -0
- data/lib/extensions/usa_state.rb +46 -0
- data/lib/generators/active_scaffold/USAGE +29 -0
- data/lib/generators/active_scaffold/active_scaffold_generator.rb +20 -0
- data/lib/generators/active_scaffold_controller/USAGE +19 -0
- data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +28 -0
- data/lib/generators/active_scaffold_controller/templates/controller.rb +4 -0
- data/lib/generators/active_scaffold_setup/USAGE +10 -0
- data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +53 -0
- data/lib/paginator.rb +136 -0
- data/lib/responds_to_parent.rb +70 -0
- data/public/blank.html +33 -0
- data/shoulda_macros/macros.rb +136 -0
- data/test/bridges/bridge_test.rb +47 -0
- data/test/config/base_test.rb +15 -0
- data/test/config/create_test.rb +55 -0
- data/test/config/list_test.rb +74 -0
- data/test/config/show_test.rb +43 -0
- data/test/config/update_test.rb +17 -0
- data/test/const_mocker.rb +36 -0
- data/test/data_structures/action_columns_test.rb +113 -0
- data/test/data_structures/action_link_test.rb +78 -0
- data/test/data_structures/action_links_test.rb +78 -0
- data/test/data_structures/actions_test.rb +25 -0
- data/test/data_structures/association_column_test.rb +42 -0
- data/test/data_structures/column_test.rb +185 -0
- data/test/data_structures/columns_test.rb +69 -0
- data/test/data_structures/error_message_test.rb +28 -0
- data/test/data_structures/set_test.rb +86 -0
- data/test/data_structures/sorting_test.rb +126 -0
- data/test/data_structures/standard_column_test.rb +24 -0
- data/test/data_structures/virtual_column_test.rb +23 -0
- data/test/extensions/active_record_test.rb +45 -0
- data/test/extensions/array_test.rb +12 -0
- data/test/helpers/form_column_helpers_test.rb +31 -0
- data/test/helpers/list_column_helpers_test.rb +31 -0
- data/test/helpers/pagination_helpers_test.rb +55 -0
- data/test/misc/active_record_permissions_test.rb +154 -0
- data/test/misc/attribute_params_test.rb +110 -0
- data/test/misc/configurable_test.rb +96 -0
- data/test/misc/constraints_test.rb +193 -0
- data/test/misc/finder_test.rb +93 -0
- data/test/misc/lang_test.rb +12 -0
- data/test/mock_app/.gitignore +2 -0
- data/test/mock_app/app/controllers/application_controller.rb +10 -0
- data/test/mock_app/app/helpers/application_helper.rb +3 -0
- data/test/mock_app/config/boot.rb +110 -0
- data/test/mock_app/config/database.yml +16 -0
- data/test/mock_app/config/environment.rb +43 -0
- data/test/mock_app/config/environments/development.rb +17 -0
- data/test/mock_app/config/environments/production.rb +28 -0
- data/test/mock_app/config/environments/test.rb +28 -0
- data/test/mock_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/mock_app/config/initializers/inflections.rb +10 -0
- data/test/mock_app/config/initializers/mime_types.rb +5 -0
- data/test/mock_app/config/initializers/new_rails_defaults.rb +19 -0
- data/test/mock_app/config/initializers/session_store.rb +15 -0
- data/test/mock_app/config/locales/en.yml +5 -0
- data/test/mock_app/config/routes.rb +43 -0
- data/test/mock_app/db/test.sqlite3 +1 -0
- data/test/mock_app/public/blank.html +33 -0
- data/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/images/active_scaffold/default/add.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/arrow_down.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/arrow_up.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/close.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/cross.png +0 -0
- data/test/mock_app/public/images/active_scaffold/default/indicator-small.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/indicator.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/magnifier.png +0 -0
- data/test/mock_app/public/javascripts/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +532 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +867 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js +117 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js +370 -0
- data/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css +35 -0
- data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +839 -0
- data/test/model_stub.rb +55 -0
- data/test/run_all.rb +8 -0
- data/test/test_helper.rb +39 -0
- data/uninstall.rb +13 -0
- metadata +478 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
# require 'test/model_stub'
|
3
|
+
|
4
|
+
class StandardColumnTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@standard_column = ActiveScaffold::DataStructures::Column.new(ModelStub.columns.first.name, ModelStub)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_virtuality
|
10
|
+
assert @standard_column.column
|
11
|
+
assert !@standard_column.virtual?
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_sorting
|
15
|
+
hash = {:sql => '"model_stubs"."a"'}
|
16
|
+
assert @standard_column.sortable?
|
17
|
+
assert_equal hash, @standard_column.sort # check default
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_searching
|
21
|
+
assert @standard_column.searchable?
|
22
|
+
assert_equal '"model_stubs"."a"', @standard_column.search_sql # check default
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
|
3
|
+
class VirtualColumnTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@virtual_column = ActiveScaffold::DataStructures::Column.new(:fake, ModelStub)
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_virtuality
|
9
|
+
assert !@virtual_column.column
|
10
|
+
assert !@virtual_column.association
|
11
|
+
assert @virtual_column.virtual?
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_sorting
|
15
|
+
# right now, there's no intelligent sorting on virtual columns
|
16
|
+
assert !@virtual_column.sortable?
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_searching
|
20
|
+
# right now, there's no intelligent searching on virtual columns
|
21
|
+
assert !@virtual_column.searchable?
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
#require 'test/model_stub'
|
3
|
+
|
4
|
+
class ActiveRecordTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@record = ModelStub.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_to_label
|
10
|
+
# without anything defined, it'll use the to_s method (e.g. #<ModelStub:0xb7379300>)
|
11
|
+
assert_match /^#<[a-z]+:0x[0-9a-f]+>$/i, @record.to_label
|
12
|
+
|
13
|
+
class << @record
|
14
|
+
def to_s
|
15
|
+
'to_s'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
assert_equal 'to_s', @record.to_label
|
20
|
+
|
21
|
+
class << @record
|
22
|
+
def title
|
23
|
+
'title'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
assert_equal 'title', @record.to_label
|
28
|
+
|
29
|
+
class << @record
|
30
|
+
def label
|
31
|
+
'label'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
assert_equal 'label', @record.to_label
|
36
|
+
|
37
|
+
class << @record
|
38
|
+
def name
|
39
|
+
'name'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
assert_equal 'name', @record.to_label
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
|
3
|
+
class ArrayTest < Test::Unit::TestCase
|
4
|
+
def test_after
|
5
|
+
@sequence = ['a', 'b', 'c']
|
6
|
+
|
7
|
+
assert_equal 'b', @sequence.after('a')
|
8
|
+
assert_equal 'c', @sequence.after('b')
|
9
|
+
assert_equal 'a', @sequence.after('c')
|
10
|
+
assert_equal nil, @sequence.after('d')
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
|
3
|
+
class FormColumnHelpersTest < ActionView::TestCase
|
4
|
+
include ActiveScaffold::Helpers::FormColumnHelpers
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@column = ActiveScaffold::DataStructures::Column.new(:a, ModelStub)
|
8
|
+
@record = stub(:a => nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_choices_for_select_form_ui_for_simple_column
|
12
|
+
@column.options[:options] = [:value_1, :value_2, :value_3]
|
13
|
+
assert_dom_equal '<select name="record[a]" id="record_a"><option value="value_1">Value 1</option><option value="value_2">Value 2</option><option value="value_3">Value 3</option></select>', active_scaffold_input_select(@column, {})
|
14
|
+
|
15
|
+
@column.options[:options] = %w(value_1 value_2 value_3)
|
16
|
+
assert_dom_equal '<select name="record[a]" id="record_a"><option value="value_1">value_1</option><option value="value_2">value_2</option><option value="value_3">value_3</option></select>', active_scaffold_input_select(@column, {})
|
17
|
+
|
18
|
+
@column.options[:options] = [%w(text_1 value_1), %w(text_2 value_2), %w(text_3 value_3)]
|
19
|
+
assert_dom_equal '<select name="record[a]" id="record_a"><option value="value_1">text_1</option><option value="value_2">text_2</option><option value="value_3">text_3</option></select>', active_scaffold_input_select(@column, {})
|
20
|
+
|
21
|
+
@column.options[:options] = [[:text_1, :value_1], [:text_2, :value_2], [:text_3, :value_3]]
|
22
|
+
assert_dom_equal '<select name="record[a]" id="record_a"><option value="value_1">Text 1</option><option value="value_2">Text 2</option><option value="value_3">Text 3</option></select>', active_scaffold_input_select(@column, {})
|
23
|
+
end
|
24
|
+
|
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)
|
28
|
+
@column.options[:html_options] = {:class => 'big'}
|
29
|
+
assert_dom_equal '<select name="record[a]" class="big" id="record_a"><option value="">None</option><option disabled="disabled" value="value_1">value_1</option><option selected="selected" value="value_2">value_2</option><option disabled="disabled" value="value_3">value_3</option></select>', active_scaffold_input_select(@column, {})
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
|
3
|
+
class ListColumnHelpersTest < ActionView::TestCase
|
4
|
+
include ActiveScaffold::Helpers::ListColumnHelpers
|
5
|
+
include ActiveScaffold::Helpers::ViewHelpers
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@column = ActiveScaffold::DataStructures::Column.new(:a, ModelStub)
|
9
|
+
@record = stub(:a => 'value_2')
|
10
|
+
@config = stub(:list => stub(:empty_field_text => '-'))
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_options_for_select_list_ui_for_simple_column
|
14
|
+
@column.options[:options] = [:value_1, :value_2, :value_3]
|
15
|
+
assert_equal 'Value 2', active_scaffold_column_select(@column, @record)
|
16
|
+
|
17
|
+
@column.options[:options] = %w(value_1 value_2 value_3)
|
18
|
+
assert_equal 'value_2', active_scaffold_column_select(@column, @record)
|
19
|
+
|
20
|
+
@column.options[:options] = [%w(text_1 value_1), %w(text_2 value_2), %w(text_3 value_3)]
|
21
|
+
assert_equal 'text_2', active_scaffold_column_select(@column, @record)
|
22
|
+
|
23
|
+
@column.options[:options] = [[:text_1, :value_1], [:text_2, :value_2], [:text_3, :value_3]]
|
24
|
+
assert_equal 'Text 2', active_scaffold_column_select(@column, @record)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def active_scaffold_config
|
29
|
+
@config
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
|
3
|
+
class PaginationHelpersTest < Test::Unit::TestCase
|
4
|
+
include ActiveScaffold::Helpers::PaginationHelpers
|
5
|
+
|
6
|
+
def test_links
|
7
|
+
self.stubs(:pagination_ajax_link).returns('l')
|
8
|
+
|
9
|
+
assert_equal '1', links(1, 1)
|
10
|
+
assert_equal '1 l', links(1, 2)
|
11
|
+
assert_equal '1 l l', links(1, 3)
|
12
|
+
assert_equal '1 l l l', links(1, 4)
|
13
|
+
assert_equal '1 l l .. l', links(1, 5)
|
14
|
+
assert_equal '1 l l .. l', links(1, 6)
|
15
|
+
|
16
|
+
assert_equal 'l 2 l l .. l', links(2, 10)
|
17
|
+
assert_equal 'l l 3 l l .. l', links(3, 10)
|
18
|
+
assert_equal 'l l l 4 l l .. l', links(4, 10)
|
19
|
+
assert_equal 'l .. l l 5 l l .. l', links(5, 10)
|
20
|
+
assert_equal 'l .. l l 6 l l .. l', links(6, 10)
|
21
|
+
|
22
|
+
assert_equal '1 l l l l', links(1, 5, 3)
|
23
|
+
assert_equal '1 l l l .. l', links(1, 6, 3)
|
24
|
+
assert_equal 'l l l l 5 l l l .. l', links(5, 10, 3)
|
25
|
+
assert_equal 'l .. l l l 6 l l l l', links(6, 10, 3)
|
26
|
+
assert_equal 'l .. l l l 6 l l l .. l', links(6, 20, 3)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_links_with_infinite_pagination
|
30
|
+
self.stubs(:pagination_ajax_link).returns('l')
|
31
|
+
|
32
|
+
assert_equal '1 l l .. l .. l', links(1, nil, 2, true)
|
33
|
+
assert_equal 'l 2 l l .. l .. l', links(2, nil, 2, true)
|
34
|
+
assert_equal 'l l 3 l l .. l .. l', links(3, nil, 2, true)
|
35
|
+
assert_equal 'l l l 4 l l .. l .. l', links(4, nil, 2, true)
|
36
|
+
assert_equal 'l .. l l 5 l l .. l .. l', links(5, nil, 2, true)
|
37
|
+
|
38
|
+
assert_equal 'l .. l l 20 l l .. l .. l', links(20, nil, 2, true)
|
39
|
+
assert_equal 'l .. l l 21 l l .. l .. l', links(21, nil, 2, true)
|
40
|
+
assert_equal 'l l .. l l 22 l l .. l .. l', links(22, nil, 2, true)
|
41
|
+
assert_equal 'l .. l .. l l 23 l l .. l .. l', links(23, nil, 2, true)
|
42
|
+
|
43
|
+
assert_equal 'l .. l .. l l 100 l l .. l .. l', links(100, nil, 2, true)
|
44
|
+
assert_equal 'l .. l .. l l 101 l l .. l .. l', links(101, nil, 2, true)
|
45
|
+
assert_equal 'l l .. l .. l l 102 l l .. l .. l', links(102, nil, 2, true)
|
46
|
+
assert_equal 'l .. l .. l .. l l 103 l l .. l .. l', links(103, nil, 2, true)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def links(current, last_page, window_size = 2, infinite = false)
|
51
|
+
paginator = stub(:last => last_page = stub(:number => last_page), :infinite? => infinite)
|
52
|
+
current_page = stub(:number => current, :pager => paginator)
|
53
|
+
pagination_ajax_links(current_page, {}, window_size)
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
|
3
|
+
class PermissionModel < ActiveRecord::Base
|
4
|
+
def self.columns; [] end
|
5
|
+
|
6
|
+
def authorized_for_read?; true; end
|
7
|
+
def authorized_for_update?; false; end
|
8
|
+
#def authorized_for_create?; end
|
9
|
+
|
10
|
+
def a1_authorized?; true; end
|
11
|
+
def a2_authorized?; false; end
|
12
|
+
#def a3_authorized?; end
|
13
|
+
|
14
|
+
def b1_authorized?; true; end
|
15
|
+
def b2_authorized?; false; end
|
16
|
+
#def b3_authorized?; end
|
17
|
+
|
18
|
+
def c1_authorized?; true; end
|
19
|
+
def c2_authorized?; false; end
|
20
|
+
#def c3_authorized?; end
|
21
|
+
|
22
|
+
def a3_authorized_for_create?; true; end
|
23
|
+
def b3_authorized_for_create?; false; end
|
24
|
+
#def c3_authorized_for_create?; end
|
25
|
+
def a2_authorized_for_create?; true; end
|
26
|
+
def b2_authorized_for_create?; false; end
|
27
|
+
#def c2_authorized_for_create?; end
|
28
|
+
def a1_authorized_for_create?; true; end
|
29
|
+
def b1_authorized_for_create?; false; end
|
30
|
+
#def c1_authorized_for_create?; end
|
31
|
+
|
32
|
+
def a3_authorized_for_read?; true; end
|
33
|
+
def b3_authorized_for_read?; false; end
|
34
|
+
#def c3_authorized_for_read?; end
|
35
|
+
def a2_authorized_for_read?; true; end
|
36
|
+
def b2_authorized_for_read?; false; end
|
37
|
+
#def c2_authorized_for_read?; end
|
38
|
+
def a1_authorized_for_read?; true; end
|
39
|
+
def b1_authorized_for_read?; false; end
|
40
|
+
#def c1_authorized_for_read?; end
|
41
|
+
|
42
|
+
def a3_authorized_for_update?; true; end
|
43
|
+
def b3_authorized_for_update?; false; end
|
44
|
+
#def c3_authorized_for_update?; end
|
45
|
+
def a2_authorized_for_update?; true; end
|
46
|
+
def b2_authorized_for_update?; false; end
|
47
|
+
#def c2_authorized_for_update?; end
|
48
|
+
def a1_authorized_for_update?; true; end
|
49
|
+
def b1_authorized_for_update?; false; end
|
50
|
+
#def c1_authorized_for_update?; end
|
51
|
+
end
|
52
|
+
|
53
|
+
class ActiveRecordPermissionsTest < Test::Unit::TestCase
|
54
|
+
def setup
|
55
|
+
@model = PermissionModel.new
|
56
|
+
end
|
57
|
+
|
58
|
+
# Combinations Legend:
|
59
|
+
# columns are: crud_type method, column method, crud_type/column method
|
60
|
+
# symbols are: is (a)bsent, returns (f)alse, returns (t)rue, or n/a (_)
|
61
|
+
def test_method_combinations_with_default_true
|
62
|
+
ActiveRecordPermissions.default_permission = true
|
63
|
+
|
64
|
+
pass(@model.authorized_for?(:column => :a3), '_a_')
|
65
|
+
fail(@model.authorized_for?(:column => :a2), '_f_')
|
66
|
+
pass(@model.authorized_for?(:column => :a1), '_t_')
|
67
|
+
|
68
|
+
pass(@model.authorized_for?(:crud_type => :create), 'a__')
|
69
|
+
fail(@model.authorized_for?(:crud_type => :update), 'f__')
|
70
|
+
pass(@model.authorized_for?(:crud_type => :read), 't__')
|
71
|
+
|
72
|
+
pass(@model.authorized_for?(:crud_type => :create, :column => :c3), 'aaa')
|
73
|
+
fail(@model.authorized_for?(:crud_type => :create, :column => :b3), 'aaf')
|
74
|
+
pass(@model.authorized_for?(:crud_type => :create, :column => :a3), 'aat')
|
75
|
+
fail(@model.authorized_for?(:crud_type => :create, :column => :c2), 'afa')
|
76
|
+
fail(@model.authorized_for?(:crud_type => :create, :column => :b2), 'aff')
|
77
|
+
pass(@model.authorized_for?(:crud_type => :create, :column => :a2), 'aft')
|
78
|
+
pass(@model.authorized_for?(:crud_type => :create, :column => :c1), 'ata')
|
79
|
+
fail(@model.authorized_for?(:crud_type => :create, :column => :b1), 'atf')
|
80
|
+
pass(@model.authorized_for?(:crud_type => :create, :column => :a1), 'att')
|
81
|
+
|
82
|
+
fail(@model.authorized_for?(:crud_type => :update, :column => :c3), 'faa')
|
83
|
+
fail(@model.authorized_for?(:crud_type => :update, :column => :b3), 'faf')
|
84
|
+
pass(@model.authorized_for?(:crud_type => :update, :column => :a3), 'fat')
|
85
|
+
fail(@model.authorized_for?(:crud_type => :update, :column => :c2), 'ffa')
|
86
|
+
fail(@model.authorized_for?(:crud_type => :update, :column => :b2), 'fff')
|
87
|
+
pass(@model.authorized_for?(:crud_type => :update, :column => :a2), 'fft')
|
88
|
+
fail(@model.authorized_for?(:crud_type => :update, :column => :c1), 'fta')
|
89
|
+
fail(@model.authorized_for?(:crud_type => :update, :column => :b1), 'ftf')
|
90
|
+
pass(@model.authorized_for?(:crud_type => :update, :column => :a1), 'ftt')
|
91
|
+
|
92
|
+
pass(@model.authorized_for?(:crud_type => :read, :column => :c3), 'taa')
|
93
|
+
fail(@model.authorized_for?(:crud_type => :read, :column => :b3), 'taf')
|
94
|
+
pass(@model.authorized_for?(:crud_type => :read, :column => :a3), 'tat')
|
95
|
+
fail(@model.authorized_for?(:crud_type => :read, :column => :c2), 'tfa')
|
96
|
+
fail(@model.authorized_for?(:crud_type => :read, :column => :b2), 'tff')
|
97
|
+
pass(@model.authorized_for?(:crud_type => :read, :column => :a2), 'tft')
|
98
|
+
pass(@model.authorized_for?(:crud_type => :read, :column => :c1), 'tta')
|
99
|
+
fail(@model.authorized_for?(:crud_type => :read, :column => :b1), 'ttf')
|
100
|
+
pass(@model.authorized_for?(:crud_type => :read, :column => :a1), 'ttt')
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_method_combinations_with_default_false
|
104
|
+
ActiveRecordPermissions.default_permission = false
|
105
|
+
|
106
|
+
fail(@model.authorized_for?(:column => :a3), '_a_')
|
107
|
+
fail(@model.authorized_for?(:column => :a2), '_f_')
|
108
|
+
pass(@model.authorized_for?(:column => :a1), '_t_')
|
109
|
+
|
110
|
+
fail(@model.authorized_for?(:crud_type => :create), 'a__')
|
111
|
+
fail(@model.authorized_for?(:crud_type => :update), 'f__')
|
112
|
+
pass(@model.authorized_for?(:crud_type => :read), 't__')
|
113
|
+
|
114
|
+
fail(@model.authorized_for?(:crud_type => :create, :column => :c3), 'aaa')
|
115
|
+
fail(@model.authorized_for?(:crud_type => :create, :column => :b3), 'aaf')
|
116
|
+
pass(@model.authorized_for?(:crud_type => :create, :column => :a3), 'aat')
|
117
|
+
fail(@model.authorized_for?(:crud_type => :create, :column => :c2), 'afa')
|
118
|
+
fail(@model.authorized_for?(:crud_type => :create, :column => :b2), 'aff')
|
119
|
+
pass(@model.authorized_for?(:crud_type => :create, :column => :a2), 'aft')
|
120
|
+
pass(@model.authorized_for?(:crud_type => :create, :column => :c1), 'ata')
|
121
|
+
fail(@model.authorized_for?(:crud_type => :create, :column => :b1), 'atf')
|
122
|
+
pass(@model.authorized_for?(:crud_type => :create, :column => :a1), 'att')
|
123
|
+
|
124
|
+
fail(@model.authorized_for?(:crud_type => :update, :column => :c3), 'faa')
|
125
|
+
fail(@model.authorized_for?(:crud_type => :update, :column => :b3), 'faf')
|
126
|
+
pass(@model.authorized_for?(:crud_type => :update, :column => :a3), 'fat')
|
127
|
+
fail(@model.authorized_for?(:crud_type => :update, :column => :c2), 'ffa')
|
128
|
+
fail(@model.authorized_for?(:crud_type => :update, :column => :b2), 'fff')
|
129
|
+
pass(@model.authorized_for?(:crud_type => :update, :column => :a2), 'fft')
|
130
|
+
fail(@model.authorized_for?(:crud_type => :update, :column => :c1), 'fta')
|
131
|
+
fail(@model.authorized_for?(:crud_type => :update, :column => :b1), 'ftf')
|
132
|
+
pass(@model.authorized_for?(:crud_type => :update, :column => :a1), 'ftt')
|
133
|
+
|
134
|
+
pass(@model.authorized_for?(:crud_type => :read, :column => :c3), 'taa')
|
135
|
+
fail(@model.authorized_for?(:crud_type => :read, :column => :b3), 'taf')
|
136
|
+
pass(@model.authorized_for?(:crud_type => :read, :column => :a3), 'tat')
|
137
|
+
fail(@model.authorized_for?(:crud_type => :read, :column => :c2), 'tfa')
|
138
|
+
fail(@model.authorized_for?(:crud_type => :read, :column => :b2), 'tff')
|
139
|
+
pass(@model.authorized_for?(:crud_type => :read, :column => :a2), 'tft')
|
140
|
+
pass(@model.authorized_for?(:crud_type => :read, :column => :c1), 'tta')
|
141
|
+
fail(@model.authorized_for?(:crud_type => :read, :column => :b1), 'ttf')
|
142
|
+
pass(@model.authorized_for?(:crud_type => :read, :column => :a1), 'ttt')
|
143
|
+
end
|
144
|
+
|
145
|
+
private
|
146
|
+
|
147
|
+
def pass(value, message = nil)
|
148
|
+
assert value, "#{message} should pass"
|
149
|
+
end
|
150
|
+
|
151
|
+
def fail(value, message = nil)
|
152
|
+
assert !value, "#{message} should fail"
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
|
3
|
+
class NumberModel < ActiveRecord::Base
|
4
|
+
abstract_class = true
|
5
|
+
def self.columns
|
6
|
+
@columns ||= [ActiveRecord::ConnectionAdapters::Column.new('number', '', 'double(10,2)')]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class AttributeParamsTest < Test::Unit::TestCase
|
11
|
+
include ActiveScaffold::AttributeParams
|
12
|
+
|
13
|
+
def setup
|
14
|
+
I18n.backend.store_translations :en, :number => {:format => {
|
15
|
+
:delimiter => ',',
|
16
|
+
:separator => '.'
|
17
|
+
}}
|
18
|
+
I18n.backend.store_translations :es, :number => {:format => {
|
19
|
+
:delimiter => '.',
|
20
|
+
:separator => ','
|
21
|
+
}}
|
22
|
+
|
23
|
+
@config = config_for('number_model')
|
24
|
+
class << @config.list.columns
|
25
|
+
include ActiveScaffold::DataStructures::ActionColumns::AfterConfiguration
|
26
|
+
end
|
27
|
+
@config.list.columns.set_columns @config.columns
|
28
|
+
end
|
29
|
+
|
30
|
+
def teardown
|
31
|
+
I18n.locale = :en
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_english_format_with_decimal_separator_using_english_language
|
35
|
+
I18n.locale = :en
|
36
|
+
assert_equal 0.1, convert_number('.1')
|
37
|
+
assert_equal 0.1, convert_number('.100')
|
38
|
+
assert_equal 0.1, convert_number('0.1')
|
39
|
+
assert_equal 0.345, convert_number('0.345')
|
40
|
+
assert_equal 0.345, convert_number('+0.345')
|
41
|
+
assert_equal -0.345, convert_number('-0.345')
|
42
|
+
assert_equal 9.345, convert_number('9.345')
|
43
|
+
assert_equal 9.1, convert_number('9.1')
|
44
|
+
assert_equal 90.1, convert_number('90.1')
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_english_format_with_thousand_delimiter_using_english_language
|
48
|
+
I18n.locale = :en
|
49
|
+
assert_equal 1000, convert_number('1,000')
|
50
|
+
assert_equal 1000, convert_number('+1,000')
|
51
|
+
assert_equal -1000, convert_number('-1,000')
|
52
|
+
assert_equal 1000000, convert_number('1,000,000')
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_english_format_with_separator_and_delimiter_using_english_language
|
56
|
+
I18n.locale = :en
|
57
|
+
assert_equal 1234.1, convert_number('1,234.1')
|
58
|
+
assert_equal 1234.1, convert_number('1,234.100')
|
59
|
+
assert_equal 1234.345, convert_number('+1,234.345')
|
60
|
+
assert_equal -1234.345, convert_number('-1,234.345')
|
61
|
+
assert_equal 1234000.1, convert_number('1,234,000.100')
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_english_format_with_decimal_separator_using_spanish_language
|
65
|
+
I18n.locale = :es
|
66
|
+
assert_equal 0.1, convert_number('.1')
|
67
|
+
assert_equal 0.1, convert_number('0.1')
|
68
|
+
assert_equal 0.12, convert_number('+0.12')
|
69
|
+
assert_equal -0.12, convert_number('-0.12')
|
70
|
+
assert_equal 9.1, convert_number('9.1')
|
71
|
+
assert_equal 90.1, convert_number('90.1')
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_spanish_format_with_decimal_separator_using_spanish_language
|
75
|
+
I18n.locale = :es
|
76
|
+
assert_equal 0.1, convert_number(',1')
|
77
|
+
assert_equal 0.1, convert_number(',100')
|
78
|
+
assert_equal 0.1, convert_number('0,1')
|
79
|
+
assert_equal 0.345, convert_number('0,345')
|
80
|
+
assert_equal 0.345, convert_number('+0,345')
|
81
|
+
assert_equal -0.345, convert_number('-0,345')
|
82
|
+
assert_equal 9.1, convert_number('9,1')
|
83
|
+
assert_equal 90.1, convert_number('90,1')
|
84
|
+
assert_equal 9.1, convert_number('9,100')
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_spanish_format_with_thousand_delimiter_using_spanish_language
|
88
|
+
I18n.locale = :es
|
89
|
+
assert_equal 1000, convert_number('1.000')
|
90
|
+
assert_equal 1000, convert_number('+1.000')
|
91
|
+
assert_equal -1000, convert_number('-1.000')
|
92
|
+
assert_equal 1000000, convert_number('1.000.000')
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_spanish_format_with_separator_and_decimal_using_spanish_language
|
96
|
+
I18n.locale = :es
|
97
|
+
assert_equal 1230.1, convert_number('1.230,1')
|
98
|
+
assert_equal 1230.1, convert_number('1.230,100')
|
99
|
+
assert_equal 1234.345, convert_number('+1.234,345')
|
100
|
+
assert_equal -1234.345, convert_number('-1.234,345')
|
101
|
+
assert_equal 1234000.1, convert_number('1.234.000,100')
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
def convert_number(value)
|
106
|
+
record = NumberModel.new
|
107
|
+
update_record_from_params(record, @config.list.columns, HashWithIndifferentAccess.new({:number => value}))
|
108
|
+
record.number
|
109
|
+
end
|
110
|
+
end
|