formtastic-bootstrap 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. data/Gemfile +5 -3
  2. data/Gemfile.lock +72 -60
  3. data/README.md +4 -1
  4. data/Rakefile +1 -1
  5. data/VERSION +1 -1
  6. data/formtastic-bootstrap.gemspec +49 -16
  7. data/lib/formtastic-bootstrap/actions/base.rb +22 -0
  8. data/lib/formtastic-bootstrap/actions/button_action.rb +13 -0
  9. data/lib/formtastic-bootstrap/actions/input_action.rb +13 -0
  10. data/lib/formtastic-bootstrap/actions/link_action.rb +12 -0
  11. data/lib/formtastic-bootstrap/actions.rb +10 -0
  12. data/lib/formtastic-bootstrap/form_builder.rb +4 -2
  13. data/lib/formtastic-bootstrap/helpers/action_helper.rb +12 -0
  14. data/lib/formtastic-bootstrap/helpers/actions_helper.rb +24 -0
  15. data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +2 -4
  16. data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +0 -2
  17. data/lib/formtastic-bootstrap/helpers.rb +6 -8
  18. data/lib/formtastic-bootstrap/inputs/base/choices.rb +6 -35
  19. data/lib/formtastic-bootstrap/inputs/base/collections.rb +9 -0
  20. data/lib/formtastic-bootstrap/inputs/base/grouped_collections.rb +9 -0
  21. data/lib/formtastic-bootstrap/inputs/base/hints.rb +1 -1
  22. data/lib/formtastic-bootstrap/inputs/base/labelling.rb +14 -3
  23. data/lib/formtastic-bootstrap/inputs/base/numeric.rb +9 -0
  24. data/lib/formtastic-bootstrap/inputs/base/stringish.rb +4 -5
  25. data/lib/formtastic-bootstrap/inputs/base/timeish.rb +38 -18
  26. data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +22 -34
  27. data/lib/formtastic-bootstrap/inputs/base.rb +29 -6
  28. data/lib/formtastic-bootstrap/inputs/boolean_input.rb +14 -18
  29. data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +16 -11
  30. data/lib/formtastic-bootstrap/inputs/date_input.rb +3 -9
  31. data/lib/formtastic-bootstrap/inputs/date_select_input.rb +8 -0
  32. data/lib/formtastic-bootstrap/inputs/datetime_input.rb +3 -12
  33. data/lib/formtastic-bootstrap/inputs/datetime_select_input.rb +8 -0
  34. data/lib/formtastic-bootstrap/inputs/email_input.rb +1 -1
  35. data/lib/formtastic-bootstrap/inputs/file_input.rb +1 -1
  36. data/lib/formtastic-bootstrap/inputs/hidden_input.rb +1 -1
  37. data/lib/formtastic-bootstrap/inputs/number_input.rb +3 -3
  38. data/lib/formtastic-bootstrap/inputs/password_input.rb +1 -1
  39. data/lib/formtastic-bootstrap/inputs/phone_input.rb +1 -1
  40. data/lib/formtastic-bootstrap/inputs/radio_input.rb +28 -14
  41. data/lib/formtastic-bootstrap/inputs/range_input.rb +1 -1
  42. data/lib/formtastic-bootstrap/inputs/search_input.rb +1 -1
  43. data/lib/formtastic-bootstrap/inputs/select_input.rb +3 -1
  44. data/lib/formtastic-bootstrap/inputs/string_input.rb +0 -7
  45. data/lib/formtastic-bootstrap/inputs/text_input.rb +1 -1
  46. data/lib/formtastic-bootstrap/inputs/time_input.rb +3 -9
  47. data/lib/formtastic-bootstrap/inputs/time_select_input.rb +8 -0
  48. data/lib/formtastic-bootstrap/inputs/time_zone_input.rb +1 -1
  49. data/lib/formtastic-bootstrap/inputs/url_input.rb +1 -1
  50. data/lib/formtastic-bootstrap/inputs.rb +30 -23
  51. data/lib/formtastic-bootstrap.rb +16 -1
  52. data/spec/actions/button_action_spec.rb +63 -0
  53. data/spec/actions/input_action_spec.rb +59 -0
  54. data/spec/actions/link_action_spec.rb +92 -0
  55. data/spec/helpers/action_helper_spec.rb +368 -0
  56. data/spec/helpers/actions_helper_spec.rb +147 -0
  57. data/spec/helpers/input_helper_spec.rb +238 -259
  58. data/spec/helpers/inputs_helper_spec.rb +84 -25
  59. data/spec/inputs/boolean_input_spec.rb +108 -75
  60. data/spec/inputs/check_boxes_input_spec.rb +106 -91
  61. data/spec/inputs/date_select_input_spec.rb +164 -0
  62. data/spec/inputs/datetime_select_input_spec.rb +112 -0
  63. data/spec/inputs/deprecated_time_date_datetime_inputs_spec.rb +48 -0
  64. data/spec/inputs/email_input_spec.rb +30 -3
  65. data/spec/inputs/file_input_spec.rb +31 -4
  66. data/spec/inputs/hidden_input_spec.rb +63 -32
  67. data/spec/inputs/number_input_spec.rb +37 -8
  68. data/spec/inputs/password_input_spec.rb +30 -3
  69. data/spec/inputs/phone_input_spec.rb +30 -3
  70. data/spec/inputs/radio_input_spec.rb +87 -60
  71. data/spec/inputs/range_input_spec.rb +32 -5
  72. data/spec/inputs/search_input_spec.rb +29 -3
  73. data/spec/inputs/select_input_spec.rb +164 -107
  74. data/spec/inputs/string_input_spec.rb +33 -22
  75. data/spec/inputs/text_input_spec.rb +39 -14
  76. data/spec/inputs/time_select_input_spec.rb +191 -0
  77. data/spec/inputs/time_zone_input_spec.rb +17 -19
  78. data/spec/inputs/url_input_spec.rb +30 -3
  79. data/spec/spec_helper.rb +21 -15
  80. data/spec/support/custom_macros.rb +61 -228
  81. data/spec/support/fb_custom_macros.rb +23 -0
  82. metadata +109 -28
  83. data/lib/formtastic-bootstrap/helpers/buttons_helper.rb +0 -52
  84. data/spec/builder/errors_spec.rb +0 -214
  85. data/spec/helpers/buttons_helper_spec.rb +0 -149
  86. data/spec/inputs/date_input_spec.rb +0 -147
  87. data/spec/inputs/datetime_input_spec.rb +0 -101
  88. data/spec/inputs/time_input_spec.rb +0 -206
  89. data/spec/support/depracation.rb +0 -6
  90. data/spec/support/formtastic_spec_helper.rb +0 -382
@@ -0,0 +1,112 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'datetime select input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+ end
12
+
13
+ describe "general" do
14
+
15
+ before do
16
+ ::I18n.backend.store_translations :en, {}
17
+ output_buffer.replace ''
18
+ concat(semantic_form_for(@new_post) do |builder|
19
+ concat(builder.input(:publish_at, :as => :datetime_select))
20
+ end)
21
+ end
22
+
23
+ it_should_have_bootstrap_horizontal_wrapping
24
+ it_should_have_input_wrapper_with_class("datetime_select")
25
+ it_should_have_input_wrapper_with_class(:input)
26
+ it_should_have_input_wrapper_with_id("post_publish_at_input")
27
+ it_should_apply_error_logic_for_input_type(:datetime_select)
28
+
29
+ it 'should have a legend and label with the label text inside the fieldset' do
30
+ output_buffer.should have_tag('form div.control-group.datetime_select label.control-label', /Publish at/)
31
+ end
32
+
33
+ it 'should have five selects' do
34
+ output_buffer.should have_tag('form div.control-group.datetime_select div.controls select', :count => 5)
35
+ end
36
+ end
37
+
38
+ describe "when namespace is provided" do
39
+
40
+ before do
41
+ output_buffer.replace ''
42
+ concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
43
+ concat(builder.input(:publish_at, :as => :datetime_select))
44
+ end)
45
+ end
46
+
47
+ it_should_have_input_wrapper_with_id("context2_post_publish_at_input")
48
+ it_should_have_select_with_id("context2_post_publish_at_1i")
49
+ it_should_have_select_with_id("context2_post_publish_at_2i")
50
+ it_should_have_select_with_id("context2_post_publish_at_3i")
51
+ it_should_have_select_with_id("context2_post_publish_at_4i")
52
+ it_should_have_select_with_id("context2_post_publish_at_5i")
53
+
54
+ end
55
+
56
+ describe "when index is provided" do
57
+
58
+ before do
59
+ @output_buffer = ''
60
+ mock_everything
61
+
62
+ concat(semantic_form_for(@new_post) do |builder|
63
+ concat(builder.fields_for(:author, :index => 3) do |author|
64
+ concat(author.input(:created_at, :as => :datetime_select))
65
+ end)
66
+ end)
67
+ end
68
+
69
+ it 'should index the id of the control-group' do
70
+ output_buffer.should have_tag("div.control-group#post_author_attributes_3_created_at_input")
71
+ end
72
+
73
+ it 'should index the id of the select tag' do
74
+ output_buffer.should have_tag("select#post_author_attributes_3_created_at_1i")
75
+ output_buffer.should have_tag("select#post_author_attributes_3_created_at_2i")
76
+ output_buffer.should have_tag("select#post_author_attributes_3_created_at_3i")
77
+ output_buffer.should have_tag("select#post_author_attributes_3_created_at_4i")
78
+ output_buffer.should have_tag("select#post_author_attributes_3_created_at_5i")
79
+ end
80
+
81
+ it 'should index the name of the select tag' do
82
+ output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(1i)]']")
83
+ output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(2i)]']")
84
+ output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(3i)]']")
85
+ output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(4i)]']")
86
+ output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(5i)]']")
87
+ end
88
+
89
+ end
90
+
91
+
92
+ describe ':labels option' do
93
+ describe ':labels option' do
94
+ it "should provide a message that :labels is not supported" do
95
+ pending ':labels is not supported'
96
+ end
97
+ end
98
+
99
+ end
100
+
101
+ describe "when required" do
102
+ it "should add the required attribute to the input's html options" do
103
+ with_config :use_required_attribute, true do
104
+ concat(semantic_form_for(@new_post) do |builder|
105
+ concat(builder.input(:title, :as => :datetime_select, :required => true))
106
+ end)
107
+ output_buffer.should have_tag("select[@required]", :count => 5)
108
+ end
109
+ end
110
+ end
111
+
112
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'deprecated time, datetime and date inputs' do
4
+ include FormtasticSpecHelper
5
+
6
+ before do
7
+ @output_buffer = ''
8
+ mock_everything
9
+ end
10
+
11
+ it 'should warn :time is deprecated' do
12
+ ::ActiveSupport::Deprecation.should_receive(:warn)
13
+ semantic_form_for(@new_post) do |f|
14
+ concat(f.input :created_at, :as => :time)
15
+ end
16
+ end
17
+
18
+ it 'should warn :datetime is deprecated' do
19
+ ::ActiveSupport::Deprecation.should_receive(:warn)
20
+ semantic_form_for(@new_post) do |f|
21
+ concat(f.input :created_at, :as => :datetime)
22
+ end
23
+ end
24
+
25
+ it 'should warn :date is deprecated' do
26
+ ::ActiveSupport::Deprecation.should_receive(:warn)
27
+ semantic_form_for(@new_post) do |f|
28
+ concat(f.input :created_at, :as => :date)
29
+ end
30
+ end
31
+
32
+ it 'should use wrapper css class based off :as, not off their parent class' do
33
+ with_deprecation_silenced do
34
+ concat(semantic_form_for(@new_post) do |f|
35
+ concat(f.input :created_at, :as => :time)
36
+ concat(f.input :created_at, :as => :datetime)
37
+ concat(f.input :created_at, :as => :date)
38
+ end)
39
+ end
40
+ output_buffer.should have_tag('div.control-group.time')
41
+ output_buffer.should have_tag('div.control-group.datetime')
42
+ output_buffer.should have_tag('div.control-group.date')
43
+ output_buffer.should_not have_tag('li.time_select')
44
+ output_buffer.should_not have_tag('li.datetime_select')
45
+ output_buffer.should_not have_tag('li.date_select')
46
+ end
47
+
48
+ end
@@ -8,7 +8,6 @@ describe 'email input' do
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
12
11
  end
13
12
 
14
13
  describe "when object is provided" do
@@ -18,10 +17,10 @@ describe 'email input' do
18
17
  end)
19
18
  end
20
19
 
20
+ it_should_have_bootstrap_horizontal_wrapping
21
21
  it_should_have_input_wrapper_with_class(:email)
22
- it_should_have_input_wrapper_with_class(:clearfix)
22
+ it_should_have_input_wrapper_with_class(:input)
23
23
  it_should_have_input_wrapper_with_class(:stringish)
24
- it_should_have_input_class_in_the_right_place
25
24
  it_should_have_input_wrapper_with_id("post_email_input")
26
25
  it_should_have_label_with_text(/Email/)
27
26
  it_should_have_label_for("post_email")
@@ -44,6 +43,34 @@ describe 'email input' do
44
43
 
45
44
  end
46
45
 
46
+ describe "when index is provided" do
47
+
48
+ before do
49
+ @output_buffer = ''
50
+ mock_everything
51
+
52
+ concat(semantic_form_for(@new_post) do |builder|
53
+ concat(builder.fields_for(:author, :index => 3) do |author|
54
+ concat(author.input(:name, :as => :email))
55
+ end)
56
+ end)
57
+ end
58
+
59
+ it 'should index the id of the wrapper' do
60
+ output_buffer.should have_tag("div.control-group#post_author_attributes_3_name_input")
61
+ end
62
+
63
+ it 'should index the id of the select tag' do
64
+ output_buffer.should have_tag("input#post_author_attributes_3_name")
65
+ end
66
+
67
+ it 'should index the name of the select tag' do
68
+ output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
69
+ end
70
+
71
+ end
72
+
73
+
47
74
  describe "when required" do
48
75
  it "should add the required attribute to the input's html options" do
49
76
  with_config :use_required_attribute, true do
@@ -8,16 +8,15 @@ describe 'file input' do
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
12
11
 
13
12
  concat(semantic_form_for(@new_post) do |builder|
14
13
  concat(builder.input(:body, :as => :file))
15
14
  end)
16
15
  end
17
16
 
17
+ it_should_have_bootstrap_horizontal_wrapping
18
18
  it_should_have_input_wrapper_with_class("file")
19
- it_should_have_input_wrapper_with_class(:clearfix)
20
- it_should_have_input_class_in_the_right_place
19
+ it_should_have_input_wrapper_with_class(:input)
21
20
  it_should_have_input_wrapper_with_id("post_body_input")
22
21
  it_should_have_label_with_text(/Body/)
23
22
  it_should_have_label_for("post_body")
@@ -29,7 +28,7 @@ describe 'file input' do
29
28
  concat(semantic_form_for(@new_post) do |builder|
30
29
  concat(builder.input(:title, :as => :file, :input_html => { :class => 'myclass' }))
31
30
  end)
32
- output_buffer.should have_tag("form div.clearfix div.input input.myclass")
31
+ output_buffer.should have_tag("form div.control-group div.controls input.myclass")
33
32
  end
34
33
 
35
34
  describe "when namespace is provided" do
@@ -48,6 +47,34 @@ describe 'file input' do
48
47
 
49
48
  end
50
49
 
50
+ describe "when index is provided" do
51
+
52
+ before do
53
+ @output_buffer = ''
54
+ mock_everything
55
+
56
+ concat(semantic_form_for(@new_post) do |builder|
57
+ concat(builder.fields_for(:author, :index => 3) do |author|
58
+ concat(author.input(:name, :as => :file))
59
+ end)
60
+ end)
61
+ end
62
+
63
+ it 'should index the id of the control group' do
64
+ output_buffer.should have_tag("div.control-group#post_author_attributes_3_name_input")
65
+ end
66
+
67
+ it 'should index the id of the select tag' do
68
+ output_buffer.should have_tag("input#post_author_attributes_3_name")
69
+ end
70
+
71
+ it 'should index the name of the select tag' do
72
+ output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
73
+ end
74
+
75
+ end
76
+
77
+
51
78
  context "when required" do
52
79
  it "should add the required attribute to the input's html options" do
53
80
  with_config :use_required_attribute, true do
@@ -8,61 +8,62 @@ describe 'hidden input' do
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
12
-
13
- concat(semantic_form_for(@new_post) do |builder|
14
- concat(builder.input(:secret, :as => :hidden))
15
- concat(builder.input(:author_id, :as => :hidden, :value => 99))
16
- concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
17
- concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
18
- concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
19
- end)
11
+
12
+ with_deprecation_silenced do
13
+ concat(semantic_form_for(@new_post) do |builder|
14
+ concat(builder.input(:secret, :as => :hidden))
15
+ concat(builder.input(:author_id, :as => :hidden, :value => 99))
16
+ concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
17
+ concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
18
+ concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
19
+ end)
20
+ end
20
21
  end
21
22
 
23
+ it_should_have_bootstrap_horizontal_wrapping
22
24
  it_should_have_input_wrapper_with_class("hidden")
23
- it_should_have_input_wrapper_with_class(:clearfix)
24
- it_should_have_input_class_in_the_right_place
25
+ it_should_have_input_wrapper_with_class(:input)
25
26
  it_should_have_input_wrapper_with_id("post_secret_input")
26
27
  it_should_not_have_a_label
27
28
 
28
29
  it "should generate a input field" do
29
- output_buffer.should have_tag("form div.clearfix div.input input#post_secret")
30
- output_buffer.should have_tag("form div.clearfix div.input input#post_secret[@type=\"hidden\"]")
31
- output_buffer.should have_tag("form div.clearfix div.input input#post_secret[@name=\"post[secret]\"]")
30
+ output_buffer.should have_tag("form div.control-group div.controls input#post_secret")
31
+ output_buffer.should have_tag("form div.control-group div.controls input#post_secret[@type=\"hidden\"]")
32
+ output_buffer.should have_tag("form div.control-group div.controls input#post_secret[@name=\"post[secret]\"]")
32
33
  end
33
34
 
34
35
  it "should get value from the object" do
35
- output_buffer.should have_tag("form div.clearfix div.input input#post_secret[@type=\"hidden\"][@value=\"1\"]")
36
+ output_buffer.should have_tag("form div.control-group div.controls input#post_secret[@type=\"hidden\"][@value=\"1\"]")
36
37
  end
37
38
 
38
39
  it "should pass any explicitly specified value - using :value" do
39
- output_buffer.should have_tag("form div.clearfix div.input input#post_author_id[@type=\"hidden\"][@value=\"99\"]")
40
+ output_buffer.should have_tag("form div.control-group div.controls input#post_author_id[@type=\"hidden\"][@value=\"99\"]")
40
41
  end
41
42
 
42
43
  # Handle Formtastic :input_html options for consistency.
43
44
  it "should pass any explicitly specified value - using :input_html options" do
44
- output_buffer.should have_tag("form div.clearfix div.input input#post_published[@type=\"hidden\"][@value=\"true\"]")
45
+ output_buffer.should have_tag("form div.control-group div.controls input#post_published[@type=\"hidden\"][@value=\"true\"]")
45
46
  end
46
47
 
47
48
  it "should pass any option specified using :input_html" do
48
- output_buffer.should have_tag("form div.clearfix div.input input#new_post_reviewer[@type=\"hidden\"][@class=\"new_post_reviewer\"]")
49
+ output_buffer.should have_tag("form div.control-group div.controls input#new_post_reviewer[@type=\"hidden\"][@class=\"new_post_reviewer\"]")
49
50
  end
50
51
 
51
52
  it "should prefer :input_html over directly supplied options" do
52
- output_buffer.should have_tag("form div.clearfix div.input input#post_author_id[@type=\"hidden\"][@value=\"formtastic_value\"]")
53
+ output_buffer.should have_tag("form div.control-group div.controls input#post_author_id[@type=\"hidden\"][@value=\"formtastic_value\"]")
53
54
  end
54
55
 
55
56
  it "should not render inline errors" do
56
57
  @errors = mock('errors')
57
- @errors.stub!(:[]).with(:secret).and_return(["foo", "bah"])
58
+ @errors.stub!(:[]).with(errors_matcher(:secret)).and_return(["foo", "bah"])
58
59
  @new_post.stub!(:errors).and_return(@errors)
59
60
 
60
61
  concat(semantic_form_for(@new_post) do |builder|
61
62
  concat(builder.input(:secret, :as => :hidden))
62
63
  end)
63
64
 
64
- output_buffer.should_not have_tag("form li p.inline-errors")
65
- output_buffer.should_not have_tag("form li ul.errors")
65
+ output_buffer.should_not have_tag("form div.control-group div.controls p.inline-errors")
66
+ output_buffer.should_not have_tag("form div.control-group div.controls ul.errors")
66
67
  end
67
68
 
68
69
  it "should not render inline hints" do
@@ -70,8 +71,8 @@ describe 'hidden input' do
70
71
  concat(builder.input(:secret, :as => :hidden, :hint => "all your base are belong to use"))
71
72
  end)
72
73
 
73
- output_buffer.should_not have_tag("form li p.inline-hints")
74
- output_buffer.should_not have_tag("form li ul.hints")
74
+ output_buffer.should_not have_tag("form div.control-group div.controls p.inline-hints")
75
+ output_buffer.should_not have_tag("form div.control-group div.controls ul.hints")
75
76
  end
76
77
 
77
78
  describe "when namespace is provided" do
@@ -79,14 +80,16 @@ describe 'hidden input' do
79
80
  before do
80
81
  @output_buffer = ''
81
82
  mock_everything
82
-
83
- concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
84
- concat(builder.input(:secret, :as => :hidden))
85
- concat(builder.input(:author_id, :as => :hidden, :value => 99))
86
- concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
87
- concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
88
- concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
89
- end)
83
+
84
+ with_deprecation_silenced do
85
+ concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
86
+ concat(builder.input(:secret, :as => :hidden))
87
+ concat(builder.input(:author_id, :as => :hidden, :value => 99))
88
+ concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
89
+ concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
90
+ concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
91
+ end)
92
+ end
90
93
  end
91
94
 
92
95
  attributes_to_check = [:secret, :author_id, :published, :reviewer]
@@ -100,6 +103,34 @@ describe 'hidden input' do
100
103
 
101
104
  end
102
105
 
106
+ describe "when index is provided" do
107
+
108
+ before do
109
+ @output_buffer = ''
110
+ mock_everything
111
+
112
+ concat(semantic_form_for(@new_post) do |builder|
113
+ concat(builder.fields_for(:author, :index => 3) do |author|
114
+ concat(author.input(:name, :as => :hidden))
115
+ end)
116
+ end)
117
+ end
118
+
119
+ it 'should index the id of the control group' do
120
+ output_buffer.should have_tag("div.control-group#post_author_attributes_3_name_input")
121
+ end
122
+
123
+ it 'should index the id of the select tag' do
124
+ output_buffer.should have_tag("input#post_author_attributes_3_name")
125
+ end
126
+
127
+ it 'should index the name of the select tag' do
128
+ output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
129
+ end
130
+
131
+ end
132
+
133
+
103
134
  context "when required" do
104
135
  it "should not add the required attribute to the input's html options" do
105
136
  concat(semantic_form_for(@new_post) do |builder|
@@ -8,8 +8,7 @@ describe 'number input' do
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
12
-
11
+
13
12
  @new_post.class.stub!(:validators_on).with(:title).and_return([
14
13
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than=>2})
15
14
  ])
@@ -25,20 +24,22 @@ describe 'number input' do
25
24
  )
26
25
  end
27
26
 
27
+ it_should_have_bootstrap_horizontal_wrapping
28
28
  it_should_have_input_wrapper_with_class(:number)
29
- it_should_have_input_wrapper_with_class(:clearfix)
29
+ it_should_have_input_wrapper_with_class(:input)
30
+ it_should_have_input_wrapper_with_class(:numeric)
30
31
  it_should_have_input_wrapper_with_class(:stringish)
31
- it_should_have_input_class_in_the_right_place
32
32
  it_should_have_input_wrapper_with_id("post_title_input")
33
33
  it_should_have_label_with_text(/Title/)
34
34
  it_should_have_label_for("post_title")
35
35
  it_should_have_input_with_id("post_title")
36
36
  it_should_have_input_with_type(:number)
37
37
  it_should_have_input_with_name("post[title]")
38
- it_should_use_default_text_field_size_when_not_nil(:string)
39
- it_should_not_use_default_text_field_size_when_nil(:string)
40
- it_should_apply_custom_input_attributes_when_input_html_provided(:string)
41
- it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
38
+ # @todo this is not testing what it should be testing!
39
+ # it_should_use_default_text_field_size_when_not_nil(:string)
40
+ # it_should_not_use_default_text_field_size_when_nil(:string)
41
+ # it_should_apply_custom_input_attributes_when_input_html_provided(:string)
42
+ # it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
42
43
  it_should_apply_error_logic_for_input_type(:number)
43
44
 
44
45
  end
@@ -68,6 +69,34 @@ describe 'number input' do
68
69
  it_should_have_label_and_input_with_id("context2_post_title")
69
70
  end
70
71
 
72
+ describe "when index is provided" do
73
+
74
+ before do
75
+ @output_buffer = ''
76
+ mock_everything
77
+
78
+ concat(semantic_form_for(@new_post) do |builder|
79
+ concat(builder.fields_for(:author, :index => 3) do |author|
80
+ concat(author.input(:name, :as => :number))
81
+ end)
82
+ end)
83
+ end
84
+
85
+ it 'should index the id of the control group' do
86
+ output_buffer.should have_tag("div.control-group#post_author_attributes_3_name_input")
87
+ end
88
+
89
+ it 'should index the id of the select tag' do
90
+ output_buffer.should have_tag("input#post_author_attributes_3_name")
91
+ end
92
+
93
+ it 'should index the name of the select tag' do
94
+ output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
95
+ end
96
+
97
+ end
98
+
99
+
71
100
  describe "when required" do
72
101
  it "should add the required attribute to the input's html options" do
73
102
  with_config :use_required_attribute, true do
@@ -8,17 +8,16 @@ describe 'password input' do
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
12
11
 
13
12
  concat(semantic_form_for(@new_post) do |builder|
14
13
  concat(builder.input(:title, :as => :password))
15
14
  end)
16
15
  end
17
16
 
17
+ it_should_have_bootstrap_horizontal_wrapping
18
18
  it_should_have_input_wrapper_with_class(:password)
19
- it_should_have_input_wrapper_with_class(:clearfix)
19
+ it_should_have_input_wrapper_with_class(:input)
20
20
  it_should_have_input_wrapper_with_class(:stringish)
21
- it_should_have_input_class_in_the_right_place
22
21
  it_should_have_input_wrapper_with_id("post_title_input")
23
22
  it_should_have_label_with_text(/Title/)
24
23
  it_should_have_label_for("post_title")
@@ -59,6 +58,34 @@ describe 'password input' do
59
58
 
60
59
  end
61
60
 
61
+ describe "when index is provided" do
62
+
63
+ before do
64
+ @output_buffer = ''
65
+ mock_everything
66
+
67
+ concat(semantic_form_for(@new_post) do |builder|
68
+ concat(builder.fields_for(:author, :index => 3) do |author|
69
+ concat(author.input(:name, :as => :password))
70
+ end)
71
+ end)
72
+ end
73
+
74
+ it 'should index the id of the control-group' do
75
+ output_buffer.should have_tag("div.control-group#post_author_attributes_3_name_input")
76
+ end
77
+
78
+ it 'should index the id of the select tag' do
79
+ output_buffer.should have_tag("input#post_author_attributes_3_name")
80
+ end
81
+
82
+ it 'should index the name of the select tag' do
83
+ output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
84
+ end
85
+
86
+ end
87
+
88
+
62
89
  describe "when required" do
63
90
  it "should add the required attribute to the input's html options" do
64
91
  with_config :use_required_attribute, true do
@@ -8,7 +8,6 @@ describe 'phone input' do
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
12
11
  end
13
12
 
14
13
  describe "when object is provided" do
@@ -18,10 +17,10 @@ describe 'phone input' do
18
17
  end)
19
18
  end
20
19
 
20
+ it_should_have_bootstrap_horizontal_wrapping
21
21
  it_should_have_input_wrapper_with_class(:phone)
22
- it_should_have_input_wrapper_with_class(:clearfix)
22
+ it_should_have_input_wrapper_with_class(:input)
23
23
  it_should_have_input_wrapper_with_class(:stringish)
24
- it_should_have_input_class_in_the_right_place
25
24
  it_should_have_input_wrapper_with_id("post_phone_input")
26
25
  it_should_have_label_with_text(/Phone/)
27
26
  it_should_have_label_for("post_phone")
@@ -44,6 +43,34 @@ describe 'phone input' do
44
43
 
45
44
  end
46
45
 
46
+ describe "when index is provided" do
47
+
48
+ before do
49
+ @output_buffer = ''
50
+ mock_everything
51
+
52
+ concat(semantic_form_for(@new_post) do |builder|
53
+ concat(builder.fields_for(:author, :index => 3) do |author|
54
+ concat(author.input(:name, :as => :phone))
55
+ end)
56
+ end)
57
+ end
58
+
59
+ it 'should index the id of the control group' do
60
+ output_buffer.should have_tag("div.control-group#post_author_attributes_3_name_input")
61
+ end
62
+
63
+ it 'should index the id of the select tag' do
64
+ output_buffer.should have_tag("input#post_author_attributes_3_name")
65
+ end
66
+
67
+ it 'should index the name of the select tag' do
68
+ output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
69
+ end
70
+
71
+ end
72
+
73
+
47
74
  describe "when required" do
48
75
  it "should add the required attribute to the input's html options" do
49
76
  with_config :use_required_attribute, true do