active_scaffold 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (272) hide show
  1. data/.autotest +27 -0
  2. data/CHANGELOG +152 -0
  3. data/Gemfile +4 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README +51 -0
  6. data/Rakefile +24 -0
  7. data/active_scaffold.gemspec +24 -0
  8. data/environment.rb +22 -0
  9. data/frontends/default/images/add.gif +0 -0
  10. data/frontends/default/images/arrow_down.gif +0 -0
  11. data/frontends/default/images/arrow_up.gif +0 -0
  12. data/frontends/default/images/close.gif +0 -0
  13. data/frontends/default/images/cross.png +0 -0
  14. data/frontends/default/images/indicator-small.gif +0 -0
  15. data/frontends/default/images/indicator.gif +0 -0
  16. data/frontends/default/images/magnifier.png +0 -0
  17. data/frontends/default/javascripts/jquery/active_scaffold.js +957 -0
  18. data/frontends/default/javascripts/jquery/jquery.editinplace.js +726 -0
  19. data/frontends/default/javascripts/prototype/active_scaffold.js +954 -0
  20. data/frontends/default/javascripts/prototype/dhtml_history.js +867 -0
  21. data/frontends/default/javascripts/prototype/form_enhancements.js +117 -0
  22. data/frontends/default/javascripts/prototype/rico_corner.js +370 -0
  23. data/frontends/default/stylesheets/stylesheet-ie.css +35 -0
  24. data/frontends/default/stylesheets/stylesheet.css +858 -0
  25. data/frontends/default/views/_add_existing_form.html.erb +30 -0
  26. data/frontends/default/views/_base_form.html.erb +41 -0
  27. data/frontends/default/views/_create_form.html.erb +6 -0
  28. data/frontends/default/views/_create_form_on_list.html.erb +5 -0
  29. data/frontends/default/views/_field_search.html.erb +32 -0
  30. data/frontends/default/views/_form.html.erb +24 -0
  31. data/frontends/default/views/_form_association.html.erb +14 -0
  32. data/frontends/default/views/_form_association_footer.html.erb +40 -0
  33. data/frontends/default/views/_form_attribute.html.erb +15 -0
  34. data/frontends/default/views/_form_hidden_attribute.html.erb +2 -0
  35. data/frontends/default/views/_form_messages.html.erb +5 -0
  36. data/frontends/default/views/_horizontal_subform.html.erb +19 -0
  37. data/frontends/default/views/_horizontal_subform_header.html.erb +10 -0
  38. data/frontends/default/views/_horizontal_subform_record.html.erb +37 -0
  39. data/frontends/default/views/_human_conditions.html.erb +1 -0
  40. data/frontends/default/views/_list.html.erb +18 -0
  41. data/frontends/default/views/_list_actions.html.erb +16 -0
  42. data/frontends/default/views/_list_calculations.html.erb +16 -0
  43. data/frontends/default/views/_list_column_headings.html.erb +12 -0
  44. data/frontends/default/views/_list_header.html.erb +12 -0
  45. data/frontends/default/views/_list_inline_adapter.html.erb +10 -0
  46. data/frontends/default/views/_list_messages.html.erb +32 -0
  47. data/frontends/default/views/_list_pagination.html.erb +11 -0
  48. data/frontends/default/views/_list_pagination_links.html.erb +9 -0
  49. data/frontends/default/views/_list_record.html.erb +14 -0
  50. data/frontends/default/views/_list_record_columns.html.erb +8 -0
  51. data/frontends/default/views/_list_with_header.html.erb +32 -0
  52. data/frontends/default/views/_messages.html.erb +10 -0
  53. data/frontends/default/views/_render_field.js.rjs +13 -0
  54. data/frontends/default/views/_row.html.erb +12 -0
  55. data/frontends/default/views/_search.html.erb +34 -0
  56. data/frontends/default/views/_search_attribute.html.erb +10 -0
  57. data/frontends/default/views/_show.html.erb +8 -0
  58. data/frontends/default/views/_show_columns.html.erb +12 -0
  59. data/frontends/default/views/_update_actions.html.erb +9 -0
  60. data/frontends/default/views/_update_form.html.erb +5 -0
  61. data/frontends/default/views/_vertical_subform.html.erb +12 -0
  62. data/frontends/default/views/_vertical_subform_record.html.erb +38 -0
  63. data/frontends/default/views/add_existing.js.rjs +17 -0
  64. data/frontends/default/views/add_existing_form.html.erb +5 -0
  65. data/frontends/default/views/create.html.erb +5 -0
  66. data/frontends/default/views/delete.html.erb +13 -0
  67. data/frontends/default/views/destroy.js.rjs +5 -0
  68. data/frontends/default/views/edit_associated.js.rjs +11 -0
  69. data/frontends/default/views/field_search.html.erb +5 -0
  70. data/frontends/default/views/form_messages.js.rjs +1 -0
  71. data/frontends/default/views/list.html.erb +1 -0
  72. data/frontends/default/views/list.js.rjs +1 -0
  73. data/frontends/default/views/on_action_update.js.rjs +8 -0
  74. data/frontends/default/views/on_create.js.rjs +24 -0
  75. data/frontends/default/views/on_update.js.rjs +15 -0
  76. data/frontends/default/views/search.html.erb +5 -0
  77. data/frontends/default/views/show.html.erb +5 -0
  78. data/frontends/default/views/update.html.erb +8 -0
  79. data/frontends/default/views/update_column.js.rjs +13 -0
  80. data/frontends/default/views/update_row.js.rjs +1 -0
  81. data/init.rb +1 -0
  82. data/install_assets.rb +44 -0
  83. data/lib/active_record_permissions.rb +134 -0
  84. data/lib/active_scaffold.rb +279 -0
  85. data/lib/active_scaffold/actions/common_search.rb +22 -0
  86. data/lib/active_scaffold/actions/core.rb +150 -0
  87. data/lib/active_scaffold/actions/create.rb +152 -0
  88. data/lib/active_scaffold/actions/delete.rb +72 -0
  89. data/lib/active_scaffold/actions/field_search.rb +82 -0
  90. data/lib/active_scaffold/actions/list.rb +128 -0
  91. data/lib/active_scaffold/actions/mark.rb +50 -0
  92. data/lib/active_scaffold/actions/nested.rb +241 -0
  93. data/lib/active_scaffold/actions/search.rb +47 -0
  94. data/lib/active_scaffold/actions/show.rb +54 -0
  95. data/lib/active_scaffold/actions/subform.rb +17 -0
  96. data/lib/active_scaffold/actions/update.rb +134 -0
  97. data/lib/active_scaffold/attribute_params.rb +207 -0
  98. data/lib/active_scaffold/bridges/ancestry/bridge.rb +5 -0
  99. data/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb +38 -0
  100. data/lib/active_scaffold/bridges/bridge.rb +52 -0
  101. data/lib/active_scaffold/bridges/calendar_date_select/bridge.rb +16 -0
  102. data/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +79 -0
  103. data/lib/active_scaffold/bridges/carrierwave/bridge.rb +7 -0
  104. data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +38 -0
  105. data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +26 -0
  106. data/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +35 -0
  107. data/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb +17 -0
  108. data/lib/active_scaffold/bridges/date_picker/bridge.rb +22 -0
  109. data/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +225 -0
  110. data/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js +22 -0
  111. data/lib/active_scaffold/bridges/file_column/bridge.rb +11 -0
  112. data/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb +46 -0
  113. data/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb +59 -0
  114. data/lib/active_scaffold/bridges/file_column/lib/form_ui.rb +37 -0
  115. data/lib/active_scaffold/bridges/file_column/lib/list_ui.rb +26 -0
  116. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +43 -0
  117. data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +9 -0
  118. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +15 -0
  119. data/lib/active_scaffold/bridges/paperclip/bridge.rb +12 -0
  120. data/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb +27 -0
  121. data/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb +16 -0
  122. data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb +38 -0
  123. data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +26 -0
  124. data/lib/active_scaffold/bridges/semantic_attributes/bridge.rb +5 -0
  125. data/lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb +20 -0
  126. data/lib/active_scaffold/bridges/shared/date_bridge.rb +187 -0
  127. data/lib/active_scaffold/bridges/tiny_mce/bridge.rb +5 -0
  128. data/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb +45 -0
  129. data/lib/active_scaffold/bridges/validation_reflection/bridge.rb +8 -0
  130. data/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb +21 -0
  131. data/lib/active_scaffold/config/base.rb +54 -0
  132. data/lib/active_scaffold/config/core.rb +229 -0
  133. data/lib/active_scaffold/config/create.rb +43 -0
  134. data/lib/active_scaffold/config/delete.rb +25 -0
  135. data/lib/active_scaffold/config/field_search.rb +74 -0
  136. data/lib/active_scaffold/config/form.rb +46 -0
  137. data/lib/active_scaffold/config/list.rb +174 -0
  138. data/lib/active_scaffold/config/mark.rb +22 -0
  139. data/lib/active_scaffold/config/nested.rb +43 -0
  140. data/lib/active_scaffold/config/search.rb +68 -0
  141. data/lib/active_scaffold/config/show.rb +34 -0
  142. data/lib/active_scaffold/config/subform.rb +35 -0
  143. data/lib/active_scaffold/config/update.rb +38 -0
  144. data/lib/active_scaffold/configurable.rb +29 -0
  145. data/lib/active_scaffold/constraints.rb +179 -0
  146. data/lib/active_scaffold/data_structures/action_columns.rb +133 -0
  147. data/lib/active_scaffold/data_structures/action_link.rb +162 -0
  148. data/lib/active_scaffold/data_structures/action_links.rb +59 -0
  149. data/lib/active_scaffold/data_structures/actions.rb +45 -0
  150. data/lib/active_scaffold/data_structures/column.rb +348 -0
  151. data/lib/active_scaffold/data_structures/columns.rb +75 -0
  152. data/lib/active_scaffold/data_structures/error_message.rb +24 -0
  153. data/lib/active_scaffold/data_structures/nested_info.rb +108 -0
  154. data/lib/active_scaffold/data_structures/set.rb +62 -0
  155. data/lib/active_scaffold/data_structures/sorting.rb +168 -0
  156. data/lib/active_scaffold/finder.rb +333 -0
  157. data/lib/active_scaffold/helpers/association_helpers.rb +40 -0
  158. data/lib/active_scaffold/helpers/controller_helpers.rb +40 -0
  159. data/lib/active_scaffold/helpers/country_helpers.rb +352 -0
  160. data/lib/active_scaffold/helpers/form_column_helpers.rb +343 -0
  161. data/lib/active_scaffold/helpers/human_condition_helpers.rb +59 -0
  162. data/lib/active_scaffold/helpers/id_helpers.rb +131 -0
  163. data/lib/active_scaffold/helpers/list_column_helpers.rb +363 -0
  164. data/lib/active_scaffold/helpers/pagination_helpers.rb +55 -0
  165. data/lib/active_scaffold/helpers/search_column_helpers.rb +238 -0
  166. data/lib/active_scaffold/helpers/show_column_helpers.rb +46 -0
  167. data/lib/active_scaffold/helpers/view_helpers.rb +315 -0
  168. data/lib/active_scaffold/locale/de.rb +113 -0
  169. data/lib/active_scaffold/locale/en.rb +118 -0
  170. data/lib/active_scaffold/locale/es.yml +112 -0
  171. data/lib/active_scaffold/locale/fr.rb +113 -0
  172. data/lib/active_scaffold/locale/hu.yml +63 -0
  173. data/lib/active_scaffold/locale/ja.yml +64 -0
  174. data/lib/active_scaffold/locale/ru.yml +62 -0
  175. data/lib/active_scaffold/marked_model.rb +38 -0
  176. data/lib/dhtml_confirm.rb +54 -0
  177. data/lib/extensions/action_controller_rendering.rb +20 -0
  178. data/lib/extensions/action_view_rendering.rb +113 -0
  179. data/lib/extensions/action_view_resolver.rb +7 -0
  180. data/lib/extensions/active_record_offset.rb +12 -0
  181. data/lib/extensions/array.rb +7 -0
  182. data/lib/extensions/localize.rb +10 -0
  183. data/lib/extensions/name_option_for_datetime.rb +12 -0
  184. data/lib/extensions/nil_id_in_url_params.rb +7 -0
  185. data/lib/extensions/paginator_extensions.rb +26 -0
  186. data/lib/extensions/reverse_associations.rb +62 -0
  187. data/lib/extensions/routing_mapper.rb +34 -0
  188. data/lib/extensions/to_label.rb +8 -0
  189. data/lib/extensions/unsaved_associated.rb +61 -0
  190. data/lib/extensions/unsaved_record.rb +20 -0
  191. data/lib/extensions/usa_state.rb +46 -0
  192. data/lib/generators/active_scaffold/USAGE +29 -0
  193. data/lib/generators/active_scaffold/active_scaffold_generator.rb +20 -0
  194. data/lib/generators/active_scaffold_controller/USAGE +19 -0
  195. data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +28 -0
  196. data/lib/generators/active_scaffold_controller/templates/controller.rb +4 -0
  197. data/lib/generators/active_scaffold_setup/USAGE +10 -0
  198. data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +53 -0
  199. data/lib/paginator.rb +136 -0
  200. data/lib/responds_to_parent.rb +70 -0
  201. data/public/blank.html +33 -0
  202. data/shoulda_macros/macros.rb +136 -0
  203. data/test/bridges/bridge_test.rb +47 -0
  204. data/test/config/base_test.rb +15 -0
  205. data/test/config/create_test.rb +55 -0
  206. data/test/config/list_test.rb +74 -0
  207. data/test/config/show_test.rb +43 -0
  208. data/test/config/update_test.rb +17 -0
  209. data/test/const_mocker.rb +36 -0
  210. data/test/data_structures/action_columns_test.rb +113 -0
  211. data/test/data_structures/action_link_test.rb +78 -0
  212. data/test/data_structures/action_links_test.rb +78 -0
  213. data/test/data_structures/actions_test.rb +25 -0
  214. data/test/data_structures/association_column_test.rb +42 -0
  215. data/test/data_structures/column_test.rb +185 -0
  216. data/test/data_structures/columns_test.rb +69 -0
  217. data/test/data_structures/error_message_test.rb +28 -0
  218. data/test/data_structures/set_test.rb +86 -0
  219. data/test/data_structures/sorting_test.rb +126 -0
  220. data/test/data_structures/standard_column_test.rb +24 -0
  221. data/test/data_structures/virtual_column_test.rb +23 -0
  222. data/test/extensions/active_record_test.rb +45 -0
  223. data/test/extensions/array_test.rb +12 -0
  224. data/test/helpers/form_column_helpers_test.rb +31 -0
  225. data/test/helpers/list_column_helpers_test.rb +31 -0
  226. data/test/helpers/pagination_helpers_test.rb +55 -0
  227. data/test/misc/active_record_permissions_test.rb +154 -0
  228. data/test/misc/attribute_params_test.rb +110 -0
  229. data/test/misc/configurable_test.rb +96 -0
  230. data/test/misc/constraints_test.rb +193 -0
  231. data/test/misc/finder_test.rb +93 -0
  232. data/test/misc/lang_test.rb +12 -0
  233. data/test/mock_app/.gitignore +2 -0
  234. data/test/mock_app/app/controllers/application_controller.rb +10 -0
  235. data/test/mock_app/app/helpers/application_helper.rb +3 -0
  236. data/test/mock_app/config/boot.rb +110 -0
  237. data/test/mock_app/config/database.yml +16 -0
  238. data/test/mock_app/config/environment.rb +43 -0
  239. data/test/mock_app/config/environments/development.rb +17 -0
  240. data/test/mock_app/config/environments/production.rb +28 -0
  241. data/test/mock_app/config/environments/test.rb +28 -0
  242. data/test/mock_app/config/initializers/backtrace_silencers.rb +7 -0
  243. data/test/mock_app/config/initializers/inflections.rb +10 -0
  244. data/test/mock_app/config/initializers/mime_types.rb +5 -0
  245. data/test/mock_app/config/initializers/new_rails_defaults.rb +19 -0
  246. data/test/mock_app/config/initializers/session_store.rb +15 -0
  247. data/test/mock_app/config/locales/en.yml +5 -0
  248. data/test/mock_app/config/routes.rb +43 -0
  249. data/test/mock_app/db/test.sqlite3 +1 -0
  250. data/test/mock_app/public/blank.html +33 -0
  251. data/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT +2 -0
  252. data/test/mock_app/public/images/active_scaffold/default/add.gif +0 -0
  253. data/test/mock_app/public/images/active_scaffold/default/arrow_down.gif +0 -0
  254. data/test/mock_app/public/images/active_scaffold/default/arrow_up.gif +0 -0
  255. data/test/mock_app/public/images/active_scaffold/default/close.gif +0 -0
  256. data/test/mock_app/public/images/active_scaffold/default/cross.png +0 -0
  257. data/test/mock_app/public/images/active_scaffold/default/indicator-small.gif +0 -0
  258. data/test/mock_app/public/images/active_scaffold/default/indicator.gif +0 -0
  259. data/test/mock_app/public/images/active_scaffold/default/magnifier.png +0 -0
  260. data/test/mock_app/public/javascripts/active_scaffold/DO_NOT_EDIT +2 -0
  261. data/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +532 -0
  262. data/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +867 -0
  263. data/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js +117 -0
  264. data/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js +370 -0
  265. data/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT +2 -0
  266. data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css +35 -0
  267. data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +839 -0
  268. data/test/model_stub.rb +55 -0
  269. data/test/run_all.rb +8 -0
  270. data/test/test_helper.rb +39 -0
  271. data/uninstall.rb +13 -0
  272. metadata +478 -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
+ '(LOWER("model_stubs"."a") LIKE ? OR LOWER("model_stubs"."b") LIKE ?) AND (LOWER("model_stubs"."a") LIKE ? OR LOWER("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
+ '(LOWER("model_stubs"."a") LIKE ? OR LOWER("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,2 @@
1
+ tmp/
2
+ log/
@@ -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,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ 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!