Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 42 lines (32 sloc) 1.965 kb
e277bd0 @josevalim Add error_messages_for, error_messages_on and friends to the plugin.
josevalim authored
1 require 'test_helper'
2
3 class DynamicFormI18nTest < Test::Unit::TestCase
4 include ActionView::Context
a28361a @josevalim Make tests green on latest Rails.
josevalim authored
5 include ActionView::Helpers::DynamicForm
e277bd0 @josevalim Add error_messages_for, error_messages_on and friends to the plugin.
josevalim authored
6
7 attr_reader :request
8
9 def setup
10 @object = stub :errors => stub(:count => 1, :full_messages => ['full_messages'])
11 @object.stubs :to_model => @object
12 @object.stubs :class => stub(:model_name => stub(:human => ""))
13
14 @object_name = 'book_seller'
15 @object_name_without_underscore = 'book seller'
16
17 stubs(:content_tag).returns 'content_tag'
18
19 I18n.stubs(:t).with(:'header', :locale => 'en', :scope => [:errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved"
20 I18n.stubs(:t).with(:'body', :locale => 'en', :scope => [:errors, :template]).returns 'There were problems with the following fields:'
21 end
22
23 def test_error_messages_for_given_a_header_option_it_does_not_translate_header_message
24 I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:errors, :template], :count => 1, :model => '').never
25 error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en')
26 end
27
28 def test_error_messages_for_given_no_header_option_it_translates_header_message
29 I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:errors, :template], :count => 1, :model => '').returns 'header message'
30 error_messages_for(:object => @object, :locale => 'en')
31 end
32
33 def test_error_messages_for_given_a_message_option_it_does_not_translate_message
34 I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:errors, :template]).never
35 error_messages_for(:object => @object, :message => 'message', :locale => 'en')
36 end
37
38 def test_error_messages_for_given_no_message_option_it_translates_message
39 I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:errors, :template]).returns 'There were problems with the following fields:'
40 error_messages_for(:object => @object, :locale => 'en')
41 end
42 end
Something went wrong with that request. Please try again.