html5_validators 1.2.1 → 1.2.2

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
  SHA1:
3
- metadata.gz: 8319ea0984eb251c4502993396dbe73647a0bb58
4
- data.tar.gz: cccc1f09e688476c89396e54c79de9fcf68a046e
3
+ metadata.gz: 63928996c2fdfa1f44d24b9b3d700a92e80f7ed2
4
+ data.tar.gz: 60ec0b62245120edc8c0cf648e50a94bdab847cf
5
5
  SHA512:
6
- metadata.gz: fbce3243954f598eef6c8815d37de9e95440aa5bd4e1e0d2eca758534e3f81f5c3c25f52bec31afa04257a2b102c4d02e114e56eac44a729e55fa89793e86eb9
7
- data.tar.gz: e920c577a538f5a799fefb5011aa133943e70a945037efa489cbc207230507d1ee89d96feddbf612a7c14645c87ee4095bda3df1b349b9100070c6bff9bc3a4e
6
+ metadata.gz: 3dd2029d72894922add01d958671899900eb3b8cc845af472bfe5e1125d3a55a9ec65d735fb501b1fbe5852868bda55613556944d56959f3e3dcba15d5cdad2e
7
+ data.tar.gz: 1121140455094da97eaec98714014ded79a9d6e54bdea1733853e3c5e8335a703d09073fdf6da32f04caecbc4311bf3d1119e427ec6a668892fc31a31475e1f5
@@ -1,5 +1,17 @@
1
+ module Html5Validators
2
+ module ActiveModelExtension
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ cattr_accessor :auto_html5_validation, :instance_accessor => false, :instance_reader => false, :instance_writer => false
7
+ end
8
+ end
9
+ end
10
+
1
11
  module ActiveModel
2
12
  module Validations
3
13
  attr_accessor :auto_html5_validation
4
14
  end
5
15
  end
16
+
17
+ ActiveModel::Validations.send(:include, Html5Validators::ActiveModelExtension)
@@ -1,3 +1,3 @@
1
1
  module Html5Validators
2
- VERSION = '1.2.1'
2
+ VERSION = '1.2.2'
3
3
  end
data/spec/fake_app.rb CHANGED
@@ -19,11 +19,28 @@ app.routes.draw do
19
19
  get :new_with_required_true
20
20
  end
21
21
  end
22
+ resources :items, :only => [:new, :create] do
23
+ collection do
24
+ get :new_without_html5_validation
25
+ get :new_with_required_true
26
+ end
27
+ end
22
28
  end
23
29
 
24
30
  # models
25
31
  class Person < ActiveRecord::Base
26
32
  end
33
+ class Item
34
+ if ActiveModel::VERSION::STRING >= '4'
35
+ include ActiveModel::Model
36
+ else
37
+ include ActiveModel::Validations
38
+ include ActiveModel::Conversion
39
+ def persisted?; false; end
40
+ end
41
+
42
+ attr_accessor :name, :description
43
+ end
27
44
 
28
45
  # controllers
29
46
  class ApplicationController < ActionController::Base; end
@@ -57,6 +74,36 @@ ERB
57
74
  ERB
58
75
  end
59
76
  end
77
+ class ItemsController < ApplicationController
78
+ def new
79
+ @item = Item.new
80
+ render :inline => <<-ERB
81
+ <%= form_for @item do |f| %>
82
+ <%= f.text_field :name %>
83
+ <%= f.text_area :description %>
84
+ <% end %>
85
+ ERB
86
+ end
87
+
88
+ def new_without_html5_validation
89
+ @item = Item.new
90
+ render :inline => <<-ERB
91
+ <%= form_for @item, :auto_html5_validation => false do |f| %>
92
+ <%= f.text_field :name %>
93
+ <%= f.text_area :description %>
94
+ <% end %>
95
+ ERB
96
+ end
97
+
98
+ def new_with_required_true
99
+ @item = Item.new
100
+ render :inline => <<-ERB
101
+ <%= form_for @item do |f| %>
102
+ <%= f.text_field :name, :required => true %>
103
+ <% end %>
104
+ ERB
105
+ end
106
+ end
60
107
 
61
108
  # helpers
62
109
  module ApplicationHelper; end
@@ -87,3 +87,91 @@ feature 'person#new' do
87
87
  end
88
88
  end
89
89
  end
90
+
91
+ feature 'item#new' do
92
+ context 'without validation' do
93
+ scenario 'new form' do
94
+ visit '/items/new'
95
+ page.should have_css('input#item_name')
96
+ page.should_not have_css('input#item_name[required=required]')
97
+ end
98
+
99
+ scenario 'new_without_html5_validation form' do
100
+ visit '/items/new_without_html5_validation'
101
+ page.should have_css('textarea#item_description')
102
+ page.should_not have_css('textarea#item_description[required=required]')
103
+ end
104
+ end
105
+
106
+ context 'with required validation' do
107
+ background do
108
+ Item.validates_presence_of :name, :description
109
+ end
110
+ after do
111
+ Item._validators.clear
112
+ end
113
+ scenario 'new form' do
114
+ visit '/items/new'
115
+
116
+ find('input#item_name')[:required].should == 'required'
117
+ find('textarea#item_description')[:required].should == 'required'
118
+ end
119
+ scenario 'new_without_html5_validation form' do
120
+ visit '/items/new_without_html5_validation'
121
+
122
+ find('input#item_name')[:required].should be_nil
123
+ end
124
+ scenario 'new_with_required_true form' do
125
+ visit '/items/new_with_required_true'
126
+
127
+ find('input#item_name')[:required].should == 'required'
128
+ end
129
+
130
+ context 'disabling html5_validation in class level' do
131
+ background do
132
+ Item.class_eval do |kls|
133
+ kls.auto_html5_validation = false
134
+ end
135
+ end
136
+ after do
137
+ Item.class_eval do |kls|
138
+ kls.auto_html5_validation = nil
139
+ end
140
+ end
141
+ scenario 'new form' do
142
+ visit '/items/new'
143
+
144
+ find('input#item_name')[:required].should be_nil
145
+ end
146
+ end
147
+
148
+ context 'disabling html5_validations in gem' do
149
+ background do
150
+ Html5Validators.enabled = false
151
+ end
152
+ after do
153
+ Html5Validators.enabled = true
154
+ end
155
+ scenario 'new form' do
156
+ visit '/items/new'
157
+
158
+ find('input#item_name')[:required].should be_nil
159
+ find('textarea#item_description')[:required].should be_nil
160
+ end
161
+ end
162
+ end
163
+
164
+ context 'with maxlength validation' do
165
+ background do
166
+ Item.validates_length_of :name, {:maximum => 20 }
167
+ Item.validates_length_of :description, {:maximum => 100}
168
+ end
169
+
170
+ scenario 'new form' do
171
+ visit '/items/new'
172
+
173
+ find('input#item_name')[:maxlength].should == '20'
174
+ find('textarea#item_description')[:maxlength].should == '100'
175
+ end
176
+ end
177
+ end
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.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-29 00:00:00.000000000 Z
11
+ date: 2015-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-rails