bootstrap-form 3.0.0 → 4.0.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.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.gitlab-ci.yml +21 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -3
- data/{Gemfile.rails.3.2 → Gemfile.rails.5.0} +2 -2
- data/{Gemfile.rails.4.0 → Gemfile.rails.6.0} +2 -2
- data/LICENSE +2 -0
- data/README.md +6 -18
- data/{bootsrap-form.gemspec → bootstrap-form.gemspec} +10 -9
- data/lib/bootstrap-form.rb +3 -0
- data/lib/bootstrap-form/form_helper.rb +21 -12
- data/lib/bootstrap-form/version.rb +1 -1
- data/spec/helpers/bootstrap_control_group_wrap_spec.rb +71 -0
- data/spec/helpers/form_helper_spec.rb +103 -0
- data/spec/spec_helper.rb +114 -0
- metadata +54 -36
- data/test/lib/action_view/helpers/form_helper_test.rb +0 -151
- data/test/test_helper.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 259a8933965fa3b7337aaf29853e24319b83eee8deae7c1639ef0807ea099b97
|
4
|
+
data.tar.gz: 18395ffb31d0c1c35010865f439cc3c074288ea30a0ce67617ce50a5cf570bed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bdab671f48b5d4d156108f5b2f7c7efc5ed8689df584628e2a71ac5bde8b74d1eb8b84cf9757a6a14c76ba33503e5dec7e29de22f6f79ca83c9f5936685e59b
|
7
|
+
data.tar.gz: e7ef6c7735974ba293184faac1a7db8b2ee47eb1a89aec09337b73b7a1ef66ab14ae73207be4308c0a997907f6ca86fe6678812e5d72ac3cc287ed9c038518de
|
data/.gitignore
CHANGED
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
image: "ruby:2.5"
|
2
|
+
|
3
|
+
cache:
|
4
|
+
paths:
|
5
|
+
- vendor/ruby
|
6
|
+
|
7
|
+
before_script:
|
8
|
+
- ruby -v # Print out ruby version for debugging
|
9
|
+
- bundle install -j $(nproc) --path vendor
|
10
|
+
|
11
|
+
rails.5:
|
12
|
+
variables:
|
13
|
+
BUNDLE_GEMFILE: "Gemfile.rails.5.0"
|
14
|
+
script:
|
15
|
+
- bundle exec rspec
|
16
|
+
|
17
|
+
rails.6:
|
18
|
+
variables:
|
19
|
+
BUNDLE_GEMFILE: "Gemfile.rails.6.0"
|
20
|
+
script:
|
21
|
+
- bundle exec rspec
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.travis.yml
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
# Bootstrap Form
|
2
2
|
|
3
|
-
[
|
4
|
-
|
5
|
-
Form Helpers to make your form inputs [look like this](http://twitter.github.io/bootstrap/base-css.html#forms).
|
3
|
+
Form Helpers to make your form inputs [look like this](https://getbootstrap.com/docs/4.3/components/forms/).
|
6
4
|
|
7
5
|
Helps you to create beautiful mocks really quickly.
|
8
6
|
|
9
|
-
Works with Bootstrap
|
7
|
+
Works with Bootstrap 4 and Rails 5+.
|
10
8
|
|
11
|
-
For older versions of Bootstrap use
|
9
|
+
For older versions of Bootstrap and Rails use older versions of this gem.
|
12
10
|
|
13
11
|
## Usage
|
14
12
|
|
@@ -20,11 +18,6 @@ Bundle install
|
|
20
18
|
|
21
19
|
bundle install
|
22
20
|
|
23
|
-
To make them look even better, I recommend you add this to your
|
24
|
-
application.rb
|
25
|
-
|
26
|
-
ActionView::Base.field_error_proc = proc { |input, instance| input }
|
27
|
-
|
28
21
|
## Example
|
29
22
|
|
30
23
|
You write this:
|
@@ -49,7 +42,7 @@ You can specify a custom label for the input by setting the label
|
|
49
42
|
option:
|
50
43
|
|
51
44
|
form_for @account do |f|
|
52
|
-
f.bootstrap_text_field :name, :
|
45
|
+
f.bootstrap_text_field :name, label: 'A custom label'
|
53
46
|
end
|
54
47
|
|
55
48
|
Then, you get something like this:
|
@@ -71,11 +64,6 @@ Then, you get something like this:
|
|
71
64
|
|
72
65
|
## Error handling
|
73
66
|
|
74
|
-
All fields will automatically add the classes to show errors with
|
75
|
-
bootstrap
|
76
|
-
|
77
|
-
## TODO
|
78
|
-
|
79
|
-
Coming soon:
|
67
|
+
All fields will automatically add the classes to show errors with
|
68
|
+
bootstrap styling.
|
80
69
|
|
81
|
-
* More form inputs
|
@@ -6,10 +6,11 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "bootstrap-form"
|
7
7
|
s.version = Bootstrap::Form::VERSION
|
8
8
|
s.authors = ["David Padilla"]
|
9
|
-
s.email = ["david@
|
10
|
-
s.homepage = ""
|
11
|
-
s.summary = %q{
|
12
|
-
s.description = %q{
|
9
|
+
s.email = ["david@padilla.io"]
|
10
|
+
s.homepage = "https://rubygems.org/gems/bootstrap-form"
|
11
|
+
s.summary = %q{Bootstrap Form helpers}
|
12
|
+
s.description = %q{Bootstrap Form helpers}
|
13
|
+
s.license = 'MIT'
|
13
14
|
|
14
15
|
s.rubyforge_project = "bootstrap-form"
|
15
16
|
|
@@ -18,10 +19,10 @@ Gem::Specification.new do |s|
|
|
18
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
20
|
s.require_paths = ["lib"]
|
20
21
|
|
22
|
+
s.add_dependency 'railties', '> 5.0'
|
23
|
+
s.add_dependency 'actionpack', '> 5.0'
|
21
24
|
|
22
|
-
s.
|
23
|
-
s.
|
24
|
-
|
25
|
-
s.add_development_dependency "minitest", "~> 4.7.5"
|
26
|
-
s.add_development_dependency "rr"
|
25
|
+
s.add_development_dependency "rspec-rails"
|
26
|
+
s.add_development_dependency "rspec-html-matchers"
|
27
|
+
s.add_development_dependency "pry"
|
27
28
|
end
|
data/lib/bootstrap-form.rb
CHANGED
@@ -5,55 +5,57 @@ module ActionView
|
|
5
5
|
BOOTSTRAP_OPTIONS = [:label, :hint].freeze
|
6
6
|
|
7
7
|
def bootstrap_text_field(object_name, method, options={})
|
8
|
-
options[:class] = (options[:class]
|
8
|
+
options[:class] = control_class(options[:class], options[:object].errors[method])
|
9
9
|
bootstrap_control_group_wrap(object_name, method, text_field(object_name, method, extract_input_options(options)), options)
|
10
10
|
end
|
11
11
|
|
12
12
|
def bootstrap_email_field(object_name, method, options={})
|
13
|
-
options[:class] = (options[:class]
|
13
|
+
options[:class] = control_class(options[:class], options[:object].errors[method])
|
14
14
|
bootstrap_control_group_wrap(object_name, method, email_field(object_name, method, extract_input_options(options)), options)
|
15
15
|
end
|
16
16
|
|
17
17
|
def bootstrap_password_field(object_name, method, options={})
|
18
|
-
options[:class] = (options[:class]
|
18
|
+
options[:class] = control_class(options[:class], options[:object].errors[method])
|
19
19
|
bootstrap_control_group_wrap(object_name, method, password_field(object_name, method, extract_input_options(options)), options)
|
20
20
|
end
|
21
21
|
|
22
22
|
def bootstrap_collection_select(object_name, method, collection, value_method, text_method, options = {}, html_options = {})
|
23
|
-
html_options[:class] = (html_options[:class]
|
23
|
+
html_options[:class] = control_class(html_options[:class], options[:object].errors[method])
|
24
24
|
bootstrap_control_group_wrap(object_name, method, collection_select(object_name, method, collection, value_method, text_method, extract_input_options(options), html_options), options)
|
25
25
|
end
|
26
26
|
|
27
27
|
def bootstrap_select(object_name, method, choices, options={}, html_options={})
|
28
|
-
html_options[:class] = (html_options[:class]
|
28
|
+
html_options[:class] = control_class(html_options[:class], options[:object].errors[method])
|
29
29
|
bootstrap_control_group_wrap(object_name, method, select(object_name, method, choices, extract_input_options(options), html_options), options)
|
30
30
|
end
|
31
31
|
|
32
32
|
def bootstrap_file_field(object_name, method, options={})
|
33
|
-
options[:class] = (options[:class]
|
33
|
+
options[:class] = control_class(options[:class], options[:object].errors[method], " form-control-file")
|
34
34
|
bootstrap_control_group_wrap(object_name, method, file_field(object_name, method, extract_input_options(options)), options)
|
35
35
|
end
|
36
36
|
|
37
37
|
def bootstrap_text_area(object_name, method, options={})
|
38
|
-
options[:class] = (options[:class]
|
38
|
+
options[:class] = control_class(options[:class], options[:object].errors[method])
|
39
39
|
bootstrap_control_group_wrap(object_name, method, text_area(object_name, method, extract_input_options(options)), options)
|
40
40
|
end
|
41
41
|
|
42
42
|
def bootstrap_control_group_wrap(object_name, method, content, options={})
|
43
43
|
error_messages = options[:object].errors[method]
|
44
|
-
|
45
|
-
|
44
|
+
error_block = inline_help_tag(error_messages.presence)
|
45
|
+
hint_block = content_tag(:small, class: "text-muted") do
|
46
|
+
options[:hint]
|
47
|
+
end if !error_messages.presence && options[:hint]
|
46
48
|
|
47
49
|
content_tag(:div, label(object_name, method, options[:label], :class => 'control-label') +
|
48
|
-
content +
|
49
|
-
:
|
50
|
+
content + error_block + hint_block,
|
51
|
+
class: 'form-group')
|
50
52
|
end
|
51
53
|
|
52
54
|
def inline_help_tag(messages)
|
53
55
|
messages = Array.wrap(messages)
|
54
56
|
return '' if messages.empty?
|
55
57
|
message_span = ActiveSupport::SafeBuffer.new(" #{messages.to_sentence}")
|
56
|
-
content_tag(:
|
58
|
+
content_tag(:div, message_span, class: 'invalid-feedback')
|
57
59
|
end
|
58
60
|
|
59
61
|
private
|
@@ -61,6 +63,13 @@ module ActionView
|
|
61
63
|
def extract_input_options(options)
|
62
64
|
options.except(*BOOTSTRAP_OPTIONS)
|
63
65
|
end
|
66
|
+
|
67
|
+
def control_class(current_class, errors=[], bootstrap_class=" form-control")
|
68
|
+
css_class = current_class || ""
|
69
|
+
css_class << bootstrap_class
|
70
|
+
css_class << " is-invalid" if errors.any?
|
71
|
+
css_class
|
72
|
+
end
|
64
73
|
end
|
65
74
|
end
|
66
75
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe '#bootstrap_control_group_wrap', type: :helper do
|
4
|
+
let(:errors) { {} }
|
5
|
+
let(:object) { double(errors: errors) }
|
6
|
+
let(:options) { { object: object } }
|
7
|
+
let(:content) do
|
8
|
+
::ActiveSupport::SafeBuffer.new('content')
|
9
|
+
end
|
10
|
+
|
11
|
+
subject do
|
12
|
+
helper.bootstrap_control_group_wrap(:post, :name, content, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
it do
|
16
|
+
is_expected.to have_tag('div.form-group') do
|
17
|
+
with_tag('label.control-label') do
|
18
|
+
with_text 'Name'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'with option label: "Custom Label"' do
|
24
|
+
let(:options) { { object: object, label: 'Custom Label' } }
|
25
|
+
|
26
|
+
it do
|
27
|
+
is_expected.to have_tag('div.form-group') do
|
28
|
+
with_tag('label.control-label') do
|
29
|
+
with_text 'Custom Label'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'with errors' do
|
36
|
+
let(:errors) { { name: ["has already been taken", "is reserved", "must be odd"] } }
|
37
|
+
|
38
|
+
it do
|
39
|
+
is_expected.to have_tag('div.form-group') do
|
40
|
+
with_tag('div.invalid-feedback') do
|
41
|
+
with_text " has already been taken, is reserved, and must be odd"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'with option hint: "format matters"' do
|
48
|
+
let(:options) { { object: object, hint: 'format matters' } }
|
49
|
+
|
50
|
+
it do
|
51
|
+
is_expected.to have_tag('div.form-group') do
|
52
|
+
with_tag('small.text-muted') do
|
53
|
+
with_text "format matters"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'with errors and option hint: "format matters"' do
|
60
|
+
let(:errors) { { name: ["has already been taken", "is reserved", "must be odd"] } }
|
61
|
+
let(:options) { { object: object, hint: 'format matters' } }
|
62
|
+
|
63
|
+
it do
|
64
|
+
is_expected.to have_tag('div.form-group') do
|
65
|
+
with_tag('div.invalid-feedback') do
|
66
|
+
with_text " has already been taken, is reserved, and must be odd"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'bootstrap helpers', type: :helper do
|
4
|
+
let(:errors) { { name: [], attachment: [] } }
|
5
|
+
let(:object) { double("object", errors: errors, name: 'object-name') }
|
6
|
+
let(:options) { { object: object } }
|
7
|
+
|
8
|
+
RSpec.shared_examples "an input with type" do |type|
|
9
|
+
it { is_expected.to have_tag("input.form-control[type=#{type}]") }
|
10
|
+
|
11
|
+
context 'with errors' do
|
12
|
+
let(:errors) { { name: ['is invalid'], attachment: ['is invalid'] } }
|
13
|
+
|
14
|
+
it { is_expected.to have_tag("input.is-invalid[type=#{type}]") }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec.shared_examples "a select element" do
|
19
|
+
it do
|
20
|
+
is_expected.to have_tag('select.form-control') do
|
21
|
+
with_tag('option[value=1]') do
|
22
|
+
with_text 'One'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with errors' do
|
28
|
+
let(:errors) { { name: ['is invalid'] } }
|
29
|
+
it { is_expected.to have_tag("select.is-invalid") }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'text_field' do
|
34
|
+
subject do
|
35
|
+
bootstrap_text_field(:post, :name, options)
|
36
|
+
end
|
37
|
+
|
38
|
+
it_behaves_like "an input with type", "text"
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'email_field' do
|
42
|
+
subject do
|
43
|
+
bootstrap_email_field(:post, :name, options)
|
44
|
+
end
|
45
|
+
|
46
|
+
it_behaves_like "an input with type", "email"
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'password_field' do
|
50
|
+
subject do
|
51
|
+
bootstrap_password_field(:post, :name, options)
|
52
|
+
end
|
53
|
+
|
54
|
+
it_behaves_like "an input with type", "password"
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'file_field' do
|
58
|
+
subject do
|
59
|
+
bootstrap_file_field(:post, :attachment, options)
|
60
|
+
end
|
61
|
+
|
62
|
+
it do
|
63
|
+
is_expected.to have_tag('input[type="file"].form-control-file')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'select' do
|
68
|
+
let(:options_for_select) { [["One", 1]] }
|
69
|
+
|
70
|
+
subject do
|
71
|
+
bootstrap_select(:post, :name, options_for_select, options, {})
|
72
|
+
end
|
73
|
+
|
74
|
+
it_behaves_like "a select element"
|
75
|
+
end
|
76
|
+
|
77
|
+
describe 'collection_select' do
|
78
|
+
let(:collection) { [double(id: 1, name: 'One')] }
|
79
|
+
subject do
|
80
|
+
bootstrap_collection_select(:post, :name, collection, :id ,:name, options)
|
81
|
+
end
|
82
|
+
|
83
|
+
it_behaves_like "a select element"
|
84
|
+
end
|
85
|
+
|
86
|
+
describe 'text_area' do
|
87
|
+
subject do
|
88
|
+
bootstrap_text_area(:post, :name, options)
|
89
|
+
end
|
90
|
+
|
91
|
+
it do
|
92
|
+
is_expected.to have_tag('textarea.form-control')
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'with errors' do
|
96
|
+
let(:errors) { { name: ['is invalid'] } }
|
97
|
+
|
98
|
+
it do
|
99
|
+
is_expected.to have_tag('textarea.is-invalid')
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
+
|
7
|
+
ENV["RAILS_ENV"] = "test"
|
8
|
+
|
9
|
+
require 'rails'
|
10
|
+
require 'action_controller'
|
11
|
+
require 'action_view'
|
12
|
+
|
13
|
+
Bundler.require(:default, :development)
|
14
|
+
|
15
|
+
require 'rspec/rails'
|
16
|
+
|
17
|
+
module BootstrapForm
|
18
|
+
class Application < Rails::Application ; end
|
19
|
+
end
|
20
|
+
|
21
|
+
BootstrapForm::Application.routes.draw do
|
22
|
+
get '/:controller(/:action(/:id))'
|
23
|
+
end
|
24
|
+
BootstrapForm::Application.config.secret_key_base = 'bootstrap'
|
25
|
+
|
26
|
+
ActionController::Base.send :include, BootstrapForm::Application.routes.url_helpers
|
27
|
+
|
28
|
+
RSpec.configure do |config|
|
29
|
+
config.include RSpecHtmlMatchers
|
30
|
+
|
31
|
+
# rspec-expectations config goes here. You can use an alternate
|
32
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
33
|
+
# assertions if you prefer.
|
34
|
+
config.expect_with :rspec do |expectations|
|
35
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
36
|
+
# and `failure_message` of custom matchers include text for helper methods
|
37
|
+
# defined using `chain`, e.g.:
|
38
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
39
|
+
# # => "be bigger than 2 and smaller than 4"
|
40
|
+
# ...rather than:
|
41
|
+
# # => "be bigger than 2"
|
42
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
43
|
+
end
|
44
|
+
|
45
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
46
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
47
|
+
config.mock_with :rspec do |mocks|
|
48
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
49
|
+
# a real object. This is generally recommended, and will default to
|
50
|
+
# `true` in RSpec 4.
|
51
|
+
mocks.verify_partial_doubles = true
|
52
|
+
end
|
53
|
+
|
54
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
55
|
+
# have no way to turn it off -- the option exists only for backwards
|
56
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
57
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
58
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
59
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
60
|
+
|
61
|
+
# The settings below are suggested to provide a good initial experience
|
62
|
+
# with RSpec, but feel free to customize to your heart's content.
|
63
|
+
=begin
|
64
|
+
# This allows you to limit a spec run to individual examples or groups
|
65
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
66
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
67
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
68
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
69
|
+
config.filter_run_when_matching :focus
|
70
|
+
|
71
|
+
# Allows RSpec to persist some state between runs in order to support
|
72
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
73
|
+
# you configure your source control system to ignore this file.
|
74
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
75
|
+
|
76
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
77
|
+
# recommended. For more details, see:
|
78
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
79
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
80
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
81
|
+
config.disable_monkey_patching!
|
82
|
+
|
83
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
84
|
+
# be too noisy due to issues in dependencies.
|
85
|
+
config.warnings = true
|
86
|
+
|
87
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
88
|
+
# file, and it's useful to allow more verbose output when running an
|
89
|
+
# individual spec file.
|
90
|
+
if config.files_to_run.one?
|
91
|
+
# Use the documentation formatter for detailed output,
|
92
|
+
# unless a formatter has already been configured
|
93
|
+
# (e.g. via a command-line flag).
|
94
|
+
config.default_formatter = "doc"
|
95
|
+
end
|
96
|
+
|
97
|
+
# Print the 10 slowest examples and example groups at the
|
98
|
+
# end of the spec run, to help surface which specs are running
|
99
|
+
# particularly slow.
|
100
|
+
config.profile_examples = 10
|
101
|
+
|
102
|
+
# Run specs in random order to surface order dependencies. If you find an
|
103
|
+
# order dependency and want to debug it, you can fix the order by providing
|
104
|
+
# the seed, which is printed after each run.
|
105
|
+
# --seed 1234
|
106
|
+
config.order = :random
|
107
|
+
|
108
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
109
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
110
|
+
# test failures related to randomization by passing the same `--seed` value
|
111
|
+
# as the one that triggered the failure.
|
112
|
+
Kernel.srand config.seed
|
113
|
+
=end
|
114
|
+
end
|
metadata
CHANGED
@@ -1,94 +1,112 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bootstrap-form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Padilla
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: actionpack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '5.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '5.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec-rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-html-matchers
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: pry
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- -
|
73
|
+
- - ">="
|
60
74
|
- !ruby/object:Gem::Version
|
61
75
|
version: '0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- -
|
80
|
+
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
|
-
description:
|
83
|
+
description: Bootstrap Form helpers
|
70
84
|
email:
|
71
|
-
- david@
|
85
|
+
- david@padilla.io
|
72
86
|
executables: []
|
73
87
|
extensions: []
|
74
88
|
extra_rdoc_files: []
|
75
89
|
files:
|
76
|
-
- .gitignore
|
77
|
-
- .
|
90
|
+
- ".gitignore"
|
91
|
+
- ".gitlab-ci.yml"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
78
94
|
- Gemfile
|
79
|
-
- Gemfile.rails.
|
80
|
-
- Gemfile.rails.
|
95
|
+
- Gemfile.rails.5.0
|
96
|
+
- Gemfile.rails.6.0
|
81
97
|
- LICENSE
|
82
98
|
- README.md
|
83
99
|
- Rakefile
|
84
|
-
-
|
100
|
+
- bootstrap-form.gemspec
|
85
101
|
- lib/bootstrap-form.rb
|
86
102
|
- lib/bootstrap-form/form_helper.rb
|
87
103
|
- lib/bootstrap-form/version.rb
|
88
|
-
-
|
89
|
-
-
|
90
|
-
|
91
|
-
|
104
|
+
- spec/helpers/bootstrap_control_group_wrap_spec.rb
|
105
|
+
- spec/helpers/form_helper_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
homepage: https://rubygems.org/gems/bootstrap-form
|
108
|
+
licenses:
|
109
|
+
- MIT
|
92
110
|
metadata: {}
|
93
111
|
post_install_message:
|
94
112
|
rdoc_options: []
|
@@ -96,20 +114,20 @@ require_paths:
|
|
96
114
|
- lib
|
97
115
|
required_ruby_version: !ruby/object:Gem::Requirement
|
98
116
|
requirements:
|
99
|
-
- -
|
117
|
+
- - ">="
|
100
118
|
- !ruby/object:Gem::Version
|
101
119
|
version: '0'
|
102
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
121
|
requirements:
|
104
|
-
- -
|
122
|
+
- - ">="
|
105
123
|
- !ruby/object:Gem::Version
|
106
124
|
version: '0'
|
107
125
|
requirements: []
|
108
|
-
|
109
|
-
rubygems_version: 2.0.3
|
126
|
+
rubygems_version: 3.0.3
|
110
127
|
signing_key:
|
111
128
|
specification_version: 4
|
112
|
-
summary:
|
129
|
+
summary: Bootstrap Form helpers
|
113
130
|
test_files:
|
114
|
-
-
|
115
|
-
-
|
131
|
+
- spec/helpers/bootstrap_control_group_wrap_spec.rb
|
132
|
+
- spec/helpers/form_helper_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
@@ -1,151 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class FormHelperTest < ActionView::TestCase
|
4
|
-
def test_bootstrap_control_group_wrap
|
5
|
-
object = mock
|
6
|
-
errors = { :name => [] }
|
7
|
-
options = { :object => object }
|
8
|
-
content = ::ActiveSupport::SafeBuffer.new('content')
|
9
|
-
stub(object).errors { errors }
|
10
|
-
stub(object).name { 'Object Name' }
|
11
|
-
|
12
|
-
expected_code = %{<div class="form-group"><label class="control-label" for="post_name">Name</label>content</div>}
|
13
|
-
assert_equal expected_code, bootstrap_control_group_wrap(:post, :name, content, options)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_bootstrap_control_group_wrap_with_label
|
17
|
-
object = mock
|
18
|
-
errors = { :name => [] }
|
19
|
-
options = { :object => object, :label => "Custom" }
|
20
|
-
content = ::ActiveSupport::SafeBuffer.new('content')
|
21
|
-
stub(object).errors { errors }
|
22
|
-
stub(object).name { 'Object Name' }
|
23
|
-
|
24
|
-
expected_code = %{<div class="form-group"><label class="control-label" for="post_name">Custom</label>content</div>}
|
25
|
-
assert_equal expected_code, bootstrap_control_group_wrap(:post, :name, content, options)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_bootstrap_control_group_wrap_with_errors
|
29
|
-
object = mock
|
30
|
-
errors = { :name => ["can't be blank"] }
|
31
|
-
options = { :object => object }
|
32
|
-
content = ::ActiveSupport::SafeBuffer.new('content')
|
33
|
-
stub(object).errors { errors }
|
34
|
-
stub(object).name { 'Object Name' }
|
35
|
-
|
36
|
-
expected_code = %{<div class="form-group has-error"><label class="control-label" for="post_name">Name</label>content<span class="help-block"> can't be blank</span></div>}
|
37
|
-
assert_equal expected_code, bootstrap_control_group_wrap(:post, :name, content, options)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_bootstrap_control_group_wrap_with_many_errors
|
41
|
-
object = mock
|
42
|
-
errors = { :name => ["has already been taken", "is reserved", "must be odd"] }
|
43
|
-
options = { :object => object }
|
44
|
-
content = ::ActiveSupport::SafeBuffer.new('content')
|
45
|
-
stub(object).errors { errors }
|
46
|
-
stub(object).name { 'Object Name' }
|
47
|
-
|
48
|
-
expected_code = %{<div class="form-group has-error"><label class="control-label" for="post_name">Name</label>content<span class="help-block"> has already been taken, is reserved, and must be odd</span></div>}
|
49
|
-
assert_equal expected_code, bootstrap_control_group_wrap(:post, :name, content, options)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_bootstrap_control_group_wrap_with_hint
|
53
|
-
object = mock
|
54
|
-
errors = {}
|
55
|
-
options = { :object => object, :hint => "format matters" }
|
56
|
-
content = ::ActiveSupport::SafeBuffer.new('content')
|
57
|
-
stub(object).errors { errors }
|
58
|
-
stub(object).name { 'Object Name' }
|
59
|
-
|
60
|
-
expected_code = %{<div class="form-group"><label class="control-label" for="post_name">Name</label>content<span class="help-block"> format matters</span></div>}
|
61
|
-
assert_equal expected_code, bootstrap_control_group_wrap(:post, :name, content, options)
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_bootstrap_control_group_wrap_with_hint_and_errors
|
65
|
-
object = mock
|
66
|
-
errors = { :name => ["can't be blank"] }
|
67
|
-
options = { :object => object, :hint => "format matters" }
|
68
|
-
content = ::ActiveSupport::SafeBuffer.new('content')
|
69
|
-
stub(object).errors { errors }
|
70
|
-
stub(object).name { 'Object Name' }
|
71
|
-
|
72
|
-
expected_code = %{<div class="form-group has-error"><label class="control-label" for="post_name">Name</label>content<span class="help-block"> can't be blank</span></div>}
|
73
|
-
assert_equal expected_code, bootstrap_control_group_wrap(:post, :name, content, options)
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_bootstrap_text_field
|
77
|
-
html, text_field = mock, mock
|
78
|
-
options = { :object => mock }
|
79
|
-
|
80
|
-
mock(self).text_field(:post, :name, options) { text_field }
|
81
|
-
mock(self).bootstrap_control_group_wrap(:post, :name, text_field, options.dup) { html }
|
82
|
-
assert_equal html, bootstrap_text_field(:post, :name, options)
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_bootstrap_email_field
|
86
|
-
html, email_field = mock, mock
|
87
|
-
options = { :object => mock }
|
88
|
-
|
89
|
-
mock(self).email_field(:post, :email, options) { email_field }
|
90
|
-
mock(self).bootstrap_control_group_wrap(:post, :email, email_field, options.dup) { html }
|
91
|
-
assert_equal html, bootstrap_email_field(:post, :email, options)
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_bootstrap_password_field
|
95
|
-
html, password_field = mock, mock
|
96
|
-
options = { :object => mock }
|
97
|
-
|
98
|
-
mock(self).password_field(:post, :password, options) { password_field }
|
99
|
-
mock(self).bootstrap_control_group_wrap(:post, :password, password_field, options.dup) { html }
|
100
|
-
assert_equal html, bootstrap_password_field(:post, :password, options)
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_bootstrap_collection_select
|
104
|
-
html, collection_select_html, collection, object = mock, mock, mock, mock
|
105
|
-
options = { :object => mock }
|
106
|
-
|
107
|
-
mock(self).collection_select(:post, :name, collection, :id, :name, options, {}) { collection_select_html }
|
108
|
-
mock(self).bootstrap_control_group_wrap(:post, :name, collection_select_html, options.dup) { html }
|
109
|
-
|
110
|
-
assert_equal html, bootstrap_collection_select(:post, :name, collection, :id ,:name, options)
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_bootstrap_select
|
114
|
-
choices, select_html, html = mock, mock, mock
|
115
|
-
options = { :object => mock }
|
116
|
-
|
117
|
-
mock(self).select(:post, :name, choices, options, {}) { select_html }
|
118
|
-
mock(self).bootstrap_control_group_wrap(:post, :name, select_html, options.dup) { html }
|
119
|
-
|
120
|
-
assert_equal html, bootstrap_select(:post, :name, choices, options, {})
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_bootstrap_file_field
|
124
|
-
html, text_field = mock, mock
|
125
|
-
options = { :object => mock }
|
126
|
-
|
127
|
-
mock(self).file_field(:post, :attachment, options) { text_field }
|
128
|
-
mock(self).bootstrap_control_group_wrap(:post, :attachment, text_field, options.dup) { html }
|
129
|
-
assert_equal html, bootstrap_file_field(:post, :attachment, options)
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_bootstrap_text_area
|
133
|
-
html, text_area = mock, mock
|
134
|
-
options = { :object => mock }
|
135
|
-
|
136
|
-
mock(self).text_area(:post, :description, options) { text_area }
|
137
|
-
mock(self).bootstrap_control_group_wrap(:post, :description, text_area, options.dup) { html }
|
138
|
-
assert_equal html, bootstrap_text_area(:post, :description, options)
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_ignore_bootstrap_options
|
142
|
-
html, text_area = mock, mock
|
143
|
-
options = { :object => mock, :label => "Custom", :hint => "be careful" }
|
144
|
-
|
145
|
-
mock(self).text_area(:post, :description, options.except(:label, :hint)) { text_area }
|
146
|
-
mock(self).bootstrap_control_group_wrap(:post, :description, text_area, options.dup) { html }
|
147
|
-
assert_equal html, bootstrap_text_area(:post, :description, options)
|
148
|
-
end
|
149
|
-
|
150
|
-
|
151
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler/setup'
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
-
|
7
|
-
ENV["RAILS_ENV"] = "test"
|
8
|
-
|
9
|
-
require 'minitest/autorun'
|
10
|
-
require 'rails'
|
11
|
-
require 'action_controller'
|
12
|
-
require 'action_view'
|
13
|
-
require 'rails/test_help'
|
14
|
-
require 'bootstrap-form'
|
15
|
-
require 'rr'
|
16
|
-
|
17
|
-
module BootstrapForm
|
18
|
-
class Application < Rails::Application ; end
|
19
|
-
end
|
20
|
-
|
21
|
-
BootstrapForm::Application.routes.draw do
|
22
|
-
get '/:controller(/:action(/:id))'
|
23
|
-
end
|
24
|
-
BootstrapForm::Application.config.secret_key_base = 'bootstrap'
|
25
|
-
|
26
|
-
ActionController::Base.send :include, BootstrapForm::Application.routes.url_helpers
|