bootstrap_form 0.3.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/README.md +12 -1
  2. data/lib/bootstrap_form/form_builder.rb +16 -17
  3. data/lib/bootstrap_form/version.rb +1 -1
  4. data/test/bootstrap_form_test.rb +51 -27
  5. data/test/dummy/Gemfile +45 -0
  6. data/test/dummy/Gemfile.lock +120 -0
  7. data/test/dummy/README.rdoc +28 -0
  8. data/test/dummy/Rakefile +0 -1
  9. data/test/dummy/app/assets/javascripts/application.js +11 -4
  10. data/test/dummy/app/assets/stylesheets/application.css +11 -5
  11. data/test/dummy/app/controllers/application_controller.rb +3 -1
  12. data/test/dummy/app/models/address.rb +3 -0
  13. data/test/dummy/app/models/user.rb +3 -0
  14. data/test/dummy/app/views/layouts/application.html.erb +2 -2
  15. data/test/dummy/bin/bundle +3 -0
  16. data/test/dummy/bin/rails +4 -0
  17. data/test/dummy/bin/rake +4 -0
  18. data/test/dummy/config.ru +1 -1
  19. data/test/dummy/config/application.rb +3 -24
  20. data/test/dummy/config/boot.rb +3 -9
  21. data/test/dummy/config/environment.rb +2 -2
  22. data/test/dummy/config/environments/development.rb +12 -13
  23. data/test/dummy/config/environments/production.rb +44 -24
  24. data/test/dummy/config/environments/test.rb +15 -18
  25. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  26. data/test/dummy/config/initializers/inflections.rb +9 -3
  27. data/test/dummy/config/initializers/secret_token.rb +7 -2
  28. data/test/dummy/config/initializers/session_store.rb +0 -5
  29. data/test/dummy/config/initializers/wrap_parameters.rb +6 -6
  30. data/test/dummy/config/locales/en.yml +20 -2
  31. data/test/dummy/db/migrate/{20120106063521_create_users.rb → 20130703191909_create_users.rb} +0 -0
  32. data/test/dummy/db/migrate/20130703191937_create_addresses.rb +13 -0
  33. data/test/dummy/db/schema.rb +13 -3
  34. data/test/dummy/db/seeds.rb +7 -0
  35. data/test/dummy/db/test.sqlite3 +0 -0
  36. data/test/dummy/log/development.log +0 -32
  37. data/test/dummy/log/test.log +3505 -3
  38. data/test/dummy/public/404.html +43 -11
  39. data/test/dummy/public/422.html +43 -11
  40. data/test/dummy/public/500.html +43 -12
  41. data/test/dummy/public/robots.txt +5 -0
  42. data/test/dummy/test/fixtures/addresses.yml +15 -0
  43. data/test/dummy/test/fixtures/users.yml +2 -0
  44. data/test/dummy/test/models/address_test.rb +7 -0
  45. data/test/dummy/test/{unit → models}/user_test.rb +0 -0
  46. data/test/dummy/test/test_helper.rb +15 -0
  47. metadata +36 -12
  48. data/test/dummy/db/development.sqlite3 +0 -0
  49. data/test/dummy/script/rails +0 -6
data/README.md CHANGED
@@ -8,15 +8,22 @@ integrate Twitter Bootstrap-style forms into your Rails App.
8
8
  ## Requirements
9
9
 
10
10
  * Ruby 1.9+
11
- * Rails 3.1+
11
+ * Rails 4.0+
12
12
  * Twitter Bootstrap 2.0+
13
13
 
14
14
  ## Installation
15
15
 
16
16
  Add it to your Gemfile:
17
17
 
18
+ ### Rails 4.0+
19
+
18
20
  `gem 'bootstrap_form'`
19
21
 
22
+ ### Rails 3.1+
23
+
24
+ `gem 'bootstrap_form', '~> 0.3.2'`
25
+
26
+
20
27
  Run the following command to install it:
21
28
 
22
29
  `bundle`
@@ -264,6 +271,10 @@ classes, you can use the `alert_message` helper:
264
271
  <%= f.alert_message "Please fix the errors below." %>
265
272
  ```
266
273
 
274
+ ## Code Triage page
275
+
276
+ http://www.codetriage.com/potenza/bootstrap_form
277
+
267
278
  ## Contributors
268
279
 
269
280
  https://github.com/potenza/bootstrap_form/graphs/contributors
@@ -5,14 +5,13 @@ module BootstrapForm
5
5
  select collection_select date_select time_select datetime_select}
6
6
 
7
7
  delegate :content_tag, to: :@template
8
+ delegate :capture, to: :@template
9
+
10
+ def initialize(object_name, object, template, options, proc=nil)
11
+ help = options.fetch(:help, nil)
12
+ @help_class = help.eql?(:block) ? 'help-block' : 'help-inline'
8
13
 
9
- def initialize(object_name, object, template, options, proc)
10
14
  super
11
- @help_tag, @help_css = if options.fetch(:help, '').to_sym == :block
12
- [:p, 'help-block']
13
- else
14
- [:span, 'help-inline']
15
- end
16
15
  end
17
16
 
18
17
  FORM_HELPERS.each do |method_name|
@@ -44,11 +43,11 @@ module BootstrapForm
44
43
  end
45
44
  end
46
45
 
47
- def check_box(name, *args)
48
- options = args.extract_options!.symbolize_keys!
49
- args << options.except(:label, :help, :inline)
46
+ def check_box(name, options = {}, checked_value = "1", unchecked_value = "0")
47
+ options = options.symbolize_keys!
50
48
 
51
- html = super(name, *args) + ' ' + options[:label]
49
+ html = super(name, options.except(:label, :help, :inline), checked_value, unchecked_value)
50
+ html += ' ' + (options[:label] || name.to_s.humanize)
52
51
 
53
52
  css = 'checkbox'
54
53
  css << ' inline' if options[:inline]
@@ -67,10 +66,10 @@ module BootstrapForm
67
66
  end
68
67
 
69
68
  def control_group(name = nil, options = {}, &block)
70
- has_name = !(name.nil? || object.errors[name].empty?)
69
+ errors_has_name = object.respond_to?(:errors) && !(name.nil? || object.errors[name].empty?)
71
70
 
72
71
  options[:class] ||= 'control-group'
73
- options[:class] << ' error' if has_name
72
+ options[:class] << ' error' if errors_has_name
74
73
 
75
74
  label = options.delete(:label)
76
75
  _help = options.delete(:help)
@@ -86,10 +85,10 @@ module BootstrapForm
86
85
  end
87
86
 
88
87
  html << content_tag(:div, class: 'controls') do
89
- controls = block.call
88
+ controls = capture(&block)
90
89
 
91
- help = has_name ? object.errors[name].join(', ') : _help
92
- controls << content_tag(@help_tag, help, class: @help_css) if help
90
+ help = errors_has_name ? object.errors[name].join(', ') : _help
91
+ controls << content_tag(:span, help, class: @help_class) if help
93
92
 
94
93
  controls.html_safe
95
94
  end
@@ -100,7 +99,7 @@ module BootstrapForm
100
99
 
101
100
  def actions(&block)
102
101
  content_tag :div, class: "form-actions" do
103
- block.call
102
+ capture(&block)
104
103
  end
105
104
  end
106
105
 
@@ -118,7 +117,7 @@ module BootstrapForm
118
117
  options = args.extract_options!
119
118
  css = options[:class] || "alert alert-error"
120
119
 
121
- if object.errors.full_messages.any?
120
+ if object.respond_to?(:errors) && object.errors.full_messages.any?
122
121
  content_tag :div, class: css do
123
122
  title
124
123
  end
@@ -1,3 +1,3 @@
1
1
  module BootstrapForm
2
- VERSION = "0.3.2"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -33,17 +33,17 @@ class BootstrapFormTest < ActionView::TestCase
33
33
  end
34
34
 
35
35
  test "text fields are wrapped correctly" do
36
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" size=\"30\" type=\"text\" value=\"steve@example.com\" /></div></div>}
36
+ expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" type=\"text\" value=\"steve@example.com\" /></div></div>}
37
37
  assert_equal expected, @builder.text_field(:email)
38
38
  end
39
39
 
40
40
  test "password fields are wrapped correctly" do
41
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_password\">Password</label><div class=\"controls\"><input id=\"user_password\" name=\"user[password]\" size=\"30\" type=\"text\" value=\"secret\" /></div></div>}
41
+ expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_password\">Password</label><div class=\"controls\"><input id=\"user_password\" name=\"user[password]\" type=\"text\" value=\"secret\" /></div></div>}
42
42
  assert_equal expected, @builder.text_field(:password)
43
43
  end
44
44
 
45
45
  test "text areas are wrapped correctly" do
46
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_comments\">Comments</label><div class=\"controls\"><textarea cols=\"40\" id=\"user_comments\" name=\"user[comments]\" rows=\"20\">my comment</textarea></div></div>}
46
+ expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_comments\">Comments</label><div class=\"controls\"><textarea id=\"user_comments\" name=\"user[comments]\">\nmy comment</textarea></div></div>}
47
47
  assert_equal expected, @builder.text_area(:comments)
48
48
  end
49
49
 
@@ -53,23 +53,23 @@ class BootstrapFormTest < ActionView::TestCase
53
53
  end
54
54
 
55
55
  test "number fields are wrapped correctly" do
56
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><input id=\"user_misc\" name=\"user[misc]\" size="30" type=\"number\" /></div></div>}
56
+ expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><input id=\"user_misc\" name=\"user[misc]\" type=\"number\" /></div></div>}
57
57
  assert_equal expected, @builder.number_field(:misc)
58
58
  end
59
59
 
60
60
  test "email fields are wrapped correctly" do
61
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><input id=\"user_misc\" name=\"user[misc]\" size="30" type=\"email\" /></div></div>}
61
+ expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><input id=\"user_misc\" name=\"user[misc]\" type=\"email\" /></div></div>}
62
62
  assert_equal expected, @builder.email_field(:misc)
63
63
  end
64
64
 
65
65
  test "telephone/phone fields are wrapped correctly" do
66
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><input id=\"user_misc\" name=\"user[misc]\" size="30" type=\"tel\" /></div></div>}
66
+ expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><input id=\"user_misc\" name=\"user[misc]\" type=\"tel\" /></div></div>}
67
67
  assert_equal expected, @builder.telephone_field(:misc)
68
68
  assert_equal expected, @builder.phone_field(:misc)
69
69
  end
70
70
 
71
71
  test "url fields are wrapped correctly" do
72
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><input id=\"user_misc\" name=\"user[misc]\" size="30" type=\"url\" /></div></div>}
72
+ expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><input id=\"user_misc\" name=\"user[misc]\" type=\"url\" /></div></div>}
73
73
  assert_equal expected, @builder.url_field(:misc)
74
74
  end
75
75
 
@@ -109,6 +109,11 @@ class BootstrapFormTest < ActionView::TestCase
109
109
  assert_equal expected, @builder.check_box(:misc, label: 'This is a checkbox')
110
110
  end
111
111
 
112
+ test "check_box responds to checked_value and unchecked_value arguments" do
113
+ expected = %{<label class=\"checkbox\" for=\"user_misc\"><input name=\"user[misc]\" type=\"hidden\" value=\"no\" /><input id=\"user_misc\" name=\"user[misc]\" type=\"checkbox\" value=\"yes\" /> This is a checkbox</label>}
114
+ assert_equal expected, @builder.check_box(:misc, {label: 'This is a checkbox'}, 'yes', 'no')
115
+ end
116
+
112
117
  test "check_box inline label is setted correctly" do
113
118
  expected = %{<label class=\"checkbox inline\" for=\"user_misc\"><input name=\"user[misc]\" type=\"hidden\" value=\"0\" /><input id=\"user_misc\" name=\"user[misc]\" type=\"checkbox\" value=\"1\" /> This is a checkbox</label>}
114
119
  assert_equal expected, @builder.check_box(:misc, label: 'This is a checkbox', inline: true)
@@ -125,38 +130,38 @@ class BootstrapFormTest < ActionView::TestCase
125
130
  end
126
131
 
127
132
  test "changing the label text" do
128
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email Address</label><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" size=\"30\" type=\"text\" value=\"steve@example.com\" /></div></div>}
133
+ expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email Address</label><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" type=\"text\" value=\"steve@example.com\" /></div></div>}
129
134
  assert_equal expected, @builder.text_field(:email, label: 'Email Address')
130
135
  end
131
136
 
132
137
  test "render the field without label" do
133
- expected = %{<div class=\"control-group\"><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" size=\"30\" type=\"text\" value=\"steve@example.com\" /></div></div>}
138
+ expected = %{<div class=\"control-group\"><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" type=\"text\" value=\"steve@example.com\" /></div></div>}
134
139
  assert_equal expected, @builder.text_field(:email, label: :none)
135
140
  end
136
141
 
137
142
  test "adding prepend text" do
138
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><div class=\"input-prepend\"><span class=\"add-on\">Gmail</span><input id=\"user_email\" name=\"user[email]\" size=\"30\" type=\"text\" value=\"steve@example.com\" /></div></div></div>}
143
+ expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><div class=\"input-prepend\"><span class=\"add-on\">Gmail</span><input id=\"user_email\" name=\"user[email]\" type=\"text\" value=\"steve@example.com\" /></div></div></div>}
139
144
  assert_equal expected, @builder.text_field(:email, prepend: 'Gmail')
140
145
  end
141
146
 
142
147
  test "adding append text" do
143
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><div class=\"input-append\"><input id=\"user_email\" name=\"user[email]\" size=\"30\" type=\"text\" value=\"steve@example.com\" /><span class="add-on">Gmail</span></div></div></div>}
148
+ expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><div class=\"input-append\"><input id=\"user_email\" name=\"user[email]\" type=\"text\" value=\"steve@example.com\" /><span class="add-on">Gmail</span></div></div></div>}
144
149
  assert_equal expected, @builder.text_field(:email, append: 'Gmail')
145
150
  end
146
151
 
147
152
  test "passing :help to a field displays it inline" do
148
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" size=\"30\" type=\"text\" value=\"steve@example.com\" /><span class=\"help-inline\">This is required</span></div></div>}
153
+ expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" type=\"text\" value=\"steve@example.com\" /><span class=\"help-inline\">This is required</span></div></div>}
149
154
  assert_equal expected, @builder.text_field(:email, help: 'This is required')
150
155
  end
151
156
 
152
157
  test "passing other options to a field get passed through" do
153
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><input autofocus=\"autofocus\" id=\"user_email\" name=\"user[email]\" size=\"30\" type=\"text\" value=\"steve@example.com\" /></div></div>}
158
+ expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><input autofocus=\"autofocus\" id=\"user_email\" name=\"user[email]\" type=\"text\" value=\"steve@example.com\" /></div></div>}
154
159
  assert_equal expected, @builder.text_field(:email, autofocus: true)
155
160
  end
156
161
 
157
162
  test "control_group creates a valid structure and allows arbitrary html to be added via a block" do
158
163
  output = @builder.control_group do
159
- '<span>custom control here</span>'
164
+ content_tag(:span, 'custom control here')
160
165
  end
161
166
 
162
167
  expected = %{<div class="control-group"><div class="controls"><span>custom control here</span></div></div>}
@@ -165,7 +170,7 @@ class BootstrapFormTest < ActionView::TestCase
165
170
 
166
171
  test "control_group renders the options for div.control_group" do
167
172
  output = @builder.control_group nil, id: 'foo' do
168
- '<span>custom control here</span>'
173
+ content_tag(:span, 'custom control here')
169
174
  end
170
175
 
171
176
  expected = %{<div class="control-group" id="foo"><div class="controls"><span>custom control here</span></div></div>}
@@ -174,7 +179,7 @@ class BootstrapFormTest < ActionView::TestCase
174
179
 
175
180
  test "control_group overrides the control-group class if another is passed" do
176
181
  output = @builder.control_group nil, class: 'foo' do
177
- '<span>custom control here</span>'
182
+ content_tag(:span, 'custom control here')
178
183
  end
179
184
 
180
185
  expected = %{<div class="foo"><div class="controls"><span>custom control here</span></div></div>}
@@ -183,7 +188,7 @@ class BootstrapFormTest < ActionView::TestCase
183
188
 
184
189
  test "control_group renders the label correctly" do
185
190
  output = @builder.control_group :email, label: { text: 'Custom Control' } do
186
- '<span>custom control here</span>'
191
+ content_tag(:span, 'custom control here')
187
192
  end
188
193
 
189
194
  expected = %{<div class="control-group"><label class="control-label" for="user_email">Custom Control</label><div class="controls"><span>custom control here</span></div></div>}
@@ -192,7 +197,7 @@ class BootstrapFormTest < ActionView::TestCase
192
197
 
193
198
  test "control_group overrides the label's 'class' and 'for' attributes if others are passed" do
194
199
  output = @builder.control_group nil, label: { text: 'Custom Control', class: 'foo', for: 'bar' } do
195
- '<span>custom control here</span>'
200
+ content_tag(:span, 'custom control here')
196
201
  end
197
202
 
198
203
  expected = %{<div class="control-group"><label class="foo" for="bar">Custom Control</label><div class="controls"><span>custom control here</span></div></div>}
@@ -201,7 +206,7 @@ class BootstrapFormTest < ActionView::TestCase
201
206
 
202
207
  test "control_group label's 'for' attribute should be empty if no name was passed" do
203
208
  output = @builder.control_group nil, label: { text: 'Custom Control' } do
204
- '<span>custom control here</span>'
209
+ content_tag(:span, 'custom control here')
205
210
  end
206
211
 
207
212
  expected = %{<div class="control-group"><label class="control-label" for="">Custom Control</label><div class="controls"><span>custom control here</span></div></div>}
@@ -210,7 +215,7 @@ class BootstrapFormTest < ActionView::TestCase
210
215
 
211
216
  test 'control_group renders the :help corrrectly' do
212
217
  output = @builder.control_group nil, help: 'Foobar' do
213
- '<span>custom control here</span>'
218
+ content_tag(:span, 'custom control here')
214
219
  end
215
220
 
216
221
  expected = %{<div class="control-group"><div class="controls"><span>custom control here</span><span class="help-inline">Foobar</span></div></div>}
@@ -222,10 +227,10 @@ class BootstrapFormTest < ActionView::TestCase
222
227
  @user.valid?
223
228
 
224
229
  output = @builder.control_group :email do
225
- '<span>custom control here</span>'
230
+ content_tag(:span, 'custom control here')
226
231
  end
227
232
 
228
- expected = %{<div class="control-group error"><div class="controls"><span>custom control here</span><span class="help-inline">can't be blank, is too short (minimum is 5 characters)</span></div></div>}
233
+ expected = %{<div class="control-group error"><div class="controls"><span>custom control here</span><span class="help-inline">can&#39;t be blank, is too short (minimum is 5 characters)</span></div></div>}
229
234
  assert_equal expected, output
230
235
  end
231
236
 
@@ -244,7 +249,7 @@ class BootstrapFormTest < ActionView::TestCase
244
249
 
245
250
  test "primary button with a disabled state" do
246
251
  expected = %{<input class=\"btn btn-primary\" data-disable-with="Saving..." name=\"commit\" type=\"submit\" value=\"Submit\" />}
247
- assert_equal expected, @builder.primary('Submit', disable_with: 'Saving...')
252
+ assert_equal expected, @builder.primary('Submit', data: { disable_with: 'Saving...' })
248
253
  end
249
254
 
250
255
  test "secondary button contains the correct classes" do
@@ -254,7 +259,7 @@ class BootstrapFormTest < ActionView::TestCase
254
259
 
255
260
  test "secondary button with a disabled state" do
256
261
  expected = %{<input class=\"btn\" data-disable-with="Saving..." name=\"commit\" type=\"submit\" value=\"Submit\" />}
257
- assert_equal expected, @builder.secondary('Submit', disable_with: 'Saving...')
262
+ assert_equal expected, @builder.secondary('Submit', data: { disable_with: 'Saving...' })
258
263
  end
259
264
 
260
265
  test "passing :help :block to the form builder" do
@@ -262,7 +267,7 @@ class BootstrapFormTest < ActionView::TestCase
262
267
  f.text_field(:email, help: 'This is required')
263
268
  end
264
269
 
265
- expected = %{<form accept-charset=\"UTF-8\" action=\"/users\" class=\" form-vertical\" id=\"new_user\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div><div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" size=\"30\" type=\"text\" value=\"steve@example.com\" /><p class=\"help-block\">This is required</p></div></div></form>}
270
+ expected = %{<form accept-charset=\"UTF-8\" action=\"/users\" class=\" form-vertical\" id=\"new_user\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div><div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" type=\"text\" value=\"steve@example.com\" /><span class=\"help-block\">This is required</span></div></div></form>}
266
271
  assert_equal expected, output
267
272
  end
268
273
 
@@ -274,7 +279,7 @@ class BootstrapFormTest < ActionView::TestCase
274
279
  f.text_field(:email, help: 'This is required')
275
280
  end
276
281
 
277
- expected = %{<form accept-charset=\"UTF-8\" action=\"/users\" class=\" form-vertical\" id=\"new_user\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div><div class=\"control-group error\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" size=\"30\" type=\"text\" /><p class=\"help-block\">can't be blank, is too short (minimum is 5 characters)</p></div></div></form>}
282
+ expected = %{<form accept-charset=\"UTF-8\" action=\"/users\" class=\" form-vertical\" id=\"new_user\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div><div class=\"control-group error\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" type=\"text\" /><span class=\"help-block\">can&#39;t be blank, is too short (minimum is 5 characters)</span></div></div></form>}
278
283
  assert_equal expected, output
279
284
  end
280
285
 
@@ -286,8 +291,27 @@ class BootstrapFormTest < ActionView::TestCase
286
291
  f.text_field(:email, help: 'This is required')
287
292
  end
288
293
 
289
- expected = %{<form accept-charset=\"UTF-8\" action=\"/users\" class=\"new_user\" id=\"new_user\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div><div class=\"control-group error\"><div class=\"field_with_errors\"><label class=\"control-label\" for=\"user_email\">Email</label></div><div class=\"controls\"><div class=\"field_with_errors\"><input id=\"user_email\" name=\"user[email]\" size=\"30\" type=\"text\" /></div><p class=\"help-block\">can't be blank, is too short (minimum is 5 characters)</p></div></div></form>}
294
+ expected = %{<form accept-charset=\"UTF-8\" action=\"/users\" class=\"new_user\" id=\"new_user\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div><div class=\"control-group error\"><div class=\"field_with_errors\"><label class=\"control-label\" for=\"user_email\">Email</label></div><div class=\"controls\"><div class=\"field_with_errors\"><input id=\"user_email\" name=\"user[email]\" type=\"text\" /></div><span class=\"help-block\">can&#39;t be blank, is too short (minimum is 5 characters)</span></div></div></form>}
295
+ assert_equal expected, output
296
+ end
297
+
298
+ test "form_for helper works for associations" do
299
+ @user.address = Address.new(street: '123 Main Street')
300
+
301
+ output = bootstrap_form_for(@user) do |f|
302
+ f.fields_for :address do |af|
303
+ af.text_field(:street)
304
+ end
305
+ end
306
+
307
+ expected = %{<form accept-charset=\"UTF-8\" action=\"/users\" class=\" form-vertical\" id=\"new_user\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div><div class=\"control-group\"><label class=\"control-label\" for=\"user_address_attributes_street\">Street</label><div class=\"controls\"><input id=\"user_address_attributes_street\" name=\"user[address_attributes][street]\" type=\"text\" value=\"123 Main Street\" /></div></div></form>}
290
308
  assert_equal expected, output
291
309
  end
310
+
311
+ test "allows the form object to be nil" do
312
+ builder = BootstrapForm::FormBuilder.new :other_model, nil, self, {}, nil
313
+ expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"other_model_email\">Email</label><div class=\"controls\"><input id=\"other_model_email\" name=\"other_model[email]\" type=\"text\" /></div></div>}
314
+ assert_equal expected, builder.text_field(:email)
315
+ end
292
316
  end
293
317
 
@@ -0,0 +1,45 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
4
+ gem 'rails', '4.0.0'
5
+
6
+ # Use sqlite3 as the database for Active Record
7
+ gem 'sqlite3'
8
+
9
+ # Use SCSS for stylesheets
10
+ gem 'sass-rails', '~> 4.0.0'
11
+
12
+ # Use Uglifier as compressor for JavaScript assets
13
+ gem 'uglifier', '>= 1.3.0'
14
+
15
+ # Use CoffeeScript for .js.coffee assets and views
16
+ gem 'coffee-rails', '~> 4.0.0'
17
+
18
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
19
+ # gem 'therubyracer', platforms: :ruby
20
+
21
+ # Use jquery as the JavaScript library
22
+ gem 'jquery-rails'
23
+
24
+ # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
25
+ gem 'turbolinks'
26
+
27
+ # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
28
+ gem 'jbuilder', '~> 1.2'
29
+
30
+ group :doc do
31
+ # bundle exec rake doc:rails generates the API under doc/api.
32
+ gem 'sdoc', require: false
33
+ end
34
+
35
+ # Use ActiveModel has_secure_password
36
+ # gem 'bcrypt-ruby', '~> 3.0.0'
37
+
38
+ # Use unicorn as the app server
39
+ # gem 'unicorn'
40
+
41
+ # Use Capistrano for deployment
42
+ # gem 'capistrano', group: :development
43
+
44
+ # Use debugger
45
+ # gem 'debugger', group: [:development, :test]
@@ -0,0 +1,120 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ actionmailer (4.0.0)
5
+ actionpack (= 4.0.0)
6
+ mail (~> 2.5.3)
7
+ actionpack (4.0.0)
8
+ activesupport (= 4.0.0)
9
+ builder (~> 3.1.0)
10
+ erubis (~> 2.7.0)
11
+ rack (~> 1.5.2)
12
+ rack-test (~> 0.6.2)
13
+ activemodel (4.0.0)
14
+ activesupport (= 4.0.0)
15
+ builder (~> 3.1.0)
16
+ activerecord (4.0.0)
17
+ activemodel (= 4.0.0)
18
+ activerecord-deprecated_finders (~> 1.0.2)
19
+ activesupport (= 4.0.0)
20
+ arel (~> 4.0.0)
21
+ activerecord-deprecated_finders (1.0.3)
22
+ activesupport (4.0.0)
23
+ i18n (~> 0.6, >= 0.6.4)
24
+ minitest (~> 4.2)
25
+ multi_json (~> 1.3)
26
+ thread_safe (~> 0.1)
27
+ tzinfo (~> 0.3.37)
28
+ arel (4.0.0)
29
+ atomic (1.1.10)
30
+ builder (3.1.4)
31
+ coffee-rails (4.0.0)
32
+ coffee-script (>= 2.2.0)
33
+ railties (>= 4.0.0.beta, < 5.0)
34
+ coffee-script (2.2.0)
35
+ coffee-script-source
36
+ execjs
37
+ coffee-script-source (1.6.2)
38
+ erubis (2.7.0)
39
+ execjs (1.4.0)
40
+ multi_json (~> 1.0)
41
+ hike (1.2.3)
42
+ i18n (0.6.4)
43
+ jbuilder (1.4.2)
44
+ activesupport (>= 3.0.0)
45
+ multi_json (>= 1.2.0)
46
+ jquery-rails (3.0.1)
47
+ railties (>= 3.0, < 5.0)
48
+ thor (>= 0.14, < 2.0)
49
+ json (1.8.0)
50
+ mail (2.5.4)
51
+ mime-types (~> 1.16)
52
+ treetop (~> 1.4.8)
53
+ mime-types (1.23)
54
+ minitest (4.7.5)
55
+ multi_json (1.7.7)
56
+ polyglot (0.3.3)
57
+ rack (1.5.2)
58
+ rack-test (0.6.2)
59
+ rack (>= 1.0)
60
+ rails (4.0.0)
61
+ actionmailer (= 4.0.0)
62
+ actionpack (= 4.0.0)
63
+ activerecord (= 4.0.0)
64
+ activesupport (= 4.0.0)
65
+ bundler (>= 1.3.0, < 2.0)
66
+ railties (= 4.0.0)
67
+ sprockets-rails (~> 2.0.0)
68
+ railties (4.0.0)
69
+ actionpack (= 4.0.0)
70
+ activesupport (= 4.0.0)
71
+ rake (>= 0.8.7)
72
+ thor (>= 0.18.1, < 2.0)
73
+ rake (10.1.0)
74
+ rdoc (3.12.2)
75
+ json (~> 1.4)
76
+ sass (3.2.9)
77
+ sass-rails (4.0.0)
78
+ railties (>= 4.0.0.beta, < 5.0)
79
+ sass (>= 3.1.10)
80
+ sprockets-rails (~> 2.0.0)
81
+ sdoc (0.3.20)
82
+ json (>= 1.1.3)
83
+ rdoc (~> 3.10)
84
+ sprockets (2.10.0)
85
+ hike (~> 1.2)
86
+ multi_json (~> 1.0)
87
+ rack (~> 1.0)
88
+ tilt (~> 1.1, != 1.3.0)
89
+ sprockets-rails (2.0.0)
90
+ actionpack (>= 3.0)
91
+ activesupport (>= 3.0)
92
+ sprockets (~> 2.8)
93
+ sqlite3 (1.3.7)
94
+ thor (0.18.1)
95
+ thread_safe (0.1.0)
96
+ atomic
97
+ tilt (1.4.1)
98
+ treetop (1.4.14)
99
+ polyglot
100
+ polyglot (>= 0.3.1)
101
+ turbolinks (1.2.0)
102
+ coffee-rails
103
+ tzinfo (0.3.37)
104
+ uglifier (2.1.1)
105
+ execjs (>= 0.3.0)
106
+ multi_json (~> 1.0, >= 1.0.2)
107
+
108
+ PLATFORMS
109
+ ruby
110
+
111
+ DEPENDENCIES
112
+ coffee-rails (~> 4.0.0)
113
+ jbuilder (~> 1.2)
114
+ jquery-rails
115
+ rails (= 4.0.0)
116
+ sass-rails (~> 4.0.0)
117
+ sdoc
118
+ sqlite3
119
+ turbolinks
120
+ uglifier (>= 1.3.0)