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.
Files changed (38) hide show
  1. data/client_side_validations.gemspec +11 -3
  2. data/lib/client_side_validations.rb +4 -4
  3. data/lib/client_side_validations/action_view.rb +4 -3
  4. data/lib/client_side_validations/action_view/form_builder.rb +21 -26
  5. data/lib/client_side_validations/active_model.rb +1 -2
  6. data/lib/client_side_validations/active_record/middleware.rb +2 -10
  7. data/lib/client_side_validations/formtastic.rb +3 -3
  8. data/lib/client_side_validations/middleware.rb +4 -3
  9. data/lib/client_side_validations/version.rb +1 -1
  10. data/lib/generators/client_side_validations/copy_asset_generator.rb +23 -0
  11. data/lib/generators/client_side_validations/install_generator.rb +18 -6
  12. data/lib/generators/templates/client_side_validations/README.rails.3.0 +6 -0
  13. data/lib/generators/templates/client_side_validations/README.rails.3.1 +7 -0
  14. data/lib/generators/templates/client_side_validations/initializer.rb +1 -1
  15. data/test/action_view/cases/helper.rb +29 -13
  16. data/test/action_view/cases/test_helpers.rb +31 -66
  17. data/test/action_view/cases/test_legacy_helpers.rb +1 -1
  18. data/test/active_record/cases/test_middleware.rb +19 -34
  19. data/test/active_record/models/user.rb +1 -1
  20. data/test/base_helper.rb +1 -0
  21. data/test/core_ext/cases/test_core_ext.rb +1 -0
  22. data/test/formtastic/cases/helper.rb +5 -0
  23. data/test/formtastic/cases/test_form_builder.rb +3 -3
  24. data/test/formtastic/cases/test_form_helper.rb +3 -4
  25. data/test/generators/cases/test_generators.rb +31 -0
  26. data/test/javascript/public/test/form_builders/validateFormtastic.js +1 -1
  27. data/test/javascript/server.rb +1 -1
  28. data/test/middleware/cases/helper.rb +2 -0
  29. data/test/mongo_mapper/cases/test_middleware.rb +7 -7
  30. data/test/mongoid/cases/test_middleware.rb +7 -7
  31. data/test/simple_form/cases/helper.rb +3 -0
  32. data/test/simple_form/cases/test_form_helper.rb +2 -0
  33. data/test/test_loader.rb +6 -0
  34. data/vendor/assets/javascripts/rails.validations.js +135 -136
  35. metadata +153 -163
  36. checksums.yaml +0 -7
  37. data/lib/generators/templates/client_side_validations/README +0 -7
  38. 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", "put") do
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.json', { 'user[email]' => 'user@test.com', 'case_sensitive' => true }
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.json', { 'case_sensitive' => true, 'user[email]' => 'user@test.com' }
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.json', { 'user[email]' => 'user@test.com', 'case_sensitive' => true }
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.json', { 'user[email]' => 'user@test.com', 'id' => user.id, 'case_sensitive' => true }
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.json', { 'user[email]' => user.email, 'case_sensitive' => true, 'id' => user.id}
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.json', { 'user[email]' => 'user@test.com', 'scope' => { 'age' => 30 }, 'case_sensitive' => true }
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.json', { 'user[email]' => 'user@test.com', 'scope' => { 'age' => 30, 'name' => 'Robert' }, 'case_sensitive' => true }
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.json', { 'user[name]' => 'BRIAN', 'case_sensitive' => false }
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.json', { 'user[name]' => 123, 'case_sensitive' => true }
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.json', { 'user[name]' => 123, 'case_sensitive' => true }
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.json', { 'guid[key]' => 'test', 'case_sensitive' => true }
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.json', { 'user[title]' => 'abcdefgh', 'case_sensitive' => true }
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.json', { 'user[title]' => '一二三四五六七八', 'case_sensitive' => true }
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.json', { 'inept_wizard[name]' => 'Rincewind', 'case_sensitive' => true }
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.json', { 'inept_wizard[name]' => 'Rincewind', 'case_sensitive' => true }
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.json', { 'conjurer[name]' => 'Rincewind', 'case_sensitive' => true }
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.json', { 'thaumaturgist[name]' => 'The Amazing Bonko', 'case_sensitive' => true }
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.json', { '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
-
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), active BOOLEAN);}
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,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
3
  Bundler.setup
4
+ require 'ruby-debug'
4
5
  require 'test/unit'
5
6
  require 'mocha'
6
7
 
@@ -1,3 +1,4 @@
1
+ require 'base_helper'
1
2
  require 'client_side_validations/core_ext'
2
3
 
3
4
  class CoreExtTest < Test::Unit::TestCase
@@ -1,2 +1,7 @@
1
+ # encoding: utf-8
2
+ require 'active_support'
3
+ require 'formtastic/railtie' if defined?(::Rails)
4
+ require 'formtastic/engine' if defined?(::Rails)
1
5
  require 'formtastic'
2
6
  require 'client_side_validations/formtastic'
7
+
@@ -1,11 +1,11 @@
1
1
  require 'formtastic/cases/helper'
2
2
 
3
- class ClientSideValidations::Formtastic::SemanticFormBuilderTest < Test::Unit::TestCase
3
+ class ClientSideValidations::Formtastic::FormBuilderTest < Test::Unit::TestCase
4
4
  def test_client_side_form_js_hash
5
5
  expected = {
6
- :type => 'Formtastic::SemanticFormBuilder',
6
+ :type => 'Formtastic::FormBuilder',
7
7
  :inline_error_class => 'inline-errors'
8
8
  }
9
- assert_equal expected, Formtastic::SemanticFormBuilder.client_side_form_settings(nil, nil)
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::SemanticFormHelper
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="&#x2713;" /><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" /></li></form><script>window['edit_post_123'] = {"type":"Formtastic::SemanticFormBuilder","inline_error_class":"inline-errors","validators":{"post[cost]":{"presence":{"message":"can't be blank"}}}};</script>}
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="&#x2713;" /><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::SemanticFormBuilder',
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+/}}
@@ -43,7 +43,7 @@ get '/' do
43
43
  erb :index
44
44
  end
45
45
 
46
- get '/validators/uniqueness.json' do
46
+ get '/validators/uniqueness' do
47
47
  content_type 'application/json'
48
48
 
49
49
  if user = params[:user2]
@@ -1,4 +1,6 @@
1
1
  require 'base_helper'
2
+ require 'action_controller'
3
+ require 'action_controller/railtie'
2
4
  require 'rails'
3
5
 
4
6
  # Pulled from railties/test/abstract_unit in Rails 3.1
@@ -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.json', { 'magazine[author_email]' => 'magazine@test.com' }
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.json', { 'magazine[author_email]' => 'magazine@test.com' }
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.json', { 'magazine[author_email]' => 'magazine@test.com', 'id' => magazine.id }
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.json', { 'magazine[author_email]' => 'magazine@test.com', 'scope' => { 'age' => 30 } }
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.json', { 'magazine[author_email]' => 'magazine@test.com', 'scope' => { 'age' => 30, 'author_name' => 'Robert' } }
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.json', { 'magazine[author_name]' => 'BRIAN', 'case_sensitive' => false }
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.json', { 'mongo_mapper_test_module/magazine2[author_email]' => 'magazine@test.com' }
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.json', { 'book[author_email]' => 'book@test.com' }
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.json', { 'book[author_email]' => 'book@test.com' }
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.json', { 'book[author_email]' => 'book@test.com', 'id' => book.id }
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.json', { 'book[author_email]' => 'book@test.com', 'scope' => { 'age' => 30 } }
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.json', { 'book[author_email]' => 'book@test.com', 'scope' => { 'age' => 30, 'author_name' => 'Robert' } }
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.json', { 'book[author_name]' => 'BRIAN', 'case_sensitive' => false }
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.json', { 'mongoid_test_module/book2[author_email]' => 'book@test.com' }
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,2 +1,5 @@
1
+ require 'action_view'
2
+ require 'action_controller/railtie'
3
+ require 'rails'
1
4
  require 'simple_form'
2
5
  require 'client_side_validations/simple_form'
@@ -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
@@ -0,0 +1,6 @@
1
+ # Sanity check to make sure the entire library loads OK
2
+
3
+ require 'base_helper'
4
+ require 'client_side_validations'
5
+ require 'client_side_validations/files'
6
+ require 'client_side_validations/version'