Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 211 lines (174 sloc) 6.972 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
43153bc @asanghi Fixes #584 . Retry if value received from i18n is not a string
asanghi authored
133 it "should be able to translate when method name is same as model" do
134 with_config :i18n_lookups_by_default, true do
135 concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
136 concat(builder.input(:author))
137 end)
138 output_buffer.should have_tag("form label", /Author/)
139 end
140 end
141
b82fd53 @justinfrench Fixes for i18n under Rails 3.1, all tests pass under Rails 3.1.0.rc1 and...
authored
142 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
143 with_config :i18n_lookups_by_default, true do
f7d9cfd @justinfrench A bunch of Rails 3.1 compatability stuff for #564
authored
144 concat(semantic_form_for(@new_post) do |builder|
c6cc440 @justinfrench change i18n specs to use association names, not associations
authored
145 concat(builder.semantic_fields_for(:author) do |f|
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config in ...
authored
146 concat(f.input(:name))
f7d9cfd @justinfrench A bunch of Rails 3.1 compatability stuff for #564
authored
147 end)
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config in ...
authored
148 end)
f7d9cfd @justinfrench A bunch of Rails 3.1 compatability stuff for #564
authored
149 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
150 end
6b53be0 @tjtuom Translations for nested models.
tjtuom authored
151 end
152
b82fd53 @justinfrench Fixes for i18n under Rails 3.1, all tests pass under Rails 3.1.0.rc1 and...
authored
153 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
154 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
155 concat(semantic_form_for(@new_post) do |builder|
c6cc440 @justinfrench change i18n specs to use association names, not associations
authored
156 builder.semantic_fields_for(:author) do |f|
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config in ...
authored
157 concat(f.input(:name))
158 end
159 end)
b82fd53 @justinfrench Fixes for i18n under Rails 3.1, all tests pass under Rails 3.1.0.rc1 and...
authored
160 output_buffer.should have_tag("form label", /Hello author name!/)
161 end
162 end
8da6eae @crystalin fix nested object i18n scopes order
crystalin authored
163
164 it 'should be able to translate nested objects with nested object translations' do
165 with_config :i18n_lookups_by_default, true do
166 concat(semantic_form_for(@new_post) do |builder|
167 builder.semantic_fields_for(:project) do |f|
168 concat(f.input(:title))
169 end
170 end)
171 output_buffer.should have_tag("form label", /Hello project!/)
172 end
173 end
b82fd53 @justinfrench Fixes for i18n under Rails 3.1, all tests pass under Rails 3.1.0.rc1 and...
authored
174
175 it 'should be able to translate nested forms with top level translations' do
176 with_config :i18n_lookups_by_default, true do
177 concat(semantic_form_for(:post) do |builder|
178 builder.semantic_fields_for(:author) do |f|
179 concat(f.input(:name))
180 end
181 end)
182 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
183 end
6b53be0 @tjtuom Translations for nested models.
tjtuom authored
184 end
185
b82fd53 @justinfrench Fixes for i18n under Rails 3.1, all tests pass under Rails 3.1.0.rc1 and...
authored
186 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
187 with_config :i18n_lookups_by_default, true do
188 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
189 concat(builder.input(:body))
190 end)
191 output_buffer.should have_tag("form label", /Elaborate/)
192 end
193 end
194
195 it 'should be able to translate nested helper label as Rails does' do
196 with_config :i18n_lookups_by_default, true do
197 concat(semantic_form_for(@new_post) do |builder|
c6cc440 @justinfrench change i18n specs to use association names, not associations
authored
198 concat(builder.inputs(:for => :author) do |f|
b82fd53 @justinfrench Fixes for i18n under Rails 3.1, all tests pass under Rails 3.1.0.rc1 and...
authored
199 concat(f.input(:login))
200 end)
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config in ...
authored
201 end)
b82fd53 @justinfrench Fixes for i18n under Rails 3.1, all tests pass under Rails 3.1.0.rc1 and...
authored
202 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
203 end
41b7b3b @asanghi fallback on helpers.label if formtastic i18n not found
asanghi authored
204 end
6b53be0 @tjtuom Translations for nested models.
tjtuom authored
205
616c42a @grimen Removed redundant stuff with tiny refactoring, and adding a general I18n...
grimen authored
206 # TODO: Add spec for namespaced models?
433dae2 @yabawock Whitespace Cleanup
yabawock authored
207
616c42a @grimen Removed redundant stuff with tiny refactoring, and adding a general I18n...
grimen authored
208 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
209
210 end
Something went wrong with that request. Please try again.