client_side_validations 3.1.5 → 3.2.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/client_side_validations.gemspec +1 -9
- data/lib/client_side_validations.rb +6 -2
- data/lib/client_side_validations/action_view/form_builder.rb +4 -2
- data/lib/client_side_validations/action_view/form_helper.rb +15 -7
- data/lib/client_side_validations/active_model.rb +5 -2
- data/lib/client_side_validations/active_record.rb +2 -1
- data/lib/client_side_validations/active_record/middleware.rb +15 -2
- data/lib/client_side_validations/active_record/uniqueness.rb +0 -1
- data/lib/client_side_validations/core_ext/regexp.rb +1 -1
- data/lib/client_side_validations/middleware.rb +40 -16
- data/lib/client_side_validations/version.rb +1 -1
- data/lib/generators/templates/client_side_validations/initializer.rb +0 -3
- data/vendor/assets/javascripts/rails.validations.js +135 -170
- metadata +22 -329
- data/lib/client_side_validations/formtastic.rb +0 -21
- data/lib/client_side_validations/mongo_mapper.rb +0 -9
- data/lib/client_side_validations/mongo_mapper/middleware.rb +0 -20
- data/lib/client_side_validations/mongo_mapper/uniqueness.rb +0 -29
- data/lib/client_side_validations/mongoid.rb +0 -9
- data/lib/client_side_validations/mongoid/format.rb +0 -10
- data/lib/client_side_validations/mongoid/length.rb +0 -24
- data/lib/client_side_validations/mongoid/middleware.rb +0 -20
- data/lib/client_side_validations/mongoid/presence.rb +0 -10
- data/lib/client_side_validations/mongoid/uniqueness.rb +0 -29
- data/lib/client_side_validations/simple_form.rb +0 -24
- data/lib/generators/templates/client_side_validations/README.rails.3.0 +0 -6
- data/test/action_view/cases/helper.rb +0 -176
- data/test/action_view/cases/test_helpers.rb +0 -635
- data/test/action_view/cases/test_legacy_helpers.rb +0 -217
- data/test/action_view/models.rb +0 -3
- data/test/action_view/models/comment.rb +0 -35
- data/test/action_view/models/post.rb +0 -35
- data/test/active_model/cases/helper.rb +0 -4
- data/test/active_model/cases/test_acceptance_validator.rb +0 -16
- data/test/active_model/cases/test_base.rb +0 -11
- data/test/active_model/cases/test_confirmation_validator.rb +0 -16
- data/test/active_model/cases/test_exclusion_validator.rb +0 -20
- data/test/active_model/cases/test_format_validator.rb +0 -21
- data/test/active_model/cases/test_inclusion_validator.rb +0 -21
- data/test/active_model/cases/test_length_validator.rb +0 -61
- data/test/active_model/cases/test_numericality_validator.rb +0 -46
- data/test/active_model/cases/test_presence_validator.rb +0 -16
- data/test/active_model/cases/test_validations.rb +0 -175
- data/test/active_model/models/person.rb +0 -17
- data/test/active_record/cases/helper.rb +0 -12
- data/test/active_record/cases/test_base.rb +0 -11
- data/test/active_record/cases/test_middleware.rb +0 -175
- data/test/active_record/cases/test_uniqueness_validator.rb +0 -56
- data/test/active_record/models/guid.rb +0 -7
- data/test/active_record/models/user.rb +0 -14
- data/test/base_helper.rb +0 -21
- data/test/core_ext/cases/test_core_ext.rb +0 -46
- data/test/formtastic/cases/helper.rb +0 -7
- data/test/formtastic/cases/test_form_builder.rb +0 -11
- data/test/formtastic/cases/test_form_helper.rb +0 -21
- data/test/generators/cases/test_generators.rb +0 -70
- data/test/javascript/config.ru +0 -3
- data/test/javascript/public/test/callbacks/elementAfter.js +0 -54
- data/test/javascript/public/test/callbacks/elementBefore.js +0 -54
- data/test/javascript/public/test/callbacks/elementFail.js +0 -70
- data/test/javascript/public/test/callbacks/elementPass.js +0 -70
- data/test/javascript/public/test/callbacks/formAfter.js +0 -45
- data/test/javascript/public/test/callbacks/formBefore.js +0 -45
- data/test/javascript/public/test/callbacks/formFail.js +0 -51
- data/test/javascript/public/test/callbacks/formPass.js +0 -50
- data/test/javascript/public/test/form_builders/validateForm.js +0 -66
- data/test/javascript/public/test/form_builders/validateFormtastic.js +0 -54
- data/test/javascript/public/test/form_builders/validateNestedForm.js +0 -66
- data/test/javascript/public/test/form_builders/validateSimpleForm.js +0 -57
- data/test/javascript/public/test/settings.js +0 -15
- data/test/javascript/public/test/validateElement.js +0 -179
- data/test/javascript/public/test/validators/acceptance.js +0 -42
- data/test/javascript/public/test/validators/confirmation.js +0 -25
- data/test/javascript/public/test/validators/exclusion.js +0 -41
- data/test/javascript/public/test/validators/format.js +0 -27
- data/test/javascript/public/test/validators/inclusion.js +0 -42
- data/test/javascript/public/test/validators/length.js +0 -76
- data/test/javascript/public/test/validators/numericality.js +0 -158
- data/test/javascript/public/test/validators/presence.js +0 -21
- data/test/javascript/public/test/validators/uniqueness.js +0 -107
- data/test/javascript/public/vendor/jquery.metadata.js +0 -122
- data/test/javascript/public/vendor/qunit.css +0 -196
- data/test/javascript/public/vendor/qunit.js +0 -1374
- data/test/javascript/server.rb +0 -84
- data/test/javascript/views/index.erb +0 -20
- data/test/javascript/views/layout.erb +0 -21
- data/test/middleware/cases/helper.rb +0 -7
- data/test/middleware/cases/test_middleware.rb +0 -8
- data/test/mongo_mapper/cases/helper.rb +0 -9
- data/test/mongo_mapper/cases/test_base.rb +0 -15
- data/test/mongo_mapper/cases/test_middleware.rb +0 -77
- data/test/mongo_mapper/cases/test_uniqueness_validator.rb +0 -55
- data/test/mongo_mapper/models/magazine.rb +0 -11
- data/test/mongoid/cases/helper.rb +0 -12
- data/test/mongoid/cases/test_base.rb +0 -15
- data/test/mongoid/cases/test_format_validator.rb +0 -21
- data/test/mongoid/cases/test_length_validator.rb +0 -60
- data/test/mongoid/cases/test_middleware.rb +0 -77
- data/test/mongoid/cases/test_presence_validator.rb +0 -16
- data/test/mongoid/cases/test_uniqueness_validator.rb +0 -54
- data/test/mongoid/models/book.rb +0 -12
- data/test/simple_form/cases/helper.rb +0 -5
- data/test/simple_form/cases/test_form_builder.rb +0 -14
- data/test/simple_form/cases/test_form_helper.rb +0 -24
- data/test/test_loader.rb +0 -6
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'active_model/cases/test_base'
|
2
|
-
|
3
|
-
class ActiveModel::NumericalityValidatorTest < ClientSideValidations::ActiveModelTestBase
|
4
|
-
|
5
|
-
def test_numericality_client_side_hash
|
6
|
-
expected_hash = { :messages => { :numericality => "is not a number" } }
|
7
|
-
assert_equal expected_hash, NumericalityValidator.new(:attributes => [:age]).client_side_hash(@person, :age)
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_numericality_client_side_hash_with_custom_message
|
11
|
-
expected_hash = { :messages => { :numericality => "bad number" } }
|
12
|
-
assert_equal expected_hash, NumericalityValidator.new(:attributes => [:age], :message => "bad number").client_side_hash(@person, :age)
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_numericality_client_side_hash_with_options
|
16
|
-
expected_hash = {
|
17
|
-
:messages => {
|
18
|
-
:numericality => "is not a number",
|
19
|
-
:only_integer => "must be an integer",
|
20
|
-
:greater_than => "must be greater than 10",
|
21
|
-
:greater_than_or_equal_to => "must be greater than or equal to 10",
|
22
|
-
:equal_to => "must be equal to 10",
|
23
|
-
:less_than => "must be less than 10",
|
24
|
-
:less_than_or_equal_to => "must be less than or equal to 10",
|
25
|
-
:odd => "must be odd",
|
26
|
-
:even => "must be even"
|
27
|
-
},
|
28
|
-
:only_integer => true,
|
29
|
-
:greater_than => 10,
|
30
|
-
:greater_than_or_equal_to => 10,
|
31
|
-
:equal_to => 10,
|
32
|
-
:less_than => 10,
|
33
|
-
:less_than_or_equal_to => 10,
|
34
|
-
:odd => true,
|
35
|
-
:even => true
|
36
|
-
}
|
37
|
-
test_hash = NumericalityValidator.new(:attributes => [:age],
|
38
|
-
:only_integer => true, :greater_than => 10, :greater_than_or_equal_to => 10,
|
39
|
-
:equal_to => 10, :less_than => 10, :less_than_or_equal_to => 10,
|
40
|
-
:odd => true, :even => true).client_side_hash(@person, :age)
|
41
|
-
|
42
|
-
assert_equal expected_hash, test_hash
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'active_model/cases/test_base'
|
2
|
-
|
3
|
-
class ActiveModel::PresenceValidatorTest < ClientSideValidations::ActiveModelTestBase
|
4
|
-
|
5
|
-
def test_presence_client_side_hash
|
6
|
-
expected_hash = { :message => "can't be blank" }
|
7
|
-
assert_equal expected_hash, PresenceValidator.new(:attributes => [:name]).client_side_hash(@person, :age)
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_presence_client_side_hash_with_custom_message
|
11
|
-
expected_hash = { :message => "is required" }
|
12
|
-
assert_equal expected_hash, PresenceValidator.new(:attributes => [:name], :message => "is required").client_side_hash(@person, :age)
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|
@@ -1,175 +0,0 @@
|
|
1
|
-
require 'active_model/cases/test_base'
|
2
|
-
|
3
|
-
class ActiveModel::ValidationsTest < ClientSideValidations::ActiveModelTestBase
|
4
|
-
|
5
|
-
class Person
|
6
|
-
include ::ActiveModel::Validations
|
7
|
-
attr_accessor :first_name, :last_name, :age, :weight
|
8
|
-
|
9
|
-
def self.name
|
10
|
-
"Person"
|
11
|
-
end
|
12
|
-
|
13
|
-
def new_record?
|
14
|
-
true
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def new_person
|
19
|
-
person = Class.new(Person)
|
20
|
-
yield(person)
|
21
|
-
person.new
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_validations_to_client_side_hash
|
25
|
-
person = new_person do |p|
|
26
|
-
p.validates_presence_of :first_name
|
27
|
-
end
|
28
|
-
expected_hash = {
|
29
|
-
:first_name => {
|
30
|
-
:presence => {
|
31
|
-
:message => "can't be blank"
|
32
|
-
}
|
33
|
-
}
|
34
|
-
}
|
35
|
-
assert_equal expected_hash, person.client_side_validation_hash
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_validations_to_client_side_hash_with_validations_allow_blank
|
39
|
-
person = new_person do |p|
|
40
|
-
p.validates_length_of :first_name, :is => 10, :allow_blank => true
|
41
|
-
p.validates_format_of :first_name, :with => //, :allow_blank => true
|
42
|
-
end
|
43
|
-
expected_hash = {
|
44
|
-
:first_name => {
|
45
|
-
:length => {
|
46
|
-
:messages => { :is => 'is the wrong length (should be 10 characters)'},
|
47
|
-
:is => 10,
|
48
|
-
:allow_blank => true
|
49
|
-
},
|
50
|
-
:format => {
|
51
|
-
:message => 'is invalid',
|
52
|
-
:with => //,
|
53
|
-
:allow_blank => true
|
54
|
-
}
|
55
|
-
}
|
56
|
-
}
|
57
|
-
assert_equal expected_hash, person.client_side_validation_hash
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_validations_to_client_side_hash_with_validations_on_create
|
61
|
-
person = new_person do |p|
|
62
|
-
p.validates_length_of :first_name, :is => 10, :on => :create
|
63
|
-
p.validates_length_of :last_name, :is => 10, :on => :update
|
64
|
-
p.validates_format_of :first_name, :with => //, :on => :update
|
65
|
-
p.validates_format_of :last_name, :with => //, :on => :create
|
66
|
-
p.validates_numericality_of :age, :on => :create
|
67
|
-
p.validates_numericality_of :weight, :on => :update
|
68
|
-
p.class_eval do
|
69
|
-
def new_record?
|
70
|
-
true
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
expected_hash = {
|
75
|
-
:first_name => {
|
76
|
-
:length => {
|
77
|
-
:messages => { :is => 'is the wrong length (should be 10 characters)'},
|
78
|
-
:is => 10,
|
79
|
-
},
|
80
|
-
},
|
81
|
-
:last_name => {
|
82
|
-
:format => {
|
83
|
-
:message => 'is invalid',
|
84
|
-
:with => //,
|
85
|
-
}
|
86
|
-
},
|
87
|
-
:age => {
|
88
|
-
:numericality => {
|
89
|
-
:messages => { :numericality => 'is not a number' },
|
90
|
-
}
|
91
|
-
}
|
92
|
-
}
|
93
|
-
assert_equal expected_hash, person.client_side_validation_hash
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_validations_to_client_side_hash_with_validations_on_update
|
97
|
-
person = new_person do |p|
|
98
|
-
p.validates_length_of :first_name, :is => 10, :on => :update
|
99
|
-
p.validates_length_of :last_name, :is => 10, :on => :create
|
100
|
-
p.validates_format_of :first_name, :with => //, :on => :create
|
101
|
-
p.validates_format_of :last_name, :with => //, :on => :update
|
102
|
-
p.validates_numericality_of :age, :on => :update
|
103
|
-
p.validates_numericality_of :weight, :on => :create
|
104
|
-
p.class_eval do
|
105
|
-
def new_record?
|
106
|
-
false
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
expected_hash = {
|
111
|
-
:first_name => {
|
112
|
-
:length => {
|
113
|
-
:messages => { :is => 'is the wrong length (should be 10 characters)'},
|
114
|
-
:is => 10,
|
115
|
-
},
|
116
|
-
},
|
117
|
-
:last_name => {
|
118
|
-
:format => {
|
119
|
-
:message => 'is invalid',
|
120
|
-
:with => //,
|
121
|
-
}
|
122
|
-
},
|
123
|
-
:age => {
|
124
|
-
:numericality => {
|
125
|
-
:messages => { :numericality => 'is not a number' },
|
126
|
-
}
|
127
|
-
}
|
128
|
-
}
|
129
|
-
assert_equal expected_hash, person.client_side_validation_hash
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_validates_with_should_be_ignored
|
133
|
-
person = new_person do |p|
|
134
|
-
p.validates_with PersonValidator
|
135
|
-
end
|
136
|
-
|
137
|
-
expected_hash = {}
|
138
|
-
assert_equal expected_hash, person.client_side_validation_hash
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_generic_block_validators_should_be_ignored
|
142
|
-
person = new_person do |p|
|
143
|
-
p.validates_each(:first_name) do |record, attr, value|
|
144
|
-
record.errors.add(:first_name, "failed")
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
expected_hash = {}
|
149
|
-
assert_equal expected_hash, person.client_side_validation_hash
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_conditionals_persist_on_validator
|
153
|
-
person = new_person do |p|
|
154
|
-
p.validates :first_name, :presence => { :if => :can_validate? }
|
155
|
-
p.validates :last_name, :presence => { :unless => :cannot_validate? }
|
156
|
-
end
|
157
|
-
|
158
|
-
expected_hash = {
|
159
|
-
:first_name => {
|
160
|
-
:presence => {
|
161
|
-
:message => "can't be blank",
|
162
|
-
:if => :can_validate?
|
163
|
-
}
|
164
|
-
},
|
165
|
-
:last_name => {
|
166
|
-
:presence => {
|
167
|
-
:message => "can't be blank",
|
168
|
-
:unless => :cannot_validate?
|
169
|
-
}
|
170
|
-
}
|
171
|
-
}
|
172
|
-
assert_equal expected_hash, person.client_side_validation_hash
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
@@ -1,17 +0,0 @@
|
|
1
|
-
class PersonValidator < ActiveModel::Validator
|
2
|
-
def validate(record)
|
3
|
-
end
|
4
|
-
end
|
5
|
-
|
6
|
-
class Person
|
7
|
-
include ActiveModel::Validations
|
8
|
-
|
9
|
-
attr_accessor :first_name, :last_name, :email, :age
|
10
|
-
|
11
|
-
validates_presence_of :first_name
|
12
|
-
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
13
|
-
|
14
|
-
def new_record?
|
15
|
-
true
|
16
|
-
end
|
17
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'base_helper'
|
2
|
-
require 'active_record'
|
3
|
-
require 'client_side_validations/active_record'
|
4
|
-
|
5
|
-
# Connection must be establised before anything else
|
6
|
-
ActiveRecord::Base.establish_connection(
|
7
|
-
:adapter => defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3',
|
8
|
-
:database => ':memory:'
|
9
|
-
)
|
10
|
-
|
11
|
-
require 'active_record/models/user'
|
12
|
-
require 'active_record/models/guid'
|
@@ -1,175 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'middleware/cases/helper'
|
4
|
-
require 'active_record/cases/helper'
|
5
|
-
|
6
|
-
class ClientSideValidationsActiveRecordMiddlewareTest < Test::Unit::TestCase
|
7
|
-
include Rack::Test::Methods
|
8
|
-
|
9
|
-
def teardown
|
10
|
-
User.delete_all
|
11
|
-
end
|
12
|
-
|
13
|
-
def with_kcode(kcode)
|
14
|
-
if RUBY_VERSION < '1.9'
|
15
|
-
orig_kcode, $KCODE = $KCODE, kcode
|
16
|
-
begin
|
17
|
-
yield
|
18
|
-
ensure
|
19
|
-
$KCODE = orig_kcode
|
20
|
-
end
|
21
|
-
else
|
22
|
-
yield
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def app
|
27
|
-
app = Proc.new { |env| [200, {}, ['success']] }
|
28
|
-
ClientSideValidations::Middleware::Validators.new(app)
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_uniqueness_when_resource_exists
|
32
|
-
User.create(:email => 'user@test.com')
|
33
|
-
get '/validators/uniqueness', { 'user[email]' => 'user@test.com', 'case_sensitive' => true }
|
34
|
-
|
35
|
-
assert_equal 'false', last_response.body
|
36
|
-
assert last_response.ok?
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_uniqueness_when_resource_exists_and_param_order_is_backwards
|
40
|
-
User.create(:email => 'user@test.com')
|
41
|
-
get '/validators/uniqueness', { 'case_sensitive' => true, 'user[email]' => 'user@test.com' }
|
42
|
-
|
43
|
-
assert_equal 'false', last_response.body
|
44
|
-
assert last_response.ok?
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_uniqueness_when_resource_does_not_exist
|
48
|
-
get '/validators/uniqueness', { 'user[email]' => 'user@test.com', 'case_sensitive' => true }
|
49
|
-
|
50
|
-
assert_equal 'true', last_response.body
|
51
|
-
assert last_response.not_found?
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_uniqueness_when_id_is_given
|
55
|
-
user = User.create(:email => 'user@test.com')
|
56
|
-
get '/validators/uniqueness', { 'user[email]' => 'user@test.com', 'id' => user.id, 'case_sensitive' => true }
|
57
|
-
|
58
|
-
assert_equal 'true', last_response.body
|
59
|
-
assert last_response.not_found?
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_mysql_adapter_uniqueness_when_id_is_given
|
63
|
-
user = User.create(:email => 'user@test.com')
|
64
|
-
ActiveRecord::ConnectionAdapters::SQLite3Adapter.
|
65
|
-
any_instance.expects(:instance_variable_get).
|
66
|
-
with("@config").
|
67
|
-
returns({:adapter => "mysql"})
|
68
|
-
|
69
|
-
sql_without_binary = "#{User.arel_table["email"].eq(user.email).to_sql} AND #{User.arel_table.primary_key.not_eq(user.id).to_sql}"
|
70
|
-
relation = Arel::Nodes::SqlLiteral.new("BINARY #{sql_without_binary}")
|
71
|
-
|
72
|
-
#NOTE: Stubs User#where because SQLite3 don't know BINARY
|
73
|
-
result = User.where(sql_without_binary)
|
74
|
-
User.expects(:where).with(relation).returns(result)
|
75
|
-
|
76
|
-
get '/validators/uniqueness', { 'user[email]' => user.email, 'case_sensitive' => true, 'id' => user.id}
|
77
|
-
assert_equal 'true', last_response.body
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_uniqueness_when_scope_is_given
|
81
|
-
User.create(:email => 'user@test.com', :age => 25)
|
82
|
-
get '/validators/uniqueness', { 'user[email]' => 'user@test.com', 'scope' => { 'age' => 30 }, 'case_sensitive' => true }
|
83
|
-
|
84
|
-
assert_equal 'true', last_response.body
|
85
|
-
assert last_response.not_found?
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_uniqueness_when_multiple_scopes_are_given
|
89
|
-
User.create(:email => 'user@test.com', :age => 30, :name => 'Brian')
|
90
|
-
get '/validators/uniqueness', { 'user[email]' => 'user@test.com', 'scope' => { 'age' => 30, 'name' => 'Robert' }, 'case_sensitive' => true }
|
91
|
-
|
92
|
-
assert_equal 'true', last_response.body
|
93
|
-
assert last_response.not_found?
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_uniqueness_when_case_insensitive
|
97
|
-
User.create(:name => 'Brian')
|
98
|
-
get '/validators/uniqueness', { 'user[name]' => 'BRIAN', 'case_sensitive' => false }
|
99
|
-
|
100
|
-
assert_equal 'false', last_response.body
|
101
|
-
assert last_response.ok?
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_uniqueness_when_attribute_passes_as_an_integer
|
105
|
-
User.create(:name => 123)
|
106
|
-
get '/validators/uniqueness', { 'user[name]' => 123, 'case_sensitive' => true }
|
107
|
-
|
108
|
-
assert_equal 'false', last_response.body
|
109
|
-
assert last_response.ok?
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_uniqueness_when_attribute_passes_as_an_integer
|
113
|
-
User.create(:name => 123)
|
114
|
-
get '/validators/uniqueness', { 'user[name]' => 123, 'case_sensitive' => true }
|
115
|
-
|
116
|
-
assert_equal 'false', last_response.body
|
117
|
-
assert last_response.ok?
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_uniqueness_with_columns_which_are_sql_keywords
|
121
|
-
Guid.validates_uniqueness_of :key
|
122
|
-
assert_nothing_raised do
|
123
|
-
get '/validators/uniqueness', { 'guid[key]' => 'test', 'case_sensitive' => true }
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_uniqueness_with_limit
|
128
|
-
# User.title is limited to 5 characters
|
129
|
-
User.create(:title => "abcde")
|
130
|
-
get '/validators/uniqueness', { 'user[title]' => 'abcdefgh', 'case_sensitive' => true }
|
131
|
-
|
132
|
-
assert_equal 'false', last_response.body
|
133
|
-
assert last_response.ok?
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_uniqueness_with_limit_and_utf8
|
137
|
-
with_kcode('UTF8') do
|
138
|
-
# User.title is limited to 5 characters
|
139
|
-
User.create(:title => "一二三四五")
|
140
|
-
get '/validators/uniqueness', { 'user[title]' => '一二三四五六七八', 'case_sensitive' => true }
|
141
|
-
|
142
|
-
assert_equal 'false', last_response.body
|
143
|
-
assert last_response.ok?
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_validate_straight_inheritance_uniqueness
|
148
|
-
get '/validators/uniqueness', { 'inept_wizard[name]' => 'Rincewind', 'case_sensitive' => true }
|
149
|
-
assert_equal 'true', last_response.body
|
150
|
-
assert last_response.not_found?
|
151
|
-
|
152
|
-
IneptWizard.create(:name => 'Rincewind')
|
153
|
-
get '/validators/uniqueness', { 'inept_wizard[name]' => 'Rincewind', 'case_sensitive' => true }
|
154
|
-
assert_equal 'false', last_response.body
|
155
|
-
assert last_response.ok?
|
156
|
-
|
157
|
-
get '/validators/uniqueness', { 'conjurer[name]' => 'Rincewind', 'case_sensitive' => true }
|
158
|
-
assert_equal 'false', last_response.body
|
159
|
-
assert last_response.ok?
|
160
|
-
|
161
|
-
Conjurer.create(:name => 'The Amazing Bonko')
|
162
|
-
get '/validators/uniqueness', { 'thaumaturgist[name]' => 'The Amazing Bonko', 'case_sensitive' => true }
|
163
|
-
assert_equal 'false', last_response.body
|
164
|
-
assert last_response.ok?
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_uniqueness_when_resource_is_a_nested_module
|
168
|
-
ActiveRecordTestModule::User2.create(:email => 'user@test.com')
|
169
|
-
get '/validators/uniqueness', { 'active_record_test_module/user2[email]' => 'user@test.com', 'case_sensitive' => true }
|
170
|
-
|
171
|
-
assert_equal 'false', last_response.body
|
172
|
-
assert last_response.ok?
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|