-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix translating Public Body Categories
Fixes submission of form containing both existing and new translations
- Loading branch information
1 parent
11b2d86
commit 8e947a4
Showing
7 changed files
with
287 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
app/views/admin_public_body_categories/_locale_fields.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div class="tab-pane" id="div-locale-<%=locale.to_s%>"> | ||
<div class="control-group"> | ||
<%= t.hidden_field :locale, :value => locale.to_s %> | ||
<label for="<%= form_tag_id(t.object_name, :title, locale) %>" class="control-label">Title</label> | ||
<div class="controls"> | ||
<%= t.text_field :title, :id => form_tag_id(t.object_name, :title, locale), :class => "span4" %> | ||
</div> | ||
</div> | ||
<div class="control-group"> | ||
<label for="<%= form_tag_id(t.object_name, :description, locale) %>" class="control-label">Description</label> | ||
<div class="controls"> | ||
<%= t.text_field :description, :id => form_tag_id(t.object_name, :description, locale), :class => "span4" %> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') | ||
|
||
describe 'Editing a Public Body Category' do | ||
before do | ||
AlaveteliConfiguration.stub!(:skip_admin_auth).and_return(false) | ||
|
||
confirm(:admin_user) | ||
@admin = login(:admin_user) | ||
@category = FactoryGirl.create(:public_body_category) | ||
end | ||
|
||
it 'can edit the default locale' do | ||
@admin.visit edit_admin_category_path(@category) | ||
@admin.fill_in 'public_body_category_title__en', :with => 'New Category EN' | ||
@admin.click_button 'Save' | ||
|
||
@category.reload | ||
expect(@category.title).to eq('New Category EN') | ||
end | ||
|
||
it 'can add a translation for a single locale' do | ||
expect(@category.find_translation_by_locale('fr')).to be_nil | ||
|
||
@admin.visit edit_admin_category_path(@category) | ||
@admin.fill_in 'public_body_category_translations_attributes_fr_title__fr', :with => 'New Category FR' | ||
@admin.click_button 'Save' | ||
|
||
@category.reload | ||
I18n.with_locale(:fr) do | ||
expect(@category.title).to eq('New Category FR') | ||
end | ||
end | ||
|
||
it 'can add a translation for multiple locales' do | ||
# Add FR translation | ||
expect(@category.find_translation_by_locale('fr')).to be_nil | ||
@admin.visit edit_admin_category_path(@category) | ||
@admin.fill_in 'public_body_category_translations_attributes_fr_title__fr', :with => 'New Category FR' | ||
@admin.click_button 'Save' | ||
|
||
# Add ES translation | ||
expect(@category.find_translation_by_locale('es')).to be_nil | ||
@admin.visit edit_admin_category_path(@category) | ||
@admin.fill_in 'public_body_category_translations_attributes_es_title__es', :with => 'New Category ES' | ||
@admin.click_button 'Save' | ||
|
||
@category.reload | ||
I18n.with_locale(:fr) do | ||
expect(@category.title).to eq('New Category FR') | ||
end | ||
|
||
I18n.with_locale(:es) do | ||
expect(@category.title).to eq('New Category ES') | ||
end | ||
end | ||
|
||
end |
Oops, something went wrong.