i18n_backend_database_rails3 0.2.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 (71) hide show
  1. data/Gemfile +4 -0
  2. data/LICENSE +21 -0
  3. data/README.textile +125 -0
  4. data/Rakefile +1 -0
  5. data/data/locales.yml +4 -0
  6. data/generators/i18n_backend_database/i18n_backend_database_generator.rb +8 -0
  7. data/generators/i18n_backend_database/templates/migrate/create_i18n_tables.rb +19 -0
  8. data/i18n_backend_database.gemspec +24 -0
  9. data/init.rb +1 -0
  10. data/lib/controllers/locales_controller.rb +86 -0
  11. data/lib/controllers/translations_controller.rb +141 -0
  12. data/lib/ext/i18n.rb +68 -0
  13. data/lib/google_language.rb +30 -0
  14. data/lib/i18n_backend_database.rb +9 -0
  15. data/lib/i18n_backend_database/database.rb +263 -0
  16. data/lib/i18n_backend_database/version.rb +7 -0
  17. data/lib/i18n_util.rb +148 -0
  18. data/lib/models/locale.rb +67 -0
  19. data/lib/models/translation.rb +46 -0
  20. data/lib/models/translation_option.rb +26 -0
  21. data/lib/public/images/custom1_bar.gif +0 -0
  22. data/lib/public/images/custom1_box.gif +0 -0
  23. data/lib/public/images/percentImage.png +0 -0
  24. data/lib/public/images/percentImage_back.png +0 -0
  25. data/lib/public/images/percentImage_back1.png +0 -0
  26. data/lib/public/images/percentImage_back2.png +0 -0
  27. data/lib/public/images/percentImage_back3.png +0 -0
  28. data/lib/public/images/percentImage_back4.png +0 -0
  29. data/lib/public/javascripts/jsProgressBarHandler.js +509 -0
  30. data/lib/routing.rb +15 -0
  31. data/lib/views/layouts/translations.html.haml +16 -0
  32. data/lib/views/locales/edit.html.haml +16 -0
  33. data/lib/views/locales/index.html.haml +14 -0
  34. data/lib/views/locales/new.html.haml +14 -0
  35. data/lib/views/locales/show.html.haml +10 -0
  36. data/lib/views/translations/asset_translations.html.haml +23 -0
  37. data/lib/views/translations/edit.html.haml +24 -0
  38. data/lib/views/translations/index.html.haml +21 -0
  39. data/lib/views/translations/new.html.haml +14 -0
  40. data/lib/views/translations/show.html.haml +21 -0
  41. data/lib/views/translations/translations.html.haml +20 -0
  42. data/lib/views/translations/update.rjs +7 -0
  43. data/routes.rb +3 -0
  44. data/spec/assets/public/es/favicons/favicon1.gif +0 -0
  45. data/spec/assets/public/es/images/icons/icon1.gif +0 -0
  46. data/spec/assets/public/es/images/image1.gif +0 -0
  47. data/spec/assets/public/favicons/favicon1.gif +0 -0
  48. data/spec/assets/public/favicons/favicon2.gif +0 -0
  49. data/spec/assets/public/images/icons/icon1.gif +0 -0
  50. data/spec/assets/public/images/icons/icon2.gif +0 -0
  51. data/spec/assets/public/images/image1.gif +0 -0
  52. data/spec/assets/public/images/image2.gif +0 -0
  53. data/spec/assets/public/images/promo/sfc08_140x400_3.gif +0 -0
  54. data/spec/assets/views/test_view1.html.erb +1 -0
  55. data/spec/assets/views/test_view2.html.erb +30 -0
  56. data/spec/caching_spec.rb +87 -0
  57. data/spec/controllers/locales_controller_spec.rb +173 -0
  58. data/spec/controllers/locales_routing_spec.rb +59 -0
  59. data/spec/controllers/translations_controller_spec.rb +189 -0
  60. data/spec/controllers/translations_routing_spec.rb +59 -0
  61. data/spec/database_spec.rb +199 -0
  62. data/spec/i18n_ext_spec.rb +40 -0
  63. data/spec/localize_spec.rb +66 -0
  64. data/spec/localize_text_spec.rb +76 -0
  65. data/spec/models/locale_spec.rb +111 -0
  66. data/spec/models/translation_spec.rb +44 -0
  67. data/spec/spec_helper.rb +16 -0
  68. data/spec/translate_asset_spec.rb +57 -0
  69. data/spec/translate_spec.rb +546 -0
  70. data/tasks/i18n.rake +60 -0
  71. metadata +143 -0
@@ -0,0 +1,15 @@
1
+ module I18n
2
+ module BackendDatabase
3
+ module Routing
4
+ # Loads the set of routes from within a plugin and
5
+ # evaluates them at this point within an application’s
6
+ # main routes.rb file.
7
+ def from_plugin(name)
8
+ map = self # to make 'map' available within the plugin route file
9
+ plugin_root = File.join(RAILS_ROOT, 'vendor', 'plugins')
10
+ routes_path = File.join(plugin_root, name.to_s, 'routes.rb')
11
+ eval(IO.read(routes_path), binding, routes_path) if File.file?(routes_path)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ !!!
2
+ %html{:lang => "en", "xml:lang" => "en", :xmlns => "http://www.w3.org/1999/xhtml"}
3
+ %head
4
+ %meta{:content => "text/html;charset=UTF-8", "http-equiv" => "content-type"}/
5
+ %title
6
+ Translation Administration: #{controller.action_name}
7
+ = stylesheet_link_tag 'scaffold'
8
+ = javascript_include_tag :defaults
9
+ = javascript_include_tag 'jsProgressBarHandler.js'
10
+ %body
11
+ %p
12
+ = link_to 'Textual Translations', translations_url
13
+ \· #{link_to 'Asset Translations', asset_translations_url}
14
+ %body.content
15
+ .content
16
+ = yield
@@ -0,0 +1,16 @@
1
+ %h1 Editing locale
2
+ - form_for(@locale) do |f|
3
+ = f.error_messages
4
+ %p
5
+ = f.label :code
6
+ %br/
7
+ = f.text_field :code
8
+ %p
9
+ = f.label :name
10
+ %br/
11
+ = f.text_field :name
12
+ %p
13
+ = f.submit "Update"
14
+ = link_to 'Show', @locale
15
+ |
16
+ \#{link_to 'Back', locales_path}
@@ -0,0 +1,14 @@
1
+ %h1 Listing locales
2
+ %table
3
+ %tr
4
+ %th Code
5
+ %th Name
6
+ - for locale in @locales
7
+ %tr
8
+ %td= h locale.code
9
+ %td= h locale.name
10
+ %td= link_to 'Show', locale
11
+ %td= link_to 'Edit', edit_locale_path(locale)
12
+ %td= link_to 'Destroy', locale, :confirm => 'Are you sure?', :method => :delete
13
+ %br/
14
+ = link_to 'New locale', new_locale_path
@@ -0,0 +1,14 @@
1
+ %h1 New locale
2
+ - form_for(@locale) do |f|
3
+ = f.error_messages
4
+ %p
5
+ = f.label :code
6
+ %br/
7
+ = f.text_field :code
8
+ %p
9
+ = f.label :name
10
+ %br/
11
+ = f.text_field :name
12
+ %p
13
+ = f.submit "Create"
14
+ = link_to 'Back', locales_path
@@ -0,0 +1,10 @@
1
+ %p
2
+ %b Code:
3
+ = h @locale.code
4
+ %p
5
+ %b Name:
6
+ = h @locale.name
7
+ = link_to 'Edit', edit_locale_path(@locale)
8
+ |
9
+ \#{link_to 'Translations', locale_translations_path(@locale)} |
10
+ \#{link_to 'Back', locales_path}
@@ -0,0 +1,23 @@
1
+ - form_tag asset_translations_url do
2
+ = select_tag :locale_id, options_from_collection_for_select(Locale.all, :code, :name, @locale.code)
3
+ = select_tag :translation_option, options_from_collection_for_select(TranslationOption.all, :code, :description, @translation_option.code)
4
+ = submit_tag 'Go'
5
+ :javascript
6
+ Event.observe(window, 'load', function() {
7
+ myJsProgressBarHandler = new JS_BRAMUS.jsProgressBar($('translate_progress'), 0);
8
+ }, false);
9
+ %p
10
+ Asset Translation progress:
11
+ %span#translate_progress.progressBar= @percentage_translated
12
+ %h2
13
+ = @translation_option.description
14
+ \: #{@locale.name}
15
+ - if @asset_translations.empty?
16
+ %h3 No records for this criteria.
17
+ - for asset in @asset_translations
18
+ %p
19
+ = image_tag(asset, :size => "50x50")
20
+ = link_to(asset, image_path(asset))
21
+ - if !@locale.default_locale? && @translation_option == TranslationOption.translated
22
+ = image_tag(I18n.ta(asset, :locale => @locale.code), :size => "50x50")
23
+ = link_to(asset, image_path(I18n.ta(asset, :locale => @locale.code)))
@@ -0,0 +1,24 @@
1
+ %h1
2
+ Editing translation for #{@locale.code}
3
+ %p
4
+ %b Key:
5
+ = h @translation.key
6
+ %p
7
+ %b Raw Key:
8
+ = h @translation.raw_key
9
+ %p
10
+ %b Pluralization Index:
11
+ = h @translation.pluralization_index
12
+ %p
13
+ %b Default Locale Value:
14
+ = h @translation.default_locale_value
15
+ - form_for([@locale, @translation]) do |f|
16
+ = f.error_messages
17
+ = f.label :value
18
+ %br/
19
+ = f.text_field :value
20
+ %p
21
+ = f.submit "Update"
22
+ = link_to 'Show', locale_translation_path(@locale, @translation)
23
+ |
24
+ \#{link_to 'Back', locale_translations_path}
@@ -0,0 +1,21 @@
1
+ %h1
2
+ Listing translations for #{@locale.code}
3
+ %table
4
+ %tr
5
+ %th Key
6
+ %th Raw Key
7
+ %th Value
8
+ %th Default Locale Value
9
+ - for translation in @translations
10
+ %tr
11
+ %td= h translation.key
12
+ %td= h translation.raw_key
13
+ %td= h translation.value
14
+ %td= h translation.default_locale_value
15
+ %td= link_to 'Show', locale_translation_path(@locale, translation)
16
+ %td= link_to 'Edit', edit_locale_translation_path(@locale, translation)
17
+ %td= link_to 'Destroy', locale_translation_path(@locale, translation), :confirm => 'Are you sure?', :method => :delete
18
+ %br/
19
+ = link_to 'New translation', new_locale_translation_path
20
+ |
21
+ \#{link_to 'Back', locales_path}
@@ -0,0 +1,14 @@
1
+ %h1 New translation
2
+ - form_for([@locale, @translation]) do |f|
3
+ = f.error_messages
4
+ %p
5
+ = f.label :key
6
+ %br/
7
+ = f.text_field :key
8
+ %p
9
+ = f.label :value
10
+ %br/
11
+ = f.text_field :value
12
+ %p
13
+ = f.submit "Create"
14
+ = link_to 'Back', locale_translations_path
@@ -0,0 +1,21 @@
1
+ %p
2
+ %b Locale:
3
+ = h @locale.code
4
+ %p
5
+ %b Key:
6
+ = h @translation.key
7
+ %p
8
+ %b Raw Key:
9
+ = h @translation.raw_key
10
+ %p
11
+ %b Pluralization Index:
12
+ = h @translation.pluralization_index
13
+ %p
14
+ %b Default Locale Value:
15
+ = h @translation.default_locale_value
16
+ %p
17
+ %b Value:
18
+ = h @translation.value
19
+ = link_to 'Edit', edit_locale_translation_path(@locale, @translation)
20
+ |
21
+ \#{link_to 'Back', locale_translations_path}
@@ -0,0 +1,20 @@
1
+ - form_tag translations_url do
2
+ = select_tag :locale_id, options_from_collection_for_select(Locale.all, :code, :name, @locale.code)
3
+ = select_tag :translation_option, options_from_collection_for_select(TranslationOption.all, :code, :description, @translation_option.code)
4
+ = submit_tag 'Go'
5
+ %p
6
+ Textual Translation progress:
7
+ %span#translate_progress.progressBar= @locale.percentage_translated
8
+ %h2
9
+ = @translation_option.description
10
+ \: #{@locale.name}
11
+ - if @translations.empty?
12
+ %h3 No records for this criteria.
13
+ - for translation in @translations
14
+ %div{:id => "translation_#{translation.class}_#{translation.id}"}
15
+ - remote_form_for([@locale, translation]) do |f|
16
+ %p= h translation.default_locale_value || translation.raw_key
17
+ %p
18
+ = f.text_field :value, :size => 128
19
+ = f.submit "Update"
20
+ %hr/
@@ -0,0 +1,7 @@
1
+ # update the percentage and remove the translated record if translated for first time otherwise highlight change
2
+ if @first_time_translating
3
+ page.call 'myJsProgressBarHandler.setPercentage', 'translate_progress', @locale.percentage_translated
4
+ page.remove("translation_#{@translation.class}_#{@translation.id}")
5
+ else
6
+ page.visual_effect :highlight, "translation_#{@translation.class}_#{@translation.id}"
7
+ end
@@ -0,0 +1,3 @@
1
+ map.resources :locales, :has_many => :translations
2
+ map.translations '/translations', :controller => 'translations', :action => 'translations'
3
+ map.asset_translations '/asset_translations', :controller => 'translations', :action => 'asset_translations'
File without changes
File without changes
@@ -0,0 +1 @@
1
+ <div class="promo-ad"><%= link_to (translated_image_tag(I18n.ta("promo/sfc08_140x400_3.gif")), "http://streak.espn.go.com/") %></div>
@@ -0,0 +1,30 @@
1
+ <h1>Listing people</h1>
2
+ <%= image_tag(I18n.ta('image1.gif')) %>
3
+ <%= image_tag(I18n.ta('image2.gif')) %>
4
+ <%= image_tag(I18n.ta('image2.gif')) %> <!-- test duplicate tag ... image should only appear once -->
5
+ <%= image_tag(I18n.ta('icons/icon1.gif')) %>
6
+ <%= image_tag(I18n.ta('icons/icon2.gif')) %>
7
+ <%= image_tag(I18n.ta('/favicons/favicon1.gif')) image_tag(I18n.ta('/favicons/favicon2.gif')) %> <!-- should find tags on same line -->
8
+
9
+ <table>
10
+ <tr>
11
+ <th>Name</th>
12
+ <th>City</th>
13
+ <th>Age</th>
14
+ </tr>
15
+
16
+ <% for person in @people %>
17
+ <tr>
18
+ <td><%=h person.name %></td>
19
+ <td><%=h person.city %></td>
20
+ <td><%=h person.age %></td>
21
+ <td><%= link_to 'Show', person %></td>
22
+ <td><%= link_to 'Edit', edit_person_path(person) %></td>
23
+ <td><%= link_to 'Destroy', person, :confirm => 'Are you sure?', :method => :delete %></td>
24
+ </tr>
25
+ <% end %>
26
+ </table>
27
+
28
+ <br />
29
+
30
+ <%= link_to 'New person', new_person_path(:locale => I18n.locale) %>
@@ -0,0 +1,87 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe I18n::Backend::Database do
4
+ before(:each) do
5
+ @backend = I18n::Backend::Database.new
6
+ I18n.backend = @backend
7
+ end
8
+
9
+ after(:each) do
10
+ @backend.cache_store.clear
11
+ end
12
+
13
+ describe "with default locale en" do
14
+ before(:each) do
15
+ I18n.default_locale = "en"
16
+ @english_locale = Locale.create!(:code => "en")
17
+ end
18
+
19
+ describe "and locale en" do
20
+ before(:each) do
21
+ I18n.locale = "en"
22
+ end
23
+
24
+ it "should cache translations" do
25
+ @english_locale.translations.create!(:key => 'activerecord.errors.messages.blank', :value => 'is blank moron!')
26
+
27
+ options = {:attribute=>"Locale", :value=>nil,
28
+ :scope=>[:activerecord, :errors], :default=>[:"models.translation.blank", :"messages.blank"], :model=>"Translation"}
29
+
30
+ @backend.translate("en", :"models.translation.attributes.locale.blank", options).should == "is blank moron!"
31
+
32
+ @backend.cache_store.exist?("en:#{Translation.hk("activerecord.errors.models.translation.attributes.locale.blank")}").should be_true
33
+ @backend.cache_store.exist?("en:#{Translation.hk("activerecord.errors.models.translation.blank")}").should be_true
34
+ @backend.cache_store.exist?("en:#{Translation.hk("activerecord.errors.messages.blank")}").should be_true
35
+
36
+ @backend.cache_store.read("en:#{Translation.hk("activerecord.errors.models.translation.attributes.locale.blank")}").should == nil
37
+ @backend.cache_store.read("en:#{Translation.hk("activerecord.errors.models.translation.blank")}").should == nil
38
+ @backend.cache_store.read("en:#{Translation.hk("activerecord.errors.messages.blank")}").should == "is blank moron!"
39
+ end
40
+
41
+ it "should update a cache record if the translation record changes" do
42
+ hash_key = Translation.hk("blah")
43
+ @backend.translate("en", "blah")
44
+ @backend.cache_store.read("en:#{hash_key}").should == "blah"
45
+
46
+ translation = @english_locale.translations.find_by_key(Translation.hk("blah"))
47
+ translation.value.should == "blah"
48
+
49
+ translation.update_attribute(:value, "foo")
50
+ translation.value.should == "foo"
51
+ @backend.cache_store.read("en:#{hash_key}").should == "foo"
52
+ end
53
+ end
54
+
55
+ describe "and locale es" do
56
+ before(:each) do
57
+ I18n.locale = "es"
58
+ @spanish_locale = Locale.create!(:code => 'es')
59
+ end
60
+
61
+ it "should cache translations" do
62
+ @english_locale.translations.create!(:key => 'activerecord.errors.messages.blank', :value => 'is blank moron!')
63
+
64
+ options = {:attribute=>"Locale", :value=>nil,
65
+ :scope=>[:activerecord, :errors], :default=>[:"models.translation.blank", :"messages.blank"], :model=>"Translation"}
66
+
67
+ @backend.translate("es", :"models.translation.attributes.locale.blank", options).should == "is blank moron!"
68
+
69
+ @backend.cache_store.exist?("es:#{Translation.hk("activerecord.errors.models.translation.attributes.locale.blank")}").should be_true
70
+ @backend.cache_store.exist?("es:#{Translation.hk("activerecord.errors.models.translation.blank")}").should be_true
71
+ @backend.cache_store.exist?("es:#{Translation.hk("activerecord.errors.messages.blank")}").should be_true
72
+
73
+ @backend.cache_store.read("es:#{Translation.hk("activerecord.errors.models.translation.attributes.locale.blank")}").should == nil
74
+ @backend.cache_store.read("es:#{Translation.hk("activerecord.errors.models.translation.blank")}").should == nil
75
+ @backend.cache_store.read("es:#{Translation.hk("activerecord.errors.messages.blank")}").should == "is blank moron!"
76
+
77
+ @backend.cache_store.exist?("en:#{Translation.hk("activerecord.errors.models.translation.attributes.locale.blank")}").should be_true
78
+ @backend.cache_store.exist?("en:#{Translation.hk("activerecord.errors.models.translation.blank")}").should be_true
79
+ @backend.cache_store.exist?("en:#{Translation.hk("activerecord.errors.messages.blank")}").should be_true
80
+
81
+ @backend.cache_store.read("en:#{Translation.hk("activerecord.errors.models.translation.attributes.locale.blank")}").should == nil
82
+ @backend.cache_store.read("en:#{Translation.hk("activerecord.errors.models.translation.blank")}").should == nil
83
+ @backend.cache_store.read("en:#{Translation.hk("activerecord.errors.messages.blank")}").should == "is blank moron!"
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,173 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe LocalesController do
4
+
5
+ def mock_locale(stubs={})
6
+ @mock_locale ||= mock_model(Locale, stubs)
7
+ end
8
+
9
+ describe "responding to GET index" do
10
+
11
+ it "should expose all locales as @locales" do
12
+ Locale.should_receive(:find).with(:all).and_return([mock_locale])
13
+ get :index
14
+ assigns[:locales].should == [mock_locale]
15
+ end
16
+
17
+ describe "with mime type of xml" do
18
+
19
+ it "should render all locales as xml" do
20
+ request.env["HTTP_ACCEPT"] = "application/xml"
21
+ Locale.should_receive(:find).with(:all).and_return(locales = mock("Array of Locales"))
22
+ locales.should_receive(:to_xml).and_return("generated XML")
23
+ get :index
24
+ response.body.should == "generated XML"
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+
31
+ describe "responding to GET show" do
32
+
33
+ it "should expose the requested locale as @locale" do
34
+ Locale.should_receive(:find_by_code).with("en").and_return(mock_locale)
35
+ get :show, :id => "en"
36
+ assigns[:locale].should equal(mock_locale)
37
+ end
38
+
39
+ describe "with mime type of xml" do
40
+
41
+ it "should render the requested locale as xml" do
42
+ request.env["HTTP_ACCEPT"] = "application/xml"
43
+ Locale.should_receive(:find_by_code).with("en").and_return(mock_locale)
44
+ mock_locale.should_receive(:to_xml).and_return("generated XML")
45
+ get :show, :id => "en"
46
+ response.body.should == "generated XML"
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ describe "responding to GET new" do
54
+
55
+ it "should expose a new locale as @locale" do
56
+ Locale.should_receive(:new).and_return(mock_locale)
57
+ get :new
58
+ assigns[:locale].should equal(mock_locale)
59
+ end
60
+
61
+ end
62
+
63
+ describe "responding to GET edit" do
64
+
65
+ it "should expose the requested locale as @locale" do
66
+ Locale.should_receive(:find_by_code).with("en").and_return(mock_locale)
67
+ get :edit, :id => "en"
68
+ assigns[:locale].should equal(mock_locale)
69
+ end
70
+
71
+ end
72
+
73
+ describe "responding to POST create" do
74
+
75
+ describe "with valid params" do
76
+
77
+ it "should expose a newly created locale as @locale" do
78
+ Locale.should_receive(:new).with({'these' => 'params'}).and_return(mock_locale(:save => true))
79
+ post :create, :locale => {:these => 'params'}
80
+ assigns(:locale).should equal(mock_locale)
81
+ end
82
+
83
+ it "should redirect to the created locale" do
84
+ Locale.stub!(:new).and_return(mock_locale(:save => true))
85
+ post :create, :locale => {}
86
+ response.should redirect_to(locale_url(mock_locale))
87
+ end
88
+
89
+ end
90
+
91
+ describe "with invalid params" do
92
+
93
+ it "should expose a newly created but unsaved locale as @locale" do
94
+ Locale.stub!(:new).with({'these' => 'params'}).and_return(mock_locale(:save => false))
95
+ post :create, :locale => {:these => 'params'}
96
+ assigns(:locale).should equal(mock_locale)
97
+ end
98
+
99
+ it "should re-render the 'new' template" do
100
+ Locale.stub!(:new).and_return(mock_locale(:save => false))
101
+ post :create, :locale => {}
102
+ response.should render_template('new')
103
+ end
104
+
105
+ end
106
+
107
+ end
108
+
109
+ describe "responding to PUT udpate" do
110
+
111
+ describe "with valid params" do
112
+
113
+ it "should update the requested locale" do
114
+ Locale.should_receive(:find_by_code).with("en").and_return(mock_locale)
115
+ mock_locale.should_receive(:update_attributes).with({'these' => 'params'})
116
+ put :update, :id => "en", :locale => {:these => 'params'}
117
+ end
118
+
119
+ it "should expose the requested locale as @locale" do
120
+ Locale.stub!(:find_by_code).and_return(mock_locale(:update_attributes => true))
121
+ put :update, :id => "en"
122
+ assigns(:locale).should equal(mock_locale)
123
+ end
124
+
125
+ it "should redirect to the locale" do
126
+ Locale.stub!(:find).and_return(mock_locale(:update_attributes => true))
127
+ put :update, :id => "1"
128
+ response.should redirect_to(locale_url(mock_locale))
129
+ end
130
+
131
+ end
132
+
133
+ describe "with invalid params" do
134
+
135
+ it "should update the requested locale" do
136
+ Locale.should_receive(:find_by_code).with("en").and_return(mock_locale)
137
+ mock_locale.should_receive(:update_attributes).with({'these' => 'params'})
138
+ put :update, :id => "en", :locale => {:these => 'params'}
139
+ end
140
+
141
+ it "should expose the locale as @locale" do
142
+ Locale.stub!(:find_by_code).and_return(mock_locale(:update_attributes => false))
143
+ put :update, :id => "en"
144
+ assigns(:locale).should equal(mock_locale)
145
+ end
146
+
147
+ it "should re-render the 'edit' template" do
148
+ Locale.stub!(:find_by_code).and_return(mock_locale(:update_attributes => false))
149
+ put :update, :id => "en"
150
+ response.should render_template('edit')
151
+ end
152
+
153
+ end
154
+
155
+ end
156
+
157
+ describe "responding to DELETE destroy" do
158
+
159
+ it "should destroy the requested locale" do
160
+ Locale.should_receive(:find_by_code).with("en").and_return(mock_locale)
161
+ mock_locale.should_receive(:destroy)
162
+ delete :destroy, :id => "en"
163
+ end
164
+
165
+ it "should redirect to the locales list" do
166
+ Locale.stub!(:find_by_code).and_return(mock_locale(:destroy => true))
167
+ delete :destroy, :id => "en"
168
+ response.should redirect_to(locales_url)
169
+ end
170
+
171
+ end
172
+
173
+ end