Skip to content

Commit

Permalink
Added specs for boolean select/collection, and yes/no values back to …
Browse files Browse the repository at this point in the history
…Symbols for convention - in a way that works this time.
  • Loading branch information
grimen authored and justinfrench committed Nov 18, 2009
1 parent e3c200a commit 269e530
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/formtastic.rb
Expand Up @@ -1189,8 +1189,8 @@ def detect_label_method(collection) #:nodoc:
# is provided.
#
def create_boolean_collection(options)
options[:true] ||= ::I18n.t('yes', :default => 'Yes', :scope => [:formtastic])
options[:false] ||= ::I18n.t('no', :default => 'No', :scope => [:formtastic])
options[:true] ||= ::I18n.t(:yes, :default => 'Yes', :scope => [:formtastic])
options[:false] ||= ::I18n.t(:no, :default => 'No', :scope => [:formtastic])
options[:value_as_class] = true unless options.key?(:value_as_class)

[ [ options.delete(:true), true], [ options.delete(:false), false ] ]
Expand Down
4 changes: 2 additions & 2 deletions lib/locale/en.yml
@@ -1,7 +1,7 @@
en:
formtastic:
"yes": 'Yes'
"no": 'No'
:yes: 'Yes'
:no: 'No'
create: 'Create'
save: 'Save'
submit: 'Submit'
Expand Down
44 changes: 43 additions & 1 deletion spec/inputs/select_input_spec.rb
Expand Up @@ -259,5 +259,47 @@

end

end
describe 'boolean select' do
describe 'default formtastic locale' do
before do
# Note: Works, but something like Formtastic.root.join(...) would probably be "safer".
::I18n.load_path = [File.join(File.dirname(__FILE__), *%w[.. .. lib locale en.yml])]
::I18n.backend.send(:init_translations)

semantic_form_for(@new_post) do |builder|
concat(builder.input(:published, :as => :select))
end
end

after do
::I18n.backend.store_translations :en, {}
end

it 'should render a select with at least options: true/false' do
output_buffer.should have_tag("form li select option[@value='true']", /^Yes$/)
output_buffer.should have_tag("form li select option[@value='false']", /^No$/)
end
end

describe 'custom locale' do
before do
@boolean_select_labels = {:yes => 'Yep', :no => 'Nope'}
::I18n.backend.store_translations :en, :formtastic => @boolean_select_labels

semantic_form_for(@new_post) do |builder|
concat(builder.input(:published, :as => :select))
end
end

after do
::I18n.backend.store_translations :en, {}
end

it 'should render a select with at least options: true/false' do
output_buffer.should have_tag("form li select option[@value='true']", /#{@boolean_select_labels[:yes]}/)
output_buffer.should have_tag("form li select option[@value='false']", /#{@boolean_select_labels[:no]}/)
end
end
end

end

0 comments on commit 269e530

Please sign in to comment.