html5_validators 1.7.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f42582a45b426a624233abfd0c846d2b4253c09c
4
- data.tar.gz: f699d9d08608826ea5f7926dc55a0047e1a1866b
2
+ SHA256:
3
+ metadata.gz: 7670a14c9647d4dbeb3d0d5f80387e101305149c8dbde100f434cc797ffe261a
4
+ data.tar.gz: d7f46e24096df1490d56857bb555827369a28dc0b87796cf6ae88013fe0aa98a
5
5
  SHA512:
6
- metadata.gz: 390f53c7bd1726de0d717495680841bf7174612a2a46d2b5f0cc7a091c24195966649172c0e1dd7c51173c3cd8757e54cab5e101033e9e189b31291c16562d1e
7
- data.tar.gz: 3063081e6158297715a1a1de5efdfa6dc32dfda33adfbf267c66847956ca975b43fbec6ed1f243e75b6ceb08e5cb01e60d5655b074a518ba6aeba5c9c5e804c5
6
+ metadata.gz: 38bb1668d767d0f1a1d747241c0671d1844195338c5ed4c5fb9eeef26ecdb0d0282d8ab28011d495a59a5a2cb8fa65f5c9138b013a8db4250d0fe4fe8f66b193
7
+ data.tar.gz: ee34c8f3ec2e4c2f96e2c258551a529eb5d5f04c51b8769112da506f49aa3f2b498e9db0604b40297f11b60622635aaad39b3dd975aac5565687cd8f0292b60b
data/.travis.yml CHANGED
@@ -3,9 +3,10 @@ language: ruby
3
3
  rvm:
4
4
  - 2.0.0
5
5
  - 2.1.10
6
- - 2.2.7
7
- - 2.3.4
8
- - 2.4.1
6
+ - 2.2.10
7
+ - 2.3.7
8
+ - 2.4.4
9
+ - 2.5.1
9
10
  - ruby-head
10
11
 
11
12
  gemfile:
@@ -14,6 +15,8 @@ gemfile:
14
15
  - gemfiles/Gemfile.rails-4.1
15
16
  - gemfiles/Gemfile.rails-4.2
16
17
  - gemfiles/Gemfile.rails-5.0
18
+ - gemfiles/Gemfile.rails-5.1
19
+ - gemfiles/Gemfile.rails-5.2
17
20
  - gemfiles/Gemfile.rails-edge
18
21
 
19
22
  sudo: false
@@ -24,21 +27,41 @@ matrix:
24
27
  gemfile: gemfiles/Gemfile.rails-5.0
25
28
  - rvm: 2.1.10
26
29
  gemfile: gemfiles/Gemfile.rails-5.0
30
+ - rvm: 2.0.0
31
+ gemfile: gemfiles/Gemfile.rails-5.1
32
+ - rvm: 2.1.10
33
+ gemfile: gemfiles/Gemfile.rails-5.1
34
+ - rvm: 2.0.0
35
+ gemfile: gemfiles/Gemfile.rails-5.2
36
+ - rvm: 2.1.10
37
+ gemfile: gemfiles/Gemfile.rails-5.2
27
38
  - rvm: 2.0.0
28
39
  gemfile: gemfiles/Gemfile.rails-edge
29
40
  - rvm: 2.1.10
30
41
  gemfile: gemfiles/Gemfile.rails-edge
31
- - rvm: 2.2.7
42
+ - rvm: 2.2.10
43
+ gemfile: gemfiles/Gemfile.rails-edge
44
+ - rvm: 2.3.7
45
+ gemfile: gemfiles/Gemfile.rails-edge
46
+ - rvm: 2.2.10
47
+ gemfile: gemfiles/Gemfile.rails-3.2
48
+ - rvm: 2.3.7
32
49
  gemfile: gemfiles/Gemfile.rails-3.2
33
- - rvm: 2.3.4
50
+ - rvm: 2.4.4
34
51
  gemfile: gemfiles/Gemfile.rails-3.2
35
- - rvm: 2.4.1
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
36
59
  gemfile: gemfiles/Gemfile.rails-3.2
37
- - rvm: 2.4.1
60
+ - rvm: 2.5.1
38
61
  gemfile: gemfiles/Gemfile.rails-4.0
39
- - rvm: 2.4.1
62
+ - rvm: 2.5.1
40
63
  gemfile: gemfiles/Gemfile.rails-4.1
41
- - rvm: 2.4.1
64
+ - rvm: 2.5.1
42
65
  gemfile: gemfiles/Gemfile.rails-4.2
43
66
  - rvm: ruby-head
44
67
  gemfile: gemfiles/Gemfile.rails-3.2
data/README.md CHANGED
@@ -168,9 +168,9 @@ end
168
168
 
169
169
  ## Supported versions
170
170
 
171
- * Ruby 2.0, 2.1, 2.2, 2.3, 2.4 (trunk)
171
+ * Ruby 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6 (trunk)
172
172
 
173
- * Rails 3.2.x, 4.0.x, 4.1, 4.2, 5.0, 5.1 (edge)
173
+ * Rails 3.2.x, 4.0.x, 4.1, 4.2, 5.0, 5.1, 5.2, 6.0 (edge)
174
174
 
175
175
  * HTML5 compatible browsers
176
176
 
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'railties', '~> 5.1.0'
4
+ gem 'activerecord', '~> 5.1.0'
5
+
6
+ gemspec path: '..'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'railties', '~> 5.2.0'
4
+ gem 'activerecord', '~> 5.2.0'
5
+
6
+ gemspec path: '..'
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency 'capybara', '>= 2'
25
25
  s.add_development_dependency 'sqlite3'
26
26
  s.add_development_dependency 'rake'
27
+ s.add_dependency 'activemodel'
27
28
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'rails'
3
4
 
4
5
  module Html5Validators
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Html5Validators
3
4
  module ActionViewExtension
4
5
  module FormHelper
@@ -15,7 +16,7 @@ module Html5Validators
15
16
  module PresenceValidator
16
17
  def render
17
18
  if object.class.ancestors.include?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
18
- @options["required"] ||= @options.fetch(:required) { object.class.attribute_required?(@method_name) }
19
+ @options["required"] ||= @options.fetch(:required) { object.attribute_required?(@method_name) }
19
20
  end
20
21
  super
21
22
  end
@@ -24,8 +25,8 @@ module Html5Validators
24
25
  module LengthValidator
25
26
  def render
26
27
  if object.class.ancestors.include?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
27
- @options["maxlength"] ||= @options[:maxlength] || object.class.attribute_maxlength(@method_name)
28
- @options["minlength"] ||= @options[:minlength] || object.class.attribute_minlength(@method_name)
28
+ @options["maxlength"] ||= @options[:maxlength] || object.attribute_maxlength(@method_name)
29
+ @options["minlength"] ||= @options[:minlength] || object.attribute_minlength(@method_name)
29
30
  end
30
31
  super
31
32
  end
@@ -34,8 +35,8 @@ module Html5Validators
34
35
  module NumericalityValidator
35
36
  def render
36
37
  if object.class.ancestors.include?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
37
- @options["max"] ||= @options["max"] || @options[:max] || object.class.attribute_max(@method_name)
38
- @options["min"] ||= @options["min"] || @options[:min] || object.class.attribute_min(@method_name)
38
+ @options["max"] ||= @options["max"] || @options[:max] || object.attribute_max(@method_name)
39
+ @options["min"] ||= @options["min"] || @options[:min] || object.attribute_min(@method_name)
39
40
  end
40
41
  super
41
42
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Legacy Rails 3.x support
3
4
  module ActionView
4
5
  module Helpers
@@ -17,11 +18,11 @@ module ActionView
17
18
  class InstanceTag
18
19
  def to_input_field_tag_with_html5_attributes(field_type, options = {})
19
20
  if object.class.ancestors.include?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
20
- options["required"] ||= object.class.attribute_required?(method_name)
21
- options["maxlength"] ||= object.class.attribute_maxlength(method_name)
22
- options["minlength"] ||= object.class.attribute_minlength(method_name)
23
- options["max"] ||= object.class.attribute_max(method_name)
24
- options["min"] ||= object.class.attribute_min(method_name)
21
+ options["required"] ||= object.attribute_required?(method_name)
22
+ options["maxlength"] ||= object.attribute_maxlength(method_name)
23
+ options["minlength"] ||= object.attribute_minlength(method_name)
24
+ options["max"] ||= object.attribute_max(method_name)
25
+ options["min"] ||= object.attribute_min(method_name)
25
26
  end
26
27
  to_input_field_tag_without_html5_attributes field_type, options
27
28
  end
@@ -29,9 +30,9 @@ module ActionView
29
30
 
30
31
  def to_text_area_tag_with_html5_attributes(options = {})
31
32
  if object.class.ancestors.include?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
32
- options["required"] ||= object.class.attribute_required?(method_name)
33
- options["maxlength"] ||= object.class.attribute_maxlength(method_name)
34
- options["minlength"] ||= object.class.attribute_minlength(method_name)
33
+ options["required"] ||= object.attribute_required?(method_name)
34
+ options["maxlength"] ||= object.attribute_maxlength(method_name)
35
+ options["minlength"] ||= object.attribute_minlength(method_name)
35
36
  end
36
37
  to_text_area_tag_without_html5_attributes options
37
38
  end
@@ -39,7 +40,7 @@ module ActionView
39
40
 
40
41
  def to_radio_button_tag_with_html5_attributes(tag_value, options = {})
41
42
  if object.class.ancestors.include?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
42
- options["required"] ||= object.class.attribute_required?(method_name)
43
+ options["required"] ||= object.attribute_required?(method_name)
43
44
  end
44
45
  to_radio_button_tag_without_html5_attributes tag_value, options
45
46
  end
@@ -47,7 +48,7 @@ module ActionView
47
48
 
48
49
  def to_check_box_tag_with_html5_attributes(options = {}, checked_value = "1", unchecked_value = "0")
49
50
  if object.class.ancestors.include?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
50
- options["required"] ||= object.class.attribute_required?(method_name)
51
+ options["required"] ||= object.attribute_required?(method_name)
51
52
  end
52
53
  to_check_box_tag_without_html5_attributes options, checked_value, unchecked_value
53
54
  end
@@ -1,34 +1,64 @@
1
1
  # frozen_string_literal: true
2
+
3
+ module Html5Validators
4
+ module DafaultValidationContext
5
+ if defined?(::ActiveRecord::Base) && (::ActiveRecord::VERSION::MAJOR < 5)
6
+ refine ::ActiveRecord::Base do
7
+ def default_validation_context
8
+ new_record? ? :create : :update
9
+ end
10
+ end
11
+ end
12
+ refine Object do
13
+ def default_validation_context
14
+ nil
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ using Html5Validators::DafaultValidationContext
21
+
2
22
  module ActiveModel
3
23
  module Validations
4
24
  module HelperMethods
5
25
  def attribute_required?(attribute)
6
- self.validators.grep(PresenceValidator).any? do |v|
7
- v.attributes.include?(attribute.to_sym) && (v.options.keys & [:if, :unless]).empty?
26
+ self.class.validators.grep(PresenceValidator).any? do |v|
27
+ if v.attributes.include?(attribute.to_sym) && (v.options.keys & [:if, :unless]).empty?
28
+ !(on = v.options[:on]) || Array(on).include?(default_validation_context)
29
+ end
8
30
  end
9
31
  end
10
32
 
11
33
  def attribute_maxlength(attribute)
12
- self.validators.grep(LengthValidator).select {|v|
13
- v.attributes.include?(attribute.to_sym) && (v.options.keys & [:maximum, :is]).any? && (v.options.keys & [:if, :unless, :tokenizer]).empty?
34
+ self.class.validators.grep(LengthValidator).select {|v|
35
+ if v.attributes.include?(attribute.to_sym) && (v.options.keys & [:maximum, :is]).any? && (v.options.keys & [:if, :unless, :tokenizer]).empty?
36
+ !(on = v.options[:on]) || Array(on).include?(default_validation_context)
37
+ end
14
38
  }.map {|v| v.options.slice(:maximum, :is)}.map(&:values).flatten.max
15
39
  end
16
40
 
17
41
  def attribute_minlength(attribute)
18
- self.validators.grep(LengthValidator).select {|v|
19
- v.attributes.include?(attribute.to_sym) && (v.options.keys & [:minimum, :is]).any? && (v.options.keys & [:if, :unless, :allow_nil, :allow_blank, :tokenizer]).empty?
42
+ self.class.validators.grep(LengthValidator).select {|v|
43
+ if v.attributes.include?(attribute.to_sym) && (v.options.keys & [:minimum, :is]).any? && (v.options.keys & [:if, :unless, :allow_nil, :allow_blank, :tokenizer]).empty?
44
+ !(on = v.options[:on]) || Array(on).include?(default_validation_context)
45
+ end
20
46
  }.map {|v| v.options.slice(:minimum, :is)}.map(&:values).flatten.min
21
47
  end
22
48
 
23
49
  def attribute_max(attribute)
24
- self.validators.grep(NumericalityValidator).select {|v|
25
- v.attributes.include?(attribute.to_sym) && (v.options.keys & [:less_than, :less_than_or_equal_to]).any? && (v.options.keys & [:if, :unless, :allow_nil, :allow_blank]).empty?
50
+ self.class.validators.grep(NumericalityValidator).select {|v|
51
+ if v.attributes.include?(attribute.to_sym) && (v.options.keys & [:less_than, :less_than_or_equal_to]).any? && (v.options.keys & [:if, :unless, :allow_nil, :allow_blank]).empty?
52
+ !(on = v.options[:on]) || Array(on).include?(default_validation_context)
53
+ end
26
54
  }.map {|v| v.options.slice(:less_than, :less_than_or_equal_to)}.map(&:values).flatten.max
27
55
  end
28
56
 
29
57
  def attribute_min(attribute)
30
- self.validators.grep(NumericalityValidator).select {|v|
31
- v.attributes.include?(attribute.to_sym) && (v.options.keys & [:greater_than, :greater_than_or_equal_to]).any? && (v.options.keys & [:if, :unless, :allow_nil, :allow_blank]).empty?
58
+ self.class.validators.grep(NumericalityValidator).select {|v|
59
+ if v.attributes.include?(attribute.to_sym) && (v.options.keys & [:greater_than, :greater_than_or_equal_to]).any? && (v.options.keys & [:if, :unless, :allow_nil, :allow_blank]).empty?
60
+ !(on = v.options[:on]) || Array(on).include?(default_validation_context)
61
+ end
32
62
  }.map {|v| v.options.slice(:greater_than, :greater_than_or_equal_to)}.map(&:values).flatten.min
33
63
  end
34
64
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Html5Validators
3
4
  module ActiveModelExtension
4
5
  extend ActiveSupport::Concern
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Html5Validators
3
4
  module ActiveRecordExtension
4
5
  extend ActiveSupport::Concern
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Html5Validators
3
- VERSION = '1.7.0'
4
+ VERSION = '1.8.0'
4
5
  end
data/test/fake_app.rb CHANGED
@@ -1,19 +1,21 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'active_record'
3
4
  require 'action_controller/railtie'
4
5
 
5
6
  # config
6
7
  ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
7
8
 
8
- app = Class.new(Rails::Application)
9
- app.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!"
10
- app.config.session_store :cookie_store, key: '_myapp_session'
11
- app.config.active_support.deprecation = :log
12
- app.config.eager_load = false
13
- app.initialize!
9
+ class Html5ValidatorsTestApp < Rails::Application
10
+ 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
+ config.session_store :cookie_store, key: '_myapp_session'
12
+ config.active_support.deprecation = :log
13
+ config.eager_load = false
14
+ end
15
+ Rails.application.initialize!
14
16
 
15
17
  # routes
16
- app.routes.draw do
18
+ Rails.application.routes.draw do
17
19
  resources :people, only: [:new, :create] do
18
20
  collection do
19
21
  get :new_without_html5_validation
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class ActiveModelValidationTest < ActionDispatch::IntegrationTest
6
+ teardown do
7
+ Item._validators.clear
8
+ end
9
+
10
+ sub_test_case 'without validation' do
11
+ test 'new form' do
12
+ visit '/items/new'
13
+ assert page.has_css? 'input#item_name'
14
+ assert page.has_no_css? 'input#item_name[required=required]'
15
+ end
16
+
17
+ test 'new_without_html5_validation form' do
18
+ 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]'
21
+ end
22
+ end
23
+
24
+ sub_test_case 'with required validation' do
25
+ setup do
26
+ Item.validates_presence_of :name, :description
27
+ end
28
+ test 'new form' do
29
+ visit '/items/new'
30
+
31
+ assert_equal 'required', find('input#item_name')[:required]
32
+ assert_equal 'required', find('textarea#item_description')[:required]
33
+ end
34
+ test 'new_without_html5_validation form' do
35
+ visit '/items/new_without_html5_validation'
36
+
37
+ assert_nil find('input#item_name')[:required]
38
+ end
39
+ test 'new_with_required_true form' do
40
+ visit '/items/new_with_required_true'
41
+
42
+ assert_equal 'required', find('input#item_name')[:required]
43
+ end
44
+ test 'new_with_required_false form' do
45
+ visit '/items/new_with_required_false'
46
+
47
+ assert_nil find('input#item_name')[:required]
48
+ end
49
+ sub_test_case 'disabling html5_validation in class level' do
50
+ setup do
51
+ Item.class_eval do |kls|
52
+ kls.auto_html5_validation = false
53
+ end
54
+ end
55
+ teardown do
56
+ Item.class_eval do |kls|
57
+ kls.auto_html5_validation = nil
58
+ end
59
+ end
60
+ test 'new form' do
61
+ visit '/items/new'
62
+
63
+ assert_nil find('input#item_name')[:required]
64
+ end
65
+ end
66
+
67
+ sub_test_case 'disabling html5_validations in gem' do
68
+ setup do
69
+ Html5Validators.enabled = false
70
+ end
71
+ teardown do
72
+ Html5Validators.enabled = true
73
+ end
74
+ test 'new form' do
75
+ visit '/items/new'
76
+
77
+ assert_nil find('input#item_name')[:required]
78
+ assert_nil find('textarea#item_description')[:required]
79
+ end
80
+ end
81
+ end
82
+
83
+ sub_test_case 'with maxlength validation' do
84
+ setup do
85
+ Item.validates_length_of :name, maximum: 20
86
+ Item.validates_length_of :description, maximum: 100
87
+ end
88
+
89
+ test 'new form' do
90
+ visit '/items/new'
91
+
92
+ assert_equal '20', find('input#item_name')[:maxlength]
93
+ assert_equal '100', find('textarea#item_description')[:maxlength]
94
+ end
95
+ end
96
+
97
+ sub_test_case 'with minlength validation' do
98
+ setup do
99
+ Item.validates_length_of :name, minimum: 3
100
+ Item.validates_length_of :description, minimum: 10
101
+ end
102
+
103
+ test 'new form' do
104
+ visit '/items/new'
105
+
106
+ assert_equal '3', find('input#item_name')[:minlength]
107
+ assert_equal '10', find('textarea#item_description')[:minlength]
108
+ end
109
+ end
110
+ end
@@ -1,7 +1,12 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
 
4
5
  class ActiveRecordValidationTest < ActionDispatch::IntegrationTest
6
+ teardown do
7
+ Person._validators.clear
8
+ end
9
+
5
10
  sub_test_case 'without validation' do
6
11
  test 'new form' do
7
12
  visit '/people/new'
@@ -20,9 +25,6 @@ class ActiveRecordValidationTest < ActionDispatch::IntegrationTest
20
25
  setup do
21
26
  Person.validates_presence_of :name, :bio
22
27
  end
23
- teardown do
24
- Person._validators.clear
25
- end
26
28
  test 'new form' do
27
29
  visit '/people/new'
28
30
 
@@ -105,110 +107,31 @@ class ActiveRecordValidationTest < ActionDispatch::IntegrationTest
105
107
  assert_equal '10', find('textarea#person_bio')[:minlength]
106
108
  end
107
109
  end
108
- end
109
-
110
- class ActiveModelValidationTest < ActionDispatch::IntegrationTest
111
- sub_test_case 'without validation' do
112
- test 'new form' do
113
- visit '/items/new'
114
- assert page.has_css? 'input#item_name'
115
- assert page.has_no_css? 'input#item_name[required=required]'
116
- end
117
-
118
- test 'new_without_html5_validation form' do
119
- visit '/items/new_without_html5_validation'
120
- assert page.has_css? 'textarea#item_description'
121
- assert page.has_no_css? 'textarea#item_description[required=required]'
122
- end
123
- end
124
110
 
125
- sub_test_case 'with required validation' do
126
- setup do
127
- Item.validates_presence_of :name, :description
128
- end
129
- teardown do
130
- Item._validators.clear
131
- end
132
- test 'new form' do
133
- visit '/items/new'
134
-
135
- assert_equal 'required', find('input#item_name')[:required]
136
- assert_equal 'required', find('textarea#item_description')[:required]
137
- end
138
- test 'new_without_html5_validation form' do
139
- visit '/items/new_without_html5_validation'
140
-
141
- assert_nil find('input#item_name')[:required]
142
- end
143
- test 'new_with_required_true form' do
144
- visit '/items/new_with_required_true'
145
-
146
- assert_equal 'required', find('input#item_name')[:required]
147
- end
148
- test 'new_with_required_false form' do
149
- visit '/items/new_with_required_false'
150
-
151
- assert_nil find('input#item_name')[:required]
152
- end
153
- sub_test_case 'disabling html5_validation in class level' do
111
+ sub_test_case 'validation with context' do
112
+ sub_test_case 'with an active context' do
154
113
  setup do
155
- Item.class_eval do |kls|
156
- kls.auto_html5_validation = false
157
- end
158
- end
159
- teardown do
160
- Item.class_eval do |kls|
161
- kls.auto_html5_validation = nil
162
- end
114
+ Person.validates_presence_of :name, on: :create
115
+ Person.validates_length_of :bio, maximum: 100, on: :create
163
116
  end
164
117
  test 'new form' do
165
- visit '/items/new'
118
+ visit '/people/new'
166
119
 
167
- assert_nil find('input#item_name')[:required]
120
+ assert_equal 'required', find('input#person_name')[:required]
121
+ assert_equal '100', find('textarea#person_bio')[:maxlength]
168
122
  end
169
123
  end
170
124
 
171
- sub_test_case 'disabling html5_validations in gem' do
125
+ sub_test_case 'without an active context' do
172
126
  setup do
173
- Html5Validators.enabled = false
174
- end
175
- teardown do
176
- Html5Validators.enabled = true
127
+ Person.validates_presence_of :name, on: :update
177
128
  end
178
129
  test 'new form' do
179
- visit '/items/new'
130
+ visit '/people/new'
180
131
 
181
- assert_nil find('input#item_name')[:required]
182
- assert_nil find('textarea#item_description')[:required]
132
+ assert_nil find('input#person_name')[:required]
133
+ assert_nil find('textarea#person_bio')[:maxlength]
183
134
  end
184
135
  end
185
136
  end
186
-
187
- sub_test_case 'with maxlength validation' do
188
- setup do
189
- Item.validates_length_of :name, maximum: 20
190
- Item.validates_length_of :description, maximum: 100
191
- end
192
-
193
- test 'new form' do
194
- visit '/items/new'
195
-
196
- assert_equal '20', find('input#item_name')[:maxlength]
197
- assert_equal '100', find('textarea#item_description')[:maxlength]
198
- end
199
- end
200
-
201
- sub_test_case 'with minlength validation' do
202
- setup do
203
- Item.validates_length_of :name, minimum: 3
204
- Item.validates_length_of :description, minimum: 10
205
- end
206
-
207
- test 'new form' do
208
- visit '/items/new'
209
-
210
- assert_equal '3', find('input#item_name')[:minlength]
211
- assert_equal '10', find('textarea#item_description')[:minlength]
212
- end
213
- end
214
137
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
 
4
5
  if defined? ActiveRecord
data/test/test_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
4
5
  # load Rails first
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html5_validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.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: 2017-04-06 00:00:00.000000000 Z
11
+ date: 2018-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit-rails
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activemodel
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: A gem/plugin for Rails 3+ that enables client-side validation using ActiveModel
70
84
  + HTML5
71
85
  email:
@@ -85,6 +99,8 @@ files:
85
99
  - gemfiles/Gemfile.rails-4.1
86
100
  - gemfiles/Gemfile.rails-4.2
87
101
  - gemfiles/Gemfile.rails-5.0
102
+ - gemfiles/Gemfile.rails-5.1
103
+ - gemfiles/Gemfile.rails-5.2
88
104
  - gemfiles/Gemfile.rails-edge
89
105
  - html5_validators.gemspec
90
106
  - lib/html5_validators.rb
@@ -95,7 +111,8 @@ files:
95
111
  - lib/html5_validators/active_record/base.rb
96
112
  - lib/html5_validators/version.rb
97
113
  - test/fake_app.rb
98
- - test/features/validation_test.rb
114
+ - test/features/active_model_validation_test.rb
115
+ - test/features/active_record_validation_test.rb
99
116
  - test/models/active_record/inherited_test.rb
100
117
  - test/test_helper.rb
101
118
  homepage: https://github.com/amatsuda/html5_validators
@@ -118,12 +135,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
135
  version: '0'
119
136
  requirements: []
120
137
  rubyforge_project: html5_validators
121
- rubygems_version: 2.6.11
138
+ rubygems_version: 2.7.7
122
139
  signing_key:
123
140
  specification_version: 4
124
141
  summary: Automatic client side validation using HTML5 Form Validation
125
142
  test_files:
126
143
  - test/fake_app.rb
127
- - test/features/validation_test.rb
144
+ - test/features/active_model_validation_test.rb
145
+ - test/features/active_record_validation_test.rb
128
146
  - test/models/active_record/inherited_test.rb
129
147
  - test/test_helper.rb