Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use with_config to ensure there's no confusion about the i18n config …

…in a test
  • Loading branch information...
commit df22871a65655372da065084a969c79c272d0fbc 1 parent 29e26ca
@justinfrench authored
View
113 spec/commit_button_spec.rb
@@ -178,33 +178,36 @@
:submit => 'Custom Submit',
}
}
- Formtastic::FormBuilder.i18n_lookups_by_default = true
end
-
+
after do
::I18n.backend.reload!
end
-
+
it 'should render an input with localized label (I18n)' do
- ::I18n.backend.store_translations :en,
- :formtastic => {
- :actions => {
- :post => {
- :submit => 'Custom Submit %{model}'
+ with_config :i18n_lookups_by_default, true do
+ ::I18n.backend.store_translations :en,
+ :formtastic => {
+ :actions => {
+ :post => {
+ :submit => 'Custom Submit %{model}'
+ }
}
- }
- }
- concat(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"]})
+ }
+ concat(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
end
-
+
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
- concat(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"]})
+ with_config :i18n_lookups_by_default, true do
+ concat(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
end
end
@@ -252,7 +255,6 @@
:create => 'Custom Create',
}
}
- Formtastic::FormBuilder.i18n_lookups_by_default = true
end
after do
@@ -260,25 +262,29 @@
end
it 'should render an input with localized label (I18n)' do
- ::I18n.backend.store_translations :en,
- :formtastic => {
- :actions => {
- :post => {
- :create => 'Custom Create %{model}'
+ with_config :i18n_lookups_by_default, true do
+ ::I18n.backend.store_translations :en,
+ :formtastic => {
+ :actions => {
+ :post => {
+ :create => 'Custom Create %{model}'
+ }
}
- }
- }
- concat(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"]})
+ }
+ concat(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
end
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
- concat(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"]})
+ with_config :i18n_lookups_by_default, true do
+ concat(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
end
@@ -327,7 +333,6 @@
:update => 'Custom Save',
}
}
- Formtastic::FormBuilder.i18n_lookups_by_default = true
end
after do
@@ -335,26 +340,30 @@
end
it 'should render an input with localized label (I18n)' do
- ::I18n.backend.store_translations :en,
- :formtastic => {
- :actions => {
- :post => {
- :update => 'Custom Save %{model}'
+ with_config :i18n_lookups_by_default, true do
+ ::I18n.backend.store_translations :en,
+ :formtastic => {
+ :actions => {
+ :post => {
+ :update => 'Custom Save %{model}'
+ }
}
- }
- }
- concat(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"]})
+ }
+ concat(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
end
it 'should render an input with anoptional localized label (I18n) - if first is not set' do
- concat(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 => {}
+ with_config :i18n_lookups_by_default, true do
+ concat(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
end
end
View
64 spec/i18n_spec.rb
@@ -97,7 +97,6 @@
:post => {:author => "Written by"}
}
}}
- Formtastic::FormBuilder.i18n_lookups_by_default = true
@new_post.stub!(:title)
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :string, :limit => 255))
@@ -105,50 +104,61 @@
after do
::I18n.backend.reload!
- Formtastic::FormBuilder.i18n_lookups_by_default = false
end
it "lookup scopes should be defined" do
- lambda { Formtastic::I18n::SCOPES }.should_not raise_error(::NameError)
+ with_config :i18n_lookups_by_default, true do
+ lambda { Formtastic::I18n::SCOPES }.should_not raise_error(::NameError)
+ end
end
it "should be able to translate with namespaced object" do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title))
- end)
- output_buffer.should have_tag("form label", /Hello post!/)
+ with_config :i18n_lookups_by_default, true do
+ concat(semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title))
+ end)
+ output_buffer.should have_tag("form label", /Hello post!/)
+ end
end
it "should be able to translate without form-object" do
- concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
- concat(builder.input(:title))
- end)
- output_buffer.should have_tag("form label", /Hello project!/)
+ with_config :i18n_lookups_by_default, true do
+ concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
+ concat(builder.input(:title))
+ end)
+ output_buffer.should have_tag("form label", /Hello project!/)
+ end
end
it 'should be able to translate nested objects with nested translations' do
- concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
- builder.semantic_fields_for(:task) do |f|
- concat(f.input(:name))
- end
- end)
- output_buffer.should have_tag("form label", /Hello task name!/)
+ with_config :i18n_lookups_by_default, true do
+ concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
+ builder.semantic_fields_for(:task) do |f|
+ concat(f.input(:name))
+ end
+ end)
+ output_buffer.should have_tag("form label", /Hello task name!/)
+ end
end
it 'should be able to translate nested objects with top level translations' do
- concat(semantic_form_for(:order, :url => 'http://test.host') do |builder|
- builder.semantic_fields_for(:line_item) do |f|
- concat(f.input(:name))
- end
- end)
- output_buffer.should have_tag("form label", /Hello line item name!/)
+ with_config :i18n_lookups_by_default, true do
+ concat(semantic_form_for(:order, :url => 'http://test.host') do |builder|
+ builder.semantic_fields_for(:line_item) do |f|
+ concat(f.input(:name))
+ end
+ end)
+ output_buffer.should have_tag("form label", /Hello line item name!/)
+ end
end
it 'should be able to translate helper label as Rails does' do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:author))
- end)
- output_buffer.should have_tag("form label", /Written by/)
+ with_config :i18n_lookups_by_default, true do
+ concat(semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:author))
+ end)
+ output_buffer.should have_tag("form label", /Written by/)
+ end
end
# TODO: Add spec for namespaced models?
View
142 spec/input_spec.rb
@@ -649,32 +649,35 @@ def should_be_required(options)
}
}
}
- Formtastic::FormBuilder.i18n_lookups_by_default = false
end
it 'should render a label with localized label (I18n)' do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title, :label => true))
- concat(builder.input(:published, :as => :boolean, :label => true))
- end)
- output_buffer.should have_tag('form li label', Regexp.new('^' + @localized_label_text))
+ with_config :i18n_lookups_by_default, false do
+ concat(semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, :label => true))
+ concat(builder.input(:published, :as => :boolean, :label => true))
+ end)
+ output_buffer.should have_tag('form li label', Regexp.new('^' + @localized_label_text))
+ end
end
it 'should render a hint paragraph containing an optional localized label (I18n) if first is not set' do
- ::I18n.backend.store_translations :en,
- :formtastic => {
- :labels => {
- :post => {
- :title => nil,
- :published => nil
+ with_config :i18n_lookups_by_default, false do
+ ::I18n.backend.store_translations :en,
+ :formtastic => {
+ :labels => {
+ :post => {
+ :title => nil,
+ :published => nil
+ }
}
- }
- }
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title, :label => true))
- concat(builder.input(:published, :as => :boolean, :label => true))
- end)
- output_buffer.should have_tag('form li label', Regexp.new('^' + @default_localized_label_text))
+ }
+ concat(semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, :label => true))
+ concat(builder.input(:published, :as => :boolean, :label => true))
+ end)
+ output_buffer.should have_tag('form li label', Regexp.new('^' + @default_localized_label_text))
+ end
end
end
end
@@ -726,7 +729,6 @@ def should_be_required(options)
:title => @default_localized_hint_text,
}
}
- Formtastic::FormBuilder.i18n_lookups_by_default = false
end
after do
@@ -735,76 +737,88 @@ def should_be_required(options)
describe 'when provided value (hint value) is set to TRUE' do
it 'should render a hint paragraph containing a localized hint (I18n)' do
- ::I18n.backend.store_translations :en,
- :formtastic => {
- :hints => {
- :post => {
- :title => @localized_hint_text
+ with_config :i18n_lookups_by_default, false do
+ ::I18n.backend.store_translations :en,
+ :formtastic => {
+ :hints => {
+ :post => {
+ :title => @localized_hint_text
+ }
}
- }
- }
- concat(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)
+ }
+ concat(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
end
it 'should render a hint paragraph containing a localized hint (I18n) with a custom hint class if i ask for one' do
- ::I18n.backend.store_translations :en,
- :formtastic => {
- :hints => {
- :post => {
- :title => @localized_hint_text
+ with_config :i18n_lookups_by_default, false do
+ ::I18n.backend.store_translations :en,
+ :formtastic => {
+ :hints => {
+ :post => {
+ :title => @localized_hint_text
+ }
}
- }
- }
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title, :hint => true, :hint_class => 'custom-hint-class'))
- end)
- output_buffer.should have_tag('form li p.custom-hint-class', @localized_hint_text)
+ }
+ concat(semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, :hint => true, :hint_class => 'custom-hint-class'))
+ end)
+ output_buffer.should have_tag('form li p.custom-hint-class', @localized_hint_text)
+ end
end
it 'should render a hint paragraph containing an optional localized hint (I18n) if first is not set' do
- concat(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)
+ with_config :i18n_lookups_by_default, false do
+ concat(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
end
describe 'when provided value (label value) is set to FALSE' do
it 'should not render a hint paragraph' do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title, :hint => false))
- end)
- output_buffer.should_not have_tag('form li p.inline-hints', @localized_hint_text)
+ with_config :i18n_lookups_by_default, false do
+ concat(semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, :hint => false))
+ end)
+ output_buffer.should_not have_tag('form li p.inline-hints', @localized_hint_text)
+ end
end
end
end
describe 'when localized hint (I18n) is a model with attribute hints' do
it "should see the provided hash as a blank entry" do
- ::I18n.backend.store_translations :en,
- :formtastic => {
- :hints => {
- :title => { # movie title
- :summary => @localized_hint_text # summary of movie
+ with_config :i18n_lookups_by_default, false do
+ ::I18n.backend.store_translations :en,
+ :formtastic => {
+ :hints => {
+ :title => { # movie title
+ :summary => @localized_hint_text # summary of movie
+ }
}
- }
- }
- semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title, :hint => true))
+ }
+ semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, :hint => true))
+ end
+ output_buffer.should_not have_tag('form li p.inline-hints', @localized_hint_text)
end
- output_buffer.should_not have_tag('form li p.inline-hints', @localized_hint_text)
end
end
describe 'when localized hint (I18n) is not provided' do
it 'should not render a hint paragraph' do
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title))
- end)
- output_buffer.should_not have_tag('form li p.inline-hints')
+ with_config :i18n_lookups_by_default, false do
+ concat(semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title))
+ end)
+ output_buffer.should_not have_tag('form li p.inline-hints')
+ end
end
end
end
View
13 spec/inputs/check_boxes_input_spec.rb
@@ -235,17 +235,16 @@
before do
::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
- Formtastic::FormBuilder.i18n_lookups_by_default = true
-
- @new_post.stub!(:author_ids).and_return(nil)
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:authors, :as => :check_boxes))
- end)
+ with_config :i18n_lookups_by_default, true do
+ @new_post.stub!(:author_ids).and_return(nil)
+ concat(semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:authors, :as => :check_boxes))
+ end)
+ end
end
after do
::I18n.backend.reload!
- Formtastic::FormBuilder.i18n_lookups_by_default = false
end
it "should do foo" do
View
12 spec/inputs/radio_input_spec.rb
@@ -136,16 +136,16 @@
before do
::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
- Formtastic::FormBuilder.i18n_lookups_by_default = true
- @new_post.stub!(:author_ids).and_return(nil)
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:authors, :as => :radio))
- end)
+ with_config :i18n_lookups_by_default, true do
+ @new_post.stub!(:author_ids).and_return(nil)
+ concat(semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:authors, :as => :radio))
+ end)
+ end
end
after do
::I18n.backend.reload!
- Formtastic::FormBuilder.i18n_lookups_by_default = false
end
it "should do foo" do
Please sign in to comment.
Something went wrong with that request. Please try again.