bootstrap_forms 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ pkg/*
5
5
  .DS_Store
6
6
  .rspec
7
7
  .rvmrc
8
+ spec/dummy/log
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 1.8.7
3
4
  - 1.9.2
4
5
  - 1.9.3
@@ -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.0.1"
6
+ s.version = "2.0.2"
7
7
  s.author = "Seth Vargo"
8
8
  s.email = "sethvargo@gmail.com"
9
9
  s.homepage = "https://github.com/sethvargo/bootstrap_forms"
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
16
  s.require_paths = ["lib"]
17
17
 
18
- s.add_development_dependency "rspec-rails", "~> 2.9.0"
18
+ s.add_development_dependency "rspec-rails", "~> 2.10.1"
19
19
  s.add_development_dependency "capybara", "~> 1.1.0"
20
20
  s.add_development_dependency "rake"
21
21
  s.add_development_dependency "rails", "~> 3.2.0"
@@ -5,7 +5,7 @@ module BootstrapForms
5
5
  delegate :content_tag, :hidden_field_tag, :check_box_tag, :radio_button_tag, :button_tag, :link_to, :to => :@template
6
6
 
7
7
  def error_messages
8
- if object.errors.full_messages.any?
8
+ if object.try(:errors) and object.errors.full_messages.any?
9
9
  content_tag(:div, :class => 'alert alert-block alert-error validation-errors') do
10
10
  content_tag(:h4, I18n.t('bootstrap_forms.errors.header', :model => object.class.model_name.human), :class => 'alert-heading') +
11
11
  content_tag(:ul) do
@@ -53,16 +53,15 @@ module BootstrapForms
53
53
 
54
54
  def radio_buttons(name, values = {}, opts = {})
55
55
  @name = name
56
- @options = opts
57
56
  @field_options = opts
58
57
  control_group_div do
59
58
  label_field + input_div do
60
59
  values.map do |text, value|
61
60
  if @field_options[:label] == '' || @field_options[:label] == false
62
- extras { radio_button(name, value, @options) + text }
61
+ extras { radio_button(name, value, @field_options) + text }
63
62
  else
64
63
  label("#{@name}_#{value}", :class => [ 'radio', required_class ].compact.join(' ')) do
65
- extras { radio_button(name, value, @options) + text }
64
+ extras { radio_button(name, value, @field_options) + text }
66
65
  end
67
66
  end
68
67
  end.join.html_safe
@@ -120,8 +119,10 @@ module BootstrapForms
120
119
  control_group_div do
121
120
  label_field + input_div do
122
121
  extras do
123
- content_tag(:span, :class => 'uneditable-input') do
124
- @field_options[:value] || object.send(@name.to_sym)
122
+ options = { :class => 'uneditable-input' }
123
+ options[:id] = @field_options[:id] if @field_options[:id]
124
+ content_tag(:span, options) do
125
+ @field_options[:value] || object.send(@name.to_sym) rescue nil
125
126
  end
126
127
  end
127
128
  end
@@ -1,17 +1,21 @@
1
1
  module BootstrapForms
2
2
  module Helpers
3
- module FormHelper
3
+ module FormHelper
4
4
  def bootstrap_form_for(record, options = {}, &block)
5
5
  options[:builder] = BootstrapForms::FormBuilder
6
6
  form_for(record, options) do |f|
7
- f.error_messages.html_safe + capture(f, &block).html_safe
7
+ if f.object.respond_to?(:errors)
8
+ f.error_messages.html_safe + capture(f, &block).html_safe
9
+ else
10
+ capture(f, &block).html_safe
11
+ end
8
12
  end
9
13
  end
10
-
14
+
11
15
  def bootstrap_fields_for(record, options = {}, &block)
12
16
  options[:builder] = BootstrapForms::FormBuilder
13
17
  fields_for(record, nil, options, &block)
14
18
  end
15
19
  end
16
20
  end
17
- end
21
+ end
@@ -7,17 +7,16 @@ module BootstrapForms
7
7
  form_tag(url_for_options, options, &block)
8
8
  end
9
9
 
10
- %w(button_tag check_box_tag email_field_tag field_set_tag file_field_tag image_submit_tag label_tag number_field_tag password_field_tag phone_field_tag radio_button_tag range_field_tag search_field_tag select_tag telephone_field_tag text_area_tag text_field_tag url_field_tag utf8_enforcer_tag).each do |method_name|
10
+ %w(check_box_tag email_field_tag file_field_tag image_submit_tag number_field_tag password_field_tag phone_field_tag radio_button_tag range_field_tag search_field_tag select_tag telephone_field_tag text_area_tag text_field_tag url_field_tag).each do |method_name|
11
11
  # prefix each method with bootstrap_*
12
12
  define_method("bootstrap_#{method_name}") do |name, *args|
13
- value = args.shift
14
13
  @name = name
15
14
  @field_options = args.extract_options!
16
15
  @args = args
17
16
 
18
17
  control_group_div do
19
18
  label_field + input_div do
20
- extras { send(method_name.to_sym, name, value, *(@args << @field_options)) }
19
+ extras { send(method_name.to_sym, name, *(@args << @field_options)) }
21
20
  end
22
21
  end
23
22
  end
@@ -27,12 +26,12 @@ module BootstrapForms
27
26
  @name = name
28
27
  @field_options = args.extract_options!
29
28
  @args = args
30
-
29
+
31
30
  control_group_div do
32
31
  label_field + input_div do
33
32
  extras do
34
33
  content_tag(:span, :class => 'uneditable-input') do
35
- @field_options[:value] || object.send(@name.to_sym)
34
+ @field_options[:value]
36
35
  end
37
36
  end
38
37
  end
@@ -73,4 +72,4 @@ module BootstrapForms
73
72
  end
74
73
  end
75
74
  end
76
- end
75
+ end
@@ -20,7 +20,7 @@ module BootstrapForms
20
20
  end
21
21
 
22
22
  def error_string
23
- if respond_to?(:object)
23
+ if respond_to?(:object) and object.respond_to?(:errors)
24
24
  errors = object.errors[@name]
25
25
  if errors.present?
26
26
  errors.map { |e|
@@ -31,7 +31,7 @@ module BootstrapForms
31
31
  end
32
32
 
33
33
  def human_attribute_name
34
- object.class.human_attribute_name(@name)
34
+ object.class.human_attribute_name(@name) rescue @name.titleize
35
35
  end
36
36
 
37
37
  def input_div(&block)
@@ -61,7 +61,7 @@ module BootstrapForms
61
61
 
62
62
  def required_class
63
63
  return 'required' if @field_options[:required]
64
- if respond_to?(:object)
64
+ if respond_to?(:object) and object.respond_to?(:errors)
65
65
  return 'required' if object.class.validators_on(@name).any? { |v| v.kind_of? ActiveModel::Validations::PresenceValidator }
66
66
  end
67
67
  nil
@@ -1,6 +1,6 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
3
+ Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
4
 
5
5
  # Use the database for sessions instead of the cookie-based default,
6
6
  # which shouldn't be used to store highly confidential information
@@ -4,7 +4,7 @@
4
4
  # is enabled by default.
5
5
 
6
6
  # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
- ActionController::Base.wrap_parameters format: [:json] if ActionController::Base.respond_to?(:wrap_parameters)
7
+ ActionController::Base.wrap_parameters :format => [:json] if ActionController::Base.respond_to?(:wrap_parameters)
8
8
 
9
9
  # Disable root element in JSON by default.
10
10
  if defined?(ActiveRecord)
@@ -1,4 +1,4 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe "BootstrapForms::FormBuilder" do
4
4
  context "given a setup builder" do
@@ -9,6 +9,8 @@ describe "BootstrapForms::FormBuilder" do
9
9
  @builder = BootstrapForms::FormBuilder.new(:item, @project, @template, {}, proc {})
10
10
  end
11
11
 
12
+ it_behaves_like 'a bootstrap form'
13
+
12
14
  describe "with no options" do
13
15
  describe "error_messages" do
14
16
  it "returns empty string without errors" do
@@ -42,162 +44,55 @@ describe "BootstrapForms::FormBuilder" do
42
44
  end
43
45
  end
44
46
  end
47
+ end
45
48
 
46
- describe "text_area" do
47
- before(:each) do
48
- @result = @builder.text_area "name"
49
- end
50
-
51
- it "has textarea input" do
52
- @result.should match /textarea/
53
- end
49
+ context "with errors" do
50
+ before(:each) do
51
+ @project.errors.add("name")
52
+ @result = @builder.error_messages
54
53
  end
55
54
 
56
- describe "check_box" do
57
- it "generates wrapped input" do
58
- @builder.check_box("name").should == "<div class=\"control-group\"><div class=\"controls\"><label class=\"checkbox\" 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>"
59
- end
60
-
61
- it "allows custom label" do
62
- @builder.check_box("name", :label => "custom label").should match /custom label<\/label>/
63
- end
64
-
65
- it "allows no label with :label => false " do
66
- @builder.check_box("name", :label => false).should_not match /<\/label>/
67
- end
68
- it "allows no label with :label => '' " do
69
- @builder.check_box("name", :label => '').should_not match /<\/label>/
70
- end
55
+ it "is wrapped in error div" do
56
+ @result.should match /^<div class="alert alert-block alert-error validation-errors">.*<\/div>$/
71
57
  end
72
58
 
73
- describe "radio_buttons" do
74
- it "doesn't use field_options from previously generated field" do
75
- @builder.text_field :name, :label => 'Heading', :help_inline => 'Inline help', :help_block => 'Block help'
76
- @builder.radio_buttons(:name, {"One"=>"1", "Two"=>"2"}).should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><label class=\"radio\" for=\"item_name_1\"><input id=\"item_name_1\" name=\"item[name]\" type=\"radio\" value=\"1\" />One</label><label class=\"radio\" for=\"item_name_2\"><input id=\"item_name_2\" name=\"item[name]\" type=\"radio\" value=\"2\" />Two</label></div></div>"
77
- end
78
-
79
- it "sets field_options" do
80
- @builder.radio_buttons(:name, {"One" => "1", "Two" => "2"})
81
- @builder.instance_variable_get("@field_options").should == {:error => nil}
82
- end
83
-
84
- it "generates wrapped input" do
85
- @builder.radio_buttons(:name, {"One" => "1", "Two" => "2"}).should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><label class=\"radio\" for=\"item_name_1\"><input id=\"item_name_1\" name=\"item[name]\" type=\"radio\" value=\"1\" />One</label><label class=\"radio\" for=\"item_name_2\"><input id=\"item_name_2\" name=\"item[name]\" type=\"radio\" value=\"2\" />Two</label></div></div>"
86
- end
87
-
88
- it "allows custom label" do
89
- @builder.radio_buttons(:name, {"One" => "1", "Two" => "2"}, {:label => "custom label"}).should match /custom label<\/label>/
90
- end
59
+ it "has a list with errors" do
60
+ @result.should match /<ul><li>Name is invalid<\/li><\/ul>/
91
61
  end
92
62
 
93
- (%w{email file number password range search text url }.map{|field| ["#{field}_field",field]} + [["telephone_field", "tel"], ["phone_field", "tel"]]).each do |field, type|
94
- describe "#{field}" do
95
- context "result" do
96
- before(:each) do
97
- @result = @builder.send(field, "name")
98
- end
99
-
100
- it "is wrapped" do
101
- @result.should match /^<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name<\/label><div class=\"controls\">.*<\/div><\/div>$/
102
- end
103
-
104
- it "has an input of type: #{type}" do
105
- @result.should match /<input.*type=["#{type}"]/
106
- end
107
- end # result
108
-
109
- context "call expectations" do
110
- %w(control_group_div label_field input_div extras).map(&:to_sym).each do |method|
111
- it "calls #{method}" do
112
- @builder.should_receive(method).and_return("")
113
- end
114
- end
115
-
116
- after(:each) do
117
- @builder.send(field, "name")
118
- end
119
- end # call expectations
120
-
121
- end # field
122
- end # fields
123
- end # no options
124
-
125
- describe "extras" do
126
- context "text_field" do
127
- it "adds span for inline help" do
128
- @builder.text_field(:name, :help_inline => 'help me!').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">help me!</span></div></div>"
129
- end
130
-
131
- it "adds help block" do
132
- @builder.text_field(:name, :help_block => 'help me!').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><p class=\"help-block\">help me!</p></div></div>"
133
- end
134
-
135
- it "adds error message and class" do
136
- @builder.text_field(:name, :error => 'This is an error!').should == "<div class=\"control-group error\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">This is an error!</span></div></div>"
137
- end
138
-
139
- it "adds success message and class" do
140
- @builder.text_field(:name, :success => 'This checked out OK').should == "<div class=\"control-group success\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">This checked out OK</span></div></div>"
141
- end
142
-
143
- it "adds warning message and class" do
144
- @builder.text_field(:name, :warning => 'Take a look at this...').should == "<div class=\"control-group warning\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">Take a look at this...</span></div></div>"
145
- end
146
-
147
- it "prepends passed text" do
148
- @builder.text_field(:name, :prepend => '@').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><div class=\"input-prepend\"><span class=\"add-on\">@</span><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /></div></div></div>"
149
- end
150
-
151
- it "appends passed text" do
152
- @builder.text_field(:name, :append => '@').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><div class=\"input-append\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"add-on\">@</span></div></div></div>"
153
- end
154
-
155
- it "prepends and appends passed text" do
156
- @builder.text_field(:name, :append => '@', :prepend => '#').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><div class=\"input-prepend input-append\"><span class=\"add-on\">\#</span><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"add-on\">@</span></div></div></div>"
157
- end
63
+ it "has error title" do
64
+ @result.should match /<h4 class="alert-heading">#{I18n.t('bootstrap_forms.errors.header', :model => Project.model_name.human)}<\/h4>/
158
65
  end
159
- context "label option" do
160
- %w(select email_field file_field number_field password_field search_field text_area text_field url_field).each do |method_name|
161
-
162
- it "should not add a label when ''" do
163
- @builder.send(method_name.to_sym, 'name', :label => '').should_not match /<\/label>/
164
- end
165
66
 
166
- it "should not add a label when false" do
167
- @builder.send(method_name.to_sym, 'name', :label => false).should_not match /<\/label>/
168
- end
169
- end
170
- end
171
- end # extras
172
-
173
- describe "form actions" do
174
- context "actions" do
175
- it "adds additional block content" do
176
- @builder.actions do
177
- @builder.submit
178
- end.should == "<div class=\"form-actions\"><input class=\"btn btn-primary\" name=\"commit\" type=\"submit\" value=\"Create Project\" /></div>"
179
- end
67
+ it "has error message on field" do
68
+ @builder.text_field("name").should == "<div class=\"control-group error\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">Name is invalid</span></div></div>"
180
69
  end
181
70
 
182
- context "submit" do
183
- it "adds btn primary class" do
184
- @builder.submit.should == "<input class=\"btn btn-primary\" name=\"commit\" type=\"submit\" value=\"Create Project\" />"
185
- end
71
+ it "joins passed error message and validation errors with ', '" do
72
+ @builder.text_field("name", :error => 'This is an error!').should == "<div class=\"control-group error\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">This is an error!, Name is invalid</span></div></div>"
186
73
  end
74
+ end
187
75
 
188
- context "button" do
189
- it "adds btn primary class" do
190
- @builder.submit.should == "<input class=\"btn btn-primary\" name=\"commit\" type=\"submit\" value=\"Create Project\" />"
191
- end
76
+ context 'submit' do
77
+ it 'checks persistence of object' do
78
+ @builder.submit.should match('Create Project')
192
79
  end
80
+ end
193
81
 
194
- context "cancel" do
195
- it "creates link with correct class" do
196
- @builder.should_receive(:link_to).with(I18n.t('bootstrap_forms.buttons.cancel'), :back, :class => 'btn cancel').and_return("")
197
- @builder.cancel
198
- end
82
+ context 'button' do
83
+ it 'checks persistence of object' do
84
+ @builder.button.should match('Create Project')
199
85
  end
200
- end # actions
201
- end # setup builder
86
+ end
87
+ end
88
+
89
+ context "given a setup builder with a symbol" do
90
+ before(:each) do
91
+ @template = ActionView::Base.new
92
+ @template.output_buffer = ""
93
+ @builder = BootstrapForms::FormBuilder.new(:item, nil, @template, {}, proc {})
94
+ end
202
95
 
96
+ it_behaves_like 'a bootstrap form'
97
+ end
203
98
  end
data/spec/spec_helper.rb CHANGED
@@ -9,12 +9,16 @@ require File.expand_path("../dummy/config/environment.rb", __FILE__)
9
9
  require 'rspec/rails'
10
10
  require 'capybara/rspec'
11
11
 
12
+ require 'active_support/ordered_hash' if RUBY_VERSION < '1.9'
13
+
12
14
  require File.expand_path(File.join(File.dirname(__FILE__), '../lib/bootstrap_forms'))
13
15
 
16
+ require 'support/shared_context'
17
+
14
18
  RSpec.configure do |config|
15
19
  config.treat_symbols_as_metadata_keys_with_true_values = true
16
20
  config.run_all_when_everything_filtered = true
17
21
  config.filter_run :focus
18
22
  end
19
23
 
20
- Rails.backtrace_cleaner.remove_silencers!
24
+ Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,184 @@
1
+ shared_examples "a bootstrap form" do
2
+ describe "with no options" do
3
+ describe "error_messages" do
4
+ it "returns empty string without errors" do
5
+ @builder.error_messages.should == ""
6
+ end
7
+ end
8
+
9
+ describe "text_area" do
10
+ before(:each) do
11
+ @result = @builder.text_area "name"
12
+ end
13
+
14
+ it "has textarea input" do
15
+ @result.should match /textarea/
16
+ end
17
+ end
18
+
19
+ describe "uneditable_input" do
20
+ it "generates wrapped input" do
21
+ @builder.uneditable_input("name").should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><span class=\"uneditable-input\"></span></div></div>"
22
+ end
23
+
24
+ it "allows for an id" do
25
+ @builder.uneditable_input("name", :id => "myid").should match /<span.*id="myid"/
26
+ end
27
+ end
28
+
29
+ describe "check_box" do
30
+ it "generates wrapped input" do
31
+ @builder.check_box("name").should == "<div class=\"control-group\"><div class=\"controls\"><label class=\"checkbox\" 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>"
32
+ end
33
+
34
+ it "allows custom label" do
35
+ @builder.check_box("name", :label => "custom label").should match /custom label<\/label>/
36
+ end
37
+
38
+ it "allows no label with :label => false " do
39
+ @builder.check_box("name", :label => false).should_not match /<\/label>/
40
+ end
41
+ it "allows no label with :label => '' " do
42
+ @builder.check_box("name", :label => '').should_not match /<\/label>/
43
+ end
44
+ end
45
+
46
+ describe "radio_buttons" do
47
+ before do
48
+ if RUBY_VERSION < '1.9'
49
+ @options = ActiveSupport::OrderedHash.new
50
+ @options['One'] = '1'
51
+ @options['Two'] = '2'
52
+ else
53
+ @options = {'One' => '1', 'Two' => '2'}
54
+ end
55
+ end
56
+
57
+ it "doesn't use field_options from previously generated field" do
58
+ @builder.text_field :name, :label => 'Heading', :help_inline => 'Inline help', :help_block => 'Block help'
59
+ @builder.radio_buttons(:name, @options).should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><label class=\"radio\" for=\"item_name_1\"><input id=\"item_name_1\" name=\"item[name]\" type=\"radio\" value=\"1\" />One</label><label class=\"radio\" for=\"item_name_2\"><input id=\"item_name_2\" name=\"item[name]\" type=\"radio\" value=\"2\" />Two</label></div></div>"
60
+ end
61
+
62
+ it "sets field_options" do
63
+ @builder.radio_buttons(:name, {"One" => "1", "Two" => "2"})
64
+ @builder.instance_variable_get("@field_options").should == {:error => nil}
65
+ end
66
+
67
+ it "generates wrapped input" do
68
+ @builder.radio_buttons(:name, @options).should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><label class=\"radio\" for=\"item_name_1\"><input id=\"item_name_1\" name=\"item[name]\" type=\"radio\" value=\"1\" />One</label><label class=\"radio\" for=\"item_name_2\"><input id=\"item_name_2\" name=\"item[name]\" type=\"radio\" value=\"2\" />Two</label></div></div>"
69
+ end
70
+
71
+ it "allows custom label" do
72
+ @builder.radio_buttons(:name, @options, {:label => "custom label"}).should match /custom label<\/label>/
73
+ end
74
+ end
75
+
76
+ (%w{email file number password range search text url }.map{|field| ["#{field}_field",field]} + [["telephone_field", "tel"], ["phone_field", "tel"]]).each do |field, type|
77
+ describe "#{field}" do
78
+ context "result" do
79
+ before(:each) do
80
+ @result = @builder.send(field, "name")
81
+ end
82
+
83
+ it "is wrapped" do
84
+ @result.should match /^<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name<\/label><div class=\"controls\">.*<\/div><\/div>$/
85
+ end
86
+
87
+ it "has an input of type: #{type}" do
88
+ @result.should match /<input.*type="#{type}"/
89
+ end
90
+ end # result
91
+
92
+ context "call expectations" do
93
+ %w(control_group_div label_field input_div extras).map(&:to_sym).each do |method|
94
+ it "calls #{method}" do
95
+ @builder.should_receive(method).and_return("")
96
+ end
97
+ end
98
+
99
+ after(:each) do
100
+ @builder.send(field, "name")
101
+ end
102
+ end # call expectations
103
+
104
+ end # field
105
+ end # fields
106
+ end # no options
107
+
108
+ describe "extras" do
109
+ context "text_field" do
110
+ it "adds span for inline help" do
111
+ @builder.text_field(:name, :help_inline => 'help me!').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">help me!</span></div></div>"
112
+ end
113
+
114
+ it "adds help block" do
115
+ @builder.text_field(:name, :help_block => 'help me!').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><p class=\"help-block\">help me!</p></div></div>"
116
+ end
117
+
118
+ it "adds error message and class" do
119
+ @builder.text_field(:name, :error => 'This is an error!').should == "<div class=\"control-group error\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">This is an error!</span></div></div>"
120
+ end
121
+
122
+ it "adds success message and class" do
123
+ @builder.text_field(:name, :success => 'This checked out OK').should == "<div class=\"control-group success\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">This checked out OK</span></div></div>"
124
+ end
125
+
126
+ it "adds warning message and class" do
127
+ @builder.text_field(:name, :warning => 'Take a look at this...').should == "<div class=\"control-group warning\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">Take a look at this...</span></div></div>"
128
+ end
129
+
130
+ it "prepends passed text" do
131
+ @builder.text_field(:name, :prepend => '@').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><div class=\"input-prepend\"><span class=\"add-on\">@</span><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /></div></div></div>"
132
+ end
133
+
134
+ it "appends passed text" do
135
+ @builder.text_field(:name, :append => '@').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><div class=\"input-append\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"add-on\">@</span></div></div></div>"
136
+ end
137
+
138
+ it "prepends and appends passed text" do
139
+ @builder.text_field(:name, :append => '@', :prepend => '#').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><div class=\"input-prepend input-append\"><span class=\"add-on\">\#</span><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"add-on\">@</span></div></div></div>"
140
+ end
141
+ end
142
+ context "label option" do
143
+ %w(select email_field file_field number_field password_field search_field text_area text_field url_field).each do |method_name|
144
+
145
+ it "should not add a label when ''" do
146
+ @builder.send(method_name.to_sym, 'name', :label => '').should_not match /<\/label>/
147
+ end
148
+
149
+ it "should not add a label when false" do
150
+ @builder.send(method_name.to_sym, 'name', :label => false).should_not match /<\/label>/
151
+ end
152
+ end
153
+ end
154
+ end # extras
155
+
156
+ describe "form actions" do
157
+ context "actions" do
158
+ it "adds additional block content" do
159
+ @builder.actions do
160
+ @builder.submit
161
+ end.should match(/<div class=\"form-actions\">.*?<\/div>/)
162
+ end
163
+ end
164
+
165
+ context "submit" do
166
+ it "adds btn primary class" do
167
+ @builder.submit.should match /class=\"btn btn-primary\"/
168
+ end
169
+ end
170
+
171
+ context "button" do
172
+ it "adds btn primary class" do
173
+ @builder.button.should match /class=\"btn btn-primary\"/
174
+ end
175
+ end
176
+
177
+ context "cancel" do
178
+ it "creates link with correct class" do
179
+ @builder.should_receive(:link_to).with(I18n.t('bootstrap_forms.buttons.cancel'), :back, :class => 'btn cancel').and_return("")
180
+ @builder.cancel
181
+ end
182
+ end
183
+ end # actions
184
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-07 00:00:00.000000000 Z
12
+ date: 2012-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec-rails
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 2.9.0
21
+ version: 2.10.1
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 2.9.0
29
+ version: 2.10.1
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: capybara
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -167,7 +167,6 @@ files:
167
167
  - spec/dummy/db/migrate/20110710143903_initial_tables.rb
168
168
  - spec/dummy/db/schema.rb
169
169
  - spec/dummy/db/test.sqlite3
170
- - spec/dummy/log/development.log
171
170
  - spec/dummy/public/404.html
172
171
  - spec/dummy/public/422.html
173
172
  - spec/dummy/public/500.html
@@ -178,6 +177,7 @@ files:
178
177
  - spec/dummy/tmp/cache/.gitkeep
179
178
  - spec/lib/bootstrap_forms/form_builder_spec.rb
180
179
  - spec/spec_helper.rb
180
+ - spec/support/shared_context.rb
181
181
  homepage: https://github.com/sethvargo/bootstrap_forms
182
182
  licenses: []
183
183
  post_install_message:
@@ -192,7 +192,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
192
192
  version: '0'
193
193
  segments:
194
194
  - 0
195
- hash: 3425154550503238939
195
+ hash: 3940498627574462359
196
196
  required_rubygems_version: !ruby/object:Gem::Requirement
197
197
  none: false
198
198
  requirements:
@@ -201,10 +201,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  version: '0'
202
202
  segments:
203
203
  - 0
204
- hash: 3425154550503238939
204
+ hash: 3940498627574462359
205
205
  requirements: []
206
206
  rubyforge_project:
207
- rubygems_version: 1.8.23
207
+ rubygems_version: 1.8.24
208
208
  signing_key:
209
209
  specification_version: 3
210
210
  summary: Bootstrap Forms makes Twitter's Bootstrap on Rails easy!
@@ -243,7 +243,6 @@ test_files:
243
243
  - spec/dummy/db/migrate/20110710143903_initial_tables.rb
244
244
  - spec/dummy/db/schema.rb
245
245
  - spec/dummy/db/test.sqlite3
246
- - spec/dummy/log/development.log
247
246
  - spec/dummy/public/404.html
248
247
  - spec/dummy/public/422.html
249
248
  - spec/dummy/public/500.html
@@ -254,3 +253,4 @@ test_files:
254
253
  - spec/dummy/tmp/cache/.gitkeep
255
254
  - spec/lib/bootstrap_forms/form_builder_spec.rb
256
255
  - spec/spec_helper.rb
256
+ - spec/support/shared_context.rb
File without changes