formtastic 2.0.0.rc4 → 2.0.0.rc5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 2.0.0.rc5
2
+
3
+ * Changed perform_browser_validations and use_required_attribute configuration defaults from true to false for a better out-of-the-box experience and upgrade path
4
+ * Fixed that the `novalidate` attribute was being applied to the `<form>` tag when it shouldn't have been (and vice-versa)
5
+ * Fixed `undefined method `last' for #<Classname>` with a `:collection` containing an array of arrays
6
+
1
7
  2.0.0.rc4
2
8
 
3
9
  * Fixed that TimeInput was not rendering hidden y/m/d inputs by default.
data/RELEASE_PROCESS CHANGED
@@ -1,5 +1,5 @@
1
1
  # edit version.rb
2
- git ci formtastic.gemspec -m "new gemspec" # commit changes
2
+ git ci -am "version bump" # commit changes
3
3
  git tag X.X.X # tag the new version in the code base too
4
4
  gem build formtastic.gemspec # build the gem
5
5
  gem push formtastic-X.X.X.gem # publish the gem
@@ -28,8 +28,8 @@ module Formtastic
28
28
  configure :default_inline_error_class, 'inline-errors'
29
29
  configure :default_error_list_class, 'errors'
30
30
  configure :default_hint_class, 'inline-hints'
31
- configure :use_required_attribute, true
32
- configure :perform_browser_validations, true
31
+ configure :use_required_attribute, false
32
+ configure :perform_browser_validations, false
33
33
 
34
34
  attr_reader :template
35
35
 
@@ -143,7 +143,7 @@ module Formtastic
143
143
  options = args.extract_options!
144
144
  options[:builder] ||= @@builder
145
145
  options[:html] ||= {}
146
- options[:html][:novalidate] = !builder.perform_browser_validations unless options[:html].key?(:novalidate)
146
+ options[:html][:novalidate] = !@@builder.perform_browser_validations unless options[:html].key?(:novalidate)
147
147
  @@builder.custom_namespace = options[:namespace].to_s
148
148
 
149
149
  singularizer = defined?(ActiveModel::Naming.singular) ? ActiveModel::Naming.method(:singular) : ActionController::RecordIdentifier.method(:singular_class_name)
@@ -175,7 +175,7 @@ module Formtastic
175
175
  self.fields_for(record_name, record_object, options, &block)
176
176
  end
177
177
  end
178
-
178
+
179
179
  protected
180
180
 
181
181
  # Override the default ActiveRecordHelper behaviour of wrapping the input.
@@ -197,4 +197,4 @@ module Formtastic
197
197
 
198
198
  end
199
199
  end
200
- end
200
+ end
@@ -1,12 +1,13 @@
1
+ # -*- coding: utf-8 -*-
1
2
  module Formtastic
2
3
  module Helpers
3
-
4
- # {#input} is used to render all content (labels, form widgets, error messages, hints, etc) for
5
- # a single form input (or field), usually representing a single method or attribute on the
4
+
5
+ # {#input} is used to render all content (labels, form widgets, error messages, hints, etc) for
6
+ # a single form input (or field), usually representing a single method or attribute on the
6
7
  # form's object or model.
7
8
  #
8
- # The content is wrapped in an `<li>` tag, so it's usually called inside an {Formtastic::Helpers::InputsHelper#inputs inputs} block
9
- # (which renders an `<ol>` inside a `<fieldset>`), which should be inside a {Formtastic::Helpers::FormHelper#semantic_form_for `semantic_form_for`}
9
+ # The content is wrapped in an `<li>` tag, so it's usually called inside an {Formtastic::Helpers::InputsHelper#inputs inputs} block
10
+ # (which renders an `<ol>` inside a `<fieldset>`), which should be inside a {Formtastic::Helpers::FormHelper#semantic_form_for `semantic_form_for`}
10
11
  # block:
11
12
  #
12
13
  # <%= semantic_form_for @post do |f| %>
@@ -37,7 +38,7 @@ module Formtastic
37
38
  module InputHelper
38
39
  include Formtastic::Helpers::Reflection
39
40
  include Formtastic::Helpers::FileColumnDetection
40
-
41
+
41
42
  # Returns a chunk of HTML markup for a given `method` on the form object, wrapped in
42
43
  # an `<li>` wrapper tag with appropriate `class` and `id` attribute hooks for CSS and JS.
43
44
  # In many cases, the contents of the wrapper will be as simple as a `<label>` and an `<input>`:
@@ -105,9 +106,9 @@ module Formtastic
105
106
  # * `:time` (see {Inputs::TimeInput})
106
107
  # * `:url` (see {Inputs::UrlInput})
107
108
  #
108
- # Calling `:as => :string` (for example) will call `#to_html` on a new instance of
109
+ # Calling `:as => :string` (for example) will call `#to_html` on a new instance of
109
110
  # `Formtastic::Inputs::StringInput`. Before this, Formtastic will try to instantiate a top-level
110
- # namespace StringInput, meaning you can subclass and modify `Formtastic::Inputs::StringInput`
111
+ # namespace StringInput, meaning you can subclass and modify `Formtastic::Inputs::StringInput`
111
112
  # in `app/inputs/`. This also means you can create your own new input types in `app/inputs/`.
112
113
  #
113
114
  # @todo document the "guessing" of input style
@@ -233,7 +234,7 @@ module Formtastic
233
234
  # @example Modifying an input to suit your needs in `app/inputs`:
234
235
  # class StringInput < Formtastic::Inputs::StringInput
235
236
  # def to_html
236
- # puts "this is my custom version of StringInput"
237
+ # puts "this is my custom version of StringInput"
237
238
  # super
238
239
  # end
239
240
  # end
@@ -260,13 +261,14 @@ module Formtastic
260
261
  def input(method, options = {})
261
262
  options = options.dup # Allow options to be shared without being tainted by Formtastic
262
263
  options[:as] ||= default_input_type(method, options)
263
-
264
+
264
265
  klass = input_class(options[:as])
266
+
265
267
  klass.new(self, template, @object, @object_name, method, options).to_html
266
268
  end
267
-
269
+
268
270
  protected
269
-
271
+
270
272
  # First try if we can detect special things like :file. With CarrierWave the method does have
271
273
  # an underlying column so we don't want :string to get selected.
272
274
  #
@@ -314,7 +316,7 @@ module Formtastic
314
316
  return :string
315
317
  end
316
318
  end
317
-
319
+
318
320
  # Get a column object for a specified attribute method - if possible.
319
321
  def column_for(method) #:nodoc:
320
322
  @object.column_for_attribute(method) if @object.respond_to?(:column_for_attribute)
@@ -352,7 +354,7 @@ module Formtastic
352
354
  end
353
355
  end
354
356
  end
355
-
357
+
356
358
  # :as => :string # => StringInput
357
359
  def custom_input_class_name(as)
358
360
  "#{as.to_s.camelize}Input"
@@ -2,9 +2,9 @@ module Formtastic
2
2
  module Inputs
3
3
  module Base
4
4
  module Choices
5
-
5
+
6
6
  def choices_wrapping(&block)
7
- template.content_tag(:fieldset,
7
+ template.content_tag(:fieldset,
8
8
  template.capture(&block),
9
9
  choices_wrapping_html_options
10
10
  )
@@ -15,7 +15,7 @@ module Formtastic
15
15
  end
16
16
 
17
17
  def choices_group_wrapping(&block)
18
- template.content_tag(:ol,
18
+ template.content_tag(:ol,
19
19
  template.capture(&block),
20
20
  choices_group_wrapping_html_options
21
21
  )
@@ -26,7 +26,7 @@ module Formtastic
26
26
  end
27
27
 
28
28
  def choice_wrapping(html_options, &block)
29
- template.content_tag(:li,
29
+ template.content_tag(:li,
30
30
  template.capture(&block),
31
31
  html_options
32
32
  )
@@ -35,11 +35,11 @@ module Formtastic
35
35
  def choice_wrapping_html_options(choice)
36
36
  classes = ['choice']
37
37
  classes << "#{sanitized_method_name.singularize}_#{choice_html_safe_value(choice)}" if value_as_class?
38
-
38
+
39
39
  { :class => classes.join(" ") }
40
40
  end
41
41
 
42
- def choice_html(choice)
42
+ def choice_html(choice)
43
43
  raise "choice_html() needs to be implemented when including Formtastic::Inputs::Base::Choices"
44
44
  end
45
45
 
@@ -75,7 +75,7 @@ module Formtastic
75
75
  choice_html_safe_value(choice)
76
76
  ].compact.reject { |i| i.blank? }.join("_")
77
77
  end
78
-
78
+
79
79
  def value_as_class?
80
80
  options[:value_as_class]
81
81
  end
@@ -90,7 +90,7 @@ module Formtastic
90
90
  "".html_safe
91
91
  end
92
92
  end
93
-
93
+
94
94
  # Override to remove the for attribute since this isn't associated with any element, as it's
95
95
  # nested inside the legend.
96
96
  def label_html_options
@@ -81,14 +81,14 @@ module Formtastic
81
81
  include Base
82
82
  include Base::Collections
83
83
  include Base::Choices
84
-
84
+
85
85
  def to_html
86
86
  input_wrapping do
87
87
  choices_wrapping do
88
88
  legend_html <<
89
89
  hidden_field_for_all <<
90
90
  choices_group_wrapping do
91
- collection.map { |choice|
91
+ collection.map { |choice|
92
92
  choice_wrapping(choice_wrapping_html_options(choice)) do
93
93
  choice_html(choice)
94
94
  end
@@ -97,17 +97,17 @@ module Formtastic
97
97
  end
98
98
  end
99
99
  end
100
-
101
- def choice_html(choice)
100
+
101
+ def choice_html(choice)
102
102
  template.content_tag(:label,
103
- hidden_fields? ?
104
- check_box_with_hidden_input(choice) :
103
+ hidden_fields? ?
104
+ check_box_with_hidden_input(choice) :
105
105
  check_box_without_hidden_input(choice) <<
106
106
  choice_label(choice),
107
107
  label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil)
108
108
  )
109
109
  end
110
-
110
+
111
111
  def hidden_field_for_all
112
112
  if hidden_fields?
113
113
  ""
@@ -118,62 +118,69 @@ module Formtastic
118
118
  template.hidden_field_tag(input_name, '', options)
119
119
  end
120
120
  end
121
-
121
+
122
122
  def hidden_fields?
123
123
  options[:hidden_fields]
124
124
  end
125
-
125
+
126
126
  def check_box_with_hidden_input(choice)
127
127
  value = choice_value(choice)
128
128
  builder.check_box(
129
- association_primary_key || method,
130
- input_html_options.merge(:id => choice_input_dom_id(choice), :name => input_name, :disabled => disabled?(value), :required => false),
131
- value,
129
+ association_primary_key || method,
130
+ input_html_options.merge(:id => choice_input_dom_id(choice), :name => input_name, :disabled => disabled?(value), :required => false),
131
+ value,
132
132
  unchecked_value
133
133
  )
134
134
  end
135
-
135
+
136
136
  def check_box_without_hidden_input(choice)
137
137
  value = choice_value(choice)
138
138
  template.check_box_tag(
139
- input_name,
140
- value,
141
- checked?(value),
139
+ input_name,
140
+ value,
141
+ checked?(value),
142
142
  input_html_options.merge(:id => choice_input_dom_id(choice), :disabled => disabled?(value), :required => false)
143
- )
143
+ )
144
144
  end
145
-
145
+
146
146
  def checked?(value)
147
147
  selected_values.include?(value)
148
148
  end
149
-
149
+
150
150
  def disabled?(value)
151
151
  disabled_values.include?(value)
152
152
  end
153
-
153
+
154
154
  def selected_values
155
155
  if object.respond_to?(method)
156
- selected_items = [object.send(method)].compact.flatten
156
+ if options[:collection].is_a?(Array) and
157
+ options[:collection].flatten.all? {|i| i.is_a?(String) or i.is_a?(Integer)}
158
+
159
+ selected_items = options[:collection]
160
+ else
161
+ selected_items = [object.send(method)].compact.flatten
162
+ end
163
+
157
164
  [*selected_items.map { |o| send_or_call_or_object(value_method, o) }].compact
158
165
  else
159
166
  []
160
167
  end
161
168
  end
162
-
169
+
163
170
  def disabled_values
164
171
  vals = options[:disabled] || []
165
172
  vals = [vals] unless vals.is_a?(Array)
166
173
  vals
167
174
  end
168
-
175
+
169
176
  def unchecked_value
170
177
  options[:unchecked_value] || ''
171
178
  end
172
-
179
+
173
180
  def input_name
174
181
  "#{object_name}[#{association_primary_key || method}][]"
175
182
  end
176
-
183
+
177
184
  end
178
185
  end
179
- end
186
+ end
@@ -1,3 +1,3 @@
1
1
  module Formtastic
2
- VERSION = "2.0.0.rc4"
2
+ VERSION = "2.0.0.rc5"
3
3
  end
@@ -72,11 +72,11 @@
72
72
  # specifying that class here. Defaults to Formtastic::FormBuilder.
73
73
  # Formtastic::Helpers::FormHelper.builder = MyCustomBuilder
74
74
 
75
- # You can opt out of Formtastic's use of the HTML5 `required` attribute on `<input>`, `<select>`
75
+ # You can opt-in to Formtastic's use of the HTML5 `required` attribute on `<input>`, `<select>`
76
76
  # and `<textarea>` tags by setting this to false (defaults to true).
77
- # Formtastic::FormBuilder.use_required_attribute = false
77
+ # Formtastic::FormBuilder.use_required_attribute = true
78
78
 
79
- # You can opt out of new HTML5 browser validations (for things like email and url inputs) by setting
79
+ # You can opt-in to new HTML5 browser validations (for things like email and url inputs) by setting
80
80
  # this to false. Doing so will add a `novalidate` attribute to the `<form>` tag.
81
81
  # See http://diveintohtml5.org/forms.html#validation for more info.
82
82
  # Formtastic::FormBuilder.perform_browser_validations = true
@@ -70,6 +70,13 @@ describe 'Formtastic::Helpers::FormHelper.builder' do
70
70
  end
71
71
  end
72
72
 
73
+ # See: https://github.com/justinfrench/formtastic/issues/657
74
+ it "should not conflict with navigasmic" do
75
+ stub!(:builder).and_return('navigasmic')
76
+
77
+ lambda { semantic_form_for(@new_post) }.should_not raise_error(NoMethodError)
78
+ end
79
+
73
80
  end
74
81
 
75
82
  describe "fields_for" do
@@ -150,19 +150,25 @@ describe 'boolean input' do
150
150
  end
151
151
 
152
152
  context "when required" do
153
+
153
154
  it "should add the required attribute to the input's html options" do
154
- concat(semantic_form_for(@new_post) do |builder|
155
- concat(builder.input(:title, :as => :boolean, :required => true))
156
- end)
157
- output_buffer.should have_tag("input[@required]")
155
+ with_config :use_required_attribute, true do
156
+ concat(semantic_form_for(@new_post) do |builder|
157
+ concat(builder.input(:title, :as => :boolean, :required => true))
158
+ end)
159
+ output_buffer.should have_tag("input[@required]")
160
+ end
158
161
  end
159
-
162
+
160
163
  it "should not add the required attribute to the boolean fields input's html options" do
161
- concat(semantic_form_for(@new_post) do |builder|
162
- concat(builder.input(:title, :as => :boolean))
163
- end)
164
- output_buffer.should_not have_tag("input[@required]")
164
+ with_config :use_required_attribute, true do
165
+ concat(semantic_form_for(@new_post) do |builder|
166
+ concat(builder.input(:title, :as => :boolean))
167
+ end)
168
+ output_buffer.should_not have_tag("input[@required]")
169
+ end
165
170
  end
171
+
166
172
  end
167
173
 
168
174
  describe "when namespace is provided" do
@@ -393,5 +393,24 @@ describe 'check_boxes input' do
393
393
  it_should_have_input_wrapper_with_id("context2_author_posts_input")
394
394
  end
395
395
 
396
+ describe "when collection is an array" do
397
+ before do
398
+ @output_buffer = ''
399
+ @_collection = [["First", 1], ["Second", 2]]
400
+ mock_everything
401
+
402
+ concat(semantic_form_for(@fred) do |builder|
403
+ concat(builder.input(:posts, :as => :check_boxes, :collection => @_collection))
404
+ end)
405
+ end
406
+
407
+ it "should use array items for labels and values" do
408
+ @_collection.each do |post|
409
+ output_buffer.should have_tag('form li fieldset ol li label', /#{post.first}/)
410
+ output_buffer.should have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.last}']")
411
+ end
412
+ end
413
+ end
414
+
396
415
  end
397
416
 
@@ -56,7 +56,7 @@ describe 'country input' do
56
56
  priority_countries = ["Foo", "Bah"]
57
57
  semantic_form_for(@new_post) do |builder|
58
58
  builder.stub!(:country_select).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
59
- builder.should_receive(:country_select).with(:country, priority_countries, {}, {:id => "post_country", :required => true, :autofocus => false}).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
59
+ builder.should_receive(:country_select).with(:country, priority_countries, {}, {:id => "post_country", :required => false, :autofocus => false}).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
60
60
 
61
61
  concat(builder.input(:country, :as => :country, :priority_countries => priority_countries))
62
62
  end
@@ -69,7 +69,7 @@ describe 'country input' do
69
69
 
70
70
  semantic_form_for(@new_post) do |builder|
71
71
  builder.stub!(:country_select).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
72
- builder.should_receive(:country_select).with(:country, priority_countries, {}, {:id => "post_country", :required => true, :autofocus => false}).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
72
+ builder.should_receive(:country_select).with(:country, priority_countries, {}, {:id => "post_country", :required => false, :autofocus => false}).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
73
73
 
74
74
  concat(builder.input(:country, :as => :country))
75
75
  end
@@ -85,7 +85,7 @@ describe 'country input' do
85
85
 
86
86
  concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
87
87
  builder.stub!(:country_select).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
88
- builder.should_receive(:country_select).with(:country, [], {}, {:id => "context2_post_country", :required => true, :autofocus => false}).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
88
+ builder.should_receive(:country_select).with(:country, [], {}, {:id => "context2_post_country", :required => false, :autofocus => false}).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
89
89
  concat(builder.input(:country, :priority_countries => []))
90
90
  end)
91
91
  end
@@ -120,10 +120,12 @@ describe 'date input' do
120
120
 
121
121
  describe "when required" do
122
122
  it "should add the required attribute to the input's html options" do
123
- concat(semantic_form_for(@new_post) do |builder|
124
- concat(builder.input(:title, :as => :date, :required => true))
125
- end)
126
- output_buffer.should have_tag("select[@required]", :count => 3)
123
+ with_config :use_required_attribute, true do
124
+ concat(semantic_form_for(@new_post) do |builder|
125
+ concat(builder.input(:title, :as => :date, :required => true))
126
+ end)
127
+ output_buffer.should have_tag("select[@required]", :count => 3)
128
+ end
127
129
  end
128
130
  end
129
131
 
@@ -124,10 +124,12 @@ describe 'datetime input' do
124
124
 
125
125
  describe "when required" do
126
126
  it "should add the required attribute to the input's html options" do
127
- concat(semantic_form_for(@new_post) do |builder|
128
- concat(builder.input(:title, :as => :datetime, :required => true))
129
- end)
130
- output_buffer.should have_tag("select[@required]", :count => 5)
127
+ with_config :use_required_attribute, true do
128
+ concat(semantic_form_for(@new_post) do |builder|
129
+ concat(builder.input(:title, :as => :datetime, :required => true))
130
+ end)
131
+ output_buffer.should have_tag("select[@required]", :count => 5)
132
+ end
131
133
  end
132
134
  end
133
135
 
@@ -44,10 +44,12 @@ describe 'email input' do
44
44
 
45
45
  describe "when required" do
46
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]")
47
+ with_config :use_required_attribute, true do
48
+ concat(semantic_form_for(@new_post) do |builder|
49
+ concat(builder.input(:title, :as => :email, :required => true))
50
+ end)
51
+ output_buffer.should have_tag("input[@required]")
52
+ end
51
53
  end
52
54
  end
53
55
 
@@ -48,10 +48,12 @@ describe 'file input' do
48
48
 
49
49
  context "when required" do
50
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]")
51
+ with_config :use_required_attribute, true do
52
+ concat(semantic_form_for(@new_post) do |builder|
53
+ concat(builder.input(:title, :as => :file, :required => true))
54
+ end)
55
+ output_buffer.should have_tag("input[@required]")
56
+ end
55
57
  end
56
58
  end
57
59
 
@@ -68,10 +68,12 @@ describe 'number input' do
68
68
 
69
69
  describe "when required" do
70
70
  it "should add the required attribute to the input's html options" do
71
- concat(semantic_form_for(@new_post) do |builder|
72
- concat(builder.input(:title, :as => :number, :required => true))
73
- end)
74
- output_buffer.should have_tag("input[@required]")
71
+ with_config :use_required_attribute, true do
72
+ concat(semantic_form_for(@new_post) do |builder|
73
+ concat(builder.input(:title, :as => :number, :required => true))
74
+ end)
75
+ output_buffer.should have_tag("input[@required]")
76
+ end
75
77
  end
76
78
  end
77
79
 
@@ -59,10 +59,12 @@ describe 'password input' do
59
59
 
60
60
  describe "when required" do
61
61
  it "should add the required attribute to the input's html options" do
62
- concat(semantic_form_for(@new_post) do |builder|
63
- concat(builder.input(:title, :as => :password, :required => true))
64
- end)
65
- output_buffer.should have_tag("input[@required]")
62
+ with_config :use_required_attribute, true do
63
+ concat(semantic_form_for(@new_post) do |builder|
64
+ concat(builder.input(:title, :as => :password, :required => true))
65
+ end)
66
+ output_buffer.should have_tag("input[@required]")
67
+ end
66
68
  end
67
69
  end
68
70
 
@@ -44,10 +44,12 @@ describe 'phone input' do
44
44
 
45
45
  describe "when required" do
46
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 => :phone, :required => true))
49
- end)
50
- output_buffer.should have_tag("input[@required]")
47
+ with_config :use_required_attribute, true do
48
+ concat(semantic_form_for(@new_post) do |builder|
49
+ concat(builder.input(:title, :as => :phone, :required => true))
50
+ end)
51
+ output_buffer.should have_tag("input[@required]")
52
+ end
51
53
  end
52
54
  end
53
55
 
@@ -44,10 +44,12 @@ describe 'search input' do
44
44
 
45
45
  describe "when required" do
46
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 => :search, :required => true))
49
- end)
50
- output_buffer.should have_tag("input[@required]")
47
+ with_config :use_required_attribute, true do
48
+ concat(semantic_form_for(@new_post) do |builder|
49
+ concat(builder.input(:title, :as => :search, :required => true))
50
+ end)
51
+ output_buffer.should have_tag("input[@required]")
52
+ end
51
53
  end
52
54
  end
53
55
 
@@ -535,10 +535,12 @@ describe 'select input' do
535
535
 
536
536
  context "when required" do
537
537
  it "should add the required attribute to the select's html options" do
538
- concat(semantic_form_for(@new_post) do |builder|
539
- concat(builder.input(:author, :as => :select, :required => true))
540
- end)
541
- output_buffer.should have_tag("select[@required]")
538
+ with_config :use_required_attribute, true do
539
+ concat(semantic_form_for(@new_post) do |builder|
540
+ concat(builder.input(:author, :as => :select, :required => true))
541
+ end)
542
+ output_buffer.should have_tag("select[@required]")
543
+ end
542
544
  end
543
545
  end
544
546
 
@@ -83,10 +83,12 @@ describe 'text input' do
83
83
 
84
84
  context "when required" do
85
85
  it "should add the required attribute to the input's html options" do
86
- concat(semantic_form_for(@new_post) do |builder|
87
- concat(builder.input(:title, :as => :text, :required => true))
88
- end)
89
- output_buffer.should have_tag("textarea[@required]")
86
+ with_config :use_required_attribute, true do
87
+ concat(semantic_form_for(@new_post) do |builder|
88
+ concat(builder.input(:title, :as => :text, :required => true))
89
+ end)
90
+ output_buffer.should have_tag("textarea[@required]")
91
+ end
90
92
  end
91
93
  end
92
94
 
@@ -189,10 +189,12 @@ describe 'time input' do
189
189
 
190
190
  describe "when required" do
191
191
  it "should add the required attribute to the input's html options" do
192
- concat(semantic_form_for(@new_post) do |builder|
193
- concat(builder.input(:title, :as => :time, :required => true))
194
- end)
195
- output_buffer.should have_tag("select[@required]", :count => 2)
192
+ with_config :use_required_attribute, true do
193
+ concat(semantic_form_for(@new_post) do |builder|
194
+ concat(builder.input(:title, :as => :time, :required => true))
195
+ end)
196
+ output_buffer.should have_tag("select[@required]", :count => 2)
197
+ end
196
198
  end
197
199
  end
198
200
 
@@ -77,10 +77,12 @@ describe 'time_zone input' do
77
77
 
78
78
  context "when required" do
79
79
  it "should add the required attribute to the input's html options" do
80
- concat(semantic_form_for(@new_post) do |builder|
81
- concat(builder.input(:title, :as => :time_zone, :required => true))
82
- end)
83
- output_buffer.should have_tag("select[@required]")
80
+ with_config :use_required_attribute, true do
81
+ concat(semantic_form_for(@new_post) do |builder|
82
+ concat(builder.input(:title, :as => :time_zone, :required => true))
83
+ end)
84
+ output_buffer.should have_tag("select[@required]")
85
+ end
84
86
  end
85
87
  end
86
88
 
@@ -44,10 +44,12 @@ describe 'url input' do
44
44
 
45
45
  describe "when required" do
46
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 => :url, :required => true))
49
- end)
50
- output_buffer.should have_tag("input[@required]")
47
+ with_config :use_required_attribute, true do
48
+ concat(semantic_form_for(@new_post) do |builder|
49
+ concat(builder.input(:title, :as => :url, :required => true))
50
+ end)
51
+ output_buffer.should have_tag("input[@required]")
52
+ end
51
53
  end
52
54
  end
53
55
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formtastic
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15424093
4
+ hash: 15424095
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
9
  - 0
10
10
  - rc
11
- - 4
12
- version: 2.0.0.rc4
11
+ - 5
12
+ version: 2.0.0.rc5
13
13
  platform: ruby
14
14
  authors:
15
15
  - Justin French
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-08-16 00:00:00 Z
20
+ date: 2011-09-01 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails