parsley_simple_form 0.0.4 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/README.md +2 -0
- data/lib/parsley_simple_form/action_view_extensions/form_helper.rb +4 -2
- data/lib/parsley_simple_form/concerns/range_concern.rb +29 -0
- data/lib/parsley_simple_form/concerns/type_sensitive_concern.rb +28 -0
- data/lib/parsley_simple_form/constraints/basics/equalto_constraint.rb +2 -2
- data/lib/parsley_simple_form/constraints/basics/max_constraint.rb +23 -0
- data/lib/parsley_simple_form/constraints/basics/maxcheck_constraint.rb +23 -0
- data/lib/parsley_simple_form/constraints/basics/maxlength_constraint.rb +20 -0
- data/lib/parsley_simple_form/constraints/basics/min_constraint.rb +22 -0
- data/lib/parsley_simple_form/constraints/basics/mincheck_constraint.rb +23 -0
- data/lib/parsley_simple_form/constraints/basics/minlength_constraint.rb +20 -0
- data/lib/parsley_simple_form/constraints/basics/notblank_constraint.rb +1 -1
- data/lib/parsley_simple_form/constraints/basics/range_constraint.rb +21 -0
- data/lib/parsley_simple_form/constraints/basics/rangecheck_constraint.rb +25 -0
- data/lib/parsley_simple_form/constraints/basics/rangelength_constraint.rb +21 -0
- data/lib/parsley_simple_form/constraints/basics/regexp_constraint.rb +23 -0
- data/lib/parsley_simple_form/constraints/basics/required_constraint.rb +1 -1
- data/lib/parsley_simple_form/constraints/basics/type_constraint.rb +5 -14
- data/lib/parsley_simple_form/form_builder.rb +16 -27
- data/lib/parsley_simple_form/railtie.rb +1 -0
- data/lib/parsley_simple_form/version.rb +1 -1
- data/test/dummy/log/test.log +4129 -0
- data/test/form_builder/constraints_test.rb +139 -0
- data/test/form_builder/type_test.rb +60 -0
- data/test/form_helper_test.rb +1 -1
- data/test/support/i18n_helper.rb +7 -0
- data/test/support/models.rb +1 -0
- data/test/test_helper.rb +1 -2
- metadata +33 -17
- data/test/form_builder_test.rb +0 -57
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ConstraintsTest < ActionView::TestCase
|
4
|
+
|
5
|
+
test 'builder input is html safe' do
|
6
|
+
parsley_form_for @user do |f|
|
7
|
+
assert f.input(:name).html_safe?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'adds a valid constraint type i18n' do
|
12
|
+
with_parsley_form_for @user do |f|
|
13
|
+
f.input :credit_limit
|
14
|
+
end
|
15
|
+
assert_select 'input[data-parsley-type-number-message]'
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'doesnt add invalid constraint type i18n' do
|
19
|
+
with_parsley_form_for @user do |f|
|
20
|
+
f.input :name
|
21
|
+
end
|
22
|
+
assert_select 'input[data-parsley-type-string-message]', 0
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'required constraint' do
|
26
|
+
with_parsley_form_for @user do |f|
|
27
|
+
f.input :name, required: true
|
28
|
+
end
|
29
|
+
assert_select 'input[data-parsley-required-message]'
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'equalto constraint' do
|
33
|
+
with_parsley_form_for @user do |f|
|
34
|
+
f.input :password, required: true
|
35
|
+
f.input :confirm_password, :equalto => :password
|
36
|
+
end
|
37
|
+
assert_select 'input[data-parsley-equalto="#user_password"]'
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'equalto constraint on nested form' do
|
41
|
+
with_parsley_form_for @user do |f|
|
42
|
+
f.simple_fields_for @post do |posts_form|
|
43
|
+
posts_form.input :password
|
44
|
+
posts_form.input :password_confirmation, equalto: :password
|
45
|
+
end
|
46
|
+
end
|
47
|
+
assert_select 'input[data-parsley-equalto="#user_post_attributes_password"]'
|
48
|
+
end
|
49
|
+
|
50
|
+
test 'minlenght constraint' do
|
51
|
+
with_parsley_form_for @user do |f|
|
52
|
+
f.input :password, minlength: 10
|
53
|
+
end
|
54
|
+
assert_select 'input[data-parsley-minlength=10]'
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'maxlenght constraint' do
|
58
|
+
with_parsley_form_for @user do |f|
|
59
|
+
f.input :password, maxlength: 5
|
60
|
+
end
|
61
|
+
assert_select 'input[data-parsley-maxlength=5]'
|
62
|
+
end
|
63
|
+
|
64
|
+
test 'rangelenght constraint with string parameter' do
|
65
|
+
mock_i18n({ :form_validation => { :message => { :rangelength => "%{min},%{max}" } } })
|
66
|
+
with_parsley_form_for @user do |f|
|
67
|
+
f.input :password, rangelength: "[1,5]"
|
68
|
+
end
|
69
|
+
assert_select "input[data-parsley-rangelength='[1,5]'][data-parsley-rangelength-message=1,5]"
|
70
|
+
end
|
71
|
+
|
72
|
+
test 'rangelength constraint with Range object as parameter' do
|
73
|
+
mock_i18n({ :form_validation => { :message => { :rangelength => "%{min},%{max}" } } })
|
74
|
+
with_parsley_form_for @user do |f|
|
75
|
+
f.input :password, rangelength: 1..5
|
76
|
+
end
|
77
|
+
assert_select "input[data-parsley-rangelength='[1,5]'][data-parsley-rangelength-message=1,5]"
|
78
|
+
end
|
79
|
+
|
80
|
+
test 'notblank constraint' do
|
81
|
+
with_parsley_form_for @user do |f|
|
82
|
+
f.input :email, notblank: true
|
83
|
+
end
|
84
|
+
assert_select 'input[data-parsley-notblank]'
|
85
|
+
end
|
86
|
+
|
87
|
+
test 'min constraint' do
|
88
|
+
mock_i18n({ :form_validation => { :message => { :min => "%{min}" } } })
|
89
|
+
with_parsley_form_for @user do |f|
|
90
|
+
f.input :credit_limit, min: 6
|
91
|
+
end
|
92
|
+
assert_select 'input[data-parsley-min-message=6][min=6][type=number]'
|
93
|
+
end
|
94
|
+
|
95
|
+
test 'max constraint' do
|
96
|
+
mock_i18n({ :form_validation => { :message => { :max => "%{max}" } } })
|
97
|
+
with_parsley_form_for @user do |f|
|
98
|
+
f.input :credit_limit, input_html: { max: 6 }
|
99
|
+
end
|
100
|
+
assert_select 'input[data-parsley-max-message=6][max=6][type=number]'
|
101
|
+
end
|
102
|
+
|
103
|
+
test 'range constraint with Range object as parameter' do
|
104
|
+
mock_i18n({ :form_validation => { :message => { :range => "%{min},%{max}" } } })
|
105
|
+
with_parsley_form_for @user do |f|
|
106
|
+
f.input :credit_limit, range: 1000..5000
|
107
|
+
end
|
108
|
+
assert_select "input[data-parsley-range='[1000,5000]'][data-parsley-range-message=1000,5000]"
|
109
|
+
end
|
110
|
+
|
111
|
+
test 'regexp constraint' do
|
112
|
+
with_parsley_form_for @user do |f|
|
113
|
+
f.input :name, regexp: "$@"
|
114
|
+
end
|
115
|
+
assert_select "input[pattern=$@]"
|
116
|
+
end
|
117
|
+
|
118
|
+
test 'min check' do
|
119
|
+
with_parsley_form_for @user do |f|
|
120
|
+
f.input :active, mincheck: 2, check_group: 'group'
|
121
|
+
end
|
122
|
+
assert_select "input[data-parsley-mincheck=2][data-parsley-group=group]"
|
123
|
+
end
|
124
|
+
|
125
|
+
test 'max check' do
|
126
|
+
with_parsley_form_for @user do |f|
|
127
|
+
f.input :active, maxcheck: 1
|
128
|
+
end
|
129
|
+
assert_select "input[data-parsley-maxcheck=1]"
|
130
|
+
end
|
131
|
+
|
132
|
+
test 'range check' do
|
133
|
+
with_parsley_form_for @user do |f|
|
134
|
+
f.input :active, rangecheck: 0..1
|
135
|
+
end
|
136
|
+
assert_select "input[data-parsley-rangecheck='[0,1]']"
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TypeTest < ActionView::TestCase
|
4
|
+
|
5
|
+
test "email" do
|
6
|
+
with_parsley_form_for @user do |f|
|
7
|
+
f.input :email
|
8
|
+
end
|
9
|
+
assert_select 'input[type=email]'
|
10
|
+
end
|
11
|
+
|
12
|
+
test "url" do
|
13
|
+
with_parsley_form_for @user do |f|
|
14
|
+
f.input :action, as: :url
|
15
|
+
end
|
16
|
+
assert_select 'input[type=url]'
|
17
|
+
end
|
18
|
+
|
19
|
+
test "digits" do
|
20
|
+
with_parsley_form_for @user do |f|
|
21
|
+
f.input :lock_version
|
22
|
+
end
|
23
|
+
assert_select 'input[data-parsley-type=digits]'
|
24
|
+
end
|
25
|
+
|
26
|
+
test "number" do
|
27
|
+
with_parsley_form_for @user do |f|
|
28
|
+
f.input :age
|
29
|
+
end
|
30
|
+
assert_select 'input[type=number]'
|
31
|
+
end
|
32
|
+
|
33
|
+
test "phone" do
|
34
|
+
with_parsley_form_for @user do |f|
|
35
|
+
f.input :phone_number, as: :tel
|
36
|
+
end
|
37
|
+
assert_select 'input[type=tel]'
|
38
|
+
end
|
39
|
+
|
40
|
+
test "alphanum" do
|
41
|
+
with_parsley_form_for @user do |f|
|
42
|
+
f.input :action, input_html: { :'data-parsley-type' => 'alphanum' }
|
43
|
+
end
|
44
|
+
assert_select 'input[data-parsley-type=alphanum]'
|
45
|
+
end
|
46
|
+
|
47
|
+
test "date iso" do
|
48
|
+
with_parsley_form_for @user do |f|
|
49
|
+
f.input :created_at, as: :string, input_html: { :'data-parsley-type' => 'dateIso' }
|
50
|
+
end
|
51
|
+
assert_select 'input[data-parsley-type=dateIso]'
|
52
|
+
end
|
53
|
+
|
54
|
+
test "url strict" do
|
55
|
+
with_parsley_form_for @user do |f|
|
56
|
+
f.input :action, input_html: { :'data-parsley-type' => 'urlstrict' }
|
57
|
+
end
|
58
|
+
assert_select 'input[data-parsley-type=urlstrict]'
|
59
|
+
end
|
60
|
+
end
|
data/test/form_helper_test.rb
CHANGED
data/test/support/models.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -15,8 +15,6 @@ require "rails/generators/test_case"
|
|
15
15
|
|
16
16
|
require 'simple_form'
|
17
17
|
|
18
|
-
require_relative 'support/models'
|
19
|
-
|
20
18
|
module Rails
|
21
19
|
def self.env
|
22
20
|
ActiveSupport::StringInquirer.new("test")
|
@@ -36,6 +34,7 @@ end
|
|
36
34
|
class ActionView::TestCase
|
37
35
|
include SimpleForm::ActionViewExtensions::FormHelper
|
38
36
|
include ParsleySimpleForm::ActionViewExtensions::FormHelper
|
37
|
+
include I18nHelper
|
39
38
|
|
40
39
|
setup :setup_users
|
41
40
|
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parsley_simple_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guilherme Moretti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>'
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.2
|
19
|
+
version: '3.2'
|
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: 3.2
|
26
|
+
version: '3.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: simple_form
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '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
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: parsley-rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: sqlite3
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: Client side validation with parsley and simple_form.
|
@@ -76,17 +76,31 @@ files:
|
|
76
76
|
- lib/tasks/parsley_simple_form_tasks.rake
|
77
77
|
- lib/parsley_simple_form.rb
|
78
78
|
- lib/parsley_simple_form/action_view_extensions/form_helper.rb
|
79
|
+
- lib/parsley_simple_form/concerns/type_sensitive_concern.rb
|
80
|
+
- lib/parsley_simple_form/concerns/range_concern.rb
|
79
81
|
- lib/parsley_simple_form/constraints/base_constraint.rb
|
80
82
|
- lib/parsley_simple_form/constraints/basics/equalto_constraint.rb
|
83
|
+
- lib/parsley_simple_form/constraints/basics/range_constraint.rb
|
84
|
+
- lib/parsley_simple_form/constraints/basics/mincheck_constraint.rb
|
85
|
+
- lib/parsley_simple_form/constraints/basics/minlength_constraint.rb
|
81
86
|
- lib/parsley_simple_form/constraints/basics/type_constraint.rb
|
87
|
+
- lib/parsley_simple_form/constraints/basics/rangelength_constraint.rb
|
88
|
+
- lib/parsley_simple_form/constraints/basics/min_constraint.rb
|
89
|
+
- lib/parsley_simple_form/constraints/basics/regexp_constraint.rb
|
90
|
+
- lib/parsley_simple_form/constraints/basics/rangecheck_constraint.rb
|
91
|
+
- lib/parsley_simple_form/constraints/basics/maxlength_constraint.rb
|
82
92
|
- lib/parsley_simple_form/constraints/basics/notblank_constraint.rb
|
83
93
|
- lib/parsley_simple_form/constraints/basics/required_constraint.rb
|
94
|
+
- lib/parsley_simple_form/constraints/basics/maxcheck_constraint.rb
|
95
|
+
- lib/parsley_simple_form/constraints/basics/max_constraint.rb
|
84
96
|
- lib/parsley_simple_form/form_builder.rb
|
85
97
|
- lib/parsley_simple_form/railtie.rb
|
86
98
|
- lib/parsley_simple_form/version.rb
|
87
99
|
- MIT-LICENSE
|
88
100
|
- Rakefile
|
89
101
|
- README.md
|
102
|
+
- test/form_builder/type_test.rb
|
103
|
+
- test/form_builder/constraints_test.rb
|
90
104
|
- test/test_helper.rb
|
91
105
|
- test/parsley_simple_form_test.rb
|
92
106
|
- test/dummy/Rakefile
|
@@ -120,7 +134,7 @@ files:
|
|
120
134
|
- test/dummy/app/assets/stylesheets/application.css
|
121
135
|
- test/dummy/app/assets/javascripts/application.js
|
122
136
|
- test/support/models.rb
|
123
|
-
- test/
|
137
|
+
- test/support/i18n_helper.rb
|
124
138
|
- test/form_helper_test.rb
|
125
139
|
homepage: http://github.com/innvent/parsley_simple_form
|
126
140
|
licenses:
|
@@ -132,21 +146,23 @@ require_paths:
|
|
132
146
|
- lib
|
133
147
|
required_ruby_version: !ruby/object:Gem::Requirement
|
134
148
|
requirements:
|
135
|
-
- -
|
149
|
+
- - '>='
|
136
150
|
- !ruby/object:Gem::Version
|
137
151
|
version: '0'
|
138
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
153
|
requirements:
|
140
|
-
- -
|
154
|
+
- - '>='
|
141
155
|
- !ruby/object:Gem::Version
|
142
156
|
version: '0'
|
143
157
|
requirements: []
|
144
158
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.0.
|
159
|
+
rubygems_version: 2.0.14
|
146
160
|
signing_key:
|
147
161
|
specification_version: 4
|
148
162
|
summary: Client side validation with parsley and simple_form.
|
149
163
|
test_files:
|
164
|
+
- test/form_builder/type_test.rb
|
165
|
+
- test/form_builder/constraints_test.rb
|
150
166
|
- test/test_helper.rb
|
151
167
|
- test/parsley_simple_form_test.rb
|
152
168
|
- test/dummy/Rakefile
|
@@ -180,5 +196,5 @@ test_files:
|
|
180
196
|
- test/dummy/app/assets/stylesheets/application.css
|
181
197
|
- test/dummy/app/assets/javascripts/application.js
|
182
198
|
- test/support/models.rb
|
183
|
-
- test/
|
199
|
+
- test/support/i18n_helper.rb
|
184
200
|
- test/form_helper_test.rb
|
data/test/form_builder_test.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class FormBuilderTest < ActionView::TestCase
|
4
|
-
|
5
|
-
test 'builder input is html safe' do
|
6
|
-
parsley_form_for @user do |f|
|
7
|
-
assert f.input(:name).html_safe?
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
test 'adds a valid constraint type i18n' do
|
12
|
-
with_parsley_form_for @user do |f|
|
13
|
-
f.input :credit_limit
|
14
|
-
end
|
15
|
-
assert_select 'input'
|
16
|
-
end
|
17
|
-
|
18
|
-
test 'doesnt add invalid constraint type i18n' do
|
19
|
-
with_parsley_form_for @user do |f|
|
20
|
-
f.input :name
|
21
|
-
end
|
22
|
-
assert_select 'input[data-type-string-message]', 0
|
23
|
-
end
|
24
|
-
|
25
|
-
test 'required constraint' do
|
26
|
-
with_parsley_form_for @user do |f|
|
27
|
-
f.input :name, required: true
|
28
|
-
end
|
29
|
-
assert_select 'input[data-required-message]'
|
30
|
-
end
|
31
|
-
|
32
|
-
test 'equalto constraint' do
|
33
|
-
with_parsley_form_for @user do |f|
|
34
|
-
f.input :password, required: true
|
35
|
-
f.input :confirm_password, :equalto => :password
|
36
|
-
end
|
37
|
-
assert_select 'input[data-equalto="#user_password"]'
|
38
|
-
end
|
39
|
-
|
40
|
-
test 'equalto constraint on nested form' do
|
41
|
-
with_parsley_form_for @user do |f|
|
42
|
-
f.simple_fields_for @post do |posts_form|
|
43
|
-
posts_form.input :password
|
44
|
-
posts_form.input :password_confirmation, equalto: :password
|
45
|
-
end
|
46
|
-
end
|
47
|
-
assert_select 'input[data-equalto="#user_post_attributes_password"]'
|
48
|
-
end
|
49
|
-
|
50
|
-
test 'notblank constraint' do
|
51
|
-
with_parsley_form_for @user do |f|
|
52
|
-
f.input :email, notblank: true
|
53
|
-
end
|
54
|
-
assert_select 'input[data-notblank]'
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|