client_side_validations 3.0.14 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/client_side_validations.gemspec +11 -3
- data/lib/client_side_validations.rb +4 -4
- data/lib/client_side_validations/action_view.rb +4 -3
- data/lib/client_side_validations/action_view/form_builder.rb +21 -26
- data/lib/client_side_validations/active_model.rb +1 -2
- data/lib/client_side_validations/active_record/middleware.rb +2 -10
- data/lib/client_side_validations/formtastic.rb +3 -3
- data/lib/client_side_validations/middleware.rb +4 -3
- data/lib/client_side_validations/version.rb +1 -1
- data/lib/generators/client_side_validations/copy_asset_generator.rb +23 -0
- data/lib/generators/client_side_validations/install_generator.rb +18 -6
- data/lib/generators/templates/client_side_validations/README.rails.3.0 +6 -0
- data/lib/generators/templates/client_side_validations/README.rails.3.1 +7 -0
- data/lib/generators/templates/client_side_validations/initializer.rb +1 -1
- data/test/action_view/cases/helper.rb +29 -13
- data/test/action_view/cases/test_helpers.rb +31 -66
- data/test/action_view/cases/test_legacy_helpers.rb +1 -1
- data/test/active_record/cases/test_middleware.rb +19 -34
- data/test/active_record/models/user.rb +1 -1
- data/test/base_helper.rb +1 -0
- data/test/core_ext/cases/test_core_ext.rb +1 -0
- data/test/formtastic/cases/helper.rb +5 -0
- data/test/formtastic/cases/test_form_builder.rb +3 -3
- data/test/formtastic/cases/test_form_helper.rb +3 -4
- data/test/generators/cases/test_generators.rb +31 -0
- data/test/javascript/public/test/form_builders/validateFormtastic.js +1 -1
- data/test/javascript/server.rb +1 -1
- data/test/middleware/cases/helper.rb +2 -0
- data/test/mongo_mapper/cases/test_middleware.rb +7 -7
- data/test/mongoid/cases/test_middleware.rb +7 -7
- data/test/simple_form/cases/helper.rb +3 -0
- data/test/simple_form/cases/test_form_helper.rb +2 -0
- data/test/test_loader.rb +6 -0
- data/vendor/assets/javascripts/rails.validations.js +135 -136
- metadata +153 -163
- checksums.yaml +0 -7
- data/lib/generators/templates/client_side_validations/README +0 -7
- data/test/generators/cases/test_install_generator.rb +0 -15
@@ -30,7 +30,7 @@ class ClientSideValidations::LegacyActionViewHelpersTest < ActionView::TestCase
|
|
30
30
|
concat f.file_field(:cost)
|
31
31
|
end
|
32
32
|
|
33
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post",
|
33
|
+
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => :put, :file => true) do
|
34
34
|
%{<input id="post_cost" name="post[cost]" type="file" />}
|
35
35
|
end
|
36
36
|
assert_equal expected, output_buffer
|
@@ -30,7 +30,7 @@ class ClientSideValidationsActiveRecordMiddlewareTest < Test::Unit::TestCase
|
|
30
30
|
|
31
31
|
def test_uniqueness_when_resource_exists
|
32
32
|
User.create(:email => 'user@test.com')
|
33
|
-
get '/validators/uniqueness
|
33
|
+
get '/validators/uniqueness', { 'user[email]' => 'user@test.com', 'case_sensitive' => true }
|
34
34
|
|
35
35
|
assert_equal 'false', last_response.body
|
36
36
|
assert last_response.ok?
|
@@ -38,14 +38,14 @@ class ClientSideValidationsActiveRecordMiddlewareTest < Test::Unit::TestCase
|
|
38
38
|
|
39
39
|
def test_uniqueness_when_resource_exists_and_param_order_is_backwards
|
40
40
|
User.create(:email => 'user@test.com')
|
41
|
-
get '/validators/uniqueness
|
41
|
+
get '/validators/uniqueness', { 'case_sensitive' => true, 'user[email]' => 'user@test.com' }
|
42
42
|
|
43
43
|
assert_equal 'false', last_response.body
|
44
44
|
assert last_response.ok?
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_uniqueness_when_resource_does_not_exist
|
48
|
-
get '/validators/uniqueness
|
48
|
+
get '/validators/uniqueness', { 'user[email]' => 'user@test.com', 'case_sensitive' => true }
|
49
49
|
|
50
50
|
assert_equal 'true', last_response.body
|
51
51
|
assert last_response.not_found?
|
@@ -53,7 +53,7 @@ class ClientSideValidationsActiveRecordMiddlewareTest < Test::Unit::TestCase
|
|
53
53
|
|
54
54
|
def test_uniqueness_when_id_is_given
|
55
55
|
user = User.create(:email => 'user@test.com')
|
56
|
-
get '/validators/uniqueness
|
56
|
+
get '/validators/uniqueness', { 'user[email]' => 'user@test.com', 'id' => user.id, 'case_sensitive' => true }
|
57
57
|
|
58
58
|
assert_equal 'true', last_response.body
|
59
59
|
assert last_response.not_found?
|
@@ -73,13 +73,13 @@ class ClientSideValidationsActiveRecordMiddlewareTest < Test::Unit::TestCase
|
|
73
73
|
result = User.where(sql_without_binary)
|
74
74
|
User.expects(:where).with(relation).returns(result)
|
75
75
|
|
76
|
-
get '/validators/uniqueness
|
76
|
+
get '/validators/uniqueness', { 'user[email]' => user.email, 'case_sensitive' => true, 'id' => user.id}
|
77
77
|
assert_equal 'true', last_response.body
|
78
78
|
end
|
79
79
|
|
80
80
|
def test_uniqueness_when_scope_is_given
|
81
81
|
User.create(:email => 'user@test.com', :age => 25)
|
82
|
-
get '/validators/uniqueness
|
82
|
+
get '/validators/uniqueness', { 'user[email]' => 'user@test.com', 'scope' => { 'age' => 30 }, 'case_sensitive' => true }
|
83
83
|
|
84
84
|
assert_equal 'true', last_response.body
|
85
85
|
assert last_response.not_found?
|
@@ -87,7 +87,7 @@ class ClientSideValidationsActiveRecordMiddlewareTest < Test::Unit::TestCase
|
|
87
87
|
|
88
88
|
def test_uniqueness_when_multiple_scopes_are_given
|
89
89
|
User.create(:email => 'user@test.com', :age => 30, :name => 'Brian')
|
90
|
-
get '/validators/uniqueness
|
90
|
+
get '/validators/uniqueness', { 'user[email]' => 'user@test.com', 'scope' => { 'age' => 30, 'name' => 'Robert' }, 'case_sensitive' => true }
|
91
91
|
|
92
92
|
assert_equal 'true', last_response.body
|
93
93
|
assert last_response.not_found?
|
@@ -95,7 +95,7 @@ class ClientSideValidationsActiveRecordMiddlewareTest < Test::Unit::TestCase
|
|
95
95
|
|
96
96
|
def test_uniqueness_when_case_insensitive
|
97
97
|
User.create(:name => 'Brian')
|
98
|
-
get '/validators/uniqueness
|
98
|
+
get '/validators/uniqueness', { 'user[name]' => 'BRIAN', 'case_sensitive' => false }
|
99
99
|
|
100
100
|
assert_equal 'false', last_response.body
|
101
101
|
assert last_response.ok?
|
@@ -103,7 +103,7 @@ class ClientSideValidationsActiveRecordMiddlewareTest < Test::Unit::TestCase
|
|
103
103
|
|
104
104
|
def test_uniqueness_when_attribute_passes_as_an_integer
|
105
105
|
User.create(:name => 123)
|
106
|
-
get '/validators/uniqueness
|
106
|
+
get '/validators/uniqueness', { 'user[name]' => 123, 'case_sensitive' => true }
|
107
107
|
|
108
108
|
assert_equal 'false', last_response.body
|
109
109
|
assert last_response.ok?
|
@@ -111,7 +111,7 @@ class ClientSideValidationsActiveRecordMiddlewareTest < Test::Unit::TestCase
|
|
111
111
|
|
112
112
|
def test_uniqueness_when_attribute_passes_as_an_integer
|
113
113
|
User.create(:name => 123)
|
114
|
-
get '/validators/uniqueness
|
114
|
+
get '/validators/uniqueness', { 'user[name]' => 123, 'case_sensitive' => true }
|
115
115
|
|
116
116
|
assert_equal 'false', last_response.body
|
117
117
|
assert last_response.ok?
|
@@ -120,14 +120,14 @@ class ClientSideValidationsActiveRecordMiddlewareTest < Test::Unit::TestCase
|
|
120
120
|
def test_uniqueness_with_columns_which_are_sql_keywords
|
121
121
|
Guid.validates_uniqueness_of :key
|
122
122
|
assert_nothing_raised do
|
123
|
-
get '/validators/uniqueness
|
123
|
+
get '/validators/uniqueness', { 'guid[key]' => 'test', 'case_sensitive' => true }
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
127
|
def test_uniqueness_with_limit
|
128
128
|
# User.title is limited to 5 characters
|
129
129
|
User.create(:title => "abcde")
|
130
|
-
get '/validators/uniqueness
|
130
|
+
get '/validators/uniqueness', { 'user[title]' => 'abcdefgh', 'case_sensitive' => true }
|
131
131
|
|
132
132
|
assert_equal 'false', last_response.body
|
133
133
|
assert last_response.ok?
|
@@ -137,7 +137,7 @@ class ClientSideValidationsActiveRecordMiddlewareTest < Test::Unit::TestCase
|
|
137
137
|
with_kcode('UTF8') do
|
138
138
|
# User.title is limited to 5 characters
|
139
139
|
User.create(:title => "一二三四五")
|
140
|
-
get '/validators/uniqueness
|
140
|
+
get '/validators/uniqueness', { 'user[title]' => '一二三四五六七八', 'case_sensitive' => true }
|
141
141
|
|
142
142
|
assert_equal 'false', last_response.body
|
143
143
|
assert last_response.ok?
|
@@ -145,46 +145,31 @@ class ClientSideValidationsActiveRecordMiddlewareTest < Test::Unit::TestCase
|
|
145
145
|
end
|
146
146
|
|
147
147
|
def test_validate_straight_inheritance_uniqueness
|
148
|
-
get '/validators/uniqueness
|
148
|
+
get '/validators/uniqueness', { 'inept_wizard[name]' => 'Rincewind', 'case_sensitive' => true }
|
149
149
|
assert_equal 'true', last_response.body
|
150
150
|
assert last_response.not_found?
|
151
151
|
|
152
152
|
IneptWizard.create(:name => 'Rincewind')
|
153
|
-
get '/validators/uniqueness
|
153
|
+
get '/validators/uniqueness', { 'inept_wizard[name]' => 'Rincewind', 'case_sensitive' => true }
|
154
154
|
assert_equal 'false', last_response.body
|
155
155
|
assert last_response.ok?
|
156
156
|
|
157
|
-
get '/validators/uniqueness
|
157
|
+
get '/validators/uniqueness', { 'conjurer[name]' => 'Rincewind', 'case_sensitive' => true }
|
158
158
|
assert_equal 'false', last_response.body
|
159
159
|
assert last_response.ok?
|
160
160
|
|
161
161
|
Conjurer.create(:name => 'The Amazing Bonko')
|
162
|
-
get '/validators/uniqueness
|
162
|
+
get '/validators/uniqueness', { 'thaumaturgist[name]' => 'The Amazing Bonko', 'case_sensitive' => true }
|
163
163
|
assert_equal 'false', last_response.body
|
164
164
|
assert last_response.ok?
|
165
165
|
end
|
166
166
|
|
167
167
|
def test_uniqueness_when_resource_is_a_nested_module
|
168
168
|
ActiveRecordTestModule::User2.create(:email => 'user@test.com')
|
169
|
-
get '/validators/uniqueness
|
170
|
-
|
171
|
-
assert_equal 'false', last_response.body
|
172
|
-
assert last_response.ok?
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_uniqueness_when_value_must_be_typecast
|
176
|
-
User.create(:active => false)
|
177
|
-
get '/validators/uniqueness.json', { 'user[active]' => 'false', 'case_sensitive' => true }
|
178
|
-
|
179
|
-
assert_equal 'false', last_response.body
|
180
|
-
assert last_response.ok?
|
181
|
-
end
|
182
|
-
|
183
|
-
def test_uniqueness_when_scope_is_given_and_value_must_be_typecast
|
184
|
-
User.create(:email => 'user@test.com', :active => true)
|
185
|
-
get '/validators/uniqueness.json', { 'user[email]' => 'user@test.com', 'scope' => { 'active' => 'true' }, 'case_sensitive' => true }
|
169
|
+
get '/validators/uniqueness', { 'active_record_test_module/user2[email]' => 'user@test.com', 'case_sensitive' => true }
|
186
170
|
|
187
171
|
assert_equal 'false', last_response.body
|
188
172
|
assert last_response.ok?
|
189
173
|
end
|
190
174
|
end
|
175
|
+
|
@@ -1,4 +1,4 @@
|
|
1
|
-
users_table = %{CREATE TABLE users (id INTEGER PRIMARY KEY, age INTEGER, name TEXT, email TEXT, title VARCHAR(5)
|
1
|
+
users_table = %{CREATE TABLE users (id INTEGER PRIMARY KEY, age INTEGER, name TEXT, email TEXT, title VARCHAR(5));}
|
2
2
|
ActiveRecord::Base.connection.execute(users_table)
|
3
3
|
|
4
4
|
class User < ActiveRecord::Base
|
data/test/base_helper.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'formtastic/cases/helper'
|
2
2
|
|
3
|
-
class ClientSideValidations::Formtastic::
|
3
|
+
class ClientSideValidations::Formtastic::FormBuilderTest < Test::Unit::TestCase
|
4
4
|
def test_client_side_form_js_hash
|
5
5
|
expected = {
|
6
|
-
:type => 'Formtastic::
|
6
|
+
:type => 'Formtastic::FormBuilder',
|
7
7
|
:inline_error_class => 'inline-errors'
|
8
8
|
}
|
9
|
-
assert_equal expected, Formtastic::
|
9
|
+
assert_equal expected, Formtastic::FormBuilder.client_side_form_settings(nil, nil)
|
10
10
|
end
|
11
11
|
end
|
@@ -3,7 +3,7 @@ require 'formtastic/cases/helper'
|
|
3
3
|
|
4
4
|
class ClientSideValidations::Formtastic::FormHelperTest < ActionView::TestCase
|
5
5
|
include ActionViewTestSetup
|
6
|
-
include Formtastic::
|
6
|
+
include Formtastic::Helpers::FormHelper
|
7
7
|
|
8
8
|
def client_side_form_settings_helper
|
9
9
|
""
|
@@ -14,9 +14,8 @@ class ClientSideValidations::Formtastic::FormHelperTest < ActionView::TestCase
|
|
14
14
|
concat f.input(:cost)
|
15
15
|
end
|
16
16
|
|
17
|
-
expected = %{<form accept-charset="UTF-8" action="/posts/123" class="formtastic post" data-validate="true" id="edit_post_123" method="post" novalidate="novalidate"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="put" /></div><li class="string required" id="post_cost_input"><label for="post_cost">Cost<abbr title="required">*</abbr></label><input data-validate="true" id="post_cost" name="post[cost]" type="text"
|
17
|
+
expected = %{<form accept-charset="UTF-8" action="/posts/123" class="formtastic post" data-validate="true" id="edit_post_123" method="post" novalidate="novalidate"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="put" /></div><li class="string input required stringish" id="post_cost_input"><label class=\" label\" for="post_cost">Cost<abbr title="required">*</abbr></label><input data-validate="true" id="post_cost" name="post[cost]" required=\"required\" type="text" />\n\n</li></form><script>window['edit_post_123'] = {"type":"Formtastic::FormBuilder","inline_error_class":"inline-errors","validators":{"post[cost]":{"presence":{"message":"can't be blank"}}}};</script>}
|
18
18
|
assert_equal expected, output_buffer, "\n\n *** If you're running Ruby 1.8 and this test fails is is most likely due to 1.8's lack of insertion order persistence with Hashes ***\n"
|
19
19
|
end
|
20
20
|
|
21
|
-
end
|
22
|
-
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rails/generators/test_case'
|
2
|
+
require 'generators/client_side_validations/install_generator'
|
3
|
+
require 'generators/client_side_validations/copy_asset_generator'
|
4
|
+
|
5
|
+
class InstallGeneratorTest < Rails::Generators::TestCase
|
6
|
+
tests ClientSideValidations::Generators::InstallGenerator
|
7
|
+
destination File.expand_path('../../tmp', __FILE__)
|
8
|
+
setup :prepare_destination
|
9
|
+
|
10
|
+
test 'Assert all files are properly created' do
|
11
|
+
run_generator
|
12
|
+
assert_file 'config/initializers/client_side_validations.rb'
|
13
|
+
assert_file 'public/javascripts/rails.validations.js' if Rails.version > '3.0' && Rails.version < '3.1'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class CopyAssetGeneratorTest < Rails::Generators::TestCase
|
18
|
+
tests ClientSideValidations::Generators::CopyAssetGenerator
|
19
|
+
destination File.expand_path('../../tmp', __FILE__)
|
20
|
+
setup :prepare_destination
|
21
|
+
|
22
|
+
test 'Assert file is properly created' do
|
23
|
+
run_generator
|
24
|
+
if Rails.version >= '3.1'
|
25
|
+
assert_file 'app/assets/javascripts/rails.validations.js'
|
26
|
+
else
|
27
|
+
assert_file 'public/javascripts/rails.validations.js'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module('Validate Formtastic', {
|
2
2
|
setup: function() {
|
3
3
|
window['new_user'] = {
|
4
|
-
type: 'Formtastic::
|
4
|
+
type: 'Formtastic::FormBuilder',
|
5
5
|
inline_error_class: 'inline-errors',
|
6
6
|
validators: {
|
7
7
|
"user[name]":{"presence":{"message": "must be present"}, "format":{"message":"is invalid","with":/\d+/}}
|
data/test/javascript/server.rb
CHANGED
@@ -21,14 +21,14 @@ class ClientSideValidationsMongoMapperMiddlewareTest < Test::Unit::TestCase
|
|
21
21
|
|
22
22
|
def test_uniqueness_when_resource_exists
|
23
23
|
Magazine.create(:author_email => 'magazine@test.com')
|
24
|
-
get '/validators/uniqueness
|
24
|
+
get '/validators/uniqueness', { 'magazine[author_email]' => 'magazine@test.com' }
|
25
25
|
|
26
26
|
assert_equal 'false', last_response.body
|
27
27
|
assert last_response.ok?
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_uniqueness_when_resource_does_not_exist
|
31
|
-
get '/validators/uniqueness
|
31
|
+
get '/validators/uniqueness', { 'magazine[author_email]' => 'magazine@test.com' }
|
32
32
|
|
33
33
|
assert_equal 'true', last_response.body
|
34
34
|
assert last_response.not_found?
|
@@ -36,7 +36,7 @@ class ClientSideValidationsMongoMapperMiddlewareTest < Test::Unit::TestCase
|
|
36
36
|
|
37
37
|
def test_uniqueness_when_id_is_given
|
38
38
|
magazine = Magazine.create(:author_email => 'magazine@test.com')
|
39
|
-
get '/validators/uniqueness
|
39
|
+
get '/validators/uniqueness', { 'magazine[author_email]' => 'magazine@test.com', 'id' => magazine.id }
|
40
40
|
|
41
41
|
assert_equal 'true', last_response.body
|
42
42
|
assert last_response.not_found?
|
@@ -44,7 +44,7 @@ class ClientSideValidationsMongoMapperMiddlewareTest < Test::Unit::TestCase
|
|
44
44
|
|
45
45
|
def test_uniqueness_when_scope_is_given
|
46
46
|
Magazine.create(:author_email => 'magazine@test.com', :age => 25)
|
47
|
-
get '/validators/uniqueness
|
47
|
+
get '/validators/uniqueness', { 'magazine[author_email]' => 'magazine@test.com', 'scope' => { 'age' => 30 } }
|
48
48
|
|
49
49
|
assert_equal 'true', last_response.body
|
50
50
|
assert last_response.not_found?
|
@@ -52,7 +52,7 @@ class ClientSideValidationsMongoMapperMiddlewareTest < Test::Unit::TestCase
|
|
52
52
|
|
53
53
|
def test_uniqueness_when_multiple_scopes_are_given
|
54
54
|
Magazine.create(:author_email => 'magazine@test.com', :age => 30, :author_name => 'Brian')
|
55
|
-
get '/validators/uniqueness
|
55
|
+
get '/validators/uniqueness', { 'magazine[author_email]' => 'magazine@test.com', 'scope' => { 'age' => 30, 'author_name' => 'Robert' } }
|
56
56
|
|
57
57
|
assert_equal 'true', last_response.body
|
58
58
|
assert last_response.not_found?
|
@@ -60,7 +60,7 @@ class ClientSideValidationsMongoMapperMiddlewareTest < Test::Unit::TestCase
|
|
60
60
|
|
61
61
|
def test_uniqueness_when_case_insensitive
|
62
62
|
Magazine.create(:author_name => 'Brian')
|
63
|
-
get '/validators/uniqueness
|
63
|
+
get '/validators/uniqueness', { 'magazine[author_name]' => 'BRIAN', 'case_sensitive' => false }
|
64
64
|
|
65
65
|
assert_equal 'false', last_response.body
|
66
66
|
assert last_response.ok?
|
@@ -68,7 +68,7 @@ class ClientSideValidationsMongoMapperMiddlewareTest < Test::Unit::TestCase
|
|
68
68
|
|
69
69
|
def test_uniqueness_when_resource_exists
|
70
70
|
MongoMapperTestModule::Magazine2.create(:author_email => 'magazine@test.com')
|
71
|
-
get '/validators/uniqueness
|
71
|
+
get '/validators/uniqueness', { 'mongo_mapper_test_module/magazine2[author_email]' => 'magazine@test.com' }
|
72
72
|
|
73
73
|
assert_equal 'false', last_response.body
|
74
74
|
assert last_response.ok?
|
@@ -21,14 +21,14 @@ class ClientSideValidationsMongoidMiddlewareTest < Test::Unit::TestCase
|
|
21
21
|
|
22
22
|
def test_uniqueness_when_resource_exists
|
23
23
|
Book.create(:author_email => 'book@test.com')
|
24
|
-
get '/validators/uniqueness
|
24
|
+
get '/validators/uniqueness', { 'book[author_email]' => 'book@test.com' }
|
25
25
|
|
26
26
|
assert_equal 'false', last_response.body
|
27
27
|
assert last_response.ok?
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_uniqueness_when_resource_does_not_exist
|
31
|
-
get '/validators/uniqueness
|
31
|
+
get '/validators/uniqueness', { 'book[author_email]' => 'book@test.com' }
|
32
32
|
|
33
33
|
assert_equal 'true', last_response.body
|
34
34
|
assert last_response.not_found?
|
@@ -36,7 +36,7 @@ class ClientSideValidationsMongoidMiddlewareTest < Test::Unit::TestCase
|
|
36
36
|
|
37
37
|
def test_uniqueness_when_id_is_given
|
38
38
|
book = Book.create(:author_email => 'book@test.com')
|
39
|
-
get '/validators/uniqueness
|
39
|
+
get '/validators/uniqueness', { 'book[author_email]' => 'book@test.com', 'id' => book.id }
|
40
40
|
|
41
41
|
assert_equal 'true', last_response.body
|
42
42
|
assert last_response.not_found?
|
@@ -44,7 +44,7 @@ class ClientSideValidationsMongoidMiddlewareTest < Test::Unit::TestCase
|
|
44
44
|
|
45
45
|
def test_uniqueness_when_scope_is_given
|
46
46
|
Book.create(:author_email => 'book@test.com', :age => 25)
|
47
|
-
get '/validators/uniqueness
|
47
|
+
get '/validators/uniqueness', { 'book[author_email]' => 'book@test.com', 'scope' => { 'age' => 30 } }
|
48
48
|
|
49
49
|
assert_equal 'true', last_response.body
|
50
50
|
assert last_response.not_found?
|
@@ -52,7 +52,7 @@ class ClientSideValidationsMongoidMiddlewareTest < Test::Unit::TestCase
|
|
52
52
|
|
53
53
|
def test_uniqueness_when_multiple_scopes_are_given
|
54
54
|
Book.create(:author_email => 'book@test.com', :age => 30, :author_name => 'Brian')
|
55
|
-
get '/validators/uniqueness
|
55
|
+
get '/validators/uniqueness', { 'book[author_email]' => 'book@test.com', 'scope' => { 'age' => 30, 'author_name' => 'Robert' } }
|
56
56
|
|
57
57
|
assert_equal 'true', last_response.body
|
58
58
|
assert last_response.not_found?
|
@@ -60,7 +60,7 @@ class ClientSideValidationsMongoidMiddlewareTest < Test::Unit::TestCase
|
|
60
60
|
|
61
61
|
def test_uniqueness_when_case_insensitive
|
62
62
|
Book.create(:author_name => 'Brian')
|
63
|
-
get '/validators/uniqueness
|
63
|
+
get '/validators/uniqueness', { 'book[author_name]' => 'BRIAN', 'case_sensitive' => false }
|
64
64
|
|
65
65
|
assert_equal 'false', last_response.body
|
66
66
|
assert last_response.ok?
|
@@ -68,7 +68,7 @@ class ClientSideValidationsMongoidMiddlewareTest < Test::Unit::TestCase
|
|
68
68
|
|
69
69
|
def test_uniqueness_when_resource_is_a_nested_module
|
70
70
|
MongoidTestModule::Book2.create(:author_email => 'book@test.com')
|
71
|
-
get '/validators/uniqueness
|
71
|
+
get '/validators/uniqueness', { 'mongoid_test_module/book2[author_email]' => 'book@test.com' }
|
72
72
|
|
73
73
|
assert_equal 'false', last_response.body
|
74
74
|
assert last_response.ok?
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'action_view/cases/helper'
|
2
|
+
require 'middleware/cases/helper'
|
2
3
|
require 'simple_form/cases/helper'
|
3
4
|
|
4
5
|
class ClientSideValidations::SimpleForm::FormHelperTest < ActionView::TestCase
|
@@ -10,6 +11,7 @@ class ClientSideValidations::SimpleForm::FormHelperTest < ActionView::TestCase
|
|
10
11
|
end
|
11
12
|
|
12
13
|
def test_simple_form_for
|
14
|
+
ActionView::TestCase::TestController.any_instance.stubs(:action_name).returns('edit')
|
13
15
|
simple_form_for(@post, :validate => true) do |f|
|
14
16
|
concat f.input(:cost)
|
15
17
|
end
|