client_side_validations-rails_2 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -1,3 +1,10 @@
1
+ == 1.0.3
2
+ Better tests backporting for ActiveModel.
3
+ Fixed LengthValidator support
4
+
5
+ == 1.0.2
6
+ Updated dependency for at least ClientSideValidaitons v3.0.12
7
+
1
8
  == 1.0.1
2
9
  Updated dependency for at least ClientSideValidaitons v3.0.11
3
10
 
@@ -23,3 +23,4 @@ module ActiveModel::Validations
23
23
  end
24
24
  end
25
25
  end
26
+
@@ -0,0 +1,4 @@
1
+ class ActiveModel::Validations::LengthValidator
2
+ MESSAGES = { :is => :wrong_length, :minimum => :too_short, :maximum => :too_long }.freeze
3
+ end
4
+
@@ -41,7 +41,12 @@ require 'client_side_validations/rails_2/active_record/active_model/validations/
41
41
  MODULE
42
42
  end
43
43
 
44
- require 'client_side_validations/rails_2/active_record/active_model/validations/numericality'
44
+ %w{
45
+ length
46
+ numericality
47
+ }.each do |validator|
48
+ require "client_side_validations/rails_2/active_record/active_model/validations/#{validator}"
49
+ end
45
50
 
46
51
  module ActiveModel::Validations::ClassMethods
47
52
  def validates_size_of(*attr_names)
@@ -40,3 +40,4 @@ module ClientSideValidations::ActiveRecord
40
40
  end
41
41
  end
42
42
  end
43
+
@@ -20,3 +20,4 @@ if defined?(Rails)
20
20
  Rails.configuration.middleware.use ClientSideValidations::Middleware::Validators
21
21
  end
22
22
  end
23
+
@@ -1,5 +1,6 @@
1
1
  module ClientSideValidations
2
2
  module Rails2
3
- VERSION = '1.0.2'
3
+ VERSION = '1.0.3'
4
4
  end
5
5
  end
6
+
@@ -3,3 +3,4 @@ module ClientSideValidations::Rails2; end
3
3
  require 'client_side_validations/rails_2/middleware'
4
4
  require 'client_side_validations/rails_2/action_view'
5
5
  require 'client_side_validations/rails_2/active_record'
6
+
@@ -11,7 +11,113 @@ class ValidationsTest < ClientSideValidations::ActiveRecordTestBase
11
11
  user.new
12
12
  end
13
13
 
14
- def test_validations_to_client_side_hash
14
+ def test_acceptance_validation_to_client_side_hash
15
+ user = new_user do |p|
16
+ p.validates_acceptance_of :name
17
+ end
18
+ expected_hash = {
19
+ :name => {
20
+ :acceptance => {
21
+ :message => "must be accepted"
22
+ }
23
+ }
24
+ }
25
+ assert_equal expected_hash, user.client_side_validation_hash
26
+ end
27
+
28
+ def test_confirmation_validation_to_client_side_hash
29
+ user = new_user do |p|
30
+ p.validates_confirmation_of :name
31
+ end
32
+ expected_hash = {
33
+ :name => {
34
+ :confirmation => {
35
+ :message => "doesn't match confirmation"
36
+ }
37
+ }
38
+ }
39
+ assert_equal expected_hash, user.client_side_validation_hash
40
+ end
41
+
42
+ def test_exclusion_validation_to_client_side_hash
43
+ user = new_user do |p|
44
+ p.validates_exclusion_of :name, :in => %w{1}
45
+ end
46
+ expected_hash = {
47
+ :name => {
48
+ :exclusion => {
49
+ :message => "is reserved",
50
+ :in => ["1"]
51
+ }
52
+ }
53
+ }
54
+ assert_equal expected_hash, user.client_side_validation_hash
55
+ end
56
+
57
+ def test_format_validation_to_client_side_hash
58
+ user = new_user do |p|
59
+ p.validates_format_of :name, :with => /\.+/
60
+ end
61
+ expected_hash = {
62
+ :name => {
63
+ :format => {
64
+ :message => "is invalid",
65
+ :with => /\.+/
66
+ }
67
+ }
68
+ }
69
+ assert_equal expected_hash, user.client_side_validation_hash
70
+ end
71
+
72
+ def test_inclusion_validation_to_client_side_hash
73
+ user = new_user do |p|
74
+ p.validates_inclusion_of :name, :in => %w{1}
75
+ end
76
+ expected_hash = {
77
+ :name => {
78
+ :inclusion => {
79
+ :message => "is not included in the list",
80
+ :in => ["1"]
81
+ }
82
+ }
83
+ }
84
+ assert_equal expected_hash, user.client_side_validation_hash
85
+ end
86
+
87
+ def test_length_validation_to_client_side_hash
88
+ user = new_user do |p|
89
+ p.validates_length_of :name, :is => 5
90
+ end
91
+ expected_hash = {
92
+ :name => {
93
+ :length => {
94
+ :messages => {
95
+ :is => "is the wrong length (should be 5 characters)"
96
+ },
97
+ :is => 5
98
+ }
99
+ }
100
+ }
101
+ assert_equal expected_hash, user.client_side_validation_hash
102
+ end
103
+
104
+ def test_numericality_validation_to_client_side_hash
105
+ user = new_user do |p|
106
+ p.validates_numericality_of :name
107
+ end
108
+ expected_hash = {
109
+ :name => {
110
+ :numericality => {
111
+ :messages => {
112
+ :numericality => "is not a number"
113
+ }
114
+ }
115
+ }
116
+ }
117
+ assert_equal expected_hash, user.client_side_validation_hash
118
+ end
119
+
120
+ def test_presence_validation_to_client_side_hash
15
121
  user = new_user do |p|
16
122
  p.validates_presence_of :name
17
123
  end
@@ -24,4 +130,19 @@ class ValidationsTest < ClientSideValidations::ActiveRecordTestBase
24
130
  }
25
131
  assert_equal expected_hash, user.client_side_validation_hash
26
132
  end
133
+
134
+ def test_uniqueness_validation_to_client_side_hash
135
+ user = new_user do |p|
136
+ p.validates_uniqueness_of :name
137
+ end
138
+ expected_hash = {
139
+ :name => {
140
+ :uniqueness => {
141
+ :message => "has already been taken",
142
+ :case_sensitive => nil
143
+ }
144
+ }
145
+ }
146
+ assert_equal expected_hash, user.client_side_validation_hash
147
+ end
27
148
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: client_side_validations-rails_2
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.2
5
+ version: 1.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brian Cardarella
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-23 00:00:00 -04:00
13
+ date: 2011-06-27 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -126,6 +126,7 @@ files:
126
126
  - lib/client_side_validations/rails_2/active_record/active_model.rb
127
127
  - lib/client_side_validations/rails_2/active_record/active_model/validations.rb
128
128
  - lib/client_side_validations/rails_2/active_record/active_model/validations/base.rb
129
+ - lib/client_side_validations/rails_2/active_record/active_model/validations/length.rb
129
130
  - lib/client_side_validations/rails_2/active_record/active_model/validations/numericality.rb
130
131
  - lib/client_side_validations/rails_2/active_record/middleware.rb
131
132
  - lib/client_side_validations/rails_2/active_record/validations.rb