Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 191 lines (156 sloc) 6.25 kb
0a59e0c @yabawock Always use # encoding: utf-8 declaration
yabawock authored
1 # encoding: utf-8
480e559 @yabawock Make tests use require 'spec_helper'
yabawock authored
2 require 'spec_helper'
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
3
4 describe 'Formtastic::I18n' do
433dae2 @yabawock Whitespace Cleanup
yabawock authored
5
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
6 FORMTASTIC_KEYS = [:required, :yes, :no, :create, :update].freeze
433dae2 @yabawock Whitespace Cleanup
yabawock authored
7
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
8 it "should be defined" do
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtastic::...
authored
9 lambda { Formtastic::I18n }.should_not raise_error(::NameError)
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
10 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
11
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
12 describe "default translations" do
13 it "should be defined" do
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtastic::...
authored
14 lambda { Formtastic::I18n::DEFAULT_VALUES }.should_not raise_error(::NameError)
15 Formtastic::I18n::DEFAULT_VALUES.is_a?(::Hash).should == true
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
16 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
17
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
18 it "should exists for the core I18n lookup keys" do
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtastic::...
authored
19 (Formtastic::I18n::DEFAULT_VALUES.keys & FORMTASTIC_KEYS).size.should == FORMTASTIC_KEYS.size
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
20 end
21 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
22
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
23 describe "when I18n locales are available" do
433dae2 @yabawock Whitespace Cleanup
yabawock authored
24
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
25 before do
26 @formtastic_strings = {
27 :yes => 'Default Yes',
28 :no => 'Default No',
743b26b @yabawock Revert "Reverting two i18n patches pulled in from the rails3 branch whic...
yabawock authored
29 :create => 'Default Create %{model}',
30 :update => 'Default Update %{model}',
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
31 :custom_scope => {
32 :duck => 'Duck',
743b26b @yabawock Revert "Reverting two i18n patches pulled in from the rails3 branch whic...
yabawock authored
33 :duck_pond => '%{ducks} ducks in a pond'
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
34 }
35 }
36 ::I18n.backend.store_translations :en, :formtastic => @formtastic_strings
37 end
aea23c4 @yabawock Refactored I18n handling in spec testsuite
yabawock authored
38
39 after do
40 ::I18n.backend.reload!
41 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
42
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
43 it "should translate core strings correctly" do
aea23c4 @yabawock Refactored I18n handling in spec testsuite
yabawock authored
44 ::I18n.backend.store_translations :en, {:formtastic => {:required => 'Default Required'}}
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtastic::...
authored
45 Formtastic::I18n.t(:required).should == "Default Required"
46 Formtastic::I18n.t(:yes).should == "Default Yes"
47 Formtastic::I18n.t(:no).should == "Default No"
48 Formtastic::I18n.t(:create, :model => 'Post').should == "Default Create Post"
49 Formtastic::I18n.t(:update, :model => 'Post').should == "Default Update Post"
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
50 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
51
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
52 it "should all belong to scope 'formtastic'" do
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtastic::...
authored
53 Formtastic::I18n.t(:duck, :scope => [:custom_scope]).should == 'Duck'
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
54 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
55
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
56 it "should override default I18n lookup args if these are specified" do
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtastic::...
authored
57 Formtastic::I18n.t(:duck_pond, :scope => [:custom_scope], :ducks => 15).should == '15 ducks in a pond'
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
58 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
59
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
60 it "should be possible to override default values" do
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtastic::...
authored
61 Formtastic::I18n.t(:required, :default => 'Nothing found!').should == 'Nothing found!'
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
62 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
63
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
64 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
65
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
66 describe "when no I18n locales are available" do
433dae2 @yabawock Whitespace Cleanup
yabawock authored
67
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
68 before do
aea23c4 @yabawock Refactored I18n handling in spec testsuite
yabawock authored
69 ::I18n.backend.reload!
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
70 end
aea23c4 @yabawock Refactored I18n handling in spec testsuite
yabawock authored
71
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
72 it "should use default strings" do
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtastic::...
authored
73 (Formtastic::I18n::DEFAULT_VALUES.keys).each do |key|
74 Formtastic::I18n.t(key, :model => '%{model}').should == Formtastic::I18n::DEFAULT_VALUES[key]
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
75 end
76 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
77
382c552 @grimen Refactored I18n stuff to Formtastic::I18n with specs. Cleaner. Closes #1...
grimen authored
78 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
79
616c42a @grimen Removed redundant stuff with tiny refactoring, and adding a general I18n...
grimen authored
80 describe "I18n string lookups" do
433dae2 @yabawock Whitespace Cleanup
yabawock authored
81
616c42a @grimen Removed redundant stuff with tiny refactoring, and adding a general I18n...
grimen authored
82 include FormtasticSpecHelper
433dae2 @yabawock Whitespace Cleanup
yabawock authored
83
616c42a @grimen Removed redundant stuff with tiny refactoring, and adding a general I18n...
grimen authored
84 before do
f9c1a8a @yabawock Revert all the changes introduced in commits 8d17ca4..8d8c50
yabawock authored
85 @output_buffer = ''
616c42a @grimen Removed redundant stuff with tiny refactoring, and adding a general I18n...
grimen authored
86 mock_everything
433dae2 @yabawock Whitespace Cleanup
yabawock authored
87
41b7b3b @asanghi fallback on helpers.label if formtastic i18n not found
asanghi authored
88 ::I18n.backend.store_translations :en, {:formtastic => {
616c42a @grimen Removed redundant stuff with tiny refactoring, and adding a general I18n...
grimen authored
89 :labels => {
b82fd53 @justinfrench Fixes for i18n under Rails 3.1, all tests pass under Rails 3.1.0.rc1 and...
authored
90 :author => { :name => "Top author name transation" },
f7d9cfd @justinfrench A bunch of Rails 3.1 compatability stuff for #564
authored
91 :post => {:title => "Hello post!", :author => {:name => "Hello author name!"}},
92 :project => {:title => "Hello project!"},
616c42a @grimen Removed redundant stuff with tiny refactoring, and adding a general I18n...
grimen authored
93 }
41b7b3b @asanghi fallback on helpers.label if formtastic i18n not found
asanghi authored
94 }, :helpers => {
95 :label => {
b82fd53 @justinfrench Fixes for i18n under Rails 3.1, all tests pass under Rails 3.1.0.rc1 and...
authored
96 :post => {:body => "Elaborate..." },
97 :author => { :login => "Hello login" }
41b7b3b @asanghi fallback on helpers.label if formtastic i18n not found
asanghi authored
98 }
99 }}
433dae2 @yabawock Whitespace Cleanup
yabawock authored
100
616c42a @grimen Removed redundant stuff with tiny refactoring, and adding a general I18n...
grimen authored
101 @new_post.stub!(:title)
102 @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :string, :limit => 255))
103 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
104
616c42a @grimen Removed redundant stuff with tiny refactoring, and adding a general I18n...
grimen authored
105 after do
aea23c4 @yabawock Refactored I18n handling in spec testsuite
yabawock authored
106 ::I18n.backend.reload!
616c42a @grimen Removed redundant stuff with tiny refactoring, and adding a general I18n...
grimen authored
107 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
108
f22b7a1 @grimen I18N_SCOPES => I18n::SCOPES
grimen authored
109 it "lookup scopes should be defined" do
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config in ...
authored
110 with_config :i18n_lookups_by_default, true do
111 lambda { Formtastic::I18n::SCOPES }.should_not raise_error(::NameError)
112 end
f22b7a1 @grimen I18N_SCOPES => I18n::SCOPES
grimen authored
113 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
114
616c42a @grimen Removed redundant stuff with tiny refactoring, and adding a general I18n...
grimen authored
115 it "should be able to translate with namespaced object" do
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config in ...
authored
116 with_config :i18n_lookups_by_default, true do
117 concat(semantic_form_for(@new_post) do |builder|
118 concat(builder.input(:title))
119 end)
120 output_buffer.should have_tag("form label", /Hello post!/)
121 end
616c42a @grimen Removed redundant stuff with tiny refactoring, and adding a general I18n...
grimen authored
122 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
123
616c42a @grimen Removed redundant stuff with tiny refactoring, and adding a general I18n...
grimen authored
124 it "should be able to translate without form-object" do
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config in ...
authored
125 with_config :i18n_lookups_by_default, true do
126 concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
127 concat(builder.input(:title))
128 end)
129 output_buffer.should have_tag("form label", /Hello project!/)
130 end
616c42a @grimen Removed redundant stuff with tiny refactoring, and adding a general I18n...
grimen authored
131 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
132
b82fd53 @justinfrench Fixes for i18n under Rails 3.1, all tests pass under Rails 3.1.0.rc1 and...
authored
133 it 'should be able to translate nested objects with nested translations' do
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config in ...
authored
134 with_config :i18n_lookups_by_default, true do
f7d9cfd @justinfrench A bunch of Rails 3.1 compatability stuff for #564
authored
135 concat(semantic_form_for(@new_post) do |builder|
b82fd53 @justinfrench Fixes for i18n under Rails 3.1, all tests pass under Rails 3.1.0.rc1 and...
authored
136 concat(builder.semantic_fields_for(@new_post.author) do |f|
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config in ...
authored
137 concat(f.input(:name))
f7d9cfd @justinfrench A bunch of Rails 3.1 compatability stuff for #564
authored
138 end)
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config in ...
authored
139 end)
f7d9cfd @justinfrench A bunch of Rails 3.1 compatability stuff for #564
authored
140 output_buffer.should have_tag("form label", /Hello author name!/)
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config in ...
authored
141 end
6b53be0 @tjtuom Translations for nested models.
tjtuom authored
142 end
143
b82fd53 @justinfrench Fixes for i18n under Rails 3.1, all tests pass under Rails 3.1.0.rc1 and...
authored
144 it 'should be able to translate nested objects with top level translations' do
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config in ...
authored
145 with_config :i18n_lookups_by_default, true do
b82fd53 @justinfrench Fixes for i18n under Rails 3.1, all tests pass under Rails 3.1.0.rc1 and...
authored
146 concat(semantic_form_for(@new_post) do |builder|
147 builder.semantic_fields_for(@new_post.author) do |f|
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config in ...
authored
148 concat(f.input(:name))
149 end
150 end)
b82fd53 @justinfrench Fixes for i18n under Rails 3.1, all tests pass under Rails 3.1.0.rc1 and...
authored
151 output_buffer.should have_tag("form label", /Hello author name!/)
152 end
153 end
154
155 it 'should be able to translate nested forms with top level translations' do
156 with_config :i18n_lookups_by_default, true do
157 concat(semantic_form_for(:post) do |builder|
158 builder.semantic_fields_for(:author) do |f|
159 concat(f.input(:name))
160 end
161 end)
162 output_buffer.should have_tag("form label", /Hello author name!/)
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config in ...
authored
163 end
6b53be0 @tjtuom Translations for nested models.
tjtuom authored
164 end
165
b82fd53 @justinfrench Fixes for i18n under Rails 3.1, all tests pass under Rails 3.1.0.rc1 and...
authored
166 it 'should be able to translate helper label as Rails does' do
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config in ...
authored
167 with_config :i18n_lookups_by_default, true do
168 concat(semantic_form_for(@new_post) do |builder|
b82fd53 @justinfrench Fixes for i18n under Rails 3.1, all tests pass under Rails 3.1.0.rc1 and...
authored
169 concat(builder.input(:body))
170 end)
171 output_buffer.should have_tag("form label", /Elaborate/)
172 end
173 end
174
175 it 'should be able to translate nested helper label as Rails does' do
176 with_config :i18n_lookups_by_default, true do
177 concat(semantic_form_for(@new_post) do |builder|
178 concat(builder.inputs :for => @new_post.author do |f|
179 concat(f.input(:login))
180 end)
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config in ...
authored
181 end)
b82fd53 @justinfrench Fixes for i18n under Rails 3.1, all tests pass under Rails 3.1.0.rc1 and...
authored
182 output_buffer.should have_tag("form label", /Hello login/)
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config in ...
authored
183 end
41b7b3b @asanghi fallback on helpers.label if formtastic i18n not found
asanghi authored
184 end
6b53be0 @tjtuom Translations for nested models.
tjtuom authored
185
616c42a @grimen Removed redundant stuff with tiny refactoring, and adding a general I18n...
grimen authored
186 # TODO: Add spec for namespaced models?
433dae2 @yabawock Whitespace Cleanup
yabawock authored
187
616c42a @grimen Removed redundant stuff with tiny refactoring, and adding a general I18n...
grimen authored
188 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
189
190 end
Something went wrong with that request. Please try again.