bootstrap_forms 2.1.1 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'bootstrap_forms'
6
- s.version = '2.1.1'
6
+ s.version = '3.0.0.rc1'
7
7
  s.author = 'Seth Vargo'
8
8
  s.email = 'sethvargo@gmail.com'
9
9
  s.homepage = 'https://github.com/sethvargo/bootstrap_forms'
@@ -19,11 +19,11 @@ module BootstrapForms
19
19
  end
20
20
  end
21
21
 
22
- %w(collection_select select country_select time_zone_select email_field file_field number_field password_field phone_field range_field search_field telephone_field text_area text_field url_field datetime_select date_select time_select).each do |method_name|
22
+ %w(country_select time_zone_select email_field file_field number_field password_field phone_field range_field search_field telephone_field text_area text_field url_field datetime_select date_select time_select).each do |method_name|
23
23
  define_method(method_name) do |name, *args|
24
24
  # Workaround for ree and 1.8.7 since they don't allow block arguments with default values
25
25
  args = args.extract_options!
26
-
26
+
27
27
  @name = name
28
28
  @field_options = field_options(args)
29
29
  @args = args
@@ -38,6 +38,34 @@ module BootstrapForms
38
38
  end
39
39
  end
40
40
 
41
+ %w(collection_select select).each do |method_name|
42
+ define_method(method_name) do |name, *args|
43
+ if args[-1].is_a? Hash
44
+ if args[-2].is_a? Hash
45
+ html_options = args.pop
46
+ options = args.pop
47
+ else
48
+ html_options = {}
49
+ options = args.pop
50
+ end
51
+ else
52
+ html_options = {}
53
+ options = {}
54
+ end
55
+
56
+ @name = name
57
+ @field_options = field_options(options)
58
+ @args = args
59
+
60
+ control_group_div do
61
+ label_field + input_div do
62
+ rebuilt_args = args + [options.merge(@field_options.merge(required_attribute)), html_options]
63
+ extras { super(name, *rebuilt_args) }
64
+ end
65
+ end
66
+ end
67
+ end
68
+
41
69
  def check_box(name, args = {})
42
70
  @name = name
43
71
  @field_options = field_options(args)
@@ -83,7 +83,7 @@ module BootstrapForms
83
83
 
84
84
  def required_attribute
85
85
  return {} if @field_options.present? && @field_options.has_key?(:required) && !@field_options[:required]
86
-
86
+
87
87
  if respond_to?(:object) and object.respond_to?(:errors) and object.class.respond_to?('validators_on')
88
88
  return { :required => true } if object.class.validators_on(@name).any? { |v| v.kind_of?( ActiveModel::Validations::PresenceValidator ) && valid_validator?( v ) }
89
89
  end
@@ -95,29 +95,29 @@ describe 'BootstrapForms::FormBuilder' do
95
95
  it 'adds the required attribute' do
96
96
  @builder.text_field('owner').should match /<input .*required="required"/
97
97
  end
98
-
98
+
99
99
  it "does not add the required attribute if required: false" do
100
100
  @builder.text_field('owner', :required => false).should_not match /<input .*required="required"/
101
101
  end
102
-
102
+
103
103
  it "not require if or unless validators" do
104
104
  @builder.text_field('if_presence').should_not match /<input .*required="required"/
105
105
  @builder.text_field('unless_presence').should_not match /<input .*required="required"/
106
106
  end
107
-
107
+
108
108
  it "should not be required if presence is on update and model is created" do
109
109
  @builder.text_field('update_presence').should_not match /<input .*required="required"/
110
110
  end
111
-
111
+
112
112
  it "should be required if on create and model is new" do
113
113
  @builder.text_field('create_presence').should match /<input .*required="required"/
114
114
  end
115
-
115
+
116
116
  it "should be required if presence is on update and model is not new" do
117
117
  @project.stub!(:persisted?).and_return(true)
118
118
  @builder.text_field('update_presence').should match /<input .*required="required"/
119
119
  end
120
-
120
+
121
121
  it "should not be required if on create and model is not new" do
122
122
  @project.stub!(:persisted?).and_return(true)
123
123
  @builder.text_field('create_presence').should_not match /<input .*required="required"/
@@ -41,7 +41,7 @@ shared_examples 'a bootstrap form' do
41
41
  it 'allows no label with :label => '' ' do
42
42
  @builder.check_box('name', :label => '').should_not match /<\/label>/
43
43
  end
44
-
44
+
45
45
  it 'adds inline class' do
46
46
  @builder.check_box('name', :inline => true).should == "<div class=\"control-group\"><div class=\"controls\"><label class=\"checkbox inline\" for=\"item_name\"><input name=\"item[name]\" type=\"hidden\" value=\"0\" /><input id=\"item_name\" name=\"item[name]\" type=\"checkbox\" value=\"1\" />Name</label></div></div>"
47
47
  end
@@ -115,6 +115,27 @@ shared_examples 'a bootstrap form' do
115
115
 
116
116
  end # field
117
117
  end # fields
118
+
119
+ describe 'collection select' do
120
+ before(:each) do
121
+ @result = @builder.collection_select(:name, [["foo", "Foo"]], :first, :last)
122
+ end
123
+
124
+ it 'is wrapped' do
125
+ @result.should match /^<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name<\/label><div class=\"controls\">.*<\/div><\/div>$/
126
+ end
127
+ end
128
+
129
+ describe 'collection select with html options' do
130
+ before(:each) do
131
+ @result = @builder.collection_select(:name, [["foo", "Foo"]], :first, :last, {}, :class => "baz")
132
+ end
133
+
134
+ it 'uses html options' do
135
+ @result.should match /class=".*baz/
136
+ end
137
+ end
138
+
118
139
  end # no options
119
140
 
120
141
  describe 'extras' do
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
5
- prerelease:
4
+ version: 3.0.0.rc1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Seth Vargo
@@ -213,16 +213,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
213
  version: '0'
214
214
  segments:
215
215
  - 0
216
- hash: -1030141123140574531
216
+ hash: 594779022012185333
217
217
  required_rubygems_version: !ruby/object:Gem::Requirement
218
218
  none: false
219
219
  requirements:
220
- - - ! '>='
220
+ - - ! '>'
221
221
  - !ruby/object:Gem::Version
222
- version: '0'
223
- segments:
224
- - 0
225
- hash: -1030141123140574531
222
+ version: 1.3.1
226
223
  requirements: []
227
224
  rubyforge_project:
228
225
  rubygems_version: 1.8.23