mongo_translatable 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. data/.document +5 -0
  2. data/.gitignore +26 -0
  3. data/.gitmodules +3 -0
  4. data/LICENSE +295 -0
  5. data/README.rdoc +131 -0
  6. data/Rakefile +55 -0
  7. data/VERSION +1 -0
  8. data/app/controllers/translations_controller.rb +150 -0
  9. data/app/helpers/translations_helper.rb +71 -0
  10. data/app/views/layouts/translations.html.erb +18 -0
  11. data/app/views/translations/_form.html.erb +50 -0
  12. data/app/views/translations/_translatable_value.html.erb +17 -0
  13. data/app/views/translations/_translation_field.html.erb +34 -0
  14. data/app/views/translations/_translation_field_input.html.erb +8 -0
  15. data/app/views/translations/edit.html.erb +8 -0
  16. data/app/views/translations/index.html.erb +22 -0
  17. data/app/views/translations/new.html.erb +7 -0
  18. data/app/views/translations/show.html.erb +12 -0
  19. data/config/locales/en.yml +33 -0
  20. data/config/locales/fr.yml +18 -0
  21. data/lib/mongo_translatable.rb +336 -0
  22. data/lib/mongo_translatable_configuration.rb +5 -0
  23. data/lib/translatables_helper.rb +227 -0
  24. data/lib/translations_controller_helpers.rb +37 -0
  25. data/rails/init.rb +3 -0
  26. data/test/full_2_3_5_app_with_tests/.gitignore +27 -0
  27. data/test/full_2_3_5_app_with_tests/README +1 -0
  28. data/test/full_2_3_5_app_with_tests/Rakefile +10 -0
  29. data/test/full_2_3_5_app_with_tests/app/controllers/application_controller.rb +26 -0
  30. data/test/full_2_3_5_app_with_tests/app/controllers/items_controller.rb +85 -0
  31. data/test/full_2_3_5_app_with_tests/app/helpers/application_helper.rb +3 -0
  32. data/test/full_2_3_5_app_with_tests/app/helpers/items_helper.rb +2 -0
  33. data/test/full_2_3_5_app_with_tests/app/models/comment.rb +3 -0
  34. data/test/full_2_3_5_app_with_tests/app/models/item.rb +5 -0
  35. data/test/full_2_3_5_app_with_tests/app/models/not_swapped_in_record.rb +3 -0
  36. data/test/full_2_3_5_app_with_tests/app/models/person.rb +3 -0
  37. data/test/full_2_3_5_app_with_tests/app/models/recipe.rb +21 -0
  38. data/test/full_2_3_5_app_with_tests/app/views/items/edit.html.erb +24 -0
  39. data/test/full_2_3_5_app_with_tests/app/views/items/index.html.erb +24 -0
  40. data/test/full_2_3_5_app_with_tests/app/views/items/new.html.erb +23 -0
  41. data/test/full_2_3_5_app_with_tests/app/views/items/show.html.erb +21 -0
  42. data/test/full_2_3_5_app_with_tests/app/views/layouts/items.html.erb +19 -0
  43. data/test/full_2_3_5_app_with_tests/config/boot.rb +110 -0
  44. data/test/full_2_3_5_app_with_tests/config/database.yml +22 -0
  45. data/test/full_2_3_5_app_with_tests/config/environment.rb +54 -0
  46. data/test/full_2_3_5_app_with_tests/config/environments/development.rb +17 -0
  47. data/test/full_2_3_5_app_with_tests/config/environments/production.rb +28 -0
  48. data/test/full_2_3_5_app_with_tests/config/environments/test.rb +28 -0
  49. data/test/full_2_3_5_app_with_tests/config/initializers/backtrace_silencers.rb +7 -0
  50. data/test/full_2_3_5_app_with_tests/config/initializers/inflections.rb +10 -0
  51. data/test/full_2_3_5_app_with_tests/config/initializers/mime_types.rb +5 -0
  52. data/test/full_2_3_5_app_with_tests/config/initializers/new_rails_defaults.rb +21 -0
  53. data/test/full_2_3_5_app_with_tests/config/initializers/session_store.rb +15 -0
  54. data/test/full_2_3_5_app_with_tests/config/locales.yml +5 -0
  55. data/test/full_2_3_5_app_with_tests/config/locales/en.yml +4 -0
  56. data/test/full_2_3_5_app_with_tests/config/locales/fr.yml +4 -0
  57. data/test/full_2_3_5_app_with_tests/config/locales/zh.yml +4 -0
  58. data/test/full_2_3_5_app_with_tests/config/routes.rb +4 -0
  59. data/test/full_2_3_5_app_with_tests/db/migrate/20100407010602_create_items.rb +14 -0
  60. data/test/full_2_3_5_app_with_tests/db/migrate/20100504234216_create_not_swapped_in_records.rb +15 -0
  61. data/test/full_2_3_5_app_with_tests/db/migrate/20100509011052_create_people.rb +13 -0
  62. data/test/full_2_3_5_app_with_tests/db/migrate/20100509042718_create_comments.rb +14 -0
  63. data/test/full_2_3_5_app_with_tests/db/migrate/20110112023516_create_recipes.rb +14 -0
  64. data/test/full_2_3_5_app_with_tests/db/schema.rb +56 -0
  65. data/test/full_2_3_5_app_with_tests/db/seeds.rb +7 -0
  66. data/test/full_2_3_5_app_with_tests/doc/README_FOR_APP +2 -0
  67. data/test/full_2_3_5_app_with_tests/public/404.html +30 -0
  68. data/test/full_2_3_5_app_with_tests/public/422.html +30 -0
  69. data/test/full_2_3_5_app_with_tests/public/500.html +30 -0
  70. data/test/full_2_3_5_app_with_tests/public/favicon.ico +0 -0
  71. data/test/full_2_3_5_app_with_tests/public/images/rails.png +0 -0
  72. data/test/full_2_3_5_app_with_tests/public/index.html +275 -0
  73. data/test/full_2_3_5_app_with_tests/public/javascripts/application.js +2 -0
  74. data/test/full_2_3_5_app_with_tests/public/javascripts/controls.js +963 -0
  75. data/test/full_2_3_5_app_with_tests/public/javascripts/dragdrop.js +973 -0
  76. data/test/full_2_3_5_app_with_tests/public/javascripts/effects.js +1128 -0
  77. data/test/full_2_3_5_app_with_tests/public/javascripts/prototype.js +4320 -0
  78. data/test/full_2_3_5_app_with_tests/public/robots.txt +5 -0
  79. data/test/full_2_3_5_app_with_tests/public/stylesheets/scaffold.css +54 -0
  80. data/test/full_2_3_5_app_with_tests/script/about +4 -0
  81. data/test/full_2_3_5_app_with_tests/script/console +3 -0
  82. data/test/full_2_3_5_app_with_tests/script/dbconsole +3 -0
  83. data/test/full_2_3_5_app_with_tests/script/destroy +3 -0
  84. data/test/full_2_3_5_app_with_tests/script/generate +3 -0
  85. data/test/full_2_3_5_app_with_tests/script/performance/benchmarker +3 -0
  86. data/test/full_2_3_5_app_with_tests/script/performance/profiler +3 -0
  87. data/test/full_2_3_5_app_with_tests/script/plugin +3 -0
  88. data/test/full_2_3_5_app_with_tests/script/runner +3 -0
  89. data/test/full_2_3_5_app_with_tests/script/server +3 -0
  90. data/test/full_2_3_5_app_with_tests/test/factories.rb +18 -0
  91. data/test/full_2_3_5_app_with_tests/test/functional/translations_controller_test.rb +66 -0
  92. data/test/full_2_3_5_app_with_tests/test/integration/translation_test.rb +72 -0
  93. data/test/full_2_3_5_app_with_tests/test/performance/browsing_test.rb +9 -0
  94. data/test/full_2_3_5_app_with_tests/test/selenium.rb +83 -0
  95. data/test/full_2_3_5_app_with_tests/test/test_helper.rb +86 -0
  96. data/test/full_2_3_5_app_with_tests/test/unit/helpers/translatables_helper_test.rb +37 -0
  97. data/test/full_2_3_5_app_with_tests/test/unit/helpers/translations_helper_test.rb +62 -0
  98. data/test/full_2_3_5_app_with_tests/test/unit/mongo_translatable_test.rb +342 -0
  99. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/init.rb +1 -0
  100. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter.rb +94 -0
  101. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/base.rb +31 -0
  102. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/force_extension.rb +57 -0
  103. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/locale.rb +70 -0
  104. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/pagination.rb +33 -0
  105. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/uuid_token.rb +78 -0
  106. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/force_extension_spec.rb +65 -0
  107. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/generation_spec.rb +367 -0
  108. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/pagination_extension_spec.rb +19 -0
  109. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/recognition_spec.rb +76 -0
  110. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/routing_filter_spec.rb +114 -0
  111. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/spec_helper.rb +108 -0
  112. metadata +309 -0
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,54 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ .fieldWithErrors {
20
+ padding: 2px;
21
+ background-color: red;
22
+ display: table;
23
+ }
24
+
25
+ #errorExplanation {
26
+ width: 400px;
27
+ border: 2px solid red;
28
+ padding: 7px;
29
+ padding-bottom: 12px;
30
+ margin-bottom: 20px;
31
+ background-color: #f0f0f0;
32
+ }
33
+
34
+ #errorExplanation h2 {
35
+ text-align: left;
36
+ font-weight: bold;
37
+ padding: 5px 5px 5px 15px;
38
+ font-size: 12px;
39
+ margin: -7px;
40
+ background-color: #c00;
41
+ color: #fff;
42
+ }
43
+
44
+ #errorExplanation p {
45
+ color: #333;
46
+ margin-bottom: 0;
47
+ padding: 5px;
48
+ }
49
+
50
+ #errorExplanation ul li {
51
+ font-size: 12px;
52
+ list-style: square;
53
+ }
54
+
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
4
+ require 'commands/about'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/dbconsole'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/destroy'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/generate'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../../config/boot', __FILE__)
3
+ require 'commands/performance/benchmarker'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../../config/boot', __FILE__)
3
+ require 'commands/performance/profiler'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/plugin'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/runner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/server'
@@ -0,0 +1,18 @@
1
+ Factory.define :item do |f|
2
+ f.sequence(:label) { |n| "a label#{n}"}
3
+ f.sequence(:description) { |n| "a description#{n}"}
4
+ end
5
+
6
+ Factory.define :not_swapped_in_record do |r|
7
+ r.sequence(:name) { |n| "a name#{n}"}
8
+ end
9
+
10
+ Factory.define :person do |p|
11
+ p.sequence(:name) { |n| "a name#{n}"}
12
+ end
13
+
14
+ Factory.define :recipe do |r|
15
+ r.sequence(:name) { |n| "a name#{n}"}
16
+ r.sequence(:steps) { |n| ["steps#{n} - 1", "steps#{n} - 2"]}
17
+ r.sequence(:ingredients) { |n| ["ingredients#{n} - 1", "ingredients#{n} - 2"]}
18
+ end
@@ -0,0 +1,66 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ class TranslationsControllerTest < ActionController::TestCase
5
+ context "The translations controller" do
6
+ setup do
7
+ @item = Factory.create(:item)
8
+ end
9
+
10
+ should "get index" do
11
+ get :index, :item_id => 1
12
+ assert_response :success
13
+ assert_not_nil assigns(:translations)
14
+ end
15
+
16
+ should "get new" do
17
+ get :new, :item_id => 1
18
+ assert_response :success
19
+ end
20
+
21
+ should "create translation" do
22
+ assert_difference('Item::Translation.count') do
23
+ post :create, :translation => { :label => 'une étiquette', :locale => 'fr'}, :item_id => 1
24
+ end
25
+
26
+ assert_redirected_to :action => 'show', :locale => assigns(:translation).locale, :id => 1, :controller => 'items'
27
+ end
28
+
29
+ context "when there is an existing translation" do
30
+ setup do
31
+ @item.translate(:label => 'une étiquette', :locale => 'fr').save
32
+ @translation_1 = @item.translations.first
33
+ end
34
+
35
+ should "get index with a translation" do
36
+ get :index, :item_id => 1
37
+ assert assigns(:translations).size == 1
38
+ end
39
+
40
+ should "show translation" do
41
+ get :show, :id => @translation_1.locale, :item_id => 1
42
+ assert_response :success
43
+ end
44
+
45
+ should "get edit" do
46
+ get :edit, :id => @translation_1.locale, :item_id => 1
47
+ assert_response :success
48
+ end
49
+
50
+ should "update translation" do
51
+ put :update, :id => @translation_1.locale, :translation => { :label => "oui oui" }, :item_id => 1
52
+ assert_redirected_to :action => 'show', :locale => assigns(:translation).locale, :id => 1, :controller => 'items'
53
+ end
54
+
55
+ should "destroy translation" do
56
+ assert_difference('Item::Translation.count', -1) do
57
+ delete :destroy, :id => @translation_1.locale, :item_id => 1
58
+ end
59
+
60
+ assert_redirected_to :action => :index
61
+ end
62
+ end
63
+ end
64
+
65
+ end
66
+
@@ -0,0 +1,72 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ Webrat.configure do |config|
5
+ config.mode = :rails
6
+ end
7
+
8
+ class TranslationTest < ActionController::IntegrationTest
9
+ context "A translatable object" do
10
+ include Webrat::HaveTagMatcher
11
+ setup do
12
+ @item = Factory.create(:item)
13
+ end
14
+
15
+ should "have links to locales needing translation on its show page" do
16
+ visit "/en/items/1"
17
+ assert_contain "Needs translating to"
18
+ assert_have_tag "a", :href => "/en/items/1/translations/new?to_locale=zh", :content => "中文"
19
+ end
20
+
21
+ should "have passed in locale as hidden input on its new page" do
22
+ visit "/en/items/1/translations/new?to_locale=fr"
23
+ assert_have_tag "input", :type => "hidden", :value => "fr", :name => "item_translation[locale]"
24
+ end
25
+
26
+ should "have hidden input for locale with value of current I18n.locale" do
27
+ visit "/fr/items/1/translations/new?to_locale=fr"
28
+ assert_have_tag "input", :type => "hidden", :value => "fr", :name => "item_translation[locale]"
29
+ end
30
+
31
+ should "be able to create a new locale following links from its show page" do
32
+ visit "/en/items/1"
33
+ click_link "Français"
34
+ fill_in "item_translation_label", :with => LOCALE_LABELS[:fr]
35
+ click_button "Create"
36
+ assert_contain "Disponible en:"
37
+ # redirected show translated object in locale of translation added
38
+ assert_have_tag "li", :content => "Français"
39
+ end
40
+
41
+ context "that has been previously translated" do
42
+
43
+ setup do
44
+ translate_item_for_locales(@item, [:fr, :zh])
45
+ end
46
+
47
+ should "have locales that have been translated on its show page" do
48
+ visit "/en/items/1"
49
+ assert_have_tag "a", :href => "/fr/items/1", :content => "Français"
50
+ assert_have_tag "a", :href => "/zh/items/1", :content => "中文"
51
+ end
52
+
53
+ should "have links to translated locales on its show page, which when followed change locale for object" do
54
+ visit "/en/items/1"
55
+ click_link "中文"
56
+ assert_equal "zh", I18n.locale.to_s
57
+ assert_contain "標籤"
58
+ end
59
+
60
+ should "have original in original locale when viewing edit translation from a different locale" do
61
+ visit "/fr/items/1/translations/fr/edit"
62
+ assert_contain @item.label
63
+ end
64
+
65
+ should "be able to edit translation" do
66
+ visit "/en/items/1/translations/fr/edit"
67
+ fill_in "item_translation_label", :with => "#{LOCALE_LABELS[:fr]} 2"
68
+ click_button "Update"
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'performance_test_help'
3
+
4
+ # Profiling results for each test method are written to tmp/performance.
5
+ class BrowsingTest < ActionController::PerformanceTest
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -0,0 +1,83 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ # This file is not in integration/ because when run with
5
+ # 'rake', it causes segfaults in the test suite
6
+
7
+ # ATTN: Before runnings these tests, be sure to turn
8
+ # off all extensions and popup blockers in Safari
9
+
10
+ class ActiveSupport::TestCase
11
+ self.use_transactional_fixtures = true
12
+ setup do |session|
13
+ session.host! "localhost:3001"
14
+ end
15
+ end
16
+
17
+ Webrat.configure do |config|
18
+ config.mode = :selenium
19
+ config.application_environment = :test
20
+ config.selenium_browser_key = '*safari'
21
+ end
22
+
23
+ class SeleniumTest < ActionController::IntegrationTest
24
+ context "Using Selenium to test javascript functionality" do
25
+
26
+ # DEBUG: This works so if the others don't, try just this one
27
+ # should "be able to visit the homepage" do
28
+ # visit "/"
29
+ # assert_contain "Welcome aboard"
30
+ # end
31
+
32
+ should "be able to translate an item via AJAX" do
33
+ item = create_item
34
+ click_link "Français"
35
+ assert current_url =~ /\/en\/items\/#{item.id}$/
36
+ assert_contain "Translate from English to Français"
37
+ fill_in 'item_translation_label', :with => 'Certains Point'
38
+ click_button 'Create'
39
+ assert_contain 'Translation was successfully created.'
40
+ end
41
+
42
+ should "be able to switch translations" do
43
+ item = create_item
44
+ click_link "Français"
45
+ assert current_url =~ /\/en\/items\/#{item.id}$/
46
+ assert_contain "Translate from English to Français"
47
+ click_link "Suomi"
48
+ assert current_url =~ /\/en\/items\/#{item.id}$/
49
+ assert_contain "Translate from English to Suomi"
50
+ end
51
+
52
+ should "be able to close the translations box" do
53
+ item = create_item
54
+ click_link "Français"
55
+ click_link "[close]"
56
+ assert_not_contain "Translate from English to Français"
57
+ end
58
+
59
+ should "be able to use the auto translate functionality" do
60
+ item = create_item
61
+ visit "/en/items/#{item.id}/translations/new?to_locale=fr"
62
+ click_link '[auto translate]'
63
+ sleep 1 # ugly way to wait for google to do it's thing
64
+ click_button 'Create'
65
+ assert_contain 'Translation was successfully created.'
66
+ assert_contain 'Certains Point'
67
+ end
68
+
69
+ end
70
+
71
+ private
72
+
73
+ def create_item
74
+ visit "/en/items"
75
+ click_link "New item"
76
+ fill_in 'item_label', :with => 'Some Item'
77
+ fill_in 'item_value', :with => '$3.50'
78
+ fill_in 'item_locale', :with => 'en'
79
+ click_button 'Create'
80
+ assert_contain 'Item was successfully created.'
81
+ Item.last
82
+ end
83
+ end
@@ -0,0 +1,86 @@
1
+ # -*- coding: utf-8 -*-
2
+ ENV["RAILS_ENV"] = "test"
3
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
4
+ require 'test_help'
5
+ require 'rubygems'
6
+ require 'shoulda'
7
+ require 'factory_girl'
8
+ require "webrat"
9
+
10
+ require File.expand_path(File.dirname(__FILE__) + "/factories")
11
+
12
+ Webrat.configure do |config|
13
+ config.mode = :rails
14
+ end
15
+
16
+ LOCALE_LABELS = { :en => "a label",
17
+ :ar => "تسمية",
18
+ :fi => "etiketissä",
19
+ :fr => "une étiquette",
20
+ :zh => "標籤"}
21
+
22
+ class ActiveSupport::TestCase
23
+ # Transactional fixtures accelerate your tests by wrapping each test method
24
+ # in a transaction that's rolled back on completion. This ensures that the
25
+ # test database remains unchanged so your fixtures don't have to be reloaded
26
+ # between every test method. Fewer database queries means faster tests.
27
+ #
28
+ # Read Mike Clark's excellent walkthrough at
29
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
30
+ #
31
+ # Every Active Record database supports transactions except MyISAM tables
32
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
33
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
34
+ # is recommended.
35
+ #
36
+ # The only drawback to using transactional fixtures is when you actually
37
+ # need to test transactions. Since your test is bracketed by a transaction,
38
+ # any transactions started in your code will be automatically rolled back.
39
+ # self.use_transactional_fixtures = true
40
+
41
+ # Instantiated fixtures are slow, but give you @david where otherwise you
42
+ # would need people(:david). If you don't want to migrate your existing
43
+ # test cases which use the @david style and don't mind the speed hit (each
44
+ # instantiated fixtures translates to a database query per test method),
45
+ # then set this back to true.
46
+ # self.use_instantiated_fixtures = false
47
+
48
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
49
+ #
50
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
51
+ # -- they do not yet inherit this setting
52
+ # fixtures :all
53
+
54
+ # Add more helper methods to be used by all tests here...
55
+ # MongoDB teardown per test case
56
+ # Drop all columns after each test case.
57
+ def teardown
58
+ # because we are outside of rails proper
59
+ # the activerecord model instances weren't being wiped from the db
60
+ # doing it by hand here, but may want to change this in the future
61
+ Item.destroy_all
62
+
63
+ MongoMapper.database.collections.each do |coll|
64
+ coll.remove
65
+ end
66
+ end
67
+
68
+ # Make sure that each test case has a teardown
69
+ # method to clear the db after each test.
70
+ def inherited(base)
71
+ base.define_method teardown do
72
+ super
73
+ end
74
+ end
75
+ end
76
+
77
+ MongoMapper.database = 'test'
78
+
79
+ def translate_item_for_locales(item, locales)
80
+ locales = [locales] unless locales.is_a?(Array)
81
+ locales.each do |locale|
82
+ I18n.locale = locale
83
+ item.translate(:label => LOCALE_LABELS[locale]).save
84
+ end
85
+ end
86
+