formtastic 1.2.5 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. data/.gitignore +13 -0
  2. data/.rspec +2 -0
  3. data/.yardopts +1 -0
  4. data/CHANGELOG +279 -0
  5. data/Gemfile +3 -0
  6. data/README.textile +155 -172
  7. data/RELEASE_PROCESS +7 -0
  8. data/Rakefile +52 -0
  9. data/app/assets/stylesheets/formtastic.css +275 -0
  10. data/app/assets/stylesheets/formtastic_ie6.css +27 -0
  11. data/app/assets/stylesheets/formtastic_ie7.css +17 -0
  12. data/formtastic.gemspec +51 -0
  13. data/lib/formtastic.rb +21 -1960
  14. data/lib/formtastic/engine.rb +7 -0
  15. data/lib/formtastic/form_builder.rb +83 -0
  16. data/lib/formtastic/helpers.rb +16 -0
  17. data/lib/formtastic/helpers/buttons_helper.rb +277 -0
  18. data/lib/formtastic/helpers/errors_helper.rb +113 -0
  19. data/lib/formtastic/helpers/fieldset_wrapper.rb +75 -0
  20. data/lib/formtastic/helpers/file_column_detection.rb +16 -0
  21. data/lib/formtastic/helpers/form_helper.rb +198 -0
  22. data/lib/formtastic/helpers/input_helper.rb +366 -0
  23. data/lib/formtastic/helpers/inputs_helper.rb +392 -0
  24. data/lib/formtastic/helpers/reflection.rb +33 -0
  25. data/lib/formtastic/helpers/semantic_form_helper.rb +11 -0
  26. data/lib/formtastic/html_attributes.rb +21 -0
  27. data/lib/formtastic/i18n.rb +1 -0
  28. data/lib/formtastic/inputs.rb +31 -0
  29. data/lib/formtastic/inputs/base.rb +61 -0
  30. data/lib/formtastic/inputs/base/associations.rb +31 -0
  31. data/lib/formtastic/inputs/base/choices.rb +103 -0
  32. data/lib/formtastic/inputs/base/collections.rb +94 -0
  33. data/lib/formtastic/inputs/base/database.rb +17 -0
  34. data/lib/formtastic/inputs/base/errors.rb +58 -0
  35. data/lib/formtastic/inputs/base/fileish.rb +23 -0
  36. data/lib/formtastic/inputs/base/grouped_collections.rb +77 -0
  37. data/lib/formtastic/inputs/base/hints.rb +31 -0
  38. data/lib/formtastic/inputs/base/html.rb +52 -0
  39. data/lib/formtastic/inputs/base/labelling.rb +55 -0
  40. data/lib/formtastic/inputs/base/naming.rb +42 -0
  41. data/lib/formtastic/inputs/base/options.rb +18 -0
  42. data/lib/formtastic/inputs/base/stringish.rb +35 -0
  43. data/lib/formtastic/inputs/base/timeish.rb +128 -0
  44. data/lib/formtastic/inputs/base/validations.rb +166 -0
  45. data/lib/formtastic/inputs/base/wrapping.rb +40 -0
  46. data/lib/formtastic/inputs/boolean_input.rb +96 -0
  47. data/lib/formtastic/inputs/check_boxes_input.rb +179 -0
  48. data/lib/formtastic/inputs/country_input.rb +66 -0
  49. data/lib/formtastic/inputs/date_input.rb +14 -0
  50. data/lib/formtastic/inputs/datetime_input.rb +9 -0
  51. data/lib/formtastic/inputs/email_input.rb +40 -0
  52. data/lib/formtastic/inputs/file_input.rb +42 -0
  53. data/lib/formtastic/inputs/hidden_input.rb +66 -0
  54. data/lib/formtastic/inputs/number_input.rb +118 -0
  55. data/lib/formtastic/inputs/numeric_input.rb +21 -0
  56. data/lib/formtastic/inputs/password_input.rb +40 -0
  57. data/lib/formtastic/inputs/phone_input.rb +41 -0
  58. data/lib/formtastic/inputs/radio_input.rb +157 -0
  59. data/lib/formtastic/inputs/range_input.rb +119 -0
  60. data/lib/formtastic/inputs/search_input.rb +40 -0
  61. data/lib/formtastic/inputs/select_input.rb +210 -0
  62. data/lib/formtastic/inputs/string_input.rb +34 -0
  63. data/lib/formtastic/inputs/text_input.rb +47 -0
  64. data/lib/formtastic/inputs/time_input.rb +14 -0
  65. data/lib/formtastic/inputs/time_zone_input.rb +48 -0
  66. data/lib/formtastic/inputs/url_input.rb +40 -0
  67. data/lib/formtastic/localized_string.rb +105 -0
  68. data/lib/formtastic/railtie.rb +5 -7
  69. data/lib/formtastic/semantic_form_builder.rb +11 -0
  70. data/lib/formtastic/util.rb +6 -19
  71. data/lib/formtastic/version.rb +3 -0
  72. data/lib/generators/formtastic/install/install_generator.rb +28 -6
  73. data/lib/generators/templates/_form.html.erb +10 -4
  74. data/lib/generators/templates/_form.html.haml +8 -4
  75. data/lib/generators/templates/formtastic.rb +25 -32
  76. data/lib/locale/en.yml +1 -0
  77. data/lib/tasks/verify_rcov.rb +44 -0
  78. data/sample/basic_inputs.html +182 -0
  79. data/sample/config.ru +69 -0
  80. data/sample/index.html +14 -0
  81. data/spec/builder/custom_builder_spec.rb +109 -0
  82. data/spec/builder/error_proc_spec.rb +27 -0
  83. data/spec/builder/errors_spec.rb +193 -0
  84. data/spec/builder/semantic_fields_for_spec.rb +88 -0
  85. data/spec/helpers/buttons_helper_spec.rb +150 -0
  86. data/spec/helpers/commit_button_helper_spec.rb +470 -0
  87. data/spec/helpers/form_helper_spec.rb +135 -0
  88. data/spec/helpers/input_helper_spec.rb +837 -0
  89. data/spec/helpers/inputs_helper_spec.rb +562 -0
  90. data/spec/helpers/semantic_errors_helper_spec.rb +112 -0
  91. data/spec/i18n_spec.rb +199 -0
  92. data/spec/inputs/boolean_input_spec.rb +184 -0
  93. data/spec/inputs/check_boxes_input_spec.rb +375 -0
  94. data/spec/inputs/country_input_spec.rb +133 -0
  95. data/spec/inputs/custom_input_spec.rb +52 -0
  96. data/spec/inputs/date_input_spec.rb +110 -0
  97. data/spec/inputs/datetime_input_spec.rb +115 -0
  98. data/spec/inputs/email_input_spec.rb +55 -0
  99. data/spec/inputs/file_input_spec.rb +59 -0
  100. data/spec/inputs/hidden_input_spec.rb +120 -0
  101. data/spec/inputs/include_blank_spec.rb +70 -0
  102. data/spec/inputs/label_spec.rb +104 -0
  103. data/spec/inputs/number_input_spec.rb +487 -0
  104. data/spec/inputs/numeric_input_spec.rb +41 -0
  105. data/spec/inputs/password_input_spec.rb +69 -0
  106. data/spec/inputs/phone_input_spec.rb +55 -0
  107. data/spec/inputs/placeholder_spec.rb +71 -0
  108. data/spec/inputs/radio_input_spec.rb +234 -0
  109. data/spec/inputs/range_input_spec.rb +477 -0
  110. data/spec/inputs/search_input_spec.rb +55 -0
  111. data/spec/inputs/select_input_spec.rb +545 -0
  112. data/spec/inputs/string_input_spec.rb +163 -0
  113. data/spec/inputs/text_input_spec.rb +158 -0
  114. data/spec/inputs/time_input_spec.rb +155 -0
  115. data/spec/inputs/time_zone_input_spec.rb +87 -0
  116. data/spec/inputs/url_input_spec.rb +55 -0
  117. data/spec/spec.opts +2 -0
  118. data/spec/spec_helper.rb +361 -0
  119. data/spec/support/custom_macros.rb +656 -0
  120. data/spec/support/deferred_garbage_collection.rb +21 -0
  121. data/spec/support/deprecation.rb +6 -0
  122. data/spec/support/test_environment.rb +30 -0
  123. metadata +306 -88
  124. data/generators/form/USAGE +0 -16
  125. data/generators/form/form_generator.rb +0 -111
  126. data/generators/formtastic/formtastic_generator.rb +0 -26
  127. data/init.rb +0 -5
  128. data/lib/formtastic/layout_helper.rb +0 -12
  129. data/lib/generators/formtastic/form/form_generator.rb +0 -84
  130. data/lib/generators/templates/formtastic.css +0 -145
  131. data/lib/generators/templates/formtastic_changes.css +0 -14
  132. data/lib/generators/templates/rails2/_form.html.erb +0 -5
  133. data/lib/generators/templates/rails2/_form.html.haml +0 -4
  134. data/rails/init.rb +0 -2
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ # TODO extract out
5
+ module TestInputs
6
+
7
+ def input_args
8
+ @template = self
9
+ @object = ::Post.new
10
+ @object_name = 'post'
11
+ @method = :title
12
+ @options = {}
13
+ @proc = Proc.new {}
14
+ @builder = Formtastic::FormBuilder.new(@object_name, @object, @template, @options, @proc)
15
+
16
+ [@builder, @template, @object, @object_name, @method, @options]
17
+ end
18
+
19
+ class ::UnimplementedInput
20
+ include Formtastic::Inputs::Base
21
+ end
22
+
23
+ class ::ImplementedInput < UnimplementedInput
24
+ def to_html
25
+ "some HTML output"
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ describe 'AnyCustomInput' do
32
+
33
+ include TestInputs
34
+
35
+ describe "#to_html" do
36
+
37
+ describe 'without an implementation' do
38
+ it "should raise a NotImplementedError exception" do
39
+ expect { ::UnimplementedInput.new(*input_args).to_html }.to raise_error(NotImplementedError)
40
+ end
41
+ end
42
+
43
+ describe 'with an implementation' do
44
+ it "should raise a NotImplementedError exception" do
45
+ expect { ::ImplementedInput.new(*input_args).to_html }.to_not raise_error(NotImplementedError)
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
@@ -0,0 +1,110 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'date 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
+ output_buffer.replace ''
17
+ concat(semantic_form_for(@new_post) do |builder|
18
+ concat(builder.input(:publish_at, :as => :date, :order => [:year, :month, :day]))
19
+ end)
20
+ end
21
+
22
+ it_should_have_input_wrapper_with_class("date")
23
+ it_should_have_input_wrapper_with_class(:input)
24
+ it_should_have_input_wrapper_with_id("post_publish_at_input")
25
+ it_should_have_a_nested_fieldset
26
+ it_should_have_a_nested_fieldset_with_class('fragments')
27
+ it_should_have_a_nested_ordered_list_with_class('fragments-group')
28
+ it_should_apply_error_logic_for_input_type(:date)
29
+
30
+ it 'should have a legend and label with the label text inside the fieldset' do
31
+ output_buffer.should have_tag('form li.date fieldset legend.label label', /Publish at/)
32
+ end
33
+
34
+ it 'should associate the legend label with the first select' do
35
+ output_buffer.should have_tag('form li.date fieldset legend.label')
36
+ output_buffer.should have_tag('form li.date fieldset legend.label label')
37
+ output_buffer.should have_tag('form li.date fieldset legend.label label[@for]')
38
+ output_buffer.should have_tag('form li.date fieldset legend.label label[@for="post_publish_at_1i"]')
39
+ end
40
+
41
+ it 'should have an ordered list of three items inside the fieldset' do
42
+ output_buffer.should have_tag('form li.date fieldset ol.fragments-group')
43
+ output_buffer.should have_tag('form li.date fieldset ol li.fragment', :count => 3)
44
+ end
45
+
46
+ it 'should have three labels for year, month and day' do
47
+ output_buffer.should have_tag('form li.date fieldset ol li label', :count => 3)
48
+ output_buffer.should have_tag('form li.date fieldset ol li label', /year/i)
49
+ output_buffer.should have_tag('form li.date fieldset ol li label', /month/i)
50
+ output_buffer.should have_tag('form li.date fieldset ol li label', /day/i)
51
+ end
52
+
53
+ it 'should have three selects for year, month and day' do
54
+ output_buffer.should have_tag('form li.date fieldset ol li select', :count => 3)
55
+ end
56
+ end
57
+
58
+ describe "when namespace is provided" do
59
+
60
+ before do
61
+ output_buffer.replace ''
62
+ concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
63
+ concat(builder.input(:publish_at, :as => :date, :order => [:year, :month, :day]))
64
+ end)
65
+ end
66
+
67
+ it_should_have_input_wrapper_with_id("context2_post_publish_at_input")
68
+ it_should_have_select_with_id("context2_post_publish_at_1i")
69
+ it_should_have_select_with_id("context2_post_publish_at_2i")
70
+ it_should_have_select_with_id("context2_post_publish_at_3i")
71
+
72
+ end
73
+
74
+ describe ':labels option' do
75
+ fields = [:year, :month, :day]
76
+ fields.each do |field|
77
+ it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
78
+ output_buffer.replace ''
79
+ concat(semantic_form_for(@new_post) do |builder|
80
+ concat(builder.input(:created_at, :as => :date, :labels => { field => "another #{field} label" }))
81
+ end)
82
+ output_buffer.should have_tag('form li.date fieldset ol li label', :count => fields.length)
83
+ fields.each do |f|
84
+ output_buffer.should have_tag('form li.date fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
85
+ end
86
+ end
87
+
88
+ it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
89
+ output_buffer.replace ''
90
+ concat(semantic_form_for(@new_post) do |builder|
91
+ concat(builder.input(:created_at, :as => :date, :labels => { field => "" }))
92
+ end)
93
+ output_buffer.should have_tag('form li.date fieldset ol li label', :count => fields.length-1)
94
+ fields.each do |f|
95
+ output_buffer.should have_tag('form li.date fieldset ol li label', /#{f}/i) unless field == f
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ describe "when required" do
102
+ it "should add the required attribute to the input's html options" do
103
+ concat(semantic_form_for(@new_post) do |builder|
104
+ concat(builder.input(:title, :as => :date, :required => true))
105
+ end)
106
+ output_buffer.should have_tag("select[@required]", :count => 3)
107
+ end
108
+ end
109
+
110
+ end
@@ -0,0 +1,115 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'datetime 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))
20
+ end)
21
+ end
22
+
23
+ it_should_have_input_wrapper_with_class("datetime")
24
+ it_should_have_input_wrapper_with_class(:input)
25
+ it_should_have_input_wrapper_with_id("post_publish_at_input")
26
+ it_should_have_a_nested_fieldset
27
+ it_should_have_a_nested_fieldset_with_class('fragments')
28
+ it_should_have_a_nested_ordered_list_with_class('fragments-group')
29
+ it_should_apply_error_logic_for_input_type(:datetime)
30
+
31
+ it 'should have a legend and label with the label text inside the fieldset' do
32
+ output_buffer.should have_tag('form li.datetime fieldset legend.label label', /Publish at/)
33
+ end
34
+
35
+ it 'should associate the legend label with the first select' do
36
+ output_buffer.should have_tag('form li.datetime fieldset legend.label')
37
+ output_buffer.should have_tag('form li.datetime fieldset legend.label label')
38
+ output_buffer.should have_tag('form li.datetime fieldset legend.label label[@for]')
39
+ output_buffer.should have_tag('form li.datetime fieldset legend.label label[@for="post_publish_at_1i"]')
40
+ end
41
+
42
+ it 'should have an ordered list of five items inside the fieldset' do
43
+ output_buffer.should have_tag('form li.datetime fieldset ol.fragments-group')
44
+ output_buffer.should have_tag('form li.datetime fieldset ol li.fragment', :count => 5)
45
+ end
46
+
47
+ it 'should have five labels for year, month and day' do
48
+ output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => 5)
49
+ output_buffer.should have_tag('form li.datetime fieldset ol li label', /year/i)
50
+ output_buffer.should have_tag('form li.datetime fieldset ol li label', /month/i)
51
+ output_buffer.should have_tag('form li.datetime fieldset ol li label', /day/i)
52
+ output_buffer.should have_tag('form li.datetime fieldset ol li label', /hour/i)
53
+ output_buffer.should have_tag('form li.datetime fieldset ol li label', /min/i)
54
+ end
55
+
56
+ it 'should have five selects' do
57
+ output_buffer.should have_tag('form li.datetime fieldset ol li select', :count => 5)
58
+ end
59
+ end
60
+
61
+ describe "when namespace is provided" do
62
+
63
+ before do
64
+ output_buffer.replace ''
65
+ concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
66
+ concat(builder.input(:publish_at, :as => :datetime))
67
+ end)
68
+ end
69
+
70
+ it_should_have_input_wrapper_with_id("context2_post_publish_at_input")
71
+ it_should_have_select_with_id("context2_post_publish_at_1i")
72
+ it_should_have_select_with_id("context2_post_publish_at_2i")
73
+ it_should_have_select_with_id("context2_post_publish_at_3i")
74
+ it_should_have_select_with_id("context2_post_publish_at_4i")
75
+ it_should_have_select_with_id("context2_post_publish_at_5i")
76
+
77
+ end
78
+
79
+ describe ':labels option' do
80
+ fields = [:year, :month, :day, :hour, :minute]
81
+ fields.each do |field|
82
+ it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
83
+ output_buffer.replace ''
84
+ concat(semantic_form_for(@new_post) do |builder|
85
+ concat(builder.input(:created_at, :as => :datetime, :labels => { field => "another #{field} label" }))
86
+ end)
87
+ output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => fields.length)
88
+ fields.each do |f|
89
+ output_buffer.should have_tag('form li.datetime fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
90
+ end
91
+ end
92
+
93
+ #it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
94
+ # output_buffer.replace ''
95
+ # concat(semantic_form_for(@new_post) do |builder|
96
+ # concat(builder.input(:created_at, :as => :datetime, :labels => { field => "" }))
97
+ # end)
98
+ # output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => fields.length-1)
99
+ # fields.each do |f|
100
+ # output_buffer.should have_tag('form li.datetime fieldset ol li label', /#{f}/i) unless field == f
101
+ # end
102
+ #end
103
+ end
104
+ end
105
+
106
+ describe "when required" do
107
+ it "should add the required attribute to the input's html options" do
108
+ concat(semantic_form_for(@new_post) do |builder|
109
+ concat(builder.input(:title, :as => :datetime, :required => true))
110
+ end)
111
+ output_buffer.should have_tag("select[@required]", :count => 5)
112
+ end
113
+ end
114
+
115
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'email input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+ end
12
+
13
+ describe "when object is provided" do
14
+ before do
15
+ concat(semantic_form_for(@new_post) do |builder|
16
+ concat(builder.input(:email))
17
+ end)
18
+ end
19
+
20
+ it_should_have_input_wrapper_with_class(:email)
21
+ it_should_have_input_wrapper_with_class(:input)
22
+ it_should_have_input_wrapper_with_class(:stringish)
23
+ it_should_have_input_wrapper_with_id("post_email_input")
24
+ it_should_have_label_with_text(/Email/)
25
+ it_should_have_label_for("post_email")
26
+ it_should_have_input_with_id("post_email")
27
+ it_should_have_input_with_type(:email)
28
+ it_should_have_input_with_name("post[email]")
29
+
30
+ end
31
+
32
+ describe "when namespace is provided" do
33
+
34
+ before do
35
+ concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
36
+ concat(builder.input(:email))
37
+ end)
38
+ end
39
+
40
+ it_should_have_input_wrapper_with_id("context2_post_email_input")
41
+ it_should_have_label_and_input_with_id("context2_post_email")
42
+
43
+ end
44
+
45
+ describe "when required" do
46
+ it "should add the required attribute to the input's html options" do
47
+ concat(semantic_form_for(@new_post) do |builder|
48
+ concat(builder.input(:title, :as => :email, :required => true))
49
+ end)
50
+ output_buffer.should have_tag("input[@required]")
51
+ end
52
+ end
53
+
54
+ end
55
+
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'file input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+
12
+ concat(semantic_form_for(@new_post) do |builder|
13
+ concat(builder.input(:body, :as => :file))
14
+ end)
15
+ end
16
+
17
+ it_should_have_input_wrapper_with_class("file")
18
+ it_should_have_input_wrapper_with_class(:input)
19
+ it_should_have_input_wrapper_with_id("post_body_input")
20
+ it_should_have_label_with_text(/Body/)
21
+ it_should_have_label_for("post_body")
22
+ it_should_have_input_with_id("post_body")
23
+ it_should_have_input_with_name("post[body]")
24
+ it_should_apply_error_logic_for_input_type(:file)
25
+
26
+ it 'should use input_html to style inputs' do
27
+ concat(semantic_form_for(@new_post) do |builder|
28
+ concat(builder.input(:title, :as => :file, :input_html => { :class => 'myclass' }))
29
+ end)
30
+ output_buffer.should have_tag("form li input.myclass")
31
+ end
32
+
33
+ describe "when namespace is provided" do
34
+
35
+ before do
36
+ @output_buffer = ''
37
+ mock_everything
38
+
39
+ concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
40
+ concat(builder.input(:body, :as => :file))
41
+ end)
42
+ end
43
+
44
+ it_should_have_input_wrapper_with_id("context2_post_body_input")
45
+ it_should_have_label_and_input_with_id("context2_post_body")
46
+
47
+ end
48
+
49
+ context "when required" do
50
+ it "should add the required attribute to the input's html options" do
51
+ concat(semantic_form_for(@new_post) do |builder|
52
+ concat(builder.input(:title, :as => :file, :required => true))
53
+ end)
54
+ output_buffer.should have_tag("input[@required]")
55
+ end
56
+ end
57
+
58
+ end
59
+
@@ -0,0 +1,120 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'hidden input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+
12
+ concat(semantic_form_for(@new_post) do |builder|
13
+ concat(builder.input(:secret, :as => :hidden))
14
+ concat(builder.input(:author_id, :as => :hidden, :value => 99))
15
+ concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
16
+ concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
17
+ concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
18
+ end)
19
+ end
20
+
21
+ it_should_have_input_wrapper_with_class("hidden")
22
+ it_should_have_input_wrapper_with_class(:input)
23
+ it_should_have_input_wrapper_with_id("post_secret_input")
24
+ it_should_not_have_a_label
25
+
26
+ it "should generate a input field" do
27
+ output_buffer.should have_tag("form li input#post_secret")
28
+ output_buffer.should have_tag("form li input#post_secret[@type=\"hidden\"]")
29
+ output_buffer.should have_tag("form li input#post_secret[@name=\"post[secret]\"]")
30
+ end
31
+
32
+ it "should get value from the object" do
33
+ output_buffer.should have_tag("form li input#post_secret[@type=\"hidden\"][@value=\"1\"]")
34
+ end
35
+
36
+ it "should pass any explicitly specified value - using :value" do
37
+ output_buffer.should have_tag("form li input#post_author_id[@type=\"hidden\"][@value=\"99\"]")
38
+ end
39
+
40
+ # Handle Formtastic :input_html options for consistency.
41
+ it "should pass any explicitly specified value - using :input_html options" do
42
+ output_buffer.should have_tag("form li input#post_published[@type=\"hidden\"][@value=\"true\"]")
43
+ end
44
+
45
+ it "should pass any option specified using :input_html" do
46
+ output_buffer.should have_tag("form li input#new_post_reviewer[@type=\"hidden\"][@class=\"new_post_reviewer\"]")
47
+ end
48
+
49
+ it "should prefer :input_html over directly supplied options" do
50
+ output_buffer.should have_tag("form li input#post_author_id[@type=\"hidden\"][@value=\"formtastic_value\"]")
51
+ end
52
+
53
+ it "should not render inline errors" do
54
+ @errors = mock('errors')
55
+ @errors.stub!(:[]).with(:secret).and_return(["foo", "bah"])
56
+ @new_post.stub!(:errors).and_return(@errors)
57
+
58
+ concat(semantic_form_for(@new_post) do |builder|
59
+ concat(builder.input(:secret, :as => :hidden))
60
+ end)
61
+
62
+ output_buffer.should_not have_tag("form li p.inline-errors")
63
+ output_buffer.should_not have_tag("form li ul.errors")
64
+ end
65
+
66
+ it "should not render inline hints" do
67
+ concat(semantic_form_for(@new_post) do |builder|
68
+ concat(builder.input(:secret, :as => :hidden, :hint => "all your base are belong to use"))
69
+ end)
70
+
71
+ output_buffer.should_not have_tag("form li p.inline-hints")
72
+ output_buffer.should_not have_tag("form li ul.hints")
73
+ end
74
+
75
+ describe "when namespace is provided" do
76
+
77
+ before do
78
+ @output_buffer = ''
79
+ mock_everything
80
+
81
+ concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
82
+ concat(builder.input(:secret, :as => :hidden))
83
+ concat(builder.input(:author_id, :as => :hidden, :value => 99))
84
+ concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
85
+ concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
86
+ concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
87
+ end)
88
+ end
89
+
90
+ attributes_to_check = [:secret, :author_id, :published, :reviewer]
91
+ attributes_to_check.each do |a|
92
+ it_should_have_input_wrapper_with_id("context2_post_#{a}_input")
93
+ end
94
+
95
+ (attributes_to_check - [:reviewer]).each do |a|
96
+ it_should_have_input_with_id("context2_post_#{a}")
97
+ end
98
+
99
+ end
100
+
101
+ context "when required" do
102
+ it "should not add the required attribute to the input's html options" do
103
+ concat(semantic_form_for(@new_post) do |builder|
104
+ concat(builder.input(:title, :as => :hidden, :required => true))
105
+ end)
106
+ output_buffer.should_not have_tag("input[@required]")
107
+ end
108
+ end
109
+
110
+ context "when :autofocus is provided in :input_html" do
111
+ it "should not add the autofocus attribute to the input's html options" do
112
+ concat(semantic_form_for(@new_post) do |builder|
113
+ concat(builder.input(:title, :as => :hidden, :input_html => {:autofocus => true}))
114
+ end)
115
+ output_buffer.should_not have_tag("input[@autofocus]")
116
+ end
117
+ end
118
+
119
+ end
120
+