html5_validators 1.8.0 → 1.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7670a14c9647d4dbeb3d0d5f80387e101305149c8dbde100f434cc797ffe261a
4
- data.tar.gz: d7f46e24096df1490d56857bb555827369a28dc0b87796cf6ae88013fe0aa98a
3
+ metadata.gz: 3bd884c43fd2c924babd8c686b1a7c6647e00a3e27ab3cfff352b7db9a031867
4
+ data.tar.gz: f533a5f59e63c4269bb79468262f03e39d62f8b98b01d0f63e94898d1060358a
5
5
  SHA512:
6
- metadata.gz: 38bb1668d767d0f1a1d747241c0671d1844195338c5ed4c5fb9eeef26ecdb0d0282d8ab28011d495a59a5a2cb8fa65f5c9138b013a8db4250d0fe4fe8f66b193
7
- data.tar.gz: ee34c8f3ec2e4c2f96e2c258551a529eb5d5f04c51b8769112da506f49aa3f2b498e9db0604b40297f11b60622635aaad39b3dd975aac5565687cd8f0292b60b
6
+ metadata.gz: 87b2b2bdc69f3e15f8e14e1ed77ad02b37eb05209ef73fa69f121bc8ef94cbc0a9a46ee07df98eb0a062dbcb3c5c2c43fcb1d89bdb2f536006546053bb256f89
7
+ data.tar.gz: 42c463972f9b29a66c43e14b54fd0faac850dfb15545c0d8aeb2fe83110b950c1ec6c8acd25423aaecd9638ba32c15f6f8c1064242a92cc4c0b00014d8fa83ce
@@ -1,75 +1,107 @@
1
1
  language: ruby
2
2
 
3
+ sudo: required
4
+
5
+ addons:
6
+ chrome: stable
7
+
8
+ before_install:
9
+ - sudo apt update -qq
10
+ - sudo apt install -y chromium-chromedriver
11
+ - sudo ln -s /usr/lib/chromium-browser/chromedriver /usr/bin/
12
+ - gem install bundler
13
+
3
14
  rvm:
4
- - 2.0.0
5
- - 2.1.10
6
- - 2.2.10
7
- - 2.3.7
8
- - 2.4.4
9
- - 2.5.1
10
15
  - ruby-head
16
+ - 2.5.3
17
+ - 2.4.5
18
+ - 2.3.7
19
+ - 2.2.10
20
+ - 2.1.10
21
+ - 2.0.0
11
22
 
12
23
  gemfile:
13
- - gemfiles/Gemfile.rails-3.2
14
- - gemfiles/Gemfile.rails-4.0
15
- - gemfiles/Gemfile.rails-4.1
16
- - gemfiles/Gemfile.rails-4.2
17
- - gemfiles/Gemfile.rails-5.0
18
- - gemfiles/Gemfile.rails-5.1
19
- - gemfiles/Gemfile.rails-5.2
20
24
  - gemfiles/Gemfile.rails-edge
21
-
22
- sudo: false
25
+ - gemfiles/Gemfile.rails-5.2
26
+ - gemfiles/Gemfile.activemodel-5.2
27
+ - gemfiles/Gemfile.rails-5.1
28
+ - gemfiles/Gemfile.rails-5.0
29
+ - gemfiles/Gemfile.rails-4.2
30
+ - gemfiles/Gemfile.rails-4.1
31
+ - gemfiles/Gemfile.rails-4.0
32
+ - gemfiles/Gemfile.rails-3.2
23
33
 
24
34
  matrix:
25
35
  exclude:
36
+ - rvm: 2.4.5
37
+ gemfile: gemfiles/Gemfile.rails-edge
38
+ - rvm: 2.3.7
39
+ gemfile: gemfiles/Gemfile.rails-edge
40
+ - rvm: 2.2.10
41
+ gemfile: gemfiles/Gemfile.rails-edge
42
+ - rvm: 2.1.10
43
+ gemfile: gemfiles/Gemfile.rails-edge
26
44
  - rvm: 2.0.0
27
- gemfile: gemfiles/Gemfile.rails-5.0
45
+ gemfile: gemfiles/Gemfile.rails-edge
28
46
  - rvm: 2.1.10
29
- gemfile: gemfiles/Gemfile.rails-5.0
47
+ gemfile: gemfiles/Gemfile.rails-5.2
48
+ - rvm: 2.0.0
49
+ gemfile: gemfiles/Gemfile.rails-5.2
50
+ - rvm: 2.1.10
51
+ gemfile: gemfiles/Gemfile.activemodel-5.2
30
52
  - rvm: 2.0.0
53
+ gemfile: gemfiles/Gemfile.activemodel-5.2
54
+ - rvm: 2.4.5
55
+ gemfile: gemfiles/Gemfile.rails-5.1
56
+ - rvm: 2.3.7
31
57
  gemfile: gemfiles/Gemfile.rails-5.1
32
58
  - rvm: 2.1.10
33
59
  gemfile: gemfiles/Gemfile.rails-5.1
34
60
  - rvm: 2.0.0
35
- gemfile: gemfiles/Gemfile.rails-5.2
61
+ gemfile: gemfiles/Gemfile.rails-5.1
62
+ - rvm: 2.4.5
63
+ gemfile: gemfiles/Gemfile.rails-5.0
64
+ - rvm: 2.3.7
65
+ gemfile: gemfiles/Gemfile.rails-5.0
36
66
  - rvm: 2.1.10
37
- gemfile: gemfiles/Gemfile.rails-5.2
67
+ gemfile: gemfiles/Gemfile.rails-5.0
38
68
  - rvm: 2.0.0
39
- gemfile: gemfiles/Gemfile.rails-edge
40
- - rvm: 2.1.10
41
- gemfile: gemfiles/Gemfile.rails-edge
69
+ gemfile: gemfiles/Gemfile.rails-5.0
70
+ - rvm: ruby-head
71
+ gemfile: gemfiles/Gemfile.rails-4.2
72
+ - rvm: 2.5.3
73
+ gemfile: gemfiles/Gemfile.rails-4.2
74
+ - rvm: 2.4.5
75
+ gemfile: gemfiles/Gemfile.rails-4.2
76
+ - rvm: ruby-head
77
+ gemfile: gemfiles/Gemfile.rails-4.1
78
+ - rvm: 2.5.3
79
+ gemfile: gemfiles/Gemfile.rails-4.1
80
+ - rvm: 2.4.5
81
+ gemfile: gemfiles/Gemfile.rails-4.1
42
82
  - rvm: 2.2.10
43
- gemfile: gemfiles/Gemfile.rails-edge
44
- - rvm: 2.3.7
45
- gemfile: gemfiles/Gemfile.rails-edge
83
+ gemfile: gemfiles/Gemfile.rails-4.1
84
+ - rvm: 2.1.10
85
+ gemfile: gemfiles/Gemfile.rails-4.1
86
+ - rvm: ruby-head
87
+ gemfile: gemfiles/Gemfile.rails-4.0
88
+ - rvm: 2.5.3
89
+ gemfile: gemfiles/Gemfile.rails-4.0
90
+ - rvm: 2.4.5
91
+ gemfile: gemfiles/Gemfile.rails-4.0
46
92
  - rvm: 2.2.10
93
+ gemfile: gemfiles/Gemfile.rails-4.0
94
+ - rvm: 2.1.10
95
+ gemfile: gemfiles/Gemfile.rails-4.0
96
+ - rvm: ruby-head
47
97
  gemfile: gemfiles/Gemfile.rails-3.2
48
- - rvm: 2.3.7
98
+ - rvm: 2.5.3
49
99
  gemfile: gemfiles/Gemfile.rails-3.2
50
- - rvm: 2.4.4
100
+ - rvm: 2.4.5
51
101
  gemfile: gemfiles/Gemfile.rails-3.2
52
- - rvm: 2.4.4
53
- gemfile: gemfiles/Gemfile.rails-4.0
54
- - rvm: 2.4.4
55
- gemfile: gemfiles/Gemfile.rails-4.1
56
- - rvm: 2.4.4
57
- gemfile: gemfiles/Gemfile.rails-4.2
58
- - rvm: 2.5.1
102
+ - rvm: 2.3.7
59
103
  gemfile: gemfiles/Gemfile.rails-3.2
60
- - rvm: 2.5.1
61
- gemfile: gemfiles/Gemfile.rails-4.0
62
- - rvm: 2.5.1
63
- gemfile: gemfiles/Gemfile.rails-4.1
64
- - rvm: 2.5.1
65
- gemfile: gemfiles/Gemfile.rails-4.2
66
- - rvm: ruby-head
104
+ - rvm: 2.2.10
67
105
  gemfile: gemfiles/Gemfile.rails-3.2
68
- - rvm: ruby-head
69
- gemfile: gemfiles/Gemfile.rails-4.0
70
- - rvm: ruby-head
71
- gemfile: gemfiles/Gemfile.rails-4.1
72
- - rvm: ruby-head
73
- gemfile: gemfiles/Gemfile.rails-4.2
74
106
  allow_failures:
75
107
  - rvm: ruby-head
@@ -0,0 +1,78 @@
1
+ ## 1.9.0
2
+
3
+ * Added support for `form_with` [@DialBird]
4
+
5
+ * Enhanced support for non-AR applications to load all necessary monkey-patches on application initialization
6
+
7
+
8
+ ## 1.8.0
9
+
10
+ * Added support for AR `validation_context` such as `on: :create` or `on: :update`
11
+
12
+ ## 1.7.0
13
+
14
+ * Fixed a bug that `required: false` helper option does not override `required: true` value from PresenceValidator [@sandipransing]
15
+
16
+
17
+ ## 1.5.0
18
+
19
+ * Rails 5 support
20
+
21
+ * Changed `auto_html5_validation` config behavior not to propagate to children classes
22
+
23
+
24
+ ## 1.4.0
25
+
26
+ * Dropped Ruby 1.8 support
27
+
28
+ * Dropped Ruby 1.9 support
29
+
30
+ * Dropped Rails 3.2 support
31
+
32
+ * Fixed a bug that `maxlength` validation for inputs which can be blank was ignored [@kv109]
33
+
34
+ * Fixed a bug that `auto_html5_validation` was not properly enabled for models that are loaded after loading this gem
35
+
36
+
37
+ ## 1.3.0
38
+
39
+ * Switched from `alias_method_chain` to `Module#prepend` on Ruby 2 and Rails 4
40
+
41
+ * Added `minlength` support
42
+
43
+
44
+ ## 1.2.2
45
+
46
+ * Fixed undefined method `auto_html5_validation` error for non-AR Active Model models
47
+
48
+
49
+ ## 1.2.1
50
+
51
+ * Fixed a bug that `minlength / maxlength` values were assigned to `min / max`
52
+
53
+
54
+ ## 1.2.0
55
+
56
+ * Added global `Html5Validators.enabled` flag [@sinsoku]
57
+
58
+ * Fixed a bug that some Symbol keyed helper options were ignored [@lucas-nelson]
59
+
60
+
61
+ ## 1.1.3
62
+
63
+ * Fixed a bug that AR::Base.inherited conflicts with other gems [@tricknotes]
64
+
65
+
66
+ ## 1.1.2
67
+
68
+ * Fixed a bug that `cattr_accessor` + `:instance_accessor => false` still creates an `instance_accessor` on AR 3.0 and 3.1
69
+
70
+
71
+ ## 1.1.1
72
+
73
+ * Rails 4 support
74
+
75
+
76
+ ## 1.1.0
77
+
78
+ * Added `maxlength` validator support for `text_area` [@ursm]
data/Rakefile CHANGED
@@ -4,7 +4,11 @@ require 'rake/testtask'
4
4
 
5
5
  Rake::TestTask.new do |t|
6
6
  t.libs << 'test'
7
- t.pattern = 'test/**/*_test.rb'
7
+ if defined? ::ActiveRecord
8
+ t.test_files = Dir['test/**/*_test.rb']
9
+ else
10
+ t.test_files = Dir['test/**/*_test.rb'] - Dir['test/**/*active_record*'] - Dir['test/**/*active_record*/*.rb']
11
+ end
8
12
  t.warning = true
9
13
  t.verbose = true
10
14
  end
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'railties', '~> 5.2.0'
4
+ gem 'activemodel', '~> 5.2.0'
5
+
6
+ gemspec path: '..'
@@ -14,13 +14,14 @@ Gem::Specification.new do |s|
14
14
  s.description = 'A gem/plugin for Rails 3+ that enables client-side validation using ActiveModel + HTML5'
15
15
  s.license = 'MIT'
16
16
 
17
- s.rubyforge_project = 'html5_validators'
18
-
19
17
  s.files = `git ls-files`.split("\n")
20
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
20
  s.require_paths = ['lib']
23
- s.add_development_dependency 'test-unit-rails'
21
+ s.add_development_dependency 'test-unit-activesupport'
22
+ s.add_development_dependency 'test-unit-capybara'
23
+ s.add_development_dependency 'selenium-webdriver'
24
+ s.add_development_dependency 'puma'
24
25
  s.add_development_dependency 'capybara', '>= 2'
25
26
  s.add_development_dependency 'sqlite3'
26
27
  s.add_development_dependency 'rake'
@@ -5,21 +5,21 @@ require 'rails'
5
5
  module Html5Validators
6
6
  @enabled = true
7
7
 
8
- def self.enabled
9
- @enabled
10
- end
11
-
12
- def self.enabled=(enable)
13
- @enabled = enable
8
+ class << self
9
+ attr_accessor :enabled
14
10
  end
15
11
 
16
12
  class Railtie < ::Rails::Railtie #:nodoc:
17
- initializer 'html5_validators' do |app|
18
- ActiveSupport.on_load(:active_record) do
13
+ initializer 'html5_validators' do
14
+ config.after_initialize do
19
15
  require 'html5_validators/active_model/helper_methods'
20
16
  require 'html5_validators/active_model/validations'
17
+ end
18
+
19
+ ActiveSupport.on_load(:active_record) do
21
20
  require 'html5_validators/active_record/base'
22
21
  end
22
+
23
23
  ActiveSupport.on_load(:action_view) do
24
24
  if ActionPack::VERSION::STRING >= '4'
25
25
  require 'html5_validators/action_view/form_helpers'
@@ -11,11 +11,22 @@ module Html5Validators
11
11
  end
12
12
  super
13
13
  end
14
+
15
+ if Rails::VERSION::STRING >= '5.1'
16
+ def form_with(model: nil, scope: nil, url: nil, format: nil, **options)
17
+ if model && model.respond_to?(:auto_html5_validation=)
18
+ if !Html5Validators.enabled || (options[:auto_html5_validation] == false)
19
+ model.auto_html5_validation = false
20
+ end
21
+ end
22
+ super
23
+ end
24
+ end
14
25
  end
15
26
 
16
27
  module PresenceValidator
17
28
  def render
18
- if object.class.ancestors.include?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
29
+ if object.is_a?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
19
30
  @options["required"] ||= @options.fetch(:required) { object.attribute_required?(@method_name) }
20
31
  end
21
32
  super
@@ -24,7 +35,7 @@ module Html5Validators
24
35
 
25
36
  module LengthValidator
26
37
  def render
27
- if object.class.ancestors.include?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
38
+ if object.is_a?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
28
39
  @options["maxlength"] ||= @options[:maxlength] || object.attribute_maxlength(@method_name)
29
40
  @options["minlength"] ||= @options[:minlength] || object.attribute_minlength(@method_name)
30
41
  end
@@ -34,7 +45,7 @@ module Html5Validators
34
45
 
35
46
  module NumericalityValidator
36
47
  def render
37
- if object.class.ancestors.include?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
48
+ if object.is_a?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
38
49
  @options["max"] ||= @options["max"] || @options[:max] || object.attribute_max(@method_name)
39
50
  @options["min"] ||= @options["min"] || @options[:min] || object.attribute_min(@method_name)
40
51
  end
@@ -17,7 +17,7 @@ module ActionView
17
17
 
18
18
  class InstanceTag
19
19
  def to_input_field_tag_with_html5_attributes(field_type, options = {})
20
- if object.class.ancestors.include?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
20
+ if object.is_a?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
21
21
  options["required"] ||= object.attribute_required?(method_name)
22
22
  options["maxlength"] ||= object.attribute_maxlength(method_name)
23
23
  options["minlength"] ||= object.attribute_minlength(method_name)
@@ -29,7 +29,7 @@ module ActionView
29
29
  alias_method_chain :to_input_field_tag, :html5_attributes
30
30
 
31
31
  def to_text_area_tag_with_html5_attributes(options = {})
32
- if object.class.ancestors.include?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
32
+ if object.is_a?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
33
33
  options["required"] ||= object.attribute_required?(method_name)
34
34
  options["maxlength"] ||= object.attribute_maxlength(method_name)
35
35
  options["minlength"] ||= object.attribute_minlength(method_name)
@@ -39,7 +39,7 @@ module ActionView
39
39
  alias_method_chain :to_text_area_tag, :html5_attributes
40
40
 
41
41
  def to_radio_button_tag_with_html5_attributes(tag_value, options = {})
42
- if object.class.ancestors.include?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
42
+ if object.is_a?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
43
43
  options["required"] ||= object.attribute_required?(method_name)
44
44
  end
45
45
  to_radio_button_tag_without_html5_attributes tag_value, options
@@ -47,7 +47,7 @@ module ActionView
47
47
  alias_method_chain :to_radio_button_tag, :html5_attributes
48
48
 
49
49
  def to_check_box_tag_with_html5_attributes(options = {}, checked_value = "1", unchecked_value = "0")
50
- if object.class.ancestors.include?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
50
+ if object.is_a?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
51
51
  options["required"] ||= object.attribute_required?(method_name)
52
52
  end
53
53
  to_check_box_tag_without_html5_attributes options, checked_value, unchecked_value
@@ -17,7 +17,7 @@ module Html5Validators
17
17
 
18
18
  included do
19
19
  # Existing subclasses pick up the model extension as well
20
- self.descendants.each do |kls|
20
+ descendants.each do |kls|
21
21
  class << kls
22
22
  attr_accessor :auto_html5_validation
23
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Html5Validators
4
- VERSION = '1.8.0'
4
+ VERSION = '1.9.0'
5
5
  end
@@ -1,11 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_record'
4
3
  require 'action_controller/railtie'
4
+ require 'active_model'
5
5
 
6
6
  # config
7
- ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
8
-
9
7
  class Html5ValidatorsTestApp < Rails::Application
10
8
  config.secret_token = "You know I'm born to lose, and gambling's for fools, But that's the way I like it baby, I don't wanna live for ever, And don't forget the joker!"
11
9
  config.session_store :cookie_store, key: '_myapp_session'
@@ -33,11 +31,29 @@ Rails.application.routes.draw do
33
31
  end
34
32
 
35
33
  # models
36
- class ApplicationRecord < ActiveRecord::Base
37
- self.abstract_class = true
38
- end
39
- class Person < ApplicationRecord
34
+ begin
35
+ require 'active_record'
36
+
37
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
38
+
39
+ # migrations
40
+ ActiveRecord::Base.connection.instance_eval do
41
+ create_table :people do |t|
42
+ t.string :name
43
+ t.string :email
44
+ t.integer :age
45
+ t.text :bio
46
+ end
47
+ end
48
+
49
+ class ApplicationRecord < ActiveRecord::Base
50
+ self.abstract_class = true
51
+ end
52
+ class Person < ApplicationRecord
53
+ end
54
+ rescue LoadError
40
55
  end
56
+
41
57
  class Item
42
58
  if ActiveModel::VERSION::STRING >= '4'
43
59
  include ActiveModel::Model
@@ -56,28 +72,48 @@ class PeopleController < ApplicationController
56
72
  def new
57
73
  @person = Person.new
58
74
  render inline: <<-ERB
59
- <%= form_for @person do |f| %>
75
+ <%= form_for @person, html: { id: 'form_for' } do |f| %>
60
76
  <%= f.text_field :name %>
61
77
  <%= f.text_area :bio %>
62
78
  <% end %>
63
- ERB
79
+
80
+ <% if Rails::VERSION::STRING >= '5.1' %>
81
+ <%= form_with model: @person, id: 'form_with' do |f| %>
82
+ <%= f.text_field :name, id: 'person_name' %>
83
+ <%= f.text_area :bio, id: 'person_bio' %>
84
+ <% end %>
85
+ <% end %>
86
+ ERB
64
87
  end
65
88
 
66
89
  def new_without_html5_validation
67
90
  @person = Person.new
68
91
  render inline: <<-ERB
69
- <%= form_for @person, auto_html5_validation: false do |f| %>
92
+ <%= form_for @person, html: { id: 'form_for' }, auto_html5_validation: false do |f| %>
70
93
  <%= f.text_field :name %>
71
94
  <%= f.text_field :email %>
72
95
  <% end %>
73
- ERB
96
+
97
+ <% if Rails::VERSION::STRING >= '5.1' %>
98
+ <%= form_with model: @person, id: 'form_with', auto_html5_validation: false do |f| %>
99
+ <%= f.text_field :name, id: 'person_name' %>
100
+ <%= f.text_field :email, id: 'person_email' %>
101
+ <% end %>
102
+ <% end %>
103
+ ERB
74
104
  end
75
105
 
76
106
  def new_with_required_true
77
107
  @person = Person.new
78
108
  render inline: <<-ERB
79
- <%= form_for @person do |f| %>
109
+ <%= form_for @person, html: { id: 'form_for' } do |f| %>
80
110
  <%= f.text_field :email, required: true %>
111
+ <% end %>
112
+
113
+ <% if Rails::VERSION::STRING >= '5.1' %>
114
+ <%= form_with model: @person, id: 'form_with' do |f| %>
115
+ <%= f.text_field :email, required: true, id: 'person_email' %>
116
+ <% end %>
81
117
  <% end %>
82
118
  ERB
83
119
  end
@@ -85,8 +121,14 @@ ERB
85
121
  def new_with_required_false
86
122
  @person = Person.new
87
123
  render inline: <<-ERB
88
- <%= form_for @person do |f| %>
124
+ <%= form_for @person, html: { id: 'form_for' } do |f| %>
89
125
  <%= f.text_field :email, required: false %>
126
+ <% end %>
127
+
128
+ <% if Rails::VERSION::STRING >= '5.1' %>
129
+ <%= form_with model: @person, id: 'form_with' do |f| %>
130
+ <%= f.text_field :email, required: false, id: 'person_email' %>
131
+ <% end %>
90
132
  <% end %>
91
133
  ERB
92
134
  end
@@ -95,28 +137,48 @@ class ItemsController < ApplicationController
95
137
  def new
96
138
  @item = Item.new
97
139
  render inline: <<-ERB
98
- <%= form_for @item do |f| %>
140
+ <%= form_for @item, html: { id: 'form_for' } do |f| %>
99
141
  <%= f.text_field :name %>
100
142
  <%= f.text_area :description %>
101
143
  <% end %>
102
- ERB
144
+
145
+ <% if Rails::VERSION::STRING >= '5.1' %>
146
+ <%= form_with model: @item, id: 'form_with' do |f| %>
147
+ <%= f.text_field :name, id: 'item_name' %>
148
+ <%= f.text_area :description, id: 'item_description' %>
149
+ <% end %>
150
+ <% end %>
151
+ ERB
103
152
  end
104
153
 
105
154
  def new_without_html5_validation
106
155
  @item = Item.new
107
156
  render inline: <<-ERB
108
- <%= form_for @item, auto_html5_validation: false do |f| %>
157
+ <%= form_for @item, html: { id: 'form_for' }, auto_html5_validation: false do |f| %>
109
158
  <%= f.text_field :name %>
110
159
  <%= f.text_area :description %>
111
160
  <% end %>
112
- ERB
161
+
162
+ <% if Rails::VERSION::STRING >= '5.1' %>
163
+ <%= form_with model: @item, id: 'form_with', auto_html5_validation: false do |f| %>
164
+ <%= f.text_field :name, id: 'item_name' %>
165
+ <%= f.text_area :description, id: 'item_description' %>
166
+ <% end %>
167
+ <% end %>
168
+ ERB
113
169
  end
114
170
 
115
171
  def new_with_required_true
116
172
  @item = Item.new
117
173
  render inline: <<-ERB
118
- <%= form_for @item do |f| %>
174
+ <%= form_for @item, html: { id: 'form_for' } do |f| %>
119
175
  <%= f.text_field :name, required: true %>
176
+ <% end %>
177
+
178
+ <% if Rails::VERSION::STRING >= '5.1' %>
179
+ <%= form_with model: @item, id: 'form_with' do |f| %>
180
+ <%= f.text_field :name, required: true, id: 'item_name' %>
181
+ <% end %>
120
182
  <% end %>
121
183
  ERB
122
184
  end
@@ -124,8 +186,14 @@ ERB
124
186
  def new_with_required_false
125
187
  @item = Item.new
126
188
  render inline: <<-ERB
127
- <%= form_for @item do |f| %>
189
+ <%= form_for @item, html: { id: 'form_for' } do |f| %>
128
190
  <%= f.text_field :name, required: false %>
191
+ <% end %>
192
+
193
+ <% if Rails::VERSION::STRING >= '5.1' %>
194
+ <%= form_with model: @item, id: 'form_with' do |f| %>
195
+ <%= f.text_field :name, required: false, id: 'item_name' %>
196
+ <% end %>
129
197
  <% end %>
130
198
  ERB
131
199
  end
@@ -133,15 +201,3 @@ end
133
201
 
134
202
  # helpers
135
203
  module ApplicationHelper; end
136
-
137
- #migrations
138
- class CreateAllTables < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
139
- def self.up
140
- create_table :people do |t|
141
- t.string :name
142
- t.string :email
143
- t.integer :age
144
- t.text :bio
145
- end
146
- end
147
- end
@@ -3,6 +3,12 @@
3
3
  require 'test_helper'
4
4
 
5
5
  class ActiveModelValidationTest < ActionDispatch::IntegrationTest
6
+ FORM_ID_LIST = if Rails::VERSION::STRING >= '5.1'
7
+ %w[#form_for #form_with].freeze
8
+ else
9
+ %w[#form_for].freeze
10
+ end
11
+
6
12
  teardown do
7
13
  Item._validators.clear
8
14
  end
@@ -10,14 +16,18 @@ class ActiveModelValidationTest < ActionDispatch::IntegrationTest
10
16
  sub_test_case 'without validation' do
11
17
  test 'new form' do
12
18
  visit '/items/new'
13
- assert page.has_css? 'input#item_name'
14
- assert page.has_no_css? 'input#item_name[required=required]'
19
+ FORM_ID_LIST.each do |form|
20
+ assert page.has_css? "#{form} input#item_name"
21
+ assert page.has_no_css? "#{form} input#item_name[required=required]"
22
+ end
15
23
  end
16
24
 
17
25
  test 'new_without_html5_validation form' do
18
26
  visit '/items/new_without_html5_validation'
19
- assert page.has_css? 'textarea#item_description'
20
- assert page.has_no_css? 'textarea#item_description[required=required]'
27
+ FORM_ID_LIST.each do |form|
28
+ assert page.has_css? "#{form} textarea#item_description"
29
+ assert page.has_no_css? "#{form} textarea#item_description[required=required]"
30
+ end
21
31
  end
22
32
  end
23
33
 
@@ -27,24 +37,28 @@ class ActiveModelValidationTest < ActionDispatch::IntegrationTest
27
37
  end
28
38
  test 'new form' do
29
39
  visit '/items/new'
30
-
31
- assert_equal 'required', find('input#item_name')[:required]
32
- assert_equal 'required', find('textarea#item_description')[:required]
40
+ FORM_ID_LIST.each do |form|
41
+ assert_equal 'required', find("#{form} input#item_name")[:required]
42
+ assert_equal 'required', find("#{form} textarea#item_description")[:required]
43
+ end
33
44
  end
34
45
  test 'new_without_html5_validation form' do
35
46
  visit '/items/new_without_html5_validation'
36
-
37
- assert_nil find('input#item_name')[:required]
47
+ FORM_ID_LIST.each do |form|
48
+ assert_nil find("#{form} input#item_name")[:required]
49
+ end
38
50
  end
39
51
  test 'new_with_required_true form' do
40
52
  visit '/items/new_with_required_true'
41
-
42
- assert_equal 'required', find('input#item_name')[:required]
53
+ FORM_ID_LIST.each do |form|
54
+ assert_equal 'required', find("#{form} input#item_name")[:required]
55
+ end
43
56
  end
44
57
  test 'new_with_required_false form' do
45
58
  visit '/items/new_with_required_false'
46
-
47
- assert_nil find('input#item_name')[:required]
59
+ FORM_ID_LIST.each do |form|
60
+ assert_nil find("#{form} input#item_name")[:required]
61
+ end
48
62
  end
49
63
  sub_test_case 'disabling html5_validation in class level' do
50
64
  setup do
@@ -59,8 +73,9 @@ class ActiveModelValidationTest < ActionDispatch::IntegrationTest
59
73
  end
60
74
  test 'new form' do
61
75
  visit '/items/new'
62
-
63
- assert_nil find('input#item_name')[:required]
76
+ FORM_ID_LIST.each do |form|
77
+ assert_nil find("#{form} input#item_name")[:required]
78
+ end
64
79
  end
65
80
  end
66
81
 
@@ -73,9 +88,10 @@ class ActiveModelValidationTest < ActionDispatch::IntegrationTest
73
88
  end
74
89
  test 'new form' do
75
90
  visit '/items/new'
76
-
77
- assert_nil find('input#item_name')[:required]
78
- assert_nil find('textarea#item_description')[:required]
91
+ FORM_ID_LIST.each do |form|
92
+ assert_nil find("#{form} input#item_name")[:required]
93
+ assert_nil find("#{form} textarea#item_description")[:required]
94
+ end
79
95
  end
80
96
  end
81
97
  end
@@ -88,9 +104,10 @@ class ActiveModelValidationTest < ActionDispatch::IntegrationTest
88
104
 
89
105
  test 'new form' do
90
106
  visit '/items/new'
91
-
92
- assert_equal '20', find('input#item_name')[:maxlength]
93
- assert_equal '100', find('textarea#item_description')[:maxlength]
107
+ FORM_ID_LIST.each do |form|
108
+ assert_equal '20', find("#{form} input#item_name")[:maxlength]
109
+ assert_equal '100', find("#{form} textarea#item_description")[:maxlength]
110
+ end
94
111
  end
95
112
  end
96
113
 
@@ -102,9 +119,10 @@ class ActiveModelValidationTest < ActionDispatch::IntegrationTest
102
119
 
103
120
  test 'new form' do
104
121
  visit '/items/new'
105
-
106
- assert_equal '3', find('input#item_name')[:minlength]
107
- assert_equal '10', find('textarea#item_description')[:minlength]
122
+ FORM_ID_LIST.each do |form|
123
+ assert_equal '3', find("#{form} input#item_name")[:minlength]
124
+ assert_equal '10', find("#{form} textarea#item_description")[:minlength]
125
+ end
108
126
  end
109
127
  end
110
128
  end
@@ -3,6 +3,12 @@
3
3
  require 'test_helper'
4
4
 
5
5
  class ActiveRecordValidationTest < ActionDispatch::IntegrationTest
6
+ FORM_ID_LIST = if Rails::VERSION::STRING >= '5.1'
7
+ %w[#form_for #form_with].freeze
8
+ else
9
+ %w[#form_for].freeze
10
+ end
11
+
6
12
  teardown do
7
13
  Person._validators.clear
8
14
  end
@@ -10,14 +16,18 @@ class ActiveRecordValidationTest < ActionDispatch::IntegrationTest
10
16
  sub_test_case 'without validation' do
11
17
  test 'new form' do
12
18
  visit '/people/new'
13
- assert page.has_css? 'input#person_name'
14
- assert page.has_no_css? 'input#person_name[required=required]'
19
+ FORM_ID_LIST.each do |form|
20
+ assert page.has_css? "#{form} input#person_name"
21
+ assert page.has_no_css? "#{form} input#person_name[required=required]"
22
+ end
15
23
  end
16
24
 
17
25
  test 'new_without_html5_validation form' do
18
26
  visit '/people/new_without_html5_validation'
19
- assert page.has_css? 'input#person_email'
20
- assert page.has_no_css? 'input#person_email[required=required]'
27
+ FORM_ID_LIST.each do |form|
28
+ assert page.has_css? "#{form} input#person_email"
29
+ assert page.has_no_css? "#{form} input#person_email[required=required]"
30
+ end
21
31
  end
22
32
  end
23
33
 
@@ -27,24 +37,28 @@ class ActiveRecordValidationTest < ActionDispatch::IntegrationTest
27
37
  end
28
38
  test 'new form' do
29
39
  visit '/people/new'
30
-
31
- assert_equal 'required', find('input#person_name')[:required]
32
- assert_equal 'required', find('textarea#person_bio')[:required]
40
+ FORM_ID_LIST.each do |form|
41
+ assert_equal 'required', find("#{form} input#person_name")[:required]
42
+ assert_equal 'required', find("#{form} textarea#person_bio")[:required]
43
+ end
33
44
  end
34
45
  test 'new_without_html5_validation form' do
35
46
  visit '/people/new_without_html5_validation'
36
-
37
- assert_nil find('input#person_name')[:required]
47
+ FORM_ID_LIST.each do |form|
48
+ assert_nil find("#{form} input#person_name")[:required]
49
+ end
38
50
  end
39
51
  test 'new_with_required_true form' do
40
52
  visit '/people/new_with_required_true'
41
-
42
- assert_equal 'required', find('input#person_email')[:required]
53
+ FORM_ID_LIST.each do |form|
54
+ assert_equal 'required', find("#{form} input#person_email")[:required]
55
+ end
43
56
  end
44
57
  test 'new_with_required_false form' do
45
58
  visit '/people/new_with_required_false'
46
-
47
- assert_nil find('input#person_email')[:required]
59
+ FORM_ID_LIST.each do |form|
60
+ assert_nil find("#{form} input#person_email")[:required]
61
+ end
48
62
  end
49
63
  sub_test_case 'disabling html5_validation in class level' do
50
64
  setup do
@@ -59,8 +73,9 @@ class ActiveRecordValidationTest < ActionDispatch::IntegrationTest
59
73
  end
60
74
  test 'new form' do
61
75
  visit '/people/new'
62
-
63
- assert_nil find('input#person_name')[:required]
76
+ FORM_ID_LIST.each do |form|
77
+ assert_nil find("#{form} input#person_name")[:required]
78
+ end
64
79
  end
65
80
  end
66
81
 
@@ -73,9 +88,10 @@ class ActiveRecordValidationTest < ActionDispatch::IntegrationTest
73
88
  end
74
89
  test 'new form' do
75
90
  visit '/people/new'
76
-
77
- assert_nil find('input#person_name')[:required]
78
- assert_nil find('textarea#person_bio')[:required]
91
+ FORM_ID_LIST.each do |form|
92
+ assert_nil find("#{form} input#person_name")[:required]
93
+ assert_nil find("#{form} textarea#person_bio")[:required]
94
+ end
79
95
  end
80
96
  end
81
97
  end
@@ -88,9 +104,10 @@ class ActiveRecordValidationTest < ActionDispatch::IntegrationTest
88
104
 
89
105
  test 'new form' do
90
106
  visit '/people/new'
91
-
92
- assert_equal '20', find('input#person_name')[:maxlength]
93
- assert_equal '100', find('textarea#person_bio')[:maxlength]
107
+ FORM_ID_LIST.each do |form|
108
+ assert_equal '20', find("#{form} input#person_name")[:maxlength]
109
+ assert_equal '100', find("#{form} textarea#person_bio")[:maxlength]
110
+ end
94
111
  end
95
112
  end
96
113
 
@@ -102,9 +119,10 @@ class ActiveRecordValidationTest < ActionDispatch::IntegrationTest
102
119
 
103
120
  test 'new form' do
104
121
  visit '/people/new'
105
-
106
- assert_equal '3', find('input#person_name')[:minlength]
107
- assert_equal '10', find('textarea#person_bio')[:minlength]
122
+ FORM_ID_LIST.each do |form|
123
+ assert_equal '3', find("#{form} input#person_name")[:minlength]
124
+ assert_equal '10', find("#{form} textarea#person_bio")[:minlength]
125
+ end
108
126
  end
109
127
  end
110
128
 
@@ -116,9 +134,10 @@ class ActiveRecordValidationTest < ActionDispatch::IntegrationTest
116
134
  end
117
135
  test 'new form' do
118
136
  visit '/people/new'
119
-
120
- assert_equal 'required', find('input#person_name')[:required]
121
- assert_equal '100', find('textarea#person_bio')[:maxlength]
137
+ FORM_ID_LIST.each do |form|
138
+ assert_equal 'required', find("#{form} input#person_name")[:required]
139
+ assert_equal '100', find("#{form} textarea#person_bio")[:maxlength]
140
+ end
122
141
  end
123
142
  end
124
143
 
@@ -128,9 +147,10 @@ class ActiveRecordValidationTest < ActionDispatch::IntegrationTest
128
147
  end
129
148
  test 'new form' do
130
149
  visit '/people/new'
131
-
132
- assert_nil find('input#person_name')[:required]
133
- assert_nil find('textarea#person_bio')[:maxlength]
150
+ FORM_ID_LIST.each do |form|
151
+ assert_nil find("#{form} input#person_name")[:required]
152
+ assert_nil find("#{form} textarea#person_bio")[:maxlength]
153
+ end
134
154
  end
135
155
  end
136
156
  end
@@ -6,13 +6,31 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
6
  require 'rails'
7
7
  require 'bundler/setup'
8
8
  Bundler.require
9
+ require 'capybara'
10
+ require 'selenium/webdriver'
9
11
 
10
12
  # needs to load the app before loading rspec/rails => capybara
11
13
  require 'fake_app'
12
- require 'test/unit/rails/test_help'
14
+
15
+ require 'active_support/test_case'
16
+ require 'test/unit/active_support'
17
+ require 'test/unit/capybara'
18
+ require 'capybara/rails'
19
+ require 'capybara/dsl'
20
+ ActionDispatch::IntegrationTest.send :include, Capybara::DSL
21
+
13
22
  # Requires supporting files with custom matchers and macros, etc,
14
23
  # in ./support/ and its subdirectories.
15
24
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
16
25
 
17
- ActiveRecord::Migration.verbose = false
18
- CreateAllTables.up
26
+ begin
27
+ require "action_dispatch/system_test_case"
28
+ rescue LoadError
29
+ Capybara.register_driver :chrome do |app|
30
+ options = Selenium::WebDriver::Chrome::Options.new(args: %w[no-sandbox headless disable-gpu])
31
+ Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
32
+ end
33
+ Capybara.javascript_driver = :chrome
34
+ else
35
+ ActionDispatch::SystemTestCase.driven_by(:selenium, using: :headless_chrome)
36
+ end
metadata CHANGED
@@ -1,17 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html5_validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-08 00:00:00.000000000 Z
11
+ date: 2018-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: test-unit-rails
14
+ name: test-unit-activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit-capybara
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: selenium-webdriver
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: puma
15
57
  requirement: !ruby/object:Gem::Requirement
16
58
  requirements:
17
59
  - - ">="
@@ -90,10 +132,12 @@ extra_rdoc_files: []
90
132
  files:
91
133
  - ".gitignore"
92
134
  - ".travis.yml"
135
+ - CHANGELOG.md
93
136
  - Gemfile
94
137
  - MIT-LICENSE
95
138
  - README.md
96
139
  - Rakefile
140
+ - gemfiles/Gemfile.activemodel-5.2
97
141
  - gemfiles/Gemfile.rails-3.2
98
142
  - gemfiles/Gemfile.rails-4.0
99
143
  - gemfiles/Gemfile.rails-4.1
@@ -134,8 +178,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
178
  - !ruby/object:Gem::Version
135
179
  version: '0'
136
180
  requirements: []
137
- rubyforge_project: html5_validators
138
- rubygems_version: 2.7.7
181
+ rubyforge_project:
182
+ rubygems_version: 2.7.6
139
183
  signing_key:
140
184
  specification_version: 4
141
185
  summary: Automatic client side validation using HTML5 Form Validation