Permalink
Browse files

Refactored I18n handling in spec testsuite

* Make use of I18n.backend.reload! to clear/reinitialize translation strings
* Start with a minimal set of translation strings and add expected ones in the test
* Reinitialize the translation backend after each test to start with a known state
  • Loading branch information...
1 parent f07059c commit 731b7923f96809c313bf3a5abb38e38da2641d5c @mjonuschat mjonuschat committed Apr 15, 2010
Showing with 59 additions and 62 deletions.
  1. +2 −1 CHANGELOG
  2. +36 −39 spec/commit_button_spec.rb
  3. +8 −11 spec/i18n_spec.rb
  4. +12 −11 spec/input_spec.rb
  5. +1 −0 spec/inputs/time_input_spec.rb
View
@@ -3,8 +3,9 @@
* Changed date/time inputs to default to nil instead of Time.now when the object has no value (due to deprecation warning, #240)
* Changed the behaviour of associations with a :class_name option to be more consistent with what Rails expects
* Fixed issues with Ruby 1.9.1 and Haml
-* Add the :disabled option to check_boxes input
* Fixed inputs_for_nested_attributes only appending to the output buffer
+* Add the :disabled option to check_boxes input
+* Changed I18n handling in spec tests to use I18n.backend.reload! instead of assigning nil
0.9.8
View
@@ -140,7 +140,7 @@
end
after do
- ::I18n.backend.store_translations :en, :formtastic => {:submit => nil}
+ ::I18n.backend.reload!
end
it 'should render an input with default I18n-localized label (fallback)' do
@@ -157,33 +157,34 @@
:formtastic => {
:actions => {
:submit => 'Custom Submit',
- :post => {
- :submit => 'Custom Submit {{model}}'
- }
}
}
::Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
end
- it 'should render an input with localized label (I18n)' do
- semantic_form_for(:post, :url => 'http://example.com') do |builder|
- concat(builder.commit_button)
- end
- output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit Post"][@class~="submit"]})
+ after do
+ ::I18n.backend.reload!
end
- it 'should render an input with anoptional localized label (I18n) - if first is not set' do
+ it 'should render an input with localized label (I18n)' do
::I18n.backend.store_translations :en,
:formtastic => {
:actions => {
:post => {
- :submit => nil
+ :submit => 'Custom Submit {{model}}'
}
}
}
semantic_form_for(:post, :url => 'http://example.com') do |builder|
concat(builder.commit_button)
end
+ output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit Post"][@class~="submit"]})
+ end
+
+ it 'should render an input with anoptional localized label (I18n) - if first is not set' do
+ semantic_form_for(:post, :url => 'http://example.com') do |builder|
+ concat(builder.commit_button)
+ end
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit"][@class~="submit"]})
end
@@ -213,7 +214,7 @@
end
after do
- ::I18n.backend.store_translations :en, :formtastic => {:create => nil}
+ ::I18n.backend.reload!
end
it 'should render an input with default I18n-localized label (fallback)' do
@@ -230,40 +231,35 @@
:formtastic => {
:actions => {
:create => 'Custom Create',
- :post => {
- :create => 'Custom Create {{model}}'
- }
}
}
::Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
end
after do
- ::I18n.backend.store_translations :en, :formtastic => nil
+ ::I18n.backend.reload!
end
it 'should render an input with localized label (I18n)' do
- semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button)
- end
- output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create Post"][@class~="create"]})
- end
-
- it 'should render an input with anoptional localized label (I18n) - if first is not set' do
::I18n.backend.store_translations :en,
:formtastic => {
:actions => {
:post => {
- :create => nil
+ :create => 'Custom Create {{model}}'
}
}
}
semantic_form_for(@new_post) do |builder|
concat(builder.commit_button)
end
- output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create"][@class~="create"]})
- ::I18n.backend.store_translations :en, :formtastic => nil
-
+ output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create Post"][@class~="create"]})
+ end
+
+ it 'should render an input with anoptional localized label (I18n) - if first is not set' do
+ semantic_form_for(@new_post) do |builder|
+ concat(builder.commit_button)
+ end
+ output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create"][@class~="create"]})
end
end
@@ -292,7 +288,7 @@
end
after do
- ::I18n.backend.store_translations :en, :formtastic => {:update => nil}
+ ::I18n.backend.reload!
end
it 'should render an input with default I18n-localized label (fallback)' do
@@ -309,33 +305,34 @@
:formtastic => {
:actions => {
:update => 'Custom Save',
- :post => {
- :update => 'Custom Save {{model}}'
- }
}
}
::Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
end
- it 'should render an input with localized label (I18n)' do
- semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button)
- end
- output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save Post"][@class~="update"]})
+ after do
+ ::I18n.backend.reload!
end
-
- it 'should render an input with anoptional localized label (I18n) - if first is not set' do
+
+ it 'should render an input with localized label (I18n)' do
::I18n.backend.store_translations :en,
:formtastic => {
:actions => {
:post => {
- :update => nil
+ :update => 'Custom Save {{model}}'
}
}
}
semantic_form_for(@new_post) do |builder|
concat(builder.commit_button)
end
+ output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save Post"][@class~="update"]})
+ end
+
+ it 'should render an input with anoptional localized label (I18n) - if first is not set' do
+ semantic_form_for(@new_post) do |builder|
+ concat(builder.commit_button)
+ end
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save"][@class~="update"]})
::I18n.backend.store_translations :en, :formtastic => {}
end
View
@@ -24,7 +24,6 @@
before do
@formtastic_strings = {
- :required => 'Default Required',
:yes => 'Default Yes',
:no => 'Default No',
:create => 'Default Create {{model}}',
@@ -36,8 +35,13 @@
}
::I18n.backend.store_translations :en, :formtastic => @formtastic_strings
end
+
+ after do
+ ::I18n.backend.reload!
+ end
it "should translate core strings correctly" do
+ ::I18n.backend.store_translations :en, {:formtastic => {:required => 'Default Required'}}
::Formtastic::I18n.t(:required).should == "Default Required"
::Formtastic::I18n.t(:yes).should == "Default Yes"
::Formtastic::I18n.t(:no).should == "Default No"
@@ -54,7 +58,6 @@
end
it "should be possible to override default values" do
- ::I18n.backend.store_translations :en, {:formtastic => {:required => nil}}
::Formtastic::I18n.t(:required, :default => 'Nothing found!').should == 'Nothing found!'
end
@@ -63,15 +66,9 @@
describe "when no I18n locales are available" do
before do
- ::I18n.backend.store_translations :en, :formtastic => {
- :required => nil,
- :yes => nil,
- :no => nil,
- :create => nil,
- :update => nil
- }
+ ::I18n.backend.reload!
end
-
+
it "should use default strings" do
(::Formtastic::I18n::DEFAULT_VALUES.keys).each do |key|
::Formtastic::I18n.t(key, :model => '{{model}}').should == ::Formtastic::I18n::DEFAULT_VALUES[key]
@@ -102,7 +99,7 @@
end
after do
- ::I18n.backend.store_translations :en, :formtastic => nil
+ ::I18n.backend.reload!
::Formtastic::SemanticFormBuilder.i18n_lookups_by_default = false
end
View
@@ -528,34 +528,35 @@ def should_be_required(options)
:formtastic => {
:hints => {
:title => @default_localized_hint_text,
- :post => {
- :title => @localized_hint_text
- }
}
}
::Formtastic::SemanticFormBuilder.i18n_lookups_by_default = false
end
+ after do
+ ::I18n.backend.reload!
+ end
+
describe 'when provided value (hint value) is set to TRUE' do
it 'should render a hint paragraph containing a localized hint (I18n)' do
- semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title, :hint => true))
- end
- output_buffer.should have_tag('form li p.inline-hints', @localized_hint_text)
- end
-
- it 'should render a hint paragraph containing an optional localized hint (I18n) if first is not set' do
::I18n.backend.store_translations :en,
:formtastic => {
:hints => {
:post => {
- :title => nil
+ :title => @localized_hint_text
}
}
}
semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :hint => true))
end
+ output_buffer.should have_tag('form li p.inline-hints', @localized_hint_text)
+ end
+
+ it 'should render a hint paragraph containing an optional localized hint (I18n) if first is not set' do
+ semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, :hint => true))
+ end
output_buffer.should have_tag('form li p.inline-hints', @default_localized_hint_text)
end
end
@@ -12,6 +12,7 @@
describe "general" do
before do
+ ::I18n.backend.reload!
output_buffer.replace ''
end

0 comments on commit 731b792

Please sign in to comment.