justinfrench-formtastic 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/formtastic.rb +12 -4
  2. data/spec/formtastic_spec.rb +22 -10
  3. metadata +2 -2
data/lib/formtastic.rb CHANGED
@@ -554,10 +554,14 @@ module Formtastic #:nodoc:
554
554
  #
555
555
  # By default, all select inputs will have a blank option at the top of the list. You can add
556
556
  # a prompt with the :prompt option, or disable the blank option with :include_blank => false.
557
+ #
557
558
  def select_input(method, options)
558
559
  collection = find_collection_for_column(method, options)
559
560
  html_options = options.delete(:input_html) || {}
560
- options[:include_blank] ||= true
561
+
562
+ unless options.key?(:include_blank) || options.key?(:prompt)
563
+ options[:include_blank] = true
564
+ end
561
565
 
562
566
  reflection = find_reflection(method)
563
567
  if reflection && [ :has_many, :has_and_belongs_to_many ].include?(reflection.macro)
@@ -1081,10 +1085,14 @@ module Formtastic #:nodoc:
1081
1085
  #
1082
1086
  def generate_association_input_name(method)
1083
1087
  if reflection = find_reflection(method)
1084
- method = "#{method.to_s.singularize}_id"
1085
- method = method.pluralize if [:has_and_belongs_to_many, :has_many].include?(reflection.macro)
1088
+ if [:has_and_belongs_to_many, :has_many].include?(reflection.macro)
1089
+ "#{method.to_s.singularize}_ids"
1090
+ else
1091
+ "#{method}_id"
1092
+ end
1093
+ else
1094
+ method
1086
1095
  end
1087
- method
1088
1096
  end
1089
1097
 
1090
1098
  # If an association method is passed in (f.input :author) try to find the
@@ -106,7 +106,7 @@ describe 'Formtastic' do
106
106
  Post.stub!(:reflect_on_all_validations).and_return([])
107
107
  Post.stub!(:reflect_on_association).and_return do |column_name|
108
108
  case column_name
109
- when :author
109
+ when :author, :author_status
110
110
  mock('reflection', :klass => Author, :macro => :belongs_to)
111
111
  when :authors
112
112
  mock('reflection', :klass => Author, :macro => :has_and_belongs_to_many)
@@ -1404,6 +1404,18 @@ describe 'Formtastic' do
1404
1404
  it 'should have one option with a "selected" attribute' do
1405
1405
  output_buffer.should have_tag('form li select option[@selected]', :count => 1)
1406
1406
  end
1407
+
1408
+ it 'should not singularize the association name' do
1409
+ @new_post.stub!(:author_status).and_return(@bob)
1410
+ @new_post.stub!(:author_status_id).and_return(@bob.id)
1411
+ @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => :integer, :limit => 255))
1412
+
1413
+ semantic_form_for(@new_post) do |builder|
1414
+ concat(builder.input(:author_status, :as => :select))
1415
+ end
1416
+
1417
+ output_buffer.should have_tag('form li select#post_author_status_id')
1418
+ end
1407
1419
  end
1408
1420
 
1409
1421
  describe 'for a has_many association' do
@@ -1499,7 +1511,7 @@ describe 'Formtastic' do
1499
1511
  end
1500
1512
 
1501
1513
  it 'should have a blank option by default' do
1502
- output_buffer.should have_tag("form li select option[@value='']", //)
1514
+ output_buffer.should have_tag("form li select option[@value='']", "")
1503
1515
  end
1504
1516
  end
1505
1517
 
@@ -1512,25 +1524,25 @@ describe 'Formtastic' do
1512
1524
  end
1513
1525
 
1514
1526
  it 'should not have a blank option' do
1515
- output_buffer.should have_tag("form li select option[@value='']", //)
1527
+ output_buffer.should_not have_tag("form li select option[@value='']", "")
1516
1528
  end
1517
1529
  end
1518
-
1519
- describe 'when :include_blank => true and :prompt => "choose something" is set' do
1530
+
1531
+ describe 'when :prompt => "choose something" is set' do
1520
1532
  before do
1521
1533
  @new_post.stub!(:author_id).and_return(nil)
1522
1534
  semantic_form_for(@new_post) do |builder|
1523
- concat(builder.input(:author, :as => :select, :include_blank => true, :prompt => "choose author"))
1535
+ concat(builder.input(:author, :as => :select, :prompt => "choose author"))
1524
1536
  end
1525
1537
  end
1526
1538
 
1527
- it 'should have a blank select option' do
1528
- output_buffer.should have_tag("form li select option[@value='']", //)
1529
- end
1530
-
1531
1539
  it 'should have a select with prompt' do
1532
1540
  output_buffer.should have_tag("form li select option[@value='']", /choose author/)
1533
1541
  end
1542
+
1543
+ it 'should not have a blank select option' do
1544
+ output_buffer.should_not have_tag("form li select option[@value='']", "")
1545
+ end
1534
1546
  end
1535
1547
 
1536
1548
  describe 'when no object is given' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: justinfrench-formtastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin French
@@ -9,7 +9,7 @@ autorequire: formtastic
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-30 00:00:00 -07:00
12
+ date: 2009-06-17 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15