formtastic 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,8 +8,9 @@ DESCRIPTION
8
8
  ExistingModelName - The name of an existing model for which the generator should generate form code.
9
9
 
10
10
  Options:
11
- --haml Generate HAML instead of ERB.
12
- --partial Generate a form partial in the model views path, i.e. "_form.html.erb" or _form.html.haml".
11
+ --haml Generate HAML instead of ERB.
12
+ --partial Generate a form partial in the model views path, i.e. "_form.html.erb" or _form.html.haml".
13
+ --controller PATH Generate for custom controller/view path - in case model and controller namespace is different, i.e. "admin/posts".
13
14
 
14
15
  EXAMPLE
15
16
  ./script/generate form ExistingModelName [--haml] [--partial]
@@ -25,7 +25,7 @@
25
25
  # Formtastic::SemanticFormBuilder.inline_errors = :sentence
26
26
 
27
27
  # Set the method to call on label text to transform or format it for human-friendly
28
- # reading when formtastic is user without object. Defaults to :humanize.
28
+ # reading (overridden if :label or i18 used). Defaults to :humanize.
29
29
  # Formtastic::SemanticFormBuilder.label_str_method = :humanize
30
30
 
31
31
  # Set the array of methods to try calling on parent objects in :select and :radio inputs
data/lib/formtastic.rb CHANGED
@@ -673,7 +673,8 @@ module Formtastic #:nodoc:
673
673
  def select_input(method, options)
674
674
  html_options = options.delete(:input_html) || {}
675
675
  options = set_include_blank(options)
676
- html_options[:multiple] = options.delete(:multiple) if html_options[:multiple].nil?
676
+ html_options[:multiple] = html_options[:multiple] || options.delete(:multiple)
677
+ html_options.delete(:multiple) if html_options[:multiple].nil?
677
678
 
678
679
  reflection = self.reflection_for(method)
679
680
  if reflection && [ :has_many, :has_and_belongs_to_many ].include?(reflection.macro)
@@ -701,6 +702,7 @@ module Formtastic #:nodoc:
701
702
  strip_formtastic_options(options), html_options)
702
703
  else
703
704
  collection = find_collection_for_column(method, options)
705
+
704
706
  self.select(input_name, collection, strip_formtastic_options(options), html_options)
705
707
  end
706
708
 
@@ -46,42 +46,42 @@ describe 'SemanticFormBuilder#commit_button' do
46
46
  describe "its accesskey" do
47
47
 
48
48
  it 'should allow nil default' do
49
- ::Formtastic::SemanticFormBuilder.default_commit_button_accesskey.should == nil
50
- output_buffer.should_not have_tag('li.commit input[@accesskey]')
49
+ with_config :default_commit_button_accesskey, nil do
50
+ output_buffer.should_not have_tag('li.commit input[@accesskey]')
51
+ end
51
52
  end
52
53
 
53
54
  it 'should use the default if set' do
54
- ::Formtastic::SemanticFormBuilder.default_commit_button_accesskey = 's'
55
- @new_post.stub!(:new_record?).and_return(false)
56
- semantic_form_for(@new_post) do |builder|
57
- concat(builder.commit_button('text', :button_html => {}))
55
+ with_config :default_commit_button_accesskey, 's' do
56
+ @new_post.stub!(:new_record?).and_return(false)
57
+ semantic_form_for(@new_post) do |builder|
58
+ concat(builder.commit_button('text', :button_html => {}))
59
+ end
60
+ output_buffer.should have_tag('li.commit input[@accesskey="s"]')
58
61
  end
59
- output_buffer.should have_tag('li.commit input[@accesskey="s"]')
60
62
  end
61
63
 
62
64
  it 'should use the value set in options over the default' do
63
- ::Formtastic::SemanticFormBuilder.default_commit_button_accesskey = 's'
64
- @new_post.stub!(:new_record?).and_return(false)
65
- semantic_form_for(@new_post) do |builder|
66
- concat(builder.commit_button('text', :accesskey => 'o'))
65
+ with_config :default_commit_button_accesskey, 's' do
66
+ @new_post.stub!(:new_record?).and_return(false)
67
+ semantic_form_for(@new_post) do |builder|
68
+ concat(builder.commit_button('text', :accesskey => 'o'))
69
+ end
70
+ output_buffer.should_not have_tag('li.commit input[@accesskey="s"]')
71
+ output_buffer.should have_tag('li.commit input[@accesskey="o"]')
67
72
  end
68
- output_buffer.should_not have_tag('li.commit input[@accesskey="s"]')
69
- output_buffer.should have_tag('li.commit input[@accesskey="o"]')
70
73
  end
71
74
 
72
75
  it 'should use the value set in button_html over options' do
73
- ::Formtastic::SemanticFormBuilder.default_commit_button_accesskey = 's'
74
- @new_post.stub!(:new_record?).and_return(false)
75
- semantic_form_for(@new_post) do |builder|
76
- concat(builder.commit_button('text', :accesskey => 'o', :button_html => {:accesskey => 't'}))
76
+ with_config :default_commit_button_accesskey, 's' do
77
+ @new_post.stub!(:new_record?).and_return(false)
78
+ semantic_form_for(@new_post) do |builder|
79
+ concat(builder.commit_button('text', :accesskey => 'o', :button_html => {:accesskey => 't'}))
80
+ end
81
+ output_buffer.should_not have_tag('li.commit input[@accesskey="s"]')
82
+ output_buffer.should_not have_tag('li.commit input[@accesskey="o"]')
83
+ output_buffer.should have_tag('li.commit input[@accesskey="t"]')
77
84
  end
78
- output_buffer.should_not have_tag('li.commit input[@accesskey="s"]')
79
- output_buffer.should_not have_tag('li.commit input[@accesskey="o"]')
80
- output_buffer.should have_tag('li.commit input[@accesskey="t"]')
81
- end
82
-
83
- after do
84
- ::Formtastic::SemanticFormBuilder.default_commit_button_accesskey = nil
85
85
  end
86
86
 
87
87
  end
data/spec/input_spec.rb CHANGED
@@ -413,15 +413,12 @@ describe 'SemanticFormBuilder#input' do
413
413
 
414
414
  describe 'and label_str_method is :capitalize' do
415
415
  it 'should capitalize method name, passing it down to the label tag' do
416
- old_value = ::Formtastic::SemanticFormBuilder.label_str_method
417
- ::Formtastic::SemanticFormBuilder.label_str_method = :capitalize
418
-
419
- semantic_form_for(:project, :url => 'http://test.host') do |builder|
420
- concat(builder.input(:meta_description))
416
+ with_config :label_str_method, :capitalize do
417
+ semantic_form_for(:project, :url => 'http://test.host') do |builder|
418
+ concat(builder.input(:meta_description))
419
+ end
420
+ output_buffer.should have_tag("form li label", /#{'meta_description'.capitalize}/)
421
421
  end
422
-
423
- output_buffer.should have_tag("form li label", /#{'meta_description'.capitalize}/)
424
- ::Formtastic::SemanticFormBuilder.label_str_method = old_value
425
422
  end
426
423
  end
427
424
  end
@@ -53,7 +53,7 @@ describe 'select input' do
53
53
  concat(builder.input(:author, :as => :select))
54
54
  end
55
55
  end
56
-
56
+
57
57
  it_should_have_input_wrapper_with_class("select")
58
58
  it_should_have_input_wrapper_with_id("post_author_input")
59
59
  it_should_have_label_with_text(/Author/)
@@ -61,12 +61,17 @@ describe 'select input' do
61
61
  it_should_apply_error_logic_for_input_type(:select)
62
62
  it_should_call_find_on_association_class_when_no_collection_is_provided(:select)
63
63
  it_should_use_the_collection_when_provided(:select, 'option')
64
-
64
+
65
65
  it 'should have a select inside the wrapper' do
66
66
  output_buffer.should have_tag('form li select')
67
67
  output_buffer.should have_tag('form li select#post_author_id')
68
68
  end
69
69
 
70
+ it 'should have a valid name' do
71
+ output_buffer.should have_tag("form li select[@name='post[author_id]']")
72
+ output_buffer.should_not have_tag("form li select[@name='post[author_id][]']")
73
+ end
74
+
70
75
  it 'should not create a multi-select' do
71
76
  output_buffer.should_not have_tag('form li select[@multiple]')
72
77
  end
data/spec/spec_helper.rb CHANGED
@@ -200,6 +200,13 @@ module FormtasticSpecHelper
200
200
  end
201
201
  end
202
202
 
203
+ def with_config(config_method_name, value, &block)
204
+ old_value = ::Formtastic::SemanticFormBuilder.send(config_method_name)
205
+ ::Formtastic::SemanticFormBuilder.send(:"#{config_method_name}=", value)
206
+ yield
207
+ ::Formtastic::SemanticFormBuilder.send(:"#{config_method_name}=", old_value)
208
+ end
209
+
203
210
  end
204
211
 
205
212
  ::ActiveSupport::Deprecation.silenced = false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formtastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin French