motiro 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (309) hide show
  1. data/LICENSE +280 -0
  2. data/README +28 -0
  3. data/README.en +175 -0
  4. data/README.pt-br +175 -0
  5. data/Rakefile +10 -0
  6. data/app/controllers/account_controller.rb +62 -0
  7. data/app/controllers/application.rb +72 -0
  8. data/app/controllers/edition_controller.rb +13 -0
  9. data/app/controllers/javascript_controller.rb +21 -0
  10. data/app/controllers/report_controller.rb +79 -0
  11. data/app/controllers/root_controller.rb +7 -0
  12. data/app/controllers/wiki_controller.rb +102 -0
  13. data/app/core/cache_reporter.rb +53 -0
  14. data/app/core/cache_reporter_fetcher.rb +33 -0
  15. data/app/core/chief_editor.rb +69 -0
  16. data/app/core/reporter.rb +105 -0
  17. data/app/core/reporter_driver.rb +36 -0
  18. data/app/core/reporter_fetcher.rb +39 -0
  19. data/app/core/settings.rb +43 -0
  20. data/app/core/version.rb +1 -0
  21. data/app/core/wiki_page_not_found.rb +33 -0
  22. data/app/core/wiki_reporter.rb +83 -0
  23. data/app/helpers/account_helper.rb +2 -0
  24. data/app/helpers/application_helper.rb +68 -0
  25. data/app/helpers/default_page_provider.rb +28 -0
  26. data/app/helpers/report_helper.rb +2 -0
  27. data/app/helpers/root_helper.rb +2 -0
  28. data/app/helpers/wiki_helper.rb +3 -0
  29. data/app/models/change.rb +96 -0
  30. data/app/models/diff_table_builder.rb +285 -0
  31. data/app/models/event.rb +18 -0
  32. data/app/models/headline.rb +109 -0
  33. data/app/models/page.rb +114 -0
  34. data/app/models/page_sweeper.rb +26 -0
  35. data/app/models/user.rb +85 -0
  36. data/app/ports/chdir_runner.rb +36 -0
  37. data/app/ports/reporter_loader.rb +9 -0
  38. data/app/ports/runner.rb +64 -0
  39. data/app/reporters/darcs_connection.rb +54 -0
  40. data/app/reporters/darcs_reporter.rb +104 -0
  41. data/app/reporters/darcs_settings.rb +9 -0
  42. data/app/reporters/darcs_temp_repo.rb +40 -0
  43. data/app/reporters/events_reporter.rb +28 -0
  44. data/app/reporters/features_reporter.rb +24 -0
  45. data/app/reporters/subversion_reporter.rb +203 -0
  46. data/app/reporters/svn_connection.rb +62 -0
  47. data/app/reporters/svn_settings.rb +40 -0
  48. data/app/views/account/_authorization.rhtml +54 -0
  49. data/app/views/account/_availability.rhtml +5 -0
  50. data/app/views/account/availability.rhtml +1 -0
  51. data/app/views/account/login.rhtml +22 -0
  52. data/app/views/account/logout.rhtml +10 -0
  53. data/app/views/javascript/motiro.rjs +132 -0
  54. data/app/views/javascript/niftycube.rjs +300 -0
  55. data/app/views/layouts/_bottom.rhtml +5 -0
  56. data/app/views/layouts/_header.rhtml +7 -0
  57. data/app/views/layouts/_top.rhtml +25 -0
  58. data/app/views/layouts/application.rhtml +3 -0
  59. data/app/views/layouts/scaffold.rhtml +13 -0
  60. data/app/views/layouts/wiki_edit.rhtml +26 -0
  61. data/app/views/report/list.rhtml +32 -0
  62. data/app/views/report/older.rhtml +26 -0
  63. data/app/views/report/rss.rxml +29 -0
  64. data/app/views/report/show.rhtml +20 -0
  65. data/app/views/root/index.rhtml +33 -0
  66. data/app/views/wiki/_editbar.rhtml +26 -0
  67. data/app/views/wiki/_properties_edit.rhtml +5 -0
  68. data/app/views/wiki/_properties_show.rhtml +5 -0
  69. data/app/views/wiki/edit.rhtml +56 -0
  70. data/app/views/wiki/properties_edit.rhtml +1 -0
  71. data/app/views/wiki/show.rhtml +9 -0
  72. data/bin/motiro +44 -0
  73. data/config/boot.rb +19 -0
  74. data/config/database.yml +14 -0
  75. data/config/environment.rb +64 -0
  76. data/config/environments/development.rb +20 -0
  77. data/config/environments/production.rb +19 -0
  78. data/config/environments/test.rb +19 -0
  79. data/config/motiro.yml +43 -0
  80. data/config/routes.rb +79 -0
  81. data/db/migrate/005_globalize_migration.rb +11363 -0
  82. data/db/migrate/006_remove_headline_title.rb +14 -0
  83. data/db/migrate/007_stretch_rid.rb +11 -0
  84. data/db/migrate/008_add_page_editors.rb +12 -0
  85. data/db/migrate/009_add_page_original_author.rb +12 -0
  86. data/db/migrate/010_remove_empty_string_defaults_from_pages.rb +17 -0
  87. data/db/migrate/011_add_title_and_kind_to_pages.rb +13 -0
  88. data/db/migrate/012_page_modification_info.rb +13 -0
  89. data/db/migrate/013_nullify_initial_page_attributes.rb +21 -0
  90. data/db/migrate/014_events_are_wiki_pages.rb +13 -0
  91. data/db/migrate/015_migrate_previous_event_data.rb +23 -0
  92. data/db/migrate/1_initial_structure.rb +36 -0
  93. data/db/migrate/2_add_authentication.rb +12 -0
  94. data/db/migrate/3_drop_articles.rb +26 -0
  95. data/db/migrate/4_add_page_editing.rb +14 -0
  96. data/db/motirodb.sqlite.initial +0 -0
  97. data/db/schema_version +1 -0
  98. data/db/translation/pt-BR.rb +76 -0
  99. data/doc/README_FOR_APP +2 -0
  100. data/installer/rails_installer_defaults.yml +5 -0
  101. data/lib/import_translations.rb +154 -0
  102. data/lib/login_system.rb +89 -0
  103. data/lib/relative_time.rb +48 -0
  104. data/lib/string_extensions.rb +10 -0
  105. data/lib/stub_hash.rb +22 -0
  106. data/lib/tasks/packaging.rake +93 -0
  107. data/lib/tasks/testing.rake +32 -0
  108. data/lib/tick_daemon.rb +41 -0
  109. data/lib/translator.rb +67 -0
  110. data/lib/wiki_renderer.rb +42 -0
  111. data/lib/wiki_url_generator.rb +29 -0
  112. data/log/.keepdir +0 -0
  113. data/public/404.html +8 -0
  114. data/public/500.html +8 -0
  115. data/public/dispatch.cgi +10 -0
  116. data/public/dispatch.fcgi +24 -0
  117. data/public/dispatch.rb +10 -0
  118. data/public/favicon.ico +0 -0
  119. data/public/images/calendar.png +0 -0
  120. data/public/images/rss.png +0 -0
  121. data/public/javascripts/controls.js +750 -0
  122. data/public/javascripts/dragdrop.js +584 -0
  123. data/public/javascripts/effects.js +854 -0
  124. data/public/javascripts/prototype.js +1785 -0
  125. data/public/robots.txt +1 -0
  126. data/public/stylesheets/motiro.css +269 -0
  127. data/public/stylesheets/niftyCorners.css +35 -0
  128. data/public/stylesheets/scaffold.css +74 -0
  129. data/script/about +3 -0
  130. data/script/breakpointer +3 -0
  131. data/script/console +3 -0
  132. data/script/destroy +3 -0
  133. data/script/generate +3 -0
  134. data/script/performance/benchmarker +3 -0
  135. data/script/performance/profiler +3 -0
  136. data/script/plugin +3 -0
  137. data/script/process/reaper +3 -0
  138. data/script/process/spawner +3 -0
  139. data/script/process/spinner +3 -0
  140. data/script/runner +3 -0
  141. data/script/server +3 -0
  142. data/script/ticker +29 -0
  143. data/test/acceptance/account_test.rb +186 -0
  144. data/test/acceptance/darcs_test.rb +62 -0
  145. data/test/acceptance/events_test.rb +47 -0
  146. data/test/acceptance/main_page_test.rb +92 -0
  147. data/test/acceptance/subversion_test.rb +319 -0
  148. data/test/acceptance/ts_all_suites.rb +27 -0
  149. data/test/acceptance/wiki_test.rb +202 -0
  150. data/test/contract/darcs_test.rb +51 -0
  151. data/test/contract/remote_darcs_test.rb +61 -0
  152. data/test/contract/svn_test.rb +53 -0
  153. data/test/fixtures/changes.yml +25 -0
  154. data/test/fixtures/headlines.yml +45 -0
  155. data/test/fixtures/pages.yml +98 -0
  156. data/test/fixtures/users.yml +31 -0
  157. data/test/functional/account_controller_test.rb +96 -0
  158. data/test/functional/report_controller_test.rb +113 -0
  159. data/test/functional/report_features_test.rb +38 -0
  160. data/test/functional/report_subversion_test.rb +79 -0
  161. data/test/functional/root_controller_test.rb +127 -0
  162. data/test/functional/wiki_controller_test.rb +280 -0
  163. data/test/lib/acceptance_test_case.rb +43 -0
  164. data/test/lib/configuration.rb +53 -0
  165. data/test/lib/darcs_excerpts.rb +181 -0
  166. data/test/lib/darcs_repo.rb +77 -0
  167. data/test/lib/live_mode_test.rb +51 -0
  168. data/test/lib/local_svn.rb +157 -0
  169. data/test/lib/netutils.rb +42 -0
  170. data/test/lib/platform_thread.rb +62 -0
  171. data/test/lib/repoutils.rb +23 -0
  172. data/test/lib/selenium_extensions.rb +32 -0
  173. data/test/lib/stubio.rb +37 -0
  174. data/test/lib/svn_excerpts.rb +288 -0
  175. data/test/lib/test_configuration.rb +14 -0
  176. data/test/lib/webserver.rb +71 -0
  177. data/test/meta/configuration_test.rb +72 -0
  178. data/test/meta/darcs_repo_test.rb +118 -0
  179. data/test/meta/local_svn_test.rb +125 -0
  180. data/test/meta/platform_thread_test.rb +46 -0
  181. data/test/meta/stubio_test.rb +44 -0
  182. data/test/mocks/headline.rb +34 -0
  183. data/test/mocks/svn_reporter.rb +29 -0
  184. data/test/stubs/svn_settings.rb +19 -0
  185. data/test/stubs/url_generator.rb +24 -0
  186. data/test/test_helper.rb +36 -0
  187. data/test/unit/cache_reporter_fetcher_test.rb +46 -0
  188. data/test/unit/cache_reporter_test.rb +97 -0
  189. data/test/unit/caching_test.rb +78 -0
  190. data/test/unit/change_test.rb +152 -0
  191. data/test/unit/chdir_runner_test.rb +77 -0
  192. data/test/unit/chief_editor_test.rb +234 -0
  193. data/test/unit/darcs_connection_test.rb +109 -0
  194. data/test/unit/darcs_reporter_test.rb +146 -0
  195. data/test/unit/darcs_settings_test.rb +37 -0
  196. data/test/unit/darcs_temp_repo_test.rb +51 -0
  197. data/test/unit/default_page_provider_test.rb +46 -0
  198. data/test/unit/diff_table_builder_test.rb +602 -0
  199. data/test/unit/headline_test.rb +259 -0
  200. data/test/unit/page_test.rb +145 -0
  201. data/test/unit/relative_time_test.rb +56 -0
  202. data/test/unit/reporter_driver_test.rb +85 -0
  203. data/test/unit/reporter_fetcher_test.rb +31 -0
  204. data/test/unit/reporter_test.rb +81 -0
  205. data/test/unit/runner_test.rb +93 -0
  206. data/test/unit/settings_test.rb +55 -0
  207. data/test/unit/string_extensions_test.rb +10 -0
  208. data/test/unit/svn_connection_test.rb +183 -0
  209. data/test/unit/svn_reporter_interaction_test.rb +38 -0
  210. data/test/unit/svn_reporter_test.rb +286 -0
  211. data/test/unit/svn_settings_test.rb +86 -0
  212. data/test/unit/translator_test.rb +96 -0
  213. data/test/unit/user_test.rb +125 -0
  214. data/test/unit/wiki_renderer_test.rb +87 -0
  215. data/test/unit/wiki_reporter_test.rb +94 -0
  216. data/test/unit/wiki_url_generator_test.rb +31 -0
  217. data/vendor/motiro-installer.rb +159 -0
  218. data/vendor/plugins/globalize/LICENSE +9 -0
  219. data/vendor/plugins/globalize/README +49 -0
  220. data/vendor/plugins/globalize/data/country_data.csv +240 -0
  221. data/vendor/plugins/globalize/data/language_data.csv +188 -0
  222. data/vendor/plugins/globalize/data/translation_data.csv +3421 -0
  223. data/vendor/plugins/globalize/generators/globalize/USAGE +10 -0
  224. data/vendor/plugins/globalize/generators/globalize/globalize_generator.rb +42 -0
  225. data/vendor/plugins/globalize/generators/globalize/templates/migration.rb.gz +0 -0
  226. data/vendor/plugins/globalize/generators/globalize/templates/tiny_migration.rb.gz +0 -0
  227. data/vendor/plugins/globalize/init.rb +30 -0
  228. data/vendor/plugins/globalize/lib/globalize/localization/core_ext.rb +170 -0
  229. data/vendor/plugins/globalize/lib/globalize/localization/core_ext_hooks.rb +33 -0
  230. data/vendor/plugins/globalize/lib/globalize/localization/db_translate.rb +494 -0
  231. data/vendor/plugins/globalize/lib/globalize/localization/db_view_translator.rb +152 -0
  232. data/vendor/plugins/globalize/lib/globalize/localization/locale.rb +173 -0
  233. data/vendor/plugins/globalize/lib/globalize/localization/rfc_3066.rb +40 -0
  234. data/vendor/plugins/globalize/lib/globalize/models/country.rb +24 -0
  235. data/vendor/plugins/globalize/lib/globalize/models/currency.rb +188 -0
  236. data/vendor/plugins/globalize/lib/globalize/models/language.rb +84 -0
  237. data/vendor/plugins/globalize/lib/globalize/models/model_translation.rb +4 -0
  238. data/vendor/plugins/globalize/lib/globalize/models/translation.rb +9 -0
  239. data/vendor/plugins/globalize/lib/globalize/models/view_translation.rb +14 -0
  240. data/vendor/plugins/globalize/lib/globalize/rails/action_mailer.rb +125 -0
  241. data/vendor/plugins/globalize/lib/globalize/rails/action_view.rb +79 -0
  242. data/vendor/plugins/globalize/lib/globalize/rails/active_record.rb +129 -0
  243. data/vendor/plugins/globalize/lib/globalize/rails/active_record_helper.rb +33 -0
  244. data/vendor/plugins/globalize/populators/pop_dates.rb +81 -0
  245. data/vendor/plugins/globalize/populators/pop_migration.rb +18 -0
  246. data/vendor/plugins/globalize/populators/pop_pluralization.rb +26 -0
  247. data/vendor/plugins/globalize/populators/pop_seps.rb +32 -0
  248. data/vendor/plugins/globalize/tasks/data.rake +130 -0
  249. data/vendor/plugins/globalize/test/action_mailer_test/globalize_mailer/test.en-US.plain.text.rhtml +1 -0
  250. data/vendor/plugins/globalize/test/action_mailer_test/globalize_mailer/test.en.plain.text.rhtml +1 -0
  251. data/vendor/plugins/globalize/test/action_mailer_test/globalize_mailer/test.he.plain.text.rhtml +1 -0
  252. data/vendor/plugins/globalize/test/action_mailer_test/globalize_mailer/test.plain.text.rhtml +1 -0
  253. data/vendor/plugins/globalize/test/action_mailer_test.rb +54 -0
  254. data/vendor/plugins/globalize/test/config/database.yml.default +16 -0
  255. data/vendor/plugins/globalize/test/config/database.yml.example +22 -0
  256. data/vendor/plugins/globalize/test/core_ext_test.rb +61 -0
  257. data/vendor/plugins/globalize/test/currency_test.rb +141 -0
  258. data/vendor/plugins/globalize/test/date_helper_test.rb +634 -0
  259. data/vendor/plugins/globalize/test/db/schema.rb +90 -0
  260. data/vendor/plugins/globalize/test/db_translation_test.rb +374 -0
  261. data/vendor/plugins/globalize/test/fixtures/globalize_categories.yml +7 -0
  262. data/vendor/plugins/globalize/test/fixtures/globalize_categories_products.yml +7 -0
  263. data/vendor/plugins/globalize/test/fixtures/globalize_countries.yml +41 -0
  264. data/vendor/plugins/globalize/test/fixtures/globalize_languages.yml +64 -0
  265. data/vendor/plugins/globalize/test/fixtures/globalize_manufacturers.yml +5 -0
  266. data/vendor/plugins/globalize/test/fixtures/globalize_products.yml +29 -0
  267. data/vendor/plugins/globalize/test/fixtures/globalize_simples.yml +5 -0
  268. data/vendor/plugins/globalize/test/fixtures/globalize_translations.yml +354 -0
  269. data/vendor/plugins/globalize/test/locale_test.rb +27 -0
  270. data/vendor/plugins/globalize/test/mime_responds_test.rb +358 -0
  271. data/vendor/plugins/globalize/test/model_test.rb +17 -0
  272. data/vendor/plugins/globalize/test/standard_data_test_helper.rb +33 -0
  273. data/vendor/plugins/globalize/test/test_helper.rb +19 -0
  274. data/vendor/plugins/globalize/test/test_standard_data.rb +54 -0
  275. data/vendor/plugins/globalize/test/validation_test.rb +29 -0
  276. data/vendor/plugins/globalize/test/view_picking_test.rb +49 -0
  277. data/vendor/plugins/globalize/test/view_translation_test.rb +237 -0
  278. data/vendor/plugins/globalize/test/views/layouts/standard.rhtml +1 -0
  279. data/vendor/plugins/globalize/test/views/respond_to/all_types_with_layout.rhtml +1 -0
  280. data/vendor/plugins/globalize/test/views/respond_to/all_types_with_layout.rjs +1 -0
  281. data/vendor/plugins/globalize/test/views/respond_to/using_defaults.en.rhtml +1 -0
  282. data/vendor/plugins/globalize/test/views/respond_to/using_defaults.en.rjs +1 -0
  283. data/vendor/plugins/globalize/test/views/respond_to/using_defaults.en.rxml +1 -0
  284. data/vendor/plugins/globalize/test/views/respond_to/using_defaults.fr.rhtml +1 -0
  285. data/vendor/plugins/globalize/test/views/respond_to/using_defaults.fr.rjs +1 -0
  286. data/vendor/plugins/globalize/test/views/respond_to/using_defaults.fr.rxml +1 -0
  287. data/vendor/plugins/globalize/test/views/respond_to/using_defaults.rhtml +1 -0
  288. data/vendor/plugins/globalize/test/views/respond_to/using_defaults.rjs +1 -0
  289. data/vendor/plugins/globalize/test/views/respond_to/using_defaults.rxml +1 -0
  290. data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.en.rhtml +1 -0
  291. data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.en.rjs +1 -0
  292. data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.en.rxml +1 -0
  293. data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.fr.rhtml +1 -0
  294. data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.fr.rjs +1 -0
  295. data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.fr.rxml +1 -0
  296. data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.rhtml +1 -0
  297. data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.rjs +1 -0
  298. data/vendor/plugins/globalize/test/views/respond_to/using_defaults_with_type_list.rxml +1 -0
  299. data/vendor/plugins/globalize/test/views/test.he-IL.rhtml +1 -0
  300. data/vendor/plugins/globalize/test/views/test.rhtml +1 -0
  301. data/vendor/plugins/globalize/test/views/test2.he.rhtml +1 -0
  302. data/vendor/plugins/globalize/test/views/test2.rhtml +1 -0
  303. data/vendor/plugins/test_xml/MIT-LICENSE +20 -0
  304. data/vendor/plugins/test_xml/README +20 -0
  305. data/vendor/plugins/test_xml/Rakefile +22 -0
  306. data/vendor/plugins/test_xml/init.rb +7 -0
  307. data/vendor/plugins/test_xml/lib/xml_assertions.rb +22 -0
  308. data/vendor/plugins/test_xml/test/test_xml_test.rb +40 -0
  309. metadata +505 -0
@@ -0,0 +1,237 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ViewTranslationTest < Test::Unit::TestCase
4
+ include Globalize
5
+
6
+ fixtures :globalize_languages, :globalize_countries, :globalize_translations
7
+
8
+ def setup
9
+ Globalize::Locale.set("en-US")
10
+ Globalize::Locale.set_base_language("en-US")
11
+ end
12
+
13
+ def test_translate
14
+ assert_equal "This is the default", "This is the default".t
15
+ Locale.set("he-IL")
16
+ assert_equal "This is the default", "This is the default".t
17
+ assert_equal "ועכשיו בעברית", "And now in Hebrew".t
18
+ end
19
+
20
+ def test_plural
21
+ Locale.set("pl-PL")
22
+ assert_equal "1 plik", "%d file" / 1
23
+ assert_equal "2 pliki", "%d file" / 2
24
+ assert_equal "3 pliki", "%d file" / 3
25
+ assert_equal "4 pliki", "%d file" / 4
26
+
27
+ assert_equal "5 plików", "%d file" / 5
28
+ assert_equal "8 plików", "%d file" / 8
29
+ assert_equal "13 plików", "%d file" / 13
30
+ assert_equal "21 plików", "%d file" / 21
31
+
32
+ assert_equal "22 pliki", "%d file" / 22
33
+ assert_equal "23 pliki", "%d file" / 23
34
+ assert_equal "24 pliki", "%d file" / 24
35
+
36
+ assert_equal "25 plików", "%d file" / 25
37
+ assert_equal "31 plików", "%d file" / 31
38
+ end
39
+
40
+ def test_aliases
41
+ Locale.set("he-IL")
42
+ assert_equal "ועכשיו בעברית", "And now in Hebrew".translate
43
+ assert_equal "ועכשיו בעברית", _("And now in Hebrew")
44
+ end
45
+
46
+ def test_set_translation
47
+ assert_equal "a dark and stormy night", "a dark and stormy night".t
48
+ Locale.set_translation("a dark and stormy night", "quite a dark and stormy night")
49
+ assert_equal "quite a dark and stormy night", "a dark and stormy night".t
50
+
51
+ Locale.set("he-IL")
52
+ assert_equal "a dark and stormy night", "a dark and stormy night".t
53
+ Locale.set_translation("a dark and stormy night", "ליל קודר וגועש")
54
+ assert_equal "ליל קודר וגועש", "a dark and stormy night".t
55
+ polish = Language.pick("pl")
56
+
57
+ Locale.set_translation("a dark and stormy night", polish, "How do you say this in Polish?")
58
+
59
+ Locale.set("en-US")
60
+ assert_equal "quite a dark and stormy night", "a dark and stormy night".t
61
+ Locale.set("pl-PL")
62
+ assert_equal "How do you say this in Polish?", "a dark and stormy night".t
63
+ end
64
+
65
+ def test_set_translation_pl
66
+ Locale.set_translation("%d dark and stormy nights", "quite a dark and stormy night",
67
+ "%d dark and stormy nights")
68
+ assert_equal "quite a dark and stormy night", "%d dark and stormy nights".t
69
+ assert_equal "5 dark and stormy nights", "%d dark and stormy nights" / 5
70
+
71
+ Locale.set("he-IL")
72
+ Locale.set_translation("%d dark and stormy nights",
73
+ [ "ליל קודר וגועש", "%d לילות קודרים וגועשים" ])
74
+ assert_equal "ליל קודר וגועש", "%d dark and stormy nights".t
75
+ assert_equal "7 לילות קודרים וגועשים", "%d dark and stormy nights" / 7
76
+
77
+ Locale.set("en-US")
78
+ assert_equal "quite a dark and stormy night", "%d dark and stormy nights".t
79
+ end
80
+
81
+ def test_missed_report
82
+ Locale.set("he-IL")
83
+ assert_nil ViewTranslation.find(:first,
84
+ :conditions => %q{language_id = 2 AND tr_key = 'not in database'})
85
+ assert_equal "not in database", "not in database".t
86
+ result = ViewTranslation.find(:first,
87
+ :conditions => %q{language_id = 2 AND tr_key = 'not in database'})
88
+ assert_not_nil result, "There should be a record in the db with nil text"
89
+ assert_nil result.text
90
+ end
91
+
92
+ # for when language doesn't have a translation
93
+ def test_default_number_substitution
94
+ Locale.set("pl-PL")
95
+ assert_equal "There are 0 translations for this",
96
+ "There are %d translations for this" / 0
97
+ end
98
+
99
+ # for when language only has one pluralization form for translation
100
+ def test_default_number_substitution2
101
+ Locale.set("he-IL")
102
+ assert_equal "יש לי 5 קבצים", "I have %d files" / 5
103
+ end
104
+
105
+ def test_symbol
106
+ Locale.set("he-IL")
107
+ assert_equal "ועכשיו בעברית", :And_now_in_Hebrew.t
108
+ assert_equal "this is the default", :bogus_translation.t("this is the default")
109
+ end
110
+
111
+ def test_syntax_error
112
+ Locale.set("ur")
113
+ assert_raise(SyntaxError) { "I have %d bogus numbers" / 5 }
114
+ end
115
+
116
+ def test_illegal_code
117
+ assert_raise(SecurityError) { Locale.set("ba") }
118
+ end
119
+
120
+ def test_overflow_code
121
+ assert_raise(SecurityError) { Locale.set("tw") }
122
+ end
123
+
124
+ def test_string_substitute
125
+ assert_equal "Welcome, Josh", "welcome, %s" / "Josh"
126
+ end
127
+
128
+ def test_zero_form
129
+ Locale.set_translation("%d items in your cart",
130
+ [ "One item in your cart", "%d items in your cart" ], "Your cart is empty")
131
+ assert_equal "8 items in your cart", "%d items in your cart" / 8
132
+ assert_equal "One item in your cart", "%d items in your cart" / 1
133
+ assert_equal "Your cart is empty", "%d items in your cart" / 0
134
+ end
135
+
136
+ def test_zero_form_default
137
+ Locale.set_translation("%d items in your cart",
138
+ [ "One item in your cart", "%d items in your cart" ])
139
+ assert_equal "8 items in your cart", "%d items in your cart" / 8
140
+ assert_equal "One item in your cart", "%d items in your cart" / 1
141
+ assert_equal "0 items in your cart", "%d items in your cart" / 0
142
+ end
143
+
144
+ def test_string_substitute_he
145
+ Locale.set("he-IL")
146
+ assert_equal "ברוכים הבאים, יהושע", "welcome, %s" / "יהושע"
147
+ end
148
+
149
+ def test_no_substitute
150
+ assert_equal "Don't substitute any %s in %s",
151
+ "Don't substitute any %s in %s".t
152
+ end
153
+
154
+ def test_cache
155
+ Locale.set("he-IL")
156
+ tr = Locale.translator
157
+ tr.cache_reset
158
+ assert_equal 0, tr.cache_size
159
+ assert_equal 0, tr.cache_count
160
+ assert_equal 0, tr.cache_total_hits
161
+ assert_equal 0, tr.cache_total_queries
162
+
163
+ assert_equal "ועכשיו בעברית", :And_now_in_Hebrew.t
164
+ assert_equal 1, tr.cache_count
165
+ assert_equal 42, tr.cache_size
166
+ assert_equal 0, tr.cache_total_hits
167
+ assert_equal 1, tr.cache_total_queries
168
+
169
+ assert_equal "ועכשיו בעברית", :And_now_in_Hebrew.t
170
+ assert_equal 1, tr.cache_count
171
+ assert_equal 42, tr.cache_size
172
+ assert_equal 1, tr.cache_total_hits
173
+ assert_equal 2, tr.cache_total_queries
174
+
175
+ assert_equal "ועכשיו בעברית", :And_now_in_Hebrew.t
176
+ assert_equal 1, tr.cache_count
177
+ assert_equal 42, tr.cache_size
178
+ assert_equal 2, tr.cache_total_hits
179
+ assert_equal 3, tr.cache_total_queries
180
+
181
+ assert_equal "ועכשיו בעברית",
182
+ tr.instance_eval {
183
+ cache_fetch("And now in Hebrew", Locale.language,
184
+ Locale.language.plural_index(nil))
185
+ }
186
+
187
+ # test for purging
188
+ tr.max_cache_size = 41 / 1024 # in kb
189
+ assert_equal "יש לי 5 קבצים", "I have %d files" / 5
190
+ assert_equal 1, tr.cache_count
191
+ assert_equal 38, tr.cache_size
192
+ assert_equal 3, tr.cache_total_hits
193
+ assert_equal 5, tr.cache_total_queries
194
+
195
+ assert_equal "יש לי 5 קבצים", "I have %d files" / 5
196
+ assert_equal 1, tr.cache_count
197
+ assert_equal 38, tr.cache_size
198
+ assert_equal 4, tr.cache_total_hits
199
+ assert_equal 6, tr.cache_total_queries
200
+
201
+ tr.max_cache_size = 100000 / 1024 # in bytes
202
+
203
+ # test for two items in cache
204
+ assert_equal "ועכשיו בעברית", :And_now_in_Hebrew.t
205
+ assert_equal 2, tr.cache_count
206
+ assert_equal 80, tr.cache_size
207
+ assert_equal 4, tr.cache_total_hits
208
+ assert_equal 7, tr.cache_total_queries
209
+
210
+ tr.max_cache_size = 8192 # set it back to default
211
+ assert_equal "ועכשיו בעברית", :And_now_in_Hebrew.t
212
+ assert_equal 2, tr.cache_count
213
+ assert_equal 80, tr.cache_size
214
+ assert_equal 5, tr.cache_total_hits
215
+ assert_equal 8, tr.cache_total_queries
216
+
217
+ # test for invalidation on set_translation
218
+ Locale.set_translation(:And_now_in_Hebrew, "override")
219
+ assert_equal 1, tr.cache_count
220
+ assert_equal 21, tr.cache_size
221
+ assert_equal 5, tr.cache_total_hits
222
+ assert_equal 8, tr.cache_total_queries
223
+
224
+ assert_equal "override", :And_now_in_Hebrew.t
225
+ assert_equal 2, tr.cache_count
226
+ assert_equal 46, tr.cache_size
227
+ assert_equal 5, tr.cache_total_hits
228
+ assert_equal 9, tr.cache_total_queries
229
+
230
+ # set it back to what it was for other tests
231
+ Locale.set_translation(:And_now_in_Hebrew, "ועכשיו בעברית")
232
+ assert_equal "ועכשיו בעברית", :And_now_in_Hebrew.t
233
+
234
+ # phew!
235
+ end
236
+
237
+ end
@@ -0,0 +1 @@
1
+ <html><%= @content_for_layout %><%= @variable_for_layout %></html>
@@ -0,0 +1 @@
1
+ HTML for all_types_with_layout
@@ -0,0 +1 @@
1
+ page << "RJS for all_types_with_layout"
@@ -0,0 +1 @@
1
+ page[:body].visual_effect :highlight
@@ -0,0 +1 @@
1
+ page[:body].visual_effect :highlight
@@ -0,0 +1 @@
1
+ xml.p "Bonjour le monde !"
@@ -0,0 +1 @@
1
+ page[:body].visual_effect :highlight
@@ -0,0 +1 @@
1
+ xml.p "Hello world!"
@@ -0,0 +1 @@
1
+ page[:body].visual_effect :highlight
@@ -0,0 +1 @@
1
+ page[:body].visual_effect :highlight
@@ -0,0 +1 @@
1
+ page[:body].visual_effect :highlight
@@ -0,0 +1 @@
1
+ This is the Hebrew template.
@@ -0,0 +1 @@
1
+ This is the English template.
@@ -0,0 +1 @@
1
+ This is the second Hebrew template.
@@ -0,0 +1 @@
1
+ This is the second English template.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Thiago Arrais
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ Test XML
2
+ ========
3
+
4
+ Adds testing facilities for XML such as assert_xml_tag. XPATH can be used to
5
+ find elements inside a document.
6
+
7
+ The latest version is available at
8
+
9
+ https://svn.sourceforge.net/svnroot/motiro/trunk/vendor/plugins/test_xml
10
+
11
+ For suggestions, comments and bug reports contact the author at
12
+ thiago.arrais@gmail.com
13
+
14
+ License
15
+ =======
16
+
17
+ Copyright (c) 2007 Thiago Arrais, distributed under the terms of the
18
+ MIT-LICENSE
19
+
20
+ Originally developed as part of Motiro - http://motiro.railsplayground.com
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the test_xml plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the test_xml plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'TestXml'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
@@ -0,0 +1,7 @@
1
+ # Copyright (c) 2007 Thiago Arrais, distributed under the terms of the
2
+ # MIT-LICENSE
3
+
4
+ require 'test/unit/testcase'
5
+ require 'xml_assertions'
6
+
7
+ Test::Unit::TestCase.send :include, XmlAssertions
@@ -0,0 +1,22 @@
1
+ # Copyright (c) 2007 Thiago Arrais, distributed under the terms of the
2
+ # MIT-LICENSE
3
+
4
+ require 'rexml/rexml'
5
+
6
+ module XmlAssertions
7
+
8
+ def assert_xml_element(xpath)
9
+ assert_not_nil find_xml_element(xpath), "expected element, but found no element matching #{xpath} in #{@response.body.inspect}"
10
+ end
11
+
12
+ def assert_no_xml_element(xpath)
13
+ assert_nil find_xml_element(xpath), "expected no element, but found element matching #{xpath} in #{@response.body.inspect}"
14
+ end
15
+
16
+ private
17
+
18
+ def find_xml_element(xpath)
19
+ REXML::XPath.first(REXML::Document.new(@response.body), xpath)
20
+ end
21
+
22
+ end
@@ -0,0 +1,40 @@
1
+ # Copyright (c) 2007 Thiago Arrais, distributed under the terms of the
2
+ # MIT-LICENSE
3
+
4
+ unless defined?(RAILS_ROOT)
5
+ RAILS_ROOT = ENV["RAILS_ROOT"] || File.expand_path(File.join(File.dirname(__FILE__), "../../../.."))
6
+ end
7
+ require File.join(RAILS_ROOT, "test", "test_helper")
8
+ require File.join(File.dirname(__FILE__), "..", "init")
9
+
10
+ class TestXmlTest < Test::Unit::TestCase
11
+
12
+ SHALLOW_ELEMENT_XML = <<END
13
+ <?xml version="1.0" encoding="UTF-8"?>
14
+ <root>
15
+ <element>Element text</element>
16
+ </root>
17
+ END
18
+
19
+ def setup
20
+ @response = ActionController::TestResponse.new
21
+ @response.body = SHALLOW_ELEMENT_XML
22
+ end
23
+
24
+ def test_find_xml_tag_by_xpath
25
+ assert_raise Test::Unit::AssertionFailedError do
26
+ assert_xml_element '//absent'
27
+ end
28
+
29
+ assert_xml_element '//element'
30
+ end
31
+
32
+ def test_expect_not_to_find_xml_tag
33
+ assert_raise Test::Unit::AssertionFailedError do
34
+ assert_no_xml_element '//element'
35
+ end
36
+
37
+ assert_no_xml_element '//absent'
38
+ end
39
+
40
+ end