Updated README.rdoc again
[feedcatcher.git] / vendor / rails / actionpack / test / template / active_record_helper_i18n_test.rb
1 require 'abstract_unit'
2
3 class ActiveRecordHelperI18nTest < Test::Unit::TestCase
4 include ActionView::Helpers::ActiveRecordHelper
5
6 attr_reader :request
7 def setup
8 @object = stub :errors => stub(:count => 1, :full_messages => ['full_messages'])
9 @object_name = 'book'
10 stubs(:content_tag).returns 'content_tag'
11
12 I18n.stubs(:t).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved"
13 I18n.stubs(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:'
14 end
15
16 def test_error_messages_for_given_a_header_option_it_does_not_translate_header_message
17 I18n.expects(:translate).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').never
18 error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en')
19 end
20
21 def test_error_messages_for_given_no_header_option_it_translates_header_message
22 I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns 'header message'
23 I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns ''
24 error_messages_for(:object => @object, :locale => 'en')
25 end
26
27 def test_error_messages_for_given_a_message_option_it_does_not_translate_message
28 I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).never
29 I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns ''
30 error_messages_for(:object => @object, :message => 'message', :locale => 'en')
31 end
32
33 def test_error_messages_for_given_no_message_option_it_translates_message
34 I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:'
35 I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns ''
36 error_messages_for(:object => @object, :locale => 'en')
37 end
38
39 def test_error_messages_for_given_object_name_it_translates_object_name
40 I18n.expects(:t).with(:header, :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => @object_name).returns "1 error prohibited this #{@object_name} from being saved"
41 I18n.expects(:t).with(@object_name, :default => @object_name, :count => 1, :scope => [:activerecord, :models]).once.returns @object_name
42 error_messages_for(:object => @object, :locale => 'en', :object_name => @object_name)
43 end
44 end