active_scaffold_san 3.0.18
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +27 -0
- data/.document +5 -0
- data/CHANGELOG +179 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +20 -0
- data/MIT-LICENSE +20 -0
- data/README +69 -0
- data/Rakefile +53 -0
- data/active_scaffold_vho.gemspec +388 -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/config.png +0 -0
- data/frontends/default/images/cross.png +0 -0
- data/frontends/default/images/gears.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 +1004 -0
- data/frontends/default/javascripts/jquery/jquery.editinplace.js +743 -0
- data/frontends/default/javascripts/prototype/active_scaffold.js +1003 -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 +973 -0
- data/frontends/default/views/_action_group.html.erb +20 -0
- data/frontends/default/views/_add_existing_form.html.erb +30 -0
- data/frontends/default/views/_base_form.html.erb +51 -0
- data/frontends/default/views/_create_form.html.erb +8 -0
- data/frontends/default/views/_create_form_on_list.html.erb +6 -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 +19 -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 +29 -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 +15 -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 +10 -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 +10 -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 +15 -0
- data/frontends/default/views/_update_actions.html.erb +9 -0
- data/frontends/default/views/_update_form.html.erb +6 -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/action_confirmation.html.erb +13 -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 +23 -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 +41 -0
- data/frontends/default/views/on_mark_all.js.rjs +4 -0
- data/frontends/default/views/on_update.js.rjs +28 -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 +8 -0
- data/lib/active_scaffold.rb +360 -0
- data/lib/active_scaffold/actions/common_search.rb +22 -0
- data/lib/active_scaffold/actions/core.rb +180 -0
- data/lib/active_scaffold/actions/create.rb +149 -0
- data/lib/active_scaffold/actions/delete.rb +75 -0
- data/lib/active_scaffold/actions/field_search.rb +82 -0
- data/lib/active_scaffold/actions/list.rb +184 -0
- data/lib/active_scaffold/actions/mark.rb +63 -0
- data/lib/active_scaffold/actions/nested.rb +250 -0
- data/lib/active_scaffold/actions/search.rb +47 -0
- data/lib/active_scaffold/actions/show.rb +61 -0
- data/lib/active_scaffold/actions/subform.rb +27 -0
- data/lib/active_scaffold/actions/update.rb +151 -0
- data/lib/active_scaffold/active_record_permissions.rb +134 -0
- data/lib/active_scaffold/attribute_params.rb +211 -0
- data/lib/active_scaffold/bridges/ancestry/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb +39 -0
- data/lib/active_scaffold/bridges/bridge.rb +59 -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 +83 -0
- data/lib/active_scaffold/bridges/cancan/bridge.rb +12 -0
- data/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb +107 -0
- data/lib/active_scaffold/bridges/carrierwave/bridge.rb +9 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +33 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +12 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +45 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb +17 -0
- data/lib/active_scaffold/bridges/date_picker/bridge.rb +24 -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 +209 -0
- data/lib/active_scaffold/bridges/tiny_mce/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb +61 -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 +62 -0
- data/lib/active_scaffold/config/core.rb +220 -0
- data/lib/active_scaffold/config/create.rb +51 -0
- data/lib/active_scaffold/config/delete.rb +34 -0
- data/lib/active_scaffold/config/field_search.rb +75 -0
- data/lib/active_scaffold/config/form.rb +47 -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 +44 -0
- data/lib/active_scaffold/config/search.rb +69 -0
- data/lib/active_scaffold/config/show.rb +35 -0
- data/lib/active_scaffold/config/subform.rb +35 -0
- data/lib/active_scaffold/config/update.rb +46 -0
- data/lib/active_scaffold/configurable.rb +29 -0
- data/lib/active_scaffold/constraints.rb +184 -0
- data/lib/active_scaffold/data_structures/action_columns.rb +137 -0
- data/lib/active_scaffold/data_structures/action_link.rb +175 -0
- data/lib/active_scaffold/data_structures/action_links.rb +185 -0
- data/lib/active_scaffold/data_structures/actions.rb +45 -0
- data/lib/active_scaffold/data_structures/column.rb +355 -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 +123 -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/extensions/action_controller_rendering.rb +20 -0
- data/lib/active_scaffold/extensions/action_view_rendering.rb +123 -0
- data/lib/active_scaffold/extensions/action_view_resolver.rb +7 -0
- data/lib/active_scaffold/extensions/active_association_reflection.rb +13 -0
- data/lib/active_scaffold/extensions/active_record_offset.rb +12 -0
- data/lib/active_scaffold/extensions/array.rb +7 -0
- data/lib/active_scaffold/extensions/localize.rb +10 -0
- data/lib/active_scaffold/extensions/name_option_for_datetime.rb +12 -0
- data/lib/active_scaffold/extensions/nil_id_in_url_params.rb +7 -0
- data/lib/active_scaffold/extensions/paginator_extensions.rb +26 -0
- data/lib/active_scaffold/extensions/reverse_associations.rb +62 -0
- data/lib/active_scaffold/extensions/routing_mapper.rb +34 -0
- data/lib/active_scaffold/extensions/to_label.rb +8 -0
- data/lib/active_scaffold/extensions/unsaved_associated.rb +61 -0
- data/lib/active_scaffold/extensions/unsaved_record.rb +20 -0
- data/lib/active_scaffold/extensions/usa_state.rb +46 -0
- data/lib/active_scaffold/finder.rb +343 -0
- data/lib/active_scaffold/helpers/association_helpers.rb +40 -0
- data/lib/active_scaffold/helpers/controller_helpers.rb +87 -0
- data/lib/active_scaffold/helpers/country_helpers.rb +352 -0
- data/lib/active_scaffold/helpers/form_column_helpers.rb +350 -0
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +59 -0
- data/lib/active_scaffold/helpers/id_helpers.rb +127 -0
- data/lib/active_scaffold/helpers/list_column_helpers.rb +361 -0
- data/lib/active_scaffold/helpers/pagination_helpers.rb +55 -0
- data/lib/active_scaffold/helpers/search_column_helpers.rb +249 -0
- data/lib/active_scaffold/helpers/show_column_helpers.rb +46 -0
- data/lib/active_scaffold/helpers/view_helpers.rb +360 -0
- data/lib/active_scaffold/locale/de.rb +120 -0
- data/lib/active_scaffold/locale/en.rb +119 -0
- data/lib/active_scaffold/locale/es.yml +115 -0
- data/lib/active_scaffold/locale/fr.rb +122 -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 +119 -0
- data/lib/active_scaffold/marked_model.rb +38 -0
- data/lib/active_scaffold/paginator.rb +136 -0
- data/lib/active_scaffold/responds_to_parent.rb +70 -0
- data/lib/active_scaffold/version.rb +9 -0
- data/lib/active_scaffold_assets.rb +45 -0
- data/lib/active_scaffold_env.rb +14 -0
- data/lib/active_scaffold_vho.rb +2 -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 +29 -0
- data/lib/generators/active_scaffold_controller/templates/controller.rb +4 -0
- data/lib/generators/active_scaffold_controller/templates/helper.rb +2 -0
- data/lib/generators/active_scaffold_setup/USAGE +10 -0
- data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +61 -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 +842 -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 +497 -0
@@ -0,0 +1,96 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
|
3
|
+
class ConfigurableClass
|
4
|
+
FOO = 'bar'
|
5
|
+
def foo; FOO end
|
6
|
+
def self.foo; FOO end
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
class ConfigurableTest < Test::Unit::TestCase
|
11
|
+
##
|
12
|
+
## constants and methods for tests to check against
|
13
|
+
##
|
14
|
+
def hello; 'world' end
|
15
|
+
HELLO = 'world'
|
16
|
+
|
17
|
+
def test_instance_configuration
|
18
|
+
ConfigurableClass.send :include, ActiveScaffold::Configurable
|
19
|
+
|
20
|
+
configurable_class = ConfigurableClass.new
|
21
|
+
|
22
|
+
##
|
23
|
+
## sanity checks
|
24
|
+
##
|
25
|
+
# make sure the configure method is available
|
26
|
+
assert ConfigurableClass.respond_to?(:configure)
|
27
|
+
# make sure real functions still work
|
28
|
+
assert_equal 'bar', configurable_class.foo
|
29
|
+
# make sure other functions still don't work
|
30
|
+
assert_raise NoMethodError do
|
31
|
+
configurable_class.i_do_not_exist
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
## test normal block behaviors
|
36
|
+
##
|
37
|
+
# functions
|
38
|
+
assert_equal hello, configurable_class.configure {hello}
|
39
|
+
# variables
|
40
|
+
assert_equal configurable_class, configurable_class.configure {configurable_class}
|
41
|
+
# constants
|
42
|
+
assert_equal ConfigurableTest::HELLO, configurable_class.configure {ConfigurableTest::HELLO}
|
43
|
+
|
44
|
+
##
|
45
|
+
## test extra "localized" block behavior
|
46
|
+
##
|
47
|
+
# functions
|
48
|
+
assert_equal configurable_class.foo, configurable_class.configure {foo}
|
49
|
+
# constants - not working
|
50
|
+
# assert_equal configurable_class.FOO, configurable_class.configure {FOO}
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_class_configuration
|
55
|
+
ConfigurableClass.send :extend, ActiveScaffold::Configurable
|
56
|
+
|
57
|
+
##
|
58
|
+
## sanity checks
|
59
|
+
##
|
60
|
+
# make sure the configure method is available
|
61
|
+
assert ConfigurableClass.respond_to?(:configure)
|
62
|
+
# make sure real functions still work
|
63
|
+
assert_equal 'bar', ConfigurableClass.foo
|
64
|
+
# make sure other functions still don't work
|
65
|
+
assert_raise NoMethodError do
|
66
|
+
ConfigurableClass.i_do_not_exist
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
## test normal block behaviors
|
71
|
+
##
|
72
|
+
# functions
|
73
|
+
assert_equal hello, ConfigurableClass.configure {hello}
|
74
|
+
# variables
|
75
|
+
assert_equal ConfigurableClass, ConfigurableClass.configure {ConfigurableClass}
|
76
|
+
# constants
|
77
|
+
assert_equal ConfigurableTest::HELLO, ConfigurableClass.configure {ConfigurableTest::HELLO}
|
78
|
+
|
79
|
+
##
|
80
|
+
## test extra "localized" block behavior
|
81
|
+
##
|
82
|
+
# functions
|
83
|
+
assert_equal ConfigurableClass.foo, ConfigurableClass.configure {foo}
|
84
|
+
# constants - not working
|
85
|
+
# assert_equal ConfigurableClass.FOO, ConfigurableClass.configure {FOO}
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_arity
|
89
|
+
ConfigurableClass.send :extend, ActiveScaffold::Configurable
|
90
|
+
|
91
|
+
# this is the main style
|
92
|
+
assert_equal 'foo', ConfigurableClass.configure {'foo'}
|
93
|
+
# but we want to let people accept the configurable class as the first argument, too
|
94
|
+
assert_equal 'bar', ConfigurableClass.configure {|a| a.foo}
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
|
3
|
+
module ModelStubs
|
4
|
+
class ModelStub < ActiveRecord::Base
|
5
|
+
abstract_class = true
|
6
|
+
def self.columns; [ActiveRecord::ConnectionAdapters::Column.new('foo', '')] end
|
7
|
+
def self.table_name
|
8
|
+
to_s.split('::').last.underscore.pluralize
|
9
|
+
end
|
10
|
+
self.store_full_sti_class = false
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
## Standard associations
|
15
|
+
##
|
16
|
+
|
17
|
+
class Address < ModelStub
|
18
|
+
belongs_to :addressable, :polymorphic => true
|
19
|
+
end
|
20
|
+
|
21
|
+
class User < ModelStub
|
22
|
+
has_and_belongs_to_many :roles
|
23
|
+
has_one :subscription
|
24
|
+
has_one :address, :as => :addressable
|
25
|
+
end
|
26
|
+
|
27
|
+
class Service < ModelStub
|
28
|
+
has_many :subscriptions
|
29
|
+
has_many :users, :through => :subscriptions
|
30
|
+
end
|
31
|
+
|
32
|
+
class Subscription < ModelStub
|
33
|
+
belongs_to :service
|
34
|
+
belongs_to :user
|
35
|
+
end
|
36
|
+
|
37
|
+
class Role < ModelStub
|
38
|
+
has_and_belongs_to_many :users
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
## These versions of the associations require extra configuration to work properly
|
43
|
+
##
|
44
|
+
|
45
|
+
class OtherAddress < ModelStub
|
46
|
+
set_table_name 'addresses'
|
47
|
+
belongs_to :other_addressable, :polymorphic => true
|
48
|
+
end
|
49
|
+
|
50
|
+
class OtherUser < ModelStub
|
51
|
+
set_table_name 'users'
|
52
|
+
has_and_belongs_to_many :other_roles, :class_name => 'ModelStubs::OtherRole', :foreign_key => 'user_id', :association_foreign_key => 'role_id', :join_table => 'roles_users'
|
53
|
+
has_one :other_subscription, :class_name => 'ModelStubs::OtherSubscription', :foreign_key => 'user_id'
|
54
|
+
has_one :other_address, :as => :other_addressable, :class_name => 'ModelStubs::OtherAddress', :foreign_key => 'addressable_id'
|
55
|
+
end
|
56
|
+
|
57
|
+
class OtherService < ModelStub
|
58
|
+
set_table_name 'services'
|
59
|
+
has_many :other_subscriptions, :class_name => 'ModelStubs::OtherSubscription', :foreign_key => 'service_id'
|
60
|
+
has_many :other_users, :through => :other_subscriptions # :class_name and :foreign_key are ignored for :through
|
61
|
+
end
|
62
|
+
|
63
|
+
class OtherSubscription < ModelStub
|
64
|
+
set_table_name 'subscriptions'
|
65
|
+
belongs_to :other_service, :class_name => 'ModelStubs::OtherService', :foreign_key => 'service_id'
|
66
|
+
belongs_to :other_user, :class_name => 'ModelStubs::OtherUser', :foreign_key => 'user_id'
|
67
|
+
end
|
68
|
+
|
69
|
+
class OtherRole < ModelStub
|
70
|
+
set_table_name 'roles'
|
71
|
+
has_and_belongs_to_many :other_users, :class_name => 'ModelStubs::OtherUser', :foreign_key => 'role_id', :association_foreign_key => 'user_id', :join_table => 'roles_users'
|
72
|
+
end
|
73
|
+
|
74
|
+
class PrimaryKeyUser < ModelStub
|
75
|
+
has_many :locations, :class_name => 'PrimaryKeyLocation', :foreign_key => :username, :primary_key => :name
|
76
|
+
end
|
77
|
+
|
78
|
+
class PrimaryKeyLocation < ModelStub
|
79
|
+
belongs_to :user, :class_name => 'PrimaryKeyUser', :foreign_key => :username, :primary_key => :name
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class ConstraintsTestObject
|
84
|
+
# stub out what the mixin expects to find ...
|
85
|
+
def self.before_filter(*args); end
|
86
|
+
attr_accessor :active_scaffold_includes
|
87
|
+
attr_accessor :active_scaffold_habtm_joins
|
88
|
+
attr_accessor :active_scaffold_config
|
89
|
+
attr_accessor :params
|
90
|
+
def merge_conditions(old, new)
|
91
|
+
[old, new].compact.flatten
|
92
|
+
end
|
93
|
+
|
94
|
+
# mixin the constraint code
|
95
|
+
include ActiveScaffold::Constraints
|
96
|
+
|
97
|
+
# make the constraints read-write, instead of coming from the session
|
98
|
+
attr_accessor :active_scaffold_constraints
|
99
|
+
|
100
|
+
def initialize
|
101
|
+
@active_scaffold_includes = []
|
102
|
+
@active_scaffold_habtm_joins = []
|
103
|
+
@params = {}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class ConstraintsTest < Test::Unit::TestCase
|
108
|
+
def setup
|
109
|
+
@test_object = ConstraintsTestObject.new
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_constraint_conditions_for_default_associations
|
113
|
+
@test_object.active_scaffold_config = config_for('user')
|
114
|
+
# has_one (vs belongs_to)
|
115
|
+
assert_constraint_condition({:subscription => 5}, ['subscriptions.id = ?', 5], 'find the user with subscription #5')
|
116
|
+
# habtm (vs habtm)
|
117
|
+
assert_constraint_condition({:roles => 4}, ['roles_users.role_id = ?', 4], 'find all users with role #4')
|
118
|
+
# has_one (vs polymorphic)
|
119
|
+
assert_constraint_condition({:address => 11}, ['addresses.id = ?', 11], 'find the user with address #11')
|
120
|
+
# reverse of a has_many :through
|
121
|
+
assert_constraint_condition({:subscription => {:service => 5}}, ['services.id = ?', 5], 'find all users subscribed to service #5')
|
122
|
+
assert(@test_object.active_scaffold_includes.include?({:subscription => :service}), 'multi-level association include')
|
123
|
+
|
124
|
+
@test_object.active_scaffold_config = config_for('subscription')
|
125
|
+
# belongs_to (vs has_one)
|
126
|
+
assert_constraint_condition({:user => 2}, ['subscriptions.user_id = ?', 2], 'find the subscription for user #2')
|
127
|
+
# belongs_to (vs has_many)
|
128
|
+
assert_constraint_condition({:service => 1}, ['subscriptions.service_id = ?', 1], 'find all subscriptions for service #1')
|
129
|
+
|
130
|
+
@test_object.active_scaffold_config = config_for('service')
|
131
|
+
# has_many (vs belongs_to)
|
132
|
+
assert_constraint_condition({:subscriptions => 10}, ['subscriptions.id = ?', 10], 'find the service with subscription #10')
|
133
|
+
# has_many :through (through has_many)
|
134
|
+
assert_constraint_condition({:users => 7}, ['users.id = ?', 7], 'find the service with user #7')
|
135
|
+
|
136
|
+
@test_object.active_scaffold_config = config_for('address')
|
137
|
+
# belongs_to :polymorphic => true
|
138
|
+
@test_object.params[:parent_model] = 'User'
|
139
|
+
assert_constraint_condition({:addressable => 14}, ['addresses.addressable_id = ?', 14, 'addresses.addressable_type = ?', 'User'], 'find all addresses for user #14')
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_constraint_conditions_for_configured_associations
|
143
|
+
@test_object.active_scaffold_config = config_for('other_user')
|
144
|
+
# has_one (vs belongs_to)
|
145
|
+
assert_constraint_condition({:other_subscription => 5}, ['subscriptions.id = ?', 5], 'find the user with subscription #5')
|
146
|
+
# habtm (vs habtm)
|
147
|
+
assert_constraint_condition({:other_roles => 4}, ['roles_users.role_id = ?', 4], 'find all users with role #4')
|
148
|
+
# has_one (vs polymorphic)
|
149
|
+
assert_constraint_condition({:other_address => 11}, ['addresses.id = ?', 11], 'find the user with address #11')
|
150
|
+
# reverse of a has_many :through
|
151
|
+
assert_constraint_condition({:other_subscription => {:other_service => 5}}, ['services.id = ?', 5], 'find all users subscribed to service #5')
|
152
|
+
|
153
|
+
@test_object.active_scaffold_config = config_for('other_subscription')
|
154
|
+
# belongs_to (vs has_one)
|
155
|
+
assert_constraint_condition({:other_user => 2}, ['subscriptions.user_id = ?', 2], 'find the subscription for user #2')
|
156
|
+
# belongs_to (vs has_many)
|
157
|
+
assert_constraint_condition({:other_service => 1}, ['subscriptions.service_id = ?', 1], 'find all subscriptions for service #1')
|
158
|
+
|
159
|
+
@test_object.active_scaffold_config = config_for('other_service')
|
160
|
+
# has_many (vs belongs_to)
|
161
|
+
assert_constraint_condition({:other_subscriptions => 10}, ['subscriptions.id = ?', 10], 'find the service with subscription #10')
|
162
|
+
# has_many :through (through has_many)
|
163
|
+
assert_constraint_condition({:other_users => 7}, ['users.id = ?', 7], 'find the service with user #7')
|
164
|
+
|
165
|
+
@test_object.active_scaffold_config = config_for('other_address')
|
166
|
+
# belongs_to :polymorphic => true
|
167
|
+
@test_object.params[:parent_model] = 'OtherUser'
|
168
|
+
assert_constraint_condition({:other_addressable => 14}, ['addresses.other_addressable_id = ?', 14, 'addresses.other_addressable_type = ?', 'OtherUser'], 'find all addresses for user #14')
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_constraint_conditions_for_normal_attributes
|
172
|
+
@test_object.active_scaffold_config = config_for('user')
|
173
|
+
assert_constraint_condition({'foo' => 'bar'}, ['"users"."foo" = ?', 'bar'], 'normal column-based constraint')
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_constraint_conditions_for_associations_with_primary_key_option
|
177
|
+
@test_object.active_scaffold_config = config_for('primary_key_location')
|
178
|
+
#user = ModelStubs::PrimaryKeyUser.new(:id => 1, :name => 'User Name')
|
179
|
+
ModelStubs::PrimaryKeyUser.expects(:find).with(1).returns(stub(:id => 1, :name => 'User Name'))
|
180
|
+
assert_constraint_condition({'user' => 1}, ['primary_key_locations.username = ?', 'User Name'], 'association with primary-key constraint')
|
181
|
+
end
|
182
|
+
|
183
|
+
protected
|
184
|
+
|
185
|
+
def assert_constraint_condition(constraint, condition, message = nil)
|
186
|
+
@test_object.active_scaffold_constraints = constraint
|
187
|
+
assert_equal condition, @test_object.send(:conditions_from_constraints), message
|
188
|
+
end
|
189
|
+
|
190
|
+
def config_for(klass, namespace = nil)
|
191
|
+
super(klass, "model_stubs/")
|
192
|
+
end
|
193
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
# require 'test/model_stub'
|
3
|
+
|
4
|
+
class ClassWithFinder
|
5
|
+
include ActiveScaffold::Finder
|
6
|
+
def conditions_for_collection; end
|
7
|
+
def conditions_from_params; end
|
8
|
+
def conditions_from_constraints; end
|
9
|
+
def joins_for_collection; end
|
10
|
+
def custom_finder_options
|
11
|
+
{}
|
12
|
+
end
|
13
|
+
def beginning_of_chain
|
14
|
+
active_scaffold_config.model
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class FinderTest < Test::Unit::TestCase
|
19
|
+
def setup
|
20
|
+
@klass = ClassWithFinder.new
|
21
|
+
@klass.stubs(:active_scaffold_config).returns(mock { stubs(:model).returns(ModelStub) })
|
22
|
+
@klass.stubs(:active_scaffold_session_storage).returns({})
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_create_conditions_for_columns
|
26
|
+
columns = [
|
27
|
+
ActiveScaffold::DataStructures::Column.new(:a, ModelStub),
|
28
|
+
ActiveScaffold::DataStructures::Column.new(:b, ModelStub)
|
29
|
+
]
|
30
|
+
tokens = [
|
31
|
+
'foo',
|
32
|
+
'bar'
|
33
|
+
]
|
34
|
+
|
35
|
+
expected_conditions = [
|
36
|
+
'("model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?) AND ("model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?)',
|
37
|
+
'%foo%', '%foo%', '%bar%', '%bar%'
|
38
|
+
]
|
39
|
+
assert_equal expected_conditions, ClassWithFinder.create_conditions_for_columns(tokens, columns)
|
40
|
+
|
41
|
+
expected_conditions = [
|
42
|
+
'("model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?)',
|
43
|
+
'%foo%', '%foo%'
|
44
|
+
]
|
45
|
+
assert_equal expected_conditions, ClassWithFinder.create_conditions_for_columns('foo', columns)
|
46
|
+
|
47
|
+
assert_equal nil, ClassWithFinder.create_conditions_for_columns('foo', [])
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_method_sorting
|
51
|
+
column = ActiveScaffold::DataStructures::Column.new('a', ModelStub)
|
52
|
+
column.sort_by :method => proc{self}
|
53
|
+
|
54
|
+
collection = [16000, 2853, 98765, 6188, 4]
|
55
|
+
assert_equal collection.sort, @klass.send(:sort_collection_by_column, collection, column, 'asc')
|
56
|
+
assert_equal collection.sort.reverse, @klass.send(:sort_collection_by_column, collection, column, 'desc')
|
57
|
+
|
58
|
+
collection = ['a', nil, 'b']
|
59
|
+
result = nil
|
60
|
+
assert_nothing_raised do
|
61
|
+
result = @klass.send(:sort_collection_by_column, collection, column, 'asc')
|
62
|
+
end
|
63
|
+
assert_equal [nil, 'a', 'b'], result
|
64
|
+
|
65
|
+
column.sort_by :method => 'self'
|
66
|
+
collection = [3, 1, 2]
|
67
|
+
assert_equal collection.sort, @klass.send(:sort_collection_by_column, collection, column, 'asc')
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_count_with_group
|
71
|
+
@klass.expects(:custom_finder_options).returns({:group => :a})
|
72
|
+
ModelStub.expects(:count).returns(ActiveSupport::OrderedHash['foo', 5])
|
73
|
+
ModelStub.expects(:find).with(:all, has_entries(:limit => 20, :offset => 0))
|
74
|
+
page = @klass.send :find_page, :per_page => 20, :pagination => true
|
75
|
+
page.items
|
76
|
+
|
77
|
+
assert_kind_of Integer, page.pager.count
|
78
|
+
assert_equal 1, page.pager.count
|
79
|
+
assert_nothing_raised { page.pager.number_of_pages }
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_disabled_pagination
|
83
|
+
ModelStub.expects(:count).returns(85)
|
84
|
+
ModelStub.expects(:find).with(:all, Not(has_entries(:limit => 20, :offset => 0)))
|
85
|
+
page = @klass.send :find_page, :per_page => 20, :pagination => false
|
86
|
+
page.items
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_infinite_pagination
|
90
|
+
ModelStub.expects(:count).never
|
91
|
+
page = @klass.send :find_page, :pagination => :infinite
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
|
3
|
+
class LocalizationTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_localization
|
6
|
+
##
|
7
|
+
## test no language specified
|
8
|
+
##
|
9
|
+
assert_equal "Dutch", as_(:dutch)
|
10
|
+
assert_equal "Create Test", as_(:create_model, :model => 'Test')
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Filters added to this controller apply to all controllers in the application.
|
2
|
+
# Likewise, all the methods added will be available for all controllers.
|
3
|
+
|
4
|
+
class ApplicationController < ActionController::Base
|
5
|
+
helper :all # include all helpers, all the time
|
6
|
+
protect_from_forgery # See ActionController::RequestForgeryProtection for details
|
7
|
+
|
8
|
+
# Scrub sensitive parameters from your log
|
9
|
+
# filter_parameter_logging :password
|
10
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# Don't change this file!
|
2
|
+
# Configure your app in config/environment.rb and config/environments/*.rb
|
3
|
+
|
4
|
+
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
class << self
|
8
|
+
def boot!
|
9
|
+
unless booted?
|
10
|
+
preinitialize
|
11
|
+
pick_boot.run
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def booted?
|
16
|
+
defined? Rails::Initializer
|
17
|
+
end
|
18
|
+
|
19
|
+
def pick_boot
|
20
|
+
(vendor_rails? ? VendorBoot : GemBoot).new
|
21
|
+
end
|
22
|
+
|
23
|
+
def vendor_rails?
|
24
|
+
File.exist?("#{RAILS_ROOT}/vendor/rails")
|
25
|
+
end
|
26
|
+
|
27
|
+
def preinitialize
|
28
|
+
load(preinitializer_path) if File.exist?(preinitializer_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def preinitializer_path
|
32
|
+
"#{RAILS_ROOT}/config/preinitializer.rb"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Boot
|
37
|
+
def run
|
38
|
+
load_initializer
|
39
|
+
Rails::Initializer.run(:set_load_path)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class VendorBoot < Boot
|
44
|
+
def load_initializer
|
45
|
+
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
|
46
|
+
Rails::Initializer.run(:install_gem_spec_stubs)
|
47
|
+
Rails::GemDependency.add_frozen_gem_path
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class GemBoot < Boot
|
52
|
+
def load_initializer
|
53
|
+
self.class.load_rubygems
|
54
|
+
load_rails_gem
|
55
|
+
require 'initializer'
|
56
|
+
end
|
57
|
+
|
58
|
+
def load_rails_gem
|
59
|
+
if version = self.class.gem_version
|
60
|
+
gem 'rails', version
|
61
|
+
else
|
62
|
+
gem 'rails'
|
63
|
+
end
|
64
|
+
rescue Gem::LoadError => load_error
|
65
|
+
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
|
66
|
+
exit 1
|
67
|
+
end
|
68
|
+
|
69
|
+
class << self
|
70
|
+
def rubygems_version
|
71
|
+
Gem::RubyGemsVersion rescue nil
|
72
|
+
end
|
73
|
+
|
74
|
+
def gem_version
|
75
|
+
if defined? RAILS_GEM_VERSION
|
76
|
+
RAILS_GEM_VERSION
|
77
|
+
elsif ENV.include?('RAILS_GEM_VERSION')
|
78
|
+
ENV['RAILS_GEM_VERSION']
|
79
|
+
else
|
80
|
+
parse_gem_version(read_environment_rb)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def load_rubygems
|
85
|
+
require 'rubygems'
|
86
|
+
min_version = '1.3.1'
|
87
|
+
unless rubygems_version >= min_version
|
88
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
|
89
|
+
exit 1
|
90
|
+
end
|
91
|
+
|
92
|
+
rescue LoadError
|
93
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
|
94
|
+
exit 1
|
95
|
+
end
|
96
|
+
|
97
|
+
def parse_gem_version(text)
|
98
|
+
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
def read_environment_rb
|
103
|
+
File.read("#{RAILS_ROOT}/config/environment.rb")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# All that for this:
|
110
|
+
Rails.boot!
|