active_scaffold 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,25 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
+
3
+ class ActionsTest < Test::Unit::TestCase
4
+ def setup
5
+ @actions = ActiveScaffold::DataStructures::Actions.new(:a, 'b')
6
+ end
7
+
8
+ def test_initialization
9
+ assert @actions.include?('a')
10
+ assert @actions.include?(:b)
11
+ assert !@actions.include?(:c)
12
+ end
13
+
14
+ def test_exclude
15
+ assert @actions.include?('b')
16
+ @actions.exclude :b
17
+ assert !@actions.include?(:b)
18
+ end
19
+
20
+ def test_add
21
+ assert !@actions.include?(:c)
22
+ @actions.add 'c'
23
+ assert @actions.include?('c')
24
+ end
25
+ end
@@ -0,0 +1,42 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
+ require File.join(File.dirname(__FILE__), '../model_stub')
3
+
4
+ class AssociationColumnTest < Test::Unit::TestCase
5
+ def setup
6
+ @association_column = ActiveScaffold::DataStructures::Column.new('other_model', ModelStub)
7
+ end
8
+
9
+ def test_virtuality
10
+ assert @association_column.association
11
+ assert !@association_column.virtual?
12
+ end
13
+
14
+ def test_sorting
15
+ # sorting on association columns is method-based
16
+ hash = {:method => "other_model.to_s"}
17
+ assert_equal hash, @association_column.sort
18
+ end
19
+
20
+ def test_searching
21
+ # by default searching on association columns uses primary key
22
+ assert @association_column.searchable?
23
+ assert_equal '"model_stubs"."id"', @association_column.search_sql
24
+ end
25
+
26
+ def test_association
27
+ assert @association_column.association.is_a?(ActiveRecord::Reflection::AssociationReflection)
28
+ end
29
+
30
+ def test_includes
31
+ assert_equal [:other_model], @association_column.includes
32
+ end
33
+
34
+ def test_plurality
35
+ assert @association_column.singular_association?
36
+ assert !@association_column.plural_association?
37
+
38
+ plural_association_column = ActiveScaffold::DataStructures::Column.new('other_models', ModelStub)
39
+ assert plural_association_column.plural_association?
40
+ assert !plural_association_column.singular_association?
41
+ end
42
+ end
@@ -0,0 +1,185 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
+
3
+ class ColumnTest < Test::Unit::TestCase
4
+ def setup
5
+ @column = ActiveScaffold::DataStructures::Column.new(:a, ModelStub)
6
+ @association_col = ActiveScaffold::DataStructures::Column.new(:b, ModelStub)
7
+ @association_col.stubs(:polymorphic_association?).returns(false)
8
+ @association_col.instance_variable_set(:@association, true)
9
+ end
10
+
11
+ def test_column
12
+ assert @column.column.is_a?(ActiveRecord::ConnectionAdapters::Column)
13
+ assert @column.column.name == 'a'
14
+ end
15
+
16
+ def test_basic_properties
17
+ # test that it was set during initialization
18
+ assert_equal @column.name, :a
19
+ # test that we can change it
20
+ @column.name = :b
21
+ assert_equal @column.name, :b
22
+
23
+ # label
24
+ @column.label = 'foo'
25
+ assert_equal 'foo', @column.label
26
+
27
+ # description
28
+ @column.description = 'hello world'
29
+ assert_equal 'hello world', @column.description
30
+
31
+ # css class
32
+ @column.css_class = 'style_me'
33
+ assert_equal 'style_me', @column.css_class
34
+
35
+ # required
36
+ assert !@column.required?, 'default is false'
37
+ @column.required = true
38
+ assert @column.required?, 'can be changed'
39
+
40
+ # calculation
41
+ assert !@column.calculation?, 'default is nil'
42
+ @column.calculate = :sum
43
+ assert @column.calculation?, 'can be changed'
44
+ end
45
+
46
+ def test_field
47
+ assert_equal '"model_stubs"."a"', @column.send(:field)
48
+ end
49
+
50
+ def test_table
51
+ assert_equal 'model_stubs', @column.send(:table)
52
+ end
53
+
54
+ def test_equality
55
+ # create a separate columns object, and make sure it's not ==
56
+ columns = ActiveScaffold::DataStructures::Columns.new(ModelStub, :a, :b)
57
+ assert columns != @column
58
+
59
+ # create a separate action_columns object, and make sure it's not ==
60
+ columns = ActiveScaffold::DataStructures::ActionColumns.new(:a, :b)
61
+ assert columns != @column
62
+
63
+ # identity
64
+ assert @column == @column
65
+
66
+ # string comparison
67
+ assert @column == 'a'
68
+ assert @column != 'fake'
69
+
70
+ # symbol comparison
71
+ assert @column == :a
72
+ assert @column != :fake
73
+
74
+ # comparison with different object of same type
75
+ column2 = ActiveScaffold::DataStructures::Column.new(:fake, ModelStub)
76
+ assert @column != column2
77
+ column2.name = 'a'
78
+ assert @column == column2
79
+
80
+ # special comparisons
81
+ assert @column != nil
82
+ assert @column != ''
83
+ assert @column != 0
84
+ end
85
+
86
+ def test_ui
87
+ assert_nil @column.form_ui
88
+ assert_nil @column.list_ui
89
+ assert_nil @column.search_ui
90
+ assert_equal :select, @association_col.search_ui
91
+
92
+ @column.form_ui = :calendar
93
+ assert_equal :calendar, @column.form_ui
94
+ assert_equal :calendar, @column.list_ui
95
+ assert_equal :calendar, @column.search_ui
96
+
97
+ @association_col.form_ui = :record_select
98
+ assert_equal :record_select, @association_col.form_ui
99
+ assert_equal :record_select, @association_col.search_ui
100
+
101
+ @column.search_ui = :record_select
102
+ @column.list_ui = :checkbox
103
+ assert_equal :calendar, @column.form_ui
104
+ assert_equal :checkbox, @column.list_ui
105
+ assert_equal :record_select, @column.search_ui
106
+ end
107
+
108
+ def test_searchable
109
+ @column.search_sql = nil
110
+ assert !@column.searchable?
111
+ @column.search_sql = true
112
+ assert @column.searchable?
113
+ end
114
+
115
+ def test_sortable
116
+ @column.sort = nil
117
+ assert !@column.sortable?
118
+ @column.sort = true
119
+ assert @column.sortable?
120
+ end
121
+
122
+ def test_custom_search
123
+ @column.search_sql = true
124
+ assert_equal '"model_stubs"."a"', @column.search_sql
125
+ @column.search_sql = 'foobar'
126
+ assert_equal 'foobar', @column.search_sql
127
+ assert @column.searchable?
128
+ end
129
+
130
+ def test_custom_sort
131
+ @column.sort = true
132
+ hash = {:sql => '"model_stubs"."a"'}
133
+ assert_equal hash, @column.sort
134
+ @column.sort_by :sql => 'foobar'
135
+ hash = {:sql => 'foobar'}
136
+ assert_equal hash, @column.sort
137
+
138
+ some_proc = proc {'foobar'}
139
+ @column.sort_by :method => some_proc
140
+ hash = {:method => some_proc}
141
+ assert_equal hash, @column.sort
142
+ assert @column.sortable?
143
+ end
144
+
145
+ def test_custom_sort__should_assert_keys
146
+ assert_raise(ArgumentError) { @column.sort_by :proc => "invalid config" }
147
+ assert_raise(ArgumentError) { @column.sort={:proc => "invalid config" } }
148
+ assert_nothing_raised(ArgumentError) {@column.sort_by :method => "method" }
149
+ assert_nothing_raised(ArgumentError) {@column.sort_by :sql => "method" }
150
+ end
151
+
152
+ def test_config_block
153
+ @column.configure do |config|
154
+ # we can use the config object
155
+ config.name = 'foo'
156
+ # or not
157
+ self.label = 'hello'
158
+ end
159
+
160
+ assert_equal 'foo', @column.name
161
+ assert_equal 'hello', @column.label
162
+ end
163
+
164
+ def test_action_link
165
+ link = ActiveScaffold::DataStructures::ActionLink.new('foo/bar')
166
+ @column.set_link link
167
+ assert_equal link, @column.link
168
+
169
+ @column.set_link 'hello_world'
170
+ assert_equal 'hello_world', @column.link.action
171
+ assert_equal @column.label, @column.link.label
172
+ end
173
+
174
+ def test_includes
175
+ assert_equal [], @column.includes
176
+
177
+ # make sure that when a non-array comes in, an array comes out
178
+ @column.includes = :column_name
179
+ assert_equal([:column_name], @column.includes)
180
+
181
+ # make sure that when a non-array comes in, an array comes out
182
+ @column.includes = [:column_name]
183
+ assert_equal([:column_name], @column.includes)
184
+ end
185
+ end
@@ -0,0 +1,69 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
+ # require 'test/model_stub'
3
+
4
+ class ColumnsTest < Test::Unit::TestCase
5
+ def setup
6
+ @columns = ActiveScaffold::DataStructures::Columns.new(ModelStub, :a, :b)
7
+ end
8
+
9
+ def test_initialization
10
+ assert_equal ModelStub, @columns.active_record_class
11
+
12
+ assert @columns.include?('a'), 'checking via string'
13
+ assert @columns.include?(:b), 'checking via symbol'
14
+ assert !@columns.include?(:c)
15
+ end
16
+
17
+ def test_add
18
+ assert !@columns.include?(:c)
19
+ @columns.add 'c'
20
+ assert @columns.include?('c')
21
+
22
+ # test the alias
23
+ assert !@columns.include?(:d)
24
+ @columns << :d
25
+ assert @columns.include?(:d)
26
+
27
+ # try adding an array of columns
28
+ assert !@columns.include?(:f)
29
+ @columns.add [:f, :g]
30
+ assert @columns.include?(:f)
31
+ assert @columns.include?(:g)
32
+ end
33
+
34
+ def test_finders
35
+ # test some basic assumptions before testing the finders
36
+ assert @columns.include?(:a)
37
+ assert @columns[:a].is_a?(ActiveScaffold::DataStructures::Column)
38
+
39
+ # test the single finders
40
+ assert @columns.find_by_name(:a).name == :a
41
+ assert @columns[:b].name == :b
42
+
43
+ # test the collection finders
44
+ found = @columns.find_by_names(:a, :b)
45
+ assert found.any? {|c| c.name == :a}
46
+ assert found.any? {|c| c.name == :b}
47
+ end
48
+
49
+ def test_each
50
+ @columns.each do |column|
51
+ assert [:a, :b].include?(column.name)
52
+ end
53
+ end
54
+
55
+ def test_block_config
56
+ assert !@columns.include?(:d)
57
+ assert !@columns.include?(:c)
58
+
59
+ @columns.configure do |config|
60
+ # test that we can use the config object
61
+ config << :d
62
+ # but test that we don't have to
63
+ add 'c'
64
+ end
65
+
66
+ assert @columns.include?(:d)
67
+ assert @columns.include?(:c)
68
+ end
69
+ end
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
+
3
+ class ErrorMessageTest < Test::Unit::TestCase
4
+ def setup
5
+ @error = ActiveScaffold::DataStructures::ErrorMessage.new 'foo'
6
+ end
7
+
8
+ def test_attributes
9
+ assert @error.public_attributes.has_key?(:error)
10
+ assert_equal 'foo', @error.public_attributes[:error]
11
+ end
12
+
13
+ def test_xml
14
+ xml = Hash.from_xml(@error.to_xml)
15
+ assert xml.has_key?('errors')
16
+ assert xml['errors'].has_key?('error')
17
+ assert_equal 'foo', xml['errors']['error']
18
+ end
19
+
20
+ def test_yaml
21
+ yml = nil
22
+ assert_nothing_raised do
23
+ yml = YAML.load(@error.to_yaml)
24
+ end
25
+ assert yml.has_key?(:error)
26
+ assert_equal 'foo', yml[:error]
27
+ end
28
+ end
@@ -0,0 +1,86 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
+ # require 'test/model_stub'
3
+
4
+ class SetTest < Test::Unit::TestCase
5
+ def setup
6
+ @items = ActiveScaffold::DataStructures::Set.new(:a, :b)
7
+ end
8
+
9
+ def test_initialization
10
+ assert @items.include?(:a)
11
+ assert @items.include?(:b)
12
+ assert !@items.include?(:c)
13
+ end
14
+
15
+ def test_exclude
16
+ # exclude with a symbol
17
+ assert @items.include?(:b)
18
+ @items.exclude :b
19
+ assert !@items.include?(:b)
20
+
21
+ # exclude with a string
22
+ assert @items.include?(:a)
23
+ @items.exclude 'a'
24
+ assert !@items.include?(:a)
25
+ end
26
+
27
+ def test_exclude_array
28
+ # exclude with a symbol
29
+ assert @items.include?(:b)
30
+ @items.exclude [:a, :b]
31
+ assert !@items.include?(:b)
32
+ assert !@items.include?(:a)
33
+ end
34
+
35
+ def test_remove
36
+ assert @items.include?(:a)
37
+ @items.remove 'a'
38
+ assert !@items.include?(:a)
39
+ end
40
+
41
+ def test_add
42
+ # try adding a simple column using a string
43
+ assert !@items.include?(:c)
44
+ @items.add 'c'
45
+ assert @items.include?(:c)
46
+
47
+ # try adding a simple column using a symbol
48
+ assert !@items.include?(:d)
49
+ @items.add :d
50
+ assert @items.include?(:d)
51
+
52
+ # test that << also adds
53
+ assert !@items.include?(:e)
54
+ @items << "e"
55
+ assert @items.include?(:e)
56
+
57
+ # try adding an array of columns
58
+ assert !@items.include?(:f)
59
+ @items.add [:f, :g]
60
+ assert @items.include?(:f)
61
+ assert @items.include?(:g)
62
+
63
+ end
64
+
65
+ def test_length
66
+ assert_equal 2, @items.length
67
+ end
68
+
69
+ def test_block_config
70
+ @items.configure do |config|
71
+ # we may use the config argument
72
+ config.add :c
73
+ # or we may not
74
+ exclude :b
75
+ end
76
+
77
+ assert @items.include?(:c)
78
+ assert !@items.include?(:b)
79
+ end
80
+
81
+ def test_include
82
+ assert @items.include?(:a)
83
+ assert @items.include?(:b)
84
+ assert !@items.include?(:d)
85
+ end
86
+ end
@@ -0,0 +1,126 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
+ # require 'test/model_stub'
3
+
4
+ class SortingTest < Test::Unit::TestCase
5
+ def setup
6
+ @columns = ActiveScaffold::DataStructures::Columns.new(ModelStub, :a, :b, :c, :d)
7
+ @sorting = ActiveScaffold::DataStructures::Sorting.new(@columns)
8
+ end
9
+
10
+ def test_add
11
+ @sorting.add :a, 'ASC'
12
+ # test adding by symbol
13
+ assert @sorting.sorts_on?(:a)
14
+ # test adding an uppercase string direction
15
+ assert_equal 'ASC', @sorting.direction_of(:a)
16
+
17
+ @sorting.add 'b', :ASC
18
+ # test adding by string
19
+ assert @sorting.sorts_on?(:b)
20
+ # test adding an uppercase symbol direction
21
+ assert_equal 'ASC', @sorting.direction_of(:b)
22
+
23
+ @sorting.add @columns[:c], 'desc'
24
+ # test adding by object
25
+ assert @sorting.sorts_on?(:c)
26
+ # test adding a lowercase string direction
27
+ assert_equal 'DESC', @sorting.direction_of(:c)
28
+
29
+ @sorting << [:d, :desc]
30
+ # testing adding with the alias
31
+ assert @sorting.sorts_on?(:d)
32
+ assert_equal 'DESC', @sorting.direction_of(:d)
33
+
34
+ @sorting.clear
35
+
36
+ # test adding without a direction (test default)
37
+ @sorting.add :a
38
+ assert_equal 'ASC', @sorting.direction_of(:a)
39
+
40
+ # test adding a bad column
41
+ assert_raises ArgumentError do
42
+ @sorting.add :foo
43
+ end
44
+
45
+ # test adding a bad direction
46
+ assert_raises ArgumentError do
47
+ @sorting.add :b, :FOO
48
+ end
49
+ end
50
+
51
+ def test_set
52
+ @sorting.add :a, 'ASC'
53
+ assert @sorting.sorts_on?(:a)
54
+
55
+ @sorting.set :b, 'DESC'
56
+ assert @sorting.instance_variable_get('@clauses').size == 1
57
+ assert !@sorting.sorts_on?(:a)
58
+ assert @sorting.sorts_on?(:b)
59
+ assert_equal 'DESC', @sorting.direction_of(:b)
60
+ end
61
+
62
+ def test_sorts_on
63
+ @sorting.add :a
64
+ @sorting.add :b
65
+
66
+ assert @sorting.sorts_on?(:a)
67
+ assert @sorting.sorts_on?(:b)
68
+ assert !@sorting.sorts_on?(:c)
69
+ end
70
+
71
+ def test_direction_of
72
+ @sorting.add :a, 'ASC'
73
+ @sorting.add :b, :DESC
74
+
75
+ assert_equal 'ASC', @sorting.direction_of(:a)
76
+ assert_equal 'DESC', @sorting.direction_of(:b)
77
+ end
78
+
79
+ def test_sorts_by_method
80
+ @columns[:a].sort_by :method => proc{0}
81
+
82
+ #test pure method sorting: true
83
+ @sorting.add :a
84
+ assert @sorting.sorts_by_method?
85
+
86
+ #test mixed sql/method sorting: raise error
87
+ assert_raise ArgumentError do
88
+ @sorting.add :b
89
+ end
90
+
91
+ #test pure sql sorting: false
92
+ @sorting.clear
93
+ @sorting.add :b
94
+ assert !@sorting.sorts_by_method?
95
+ end
96
+
97
+ def test_build_order_clause
98
+ assert @sorting.clause.nil?
99
+
100
+ @sorting << [:a, 'desc']
101
+ @sorting << [:b, 'asc']
102
+
103
+ assert_equal '"model_stubs"."a" DESC, "model_stubs"."b" ASC', @sorting.clause
104
+ end
105
+
106
+ def test_set_default_sorting_with_simple_default_scope
107
+ model_stub_with_default_scope = ModelStub.clone
108
+ model_stub_with_default_scope.class_eval { default_scope :order => 'a' }
109
+ @sorting.set_default_sorting model_stub_with_default_scope
110
+
111
+ assert @sorting.sorts_on?(:a)
112
+ assert_equal 'ASC', @sorting.direction_of(:a)
113
+ assert_nil @sorting.clause
114
+ end
115
+
116
+ def test_set_default_sorting_with_complex_default_scope
117
+ model_stub_with_default_scope = ModelStub.clone
118
+ model_stub_with_default_scope.class_eval { default_scope :order => 'a DESC, players.last_name ASC' }
119
+ @sorting.set_default_sorting model_stub_with_default_scope
120
+
121
+ assert @sorting.sorts_on?(:a)
122
+ assert_equal 'DESC', @sorting.direction_of(:a)
123
+ assert_equal 1, @sorting.instance_variable_get(:@clauses).size
124
+ assert_nil @sorting.clause
125
+ end
126
+ end