bh 6.0.1 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +5 -0
  5. data/app/views/bh/_table.html.erb +2 -4
  6. data/bh.gemspec +8 -6
  7. data/lib/bh/bootstrap_helpers.rb +9 -3
  8. data/lib/bh/version.rb +1 -1
  9. metadata +3 -45
  10. data/Rakefile +0 -11
  11. data/gemfiles/Gemfile.rails-3.x +0 -8
  12. data/gemfiles/Gemfile.rails-4.x +0 -8
  13. data/gemfiles/Gemfile.rails-5.x +0 -7
  14. data/spec/padrino/button_to_helper.rb +0 -35
  15. data/spec/padrino/link_to_helper.rb +0 -12
  16. data/spec/padrino_spec.rb +0 -29
  17. data/spec/rails/button_to_helper.rb +0 -31
  18. data/spec/rails/form/check_box_helper_spec.rb +0 -112
  19. data/spec/rails/form/field_helper_spec.rb +0 -138
  20. data/spec/rails/form/fields_for_helper_spec.rb +0 -65
  21. data/spec/rails/form/fieldset_helper_spec.rb +0 -32
  22. data/spec/rails/form/file_field_helper_spec.rb +0 -74
  23. data/spec/rails/form/legend_helper_spec.rb +0 -35
  24. data/spec/rails/form/radio_button_helper_spec.rb +0 -89
  25. data/spec/rails/form/select_helper_spec.rb +0 -88
  26. data/spec/rails/form/static_control_helper_spec.rb +0 -67
  27. data/spec/rails/form/submit_helper_spec.rb +0 -30
  28. data/spec/rails/form_for_helper_spec.rb +0 -50
  29. data/spec/rails/link_to_helper.rb +0 -12
  30. data/spec/rails_helper.rb +0 -24
  31. data/spec/rails_spec.rb +0 -29
  32. data/spec/shared/alert_box_helper.rb +0 -62
  33. data/spec/shared/button_helper.rb +0 -52
  34. data/spec/shared/button_to_helper.rb +0 -51
  35. data/spec/shared/cdn_helper.rb +0 -36
  36. data/spec/shared/dropdown_helper.rb +0 -112
  37. data/spec/shared/glyphicon_helper.rb +0 -21
  38. data/spec/shared/horizontal_helper.rb +0 -37
  39. data/spec/shared/icon_helper.rb +0 -31
  40. data/spec/shared/link_to_helper.rb +0 -84
  41. data/spec/shared/modal_helper.rb +0 -104
  42. data/spec/shared/nav_helper.rb +0 -49
  43. data/spec/shared/navbar_helper.rb +0 -63
  44. data/spec/shared/panel_helper.rb +0 -76
  45. data/spec/shared/panel_row_helper.rb +0 -21
  46. data/spec/shared/progress_bar_helper.rb +0 -103
  47. data/spec/shared/vertical_helper.rb +0 -43
  48. data/spec/spec_helper.rb +0 -22
  49. data/spec/support/matchers.rb +0 -47
  50. data/spec/support/padrino.rb +0 -33
  51. data/spec/support/rails.rb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2997adea57780de74ae0a187082fe2446ac8180e0e9183fe6a43ae036960fb0e
4
- data.tar.gz: c0ca2a4e3181b4115e17cfdbdf44d784d92e21d329073af74e6df8cf10240014
3
+ metadata.gz: b38e11a246e443eaf500463cd51b36e0b97e926ab96a412ec4c737cd282fe702
4
+ data.tar.gz: 2a41e90a12dc66cf1251509f2542435f1c28b06a8d45f471432dfd187f8d80c8
5
5
  SHA512:
6
- metadata.gz: c4b95cc851a8dc1e605f7d07458e5963513bfe032ce3c04a57374a4acaec506f02aba850b900b6564463aa7e30f8f1f4854d92f14d96202f3889d50e1279341f
7
- data.tar.gz: be18223b5c9c5dee730db77e8c49dbba89c342387da9ced0f118034cb230c18632e676d58b883d623af24f365cd5c0cec2b705367628916fdbeaa1b04a9b1fe3
6
+ metadata.gz: ce3cdbab9f872be9bbb71301eec41becb424e2adf5a39a3d5c9fbfba3a52a4f10ad464b1dd6eb38a25a39a9f10db47d132f0cdec141e9f3424a063c95d88d336
7
+ data.tar.gz: f27666887c21b24f2734c88862c4144dfdee858a09e8af486a72e095c4bd96b8f95c13b9f0e534d0d405bb551b49500f681dbb85297ac46edfae4eba612ca83f
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ For more information about changelogs, check
6
6
  [Keep a Changelog](http://keepachangelog.com) and
7
7
  [Vandamme](http://tech-angels.github.io/vandamme).
8
8
 
9
+ ## 6.1.0 - 2026-03-18
10
+
11
+ * [BREAKING CHANGE] The `table` method doesn't take the `headers` parameter anymore.
12
+ * [FEATURE] New `column` method to define headers and body of a `table` at once
13
+
9
14
  ## 6.0.1 - 2026-02-23
10
15
 
11
16
  - Remove class "card-row" from card_body
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Fullscreen, Inc.
1
+ Copyright (c) 2014 Claudio Baccigalupo
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -18,3 +18,8 @@ How to install
18
18
  ```ruby
19
19
  pin_all_from Bh::Engine.root.join('app/javascript/controllers'), under: 'controllers'
20
20
  ```
21
+
22
+ Available methods
23
+ =================
24
+
25
+ See https://github.com/claudiob/bh/blob/master/lib/bh/bootstrap_helpers.rb
@@ -8,9 +8,7 @@
8
8
  <% if positioned %>
9
9
  <th scope='col'></th>
10
10
  <% end %>
11
- <% headers.each do |header| %>
12
- <th scope='col'><%= header %></th>
13
- <% end %>
11
+ <%= yield items.first, :header %>
14
12
  </tr>
15
13
  </thead>
16
14
  <% if positioned %>
@@ -26,7 +24,7 @@
26
24
  <tr>
27
25
  <% end %>
28
26
  <% cache_if (cached && !params.key?(:q)), item do %>
29
- <%= yield item %>
27
+ <%= yield item, :body %>
30
28
  <% end %>
31
29
  </tr>
32
30
  <% end %>
data/bh.gemspec CHANGED
@@ -1,17 +1,19 @@
1
1
  require_relative 'lib/bh/version'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
- spec.name = "bh"
4
+ spec.name = 'bh'
5
5
  spec.version = Bh::VERSION
6
- spec.authors = ["Claudio Baccigalupo"]
7
- spec.email = ["claudio@houseaccount.com"]
6
+ spec.authors = ['Claudio Baccigalupo']
7
+ spec.email = ['claudio@houseaccount.com']
8
8
  spec.description = %q{Bh - Bootstrap Helpers}
9
9
  spec.summary = %q{Bh provides a set of powerful helpers that
10
10
  streamlines the use of Bootstrap components in Rails views.}
11
- spec.homepage = "http://github.com/claudiob/bh"
12
- spec.license = "MIT"
11
+ spec.homepage = 'http://github.com/claudiob/bh'
12
+ spec.license = 'MIT'
13
13
 
14
14
  spec.files = `git ls-files`.split($/)
15
15
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
- spec.require_paths = ["lib"]
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.required_ruby_version = '3.0.0'
17
19
  end
@@ -84,9 +84,17 @@ module Bh
84
84
  end
85
85
 
86
86
  def table(items:, empty_label:, positioned: false, cached: true, headers: [], pagy: nil, &block)
87
+ # SAY THAT HEADERS IS REMOVED AND column SHOULD BE CALLED INSTEAD / breaking
87
88
  render 'bh/table', items: items, empty_label: empty_label, positioned: positioned, cached: cached, headers: headers, pagy: pagy, &block
88
89
  end
89
90
 
91
+ def column(header:, section:, **options, &block)
92
+ case section
93
+ when :header then tag.th(header, **options.merge(scope: :col))
94
+ when :body then tag.td(**options, &block)
95
+ end
96
+ end
97
+
90
98
  # Renders the block inside a grid row.
91
99
  def grid_row(&block)
92
100
  tag.div class: 'row p-2 border-bottom border-subtle', &block
@@ -111,9 +119,7 @@ module Bh
111
119
 
112
120
  # Display a link with an emoji to edit a resource inside a table.
113
121
  def edit_link_to(path)
114
- tag.td class: 'text-center', style: 'width: 40px' do
115
- turbo_link_to '➡️', path, class: 'text-decoration-none'
116
- end
122
+ turbo_link_to '➡️', path, class: 'text-decoration-none'
117
123
  end
118
124
 
119
125
  private
data/lib/bh/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bh
4
- VERSION = '6.0.1'
4
+ VERSION = '6.1.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bh
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.1
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo
@@ -24,57 +24,15 @@ files:
24
24
  - Gemfile
25
25
  - MIT-LICENSE
26
26
  - README.md
27
- - Rakefile
28
27
  - app/assets/stylesheets/bh.css
29
28
  - app/javascript/controllers/bh/theme_controller.js
30
29
  - app/views/bh/_grid.html.erb
31
30
  - app/views/bh/_table.html.erb
32
31
  - bh.gemspec
33
- - gemfiles/Gemfile.rails-3.x
34
- - gemfiles/Gemfile.rails-4.x
35
- - gemfiles/Gemfile.rails-5.x
36
32
  - lib/bh.rb
37
33
  - lib/bh/bootstrap_helpers.rb
38
34
  - lib/bh/engine.rb
39
35
  - lib/bh/version.rb
40
- - spec/padrino/button_to_helper.rb
41
- - spec/padrino/link_to_helper.rb
42
- - spec/padrino_spec.rb
43
- - spec/rails/button_to_helper.rb
44
- - spec/rails/form/check_box_helper_spec.rb
45
- - spec/rails/form/field_helper_spec.rb
46
- - spec/rails/form/fields_for_helper_spec.rb
47
- - spec/rails/form/fieldset_helper_spec.rb
48
- - spec/rails/form/file_field_helper_spec.rb
49
- - spec/rails/form/legend_helper_spec.rb
50
- - spec/rails/form/radio_button_helper_spec.rb
51
- - spec/rails/form/select_helper_spec.rb
52
- - spec/rails/form/static_control_helper_spec.rb
53
- - spec/rails/form/submit_helper_spec.rb
54
- - spec/rails/form_for_helper_spec.rb
55
- - spec/rails/link_to_helper.rb
56
- - spec/rails_helper.rb
57
- - spec/rails_spec.rb
58
- - spec/shared/alert_box_helper.rb
59
- - spec/shared/button_helper.rb
60
- - spec/shared/button_to_helper.rb
61
- - spec/shared/cdn_helper.rb
62
- - spec/shared/dropdown_helper.rb
63
- - spec/shared/glyphicon_helper.rb
64
- - spec/shared/horizontal_helper.rb
65
- - spec/shared/icon_helper.rb
66
- - spec/shared/link_to_helper.rb
67
- - spec/shared/modal_helper.rb
68
- - spec/shared/nav_helper.rb
69
- - spec/shared/navbar_helper.rb
70
- - spec/shared/panel_helper.rb
71
- - spec/shared/panel_row_helper.rb
72
- - spec/shared/progress_bar_helper.rb
73
- - spec/shared/vertical_helper.rb
74
- - spec/spec_helper.rb
75
- - spec/support/matchers.rb
76
- - spec/support/padrino.rb
77
- - spec/support/rails.rb
78
36
  homepage: http://github.com/claudiob/bh
79
37
  licenses:
80
38
  - MIT
@@ -84,9 +42,9 @@ require_paths:
84
42
  - lib
85
43
  required_ruby_version: !ruby/object:Gem::Requirement
86
44
  requirements:
87
- - - ">="
45
+ - - '='
88
46
  - !ruby/object:Gem::Version
89
- version: '0'
47
+ version: 3.0.0
90
48
  required_rubygems_version: !ruby/object:Gem::Requirement
91
49
  requirements:
92
50
  - - ">="
data/Rakefile DELETED
@@ -1,11 +0,0 @@
1
- require 'bundler'
2
- Bundler.setup
3
- Bundler::GemHelper.install_tasks
4
-
5
- require 'rspec/core/rake_task'
6
- require 'rspec/core/version'
7
-
8
- desc 'Run all examples'
9
- RSpec::Core::RakeTask.new :spec
10
-
11
- task default: [:spec]
@@ -1,8 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- gem 'activesupport', '~> 3.2'
4
- gem 'actionpack', '~> 3.2'
5
- gem 'activemodel', '~> 3.2'
6
- gem 'middleman-core', '~> 3.2.2'
7
-
8
- gemspec path: '../'
@@ -1,8 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- gem 'activesupport', '>= 4.0', '< 4.2'
4
- gem 'actionpack', '>= 4.0', '< 4.2'
5
- gem 'activemodel', '>= 4.0', '< 4.2'
6
- gem 'middleman-core', '~> 3.3.0'
7
-
8
- gemspec path: '../'
@@ -1,7 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- gem 'activesupport', '>= 5.0.0.beta1'
4
- gem 'actionpack', '>= 5.0.0.beta1'
5
- gem 'activemodel', '>= 5.0.0.beta1'
6
-
7
- gemspec path: '../'
@@ -1,35 +0,0 @@
1
- shared_examples_for 'the button_to helper (Padrino)' do
2
- all_tests_pass_with 'no button_to options (Padrino)'
3
- all_tests_pass_with 'only extra button_to options (Padrino)'
4
- all_tests_pass_with 'extra button_to options (Padrino)'
5
- all_tests_pass_for 'the button_to helper'
6
- end
7
-
8
- #--
9
-
10
- shared_examples_for 'no button_to options (Padrino)' do
11
- specify 'uses the original button_to helper' do
12
- html = '<form action="/" accept-charset="UTF-8" method="post"><input type="hidden" name="authenticity_token" /><input type="submit" value="content" /></form>'
13
- expect(:button_to).to generate html
14
-
15
- # @note: Only Padrino >= 0.13.0 renders the content of the block as a
16
- # <button> so the exact content is only partially tested here.
17
- expect(bh.button_to('/'){ 'content' }).to include 'content'
18
- end
19
- end
20
-
21
- shared_examples_for 'only extra button_to options (Padrino)' do
22
- specify 'uses the original button_to helper' do
23
- options = {class: 'big', id: 'my-form', submit_options: {class: 'important', data: {value: 1}, id: 'my-button_to'}}
24
- html = '<form action="/" accept-charset="UTF-8" class="big" id="my-form" method="post"><input type="hidden" name="authenticity_token" /><input type="submit" value="content" class="important" data-value="1" id="my-button_to" /></form>'
25
- expect(button_to: options).to generate html
26
- end
27
- end
28
-
29
- shared_examples_for 'extra button_to options (Padrino)' do
30
- specify 'passes the options to the form and the submit_options to the button' do
31
- options = {context: :default, class: 'big', id: 'my-form', submit_options: {class: 'important', data: {value: 1}, id: 'my-button_to'}}
32
- html = '<form action="/" accept-charset="UTF-8" class="big" id="my-form" method="post"><input type="hidden" name="authenticity_token" /><input type="submit" value="content" class="important btn btn-default" data-value="1" id="my-button_to" /></form>'
33
- expect(button_to: options).to generate html
34
- end
35
- end
@@ -1,12 +0,0 @@
1
- shared_examples_for 'the link_to helper (Padrino)' do
2
- all_tests_pass_with 'no link_to caption (Padrino)'
3
- end
4
-
5
- #--
6
-
7
- shared_examples_for 'no link_to caption (Padrino)' do
8
- specify 'uses the original link_to helper which sets an empty link text' do
9
- html = '<a href="/"></a>'
10
- expect(link_to: :nil_name).to generate html
11
- end
12
- end
data/spec/padrino_spec.rb DELETED
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
- Dir['./spec/padrino/*_helper.rb'].each {|f| require f}
3
-
4
- describe 'When used in Padrino or Middleman' do
5
- let(:bh) { PadrinoView.new }
6
- before { Bh.framework = :padrino }
7
-
8
- all_tests_pass_for 'the alert_box helper'
9
- all_tests_pass_for 'the bootstrap_css helper'
10
- all_tests_pass_for 'the bootstrap_js helper'
11
- all_tests_pass_for 'the bootstrap_theme_css helper'
12
- all_tests_pass_for 'the button helper'
13
- all_tests_pass_for 'the dropdown helper'
14
- all_tests_pass_for 'the font_awesome_css helper'
15
- all_tests_pass_for 'the glyphicon helper'
16
- all_tests_pass_for 'the horizontal helper'
17
- all_tests_pass_for 'the icon helper'
18
- all_tests_pass_for 'the modal helper'
19
- all_tests_pass_for 'the nav helper'
20
- all_tests_pass_for 'the navbar helper'
21
- all_tests_pass_for 'the panel helper'
22
- all_tests_pass_for 'the panel_row helper'
23
- all_tests_pass_for 'the progress_bar helper'
24
- all_tests_pass_for 'the vertical helper'
25
-
26
- all_tests_pass_for 'the button_to helper (Padrino)'
27
- all_tests_pass_for 'the link_to helper (Padrino)'
28
- all_tests_pass_for 'the link_to helper'
29
- end unless ENV['ONLY_RAILS']
@@ -1,31 +0,0 @@
1
- shared_examples_for 'the button_to helper (Rails)' do
2
- all_tests_pass_with 'no button_to options (Rails)'
3
- all_tests_pass_with 'only extra button_to options (Rails)'
4
- all_tests_pass_with 'extra button_to options (Rails)'
5
- all_tests_pass_for 'the button_to helper'
6
- end
7
-
8
- #--
9
-
10
- shared_examples_for 'no button_to options (Rails)' do
11
- specify 'uses the original button_to helper' do
12
- html = %r{^<form(?:| action="/") class="button_to" method="post"(?:| action="/")>(?:|<div>)<(input|button) type="submit"(>| value=")content(" />|</button>)(?:|</div>)</form>$}
13
- expect(:button_to).to generate html
14
- end
15
- end
16
-
17
- shared_examples_for 'only extra button_to options (Rails)' do
18
- specify 'uses the original button_to helper' do
19
- options = {class: 'important', data: {value: 1}, id: 'my-button_to'}
20
- html = %r{<(input|button) class="important" data-value="1" id="my-button_to" type="submit"}
21
- expect(button_to: options).to generate html
22
- end
23
- end
24
-
25
- shared_examples_for 'extra button_to options (Rails)' do
26
- specify 'passes the options to the button' do
27
- options = {context: :default, class: 'important', data: {value: 1}, id: 'my-button_to'}
28
- html = %r{<(input|button) class="important btn btn-default" data-value="1" id="my-button_to" type="submit"}
29
- expect(button_to: options).to generate html
30
- end
31
- end
@@ -1,112 +0,0 @@
1
- require 'rails_helper'
2
- require 'bh/core_ext/rails/form_for_helper'
3
- include Bh::Rails::Helpers
4
-
5
- describe 'check_box' do
6
- attr_accessor :output_buffer
7
- let(:protect_against_forgery?) { false }
8
- let(:form) { form_for user, layout: layout, errors: errors, url: '/', &block }
9
- let(:user) { User.new }
10
- let(:errors) { {} }
11
- let(:block) { Proc.new {|f| f.check_box :name, options} }
12
- let(:options) { {} }
13
-
14
- context 'given any layout' do
15
- let(:layout) { :whatever }
16
-
17
- specify 'not given a label option, automatically generates one' do
18
- expect(form).to include 'Name</label>'
19
- end
20
-
21
- context 'given a label option, uses the provided one' do
22
- let(:options) { {label: 'Given name'} }
23
- it { expect(form).to include 'Given name</label>' }
24
- end
25
-
26
- context 'not given a help option, does not display a help box' do
27
- it { expect(form).not_to include 'help-block' }
28
- end
29
-
30
- context 'given a help option, displays a help box' do
31
- let(:options) { {help: 'Please select an option'} }
32
- it { expect(form).to include '<span class="help-block text-left">Please select an option</span>' }
33
- end
34
-
35
- specify 'not given an error, does not apply has-error to the form group' do
36
- expect(form).not_to include 'has-error'
37
- end
38
-
39
- context 'given an error' do
40
- before { user.errors.add :name, 'cannot be nil' }
41
-
42
- specify 'shows errors and error messages' do
43
- expect(form).to include 'has-error'
44
- expect(form).to include '<span class="help-block text-left">cannot be nil</span>'
45
- end
46
- end
47
- end
48
-
49
- describe 'given a basic layout' do
50
- let(:layout) { :basic }
51
- specify 'applies checkbox to the container, and an inline label' do
52
- expect(form).to match %r{<div class="checkbox"><label><input.+? /> Name</label></div>}
53
- end
54
-
55
- context 'given the inline_label: false option' do
56
- let(:options) { {inline_label: false} }
57
-
58
- specify 'aligns the label on top of the check-box' do
59
- expect(form).to match %r{<label for="user_name">Name</label><input}
60
- expect(form).to include 'input class="form-control"'
61
- end
62
- end
63
- end
64
-
65
- describe 'given a horizontal layout' do
66
- let(:layout) { :horizontal }
67
- specify 'applies form-group to the outer container, .col-sm-offset-3.col-sm-9 to the field container, checkbox to the container, and an inline label' do
68
- expect(form).to match %r{<div class="form-group"><div class="col-sm-offset-3 col-sm-9"><div class="checkbox"><label><input.+? /> Name</label></div></div></div>}
69
- end
70
-
71
- context 'given the inline_label: false option' do
72
- let(:options) { {inline_label: false} }
73
-
74
- specify 'aligns the label on top of the check-box' do
75
- expect(form).to match %r{<label class="col-sm-3 control-label" for="user_name">Name</label><div class="col-sm-9"><input}
76
- expect(form).to include 'input class="form-control checkbox"'
77
- end
78
- end
79
- end
80
-
81
- describe 'given an inline layout' do
82
- let(:layout) { :inline }
83
- specify 'applies checkbox to the container, and an inline label' do
84
- expect(form).to match %r{<div class="checkbox"><label><input.+? /> Name</label></div>}
85
- end
86
-
87
- context 'given an error' do
88
- before { user.errors.add :name, 'cannot be nil' }
89
-
90
- specify 'applies sr-only to the error message' do
91
- expect(form).to include '<span class="help-block text-left sr-only">cannot be nil</span>'
92
- end
93
- end
94
-
95
- context 'given a help message' do
96
- let(:options) { {help: 'Please select an option'} }
97
-
98
- specify 'applies sr-only to the help message' do
99
- expect(form).to include '<span class="help-block text-left sr-only">Please select an option</span>'
100
- end
101
- end
102
-
103
- context 'given the inline_label: false option' do
104
- let(:options) { {inline_label: false} }
105
-
106
- specify 'aligns the label on top of the check-box' do
107
- expect(form).to match %r{<label class="sr-only" for="user_name">Name</label><input}
108
- expect(form).not_to include 'form-control'
109
- end
110
- end
111
- end
112
- end
@@ -1,138 +0,0 @@
1
- require 'rails_helper'
2
- require 'bh/core_ext/rails/form_for_helper'
3
- include Bh::Rails::Helpers
4
-
5
- def self.field_helpers_to_test
6
- types = %w(email number password phone search telephone text url)
7
- if defined?(ActionView::VERSION) # only defined in ActionView >=4
8
- # types.concat %w(color date datetime datetime_local month time week)
9
- end
10
- types.map{|type| "#{type}_field"} << "text_area"
11
- end
12
-
13
- field_helpers_to_test.each do |form_field|
14
- describe form_field do
15
- attr_accessor :output_buffer
16
- let(:protect_against_forgery?) { false }
17
- let(:form) { form_for user, layout: layout, errors: errors, url: '/', &block }
18
- let(:user) { User.new }
19
- let(:errors) { {} }
20
-
21
- let(:block) { Proc.new {|f| f.send form_field, :name, options} }
22
- let(:options) { {} }
23
-
24
- context 'given any layout' do
25
- let(:layout) { :whatever }
26
-
27
- specify 'not given a placeholder option, automatically generates one' do
28
- expect(form).to include 'placeholder="Name"'
29
- end
30
-
31
- context 'given a placeholder option, uses the provided one' do
32
- let(:options) { {placeholder: 'Given name'} }
33
- it { expect(form).to include 'placeholder="Given name"' }
34
- end
35
-
36
- specify 'not given a label option, automatically generates one' do
37
- expect(form).to include 'Name</label>'
38
- end
39
-
40
- context 'given a label option, uses the provided one' do
41
- let(:options) { {label: 'Given name'} }
42
- it { expect(form).to include 'Given name</label>' }
43
- end
44
-
45
- context 'not given a help option, does not display a help box' do
46
- it { expect(form).not_to include 'help-block' }
47
- end
48
-
49
- context 'given a help option, displays a help box' do
50
- let(:options) { {help: 'Please write the given name'} }
51
- it { expect(form).to include '<span class="help-block text-left">Please write the given name</span>' }
52
- end
53
-
54
- specify 'not given a prefix or suffix option, does not use an input group' do
55
- expect(form).not_to include 'input-group'
56
- end
57
-
58
- context 'given a prefix option, prints the prefix before the field' do
59
- let(:options) { {prefix: 'Mr.'} }
60
- it { expect(form).to include '<div class="input-group"><span class="input-group-addon">Mr.</span><' }
61
- end
62
-
63
- context 'given a suffix option, prints the prefix after the field' do
64
- let(:options) { {suffix: 'Jr'} }
65
- it { expect(form).to match %r{<div class="input-group"><.+?><span class="input-group-addon">Jr</span></div>}m }
66
- end
67
-
68
- specify 'not given an error, does not apply has-error to the form group' do
69
- expect(form).not_to include 'has-error'
70
- end
71
-
72
- context 'given an error' do
73
- before { user.errors.add :name, 'cannot be nil' }
74
-
75
- specify 'shows errors and error messages' do
76
- expect(form).to include 'has-error'
77
- expect(form).to include '<span class="help-block text-left">cannot be nil</span>'
78
- end
79
-
80
- specify 'shows error icons (except for number_field)' do
81
- expect(form).to include 'has-feedback' unless form_field == 'number_field'
82
- end
83
-
84
- context 'given an option to hide error icons, hides error icons' do
85
- let(:errors) { {icons: false} }
86
- it{ expect(form).not_to include 'has-feedback' }
87
- end
88
-
89
- context 'given the suffix option, hides error icons (or they would overlap)' do
90
- let(:options) { {suffix: 'Jr'} }
91
- it{ expect(form).not_to include 'form-control-feedback' }
92
- end
93
-
94
- context 'given an option to hide error messages, hides error messages' do
95
- let(:errors) { {messages: false} }
96
- it{ expect(form).not_to include 'help-block' }
97
- end
98
- end
99
- end
100
-
101
- describe 'given a basic layout' do
102
- let(:layout) { :basic }
103
- specify 'applies form-group to the container, form-control to the input' do
104
- expect(form).to match %r{<div class="form-group"><label.+?>Name</label><(input|textarea)(?:| placeholder="Name") class="form-control"}
105
- end
106
- end
107
-
108
- describe 'given a horizontal layout' do
109
- let(:layout) { :horizontal }
110
- specify 'applies form-group to the container, form-control to the input, col-sm-3.control-label to the label and col-sm-9 to the field container' do
111
- expect(form).to match %r{<div class="form-group"><label class="col-sm-3 control-label".+?>Name</label><div class="col-sm-9"><(input|textarea)(?:| placeholder="Name") class="form-control"}
112
- end
113
- end
114
-
115
- describe 'given an inline layout' do
116
- let(:layout) { :inline }
117
- specify 'applies form-group to the container, form-control to the input, sr-only to the label' do
118
- expect(form).to match %r{<div class="form-group"><label class="sr-only".+?>Name</label><(input|textarea)(?:| placeholder="Name") class="form-control"}
119
- end
120
-
121
- context 'given a help message' do
122
- let(:options) { {help: 'Please write the given name'} }
123
-
124
- specify 'applies sr-only to the help message' do
125
- expect(form).to include '<span class="help-block text-left sr-only">Please write the given name</span>'
126
- end
127
- end
128
-
129
- context 'given an error' do
130
- before { user.errors.add :name, 'cannot be nil' }
131
-
132
- specify 'applies sr-only to the error message' do
133
- expect(form).to include '<span class="help-block text-left sr-only">cannot be nil</span>'
134
- end
135
- end
136
- end
137
- end
138
- end