active_validation 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -6
  3. data/.rspec +3 -3
  4. data/CODE_OF_CONDUCT.md +13 -0
  5. data/LICENSE.txt +17 -18
  6. data/README.md +100 -145
  7. data/active_validation.gemspec +4 -3
  8. data/bin/console +14 -0
  9. data/bin/rake +16 -0
  10. data/bin/setup +7 -0
  11. data/config/locales/en.yml +7 -8
  12. data/lib/active_validation.rb +4 -4
  13. data/lib/active_validation/matchers/{ensure_valid_latitude_format_of.rb → ensure_valid_coordinate_format_of.rb} +5 -5
  14. data/lib/active_validation/validators/coordinate_validator.rb +38 -0
  15. data/lib/active_validation/version.rb +1 -1
  16. metadata +11 -63
  17. data/lib/active_validation/matchers/ensure_valid_longitude_format_of.rb +0 -26
  18. data/lib/active_validation/validators/latitude_validator.rb +0 -9
  19. data/lib/active_validation/validators/longitude_validator.rb +0 -9
  20. data/spec/lib/alpha_numeric_validator_spec.rb +0 -91
  21. data/spec/lib/alpha_validator_spec.rb +0 -182
  22. data/spec/lib/base64_validator_spec.rb +0 -33
  23. data/spec/lib/boolean_validator_spec.rb +0 -35
  24. data/spec/lib/credit_card_validator_spec.rb +0 -686
  25. data/spec/lib/currency_validator_spec.rb +0 -63
  26. data/spec/lib/cusip_validator_spec.rb +0 -27
  27. data/spec/lib/email_validator_spec.rb +0 -109
  28. data/spec/lib/equality_validator_spec.rb +0 -334
  29. data/spec/lib/hex_validator_spec.rb +0 -73
  30. data/spec/lib/imei_validator_spec.rb +0 -41
  31. data/spec/lib/ip_validator_spec.rb +0 -33
  32. data/spec/lib/isbn_validator_spec.rb +0 -41
  33. data/spec/lib/isin_validator_spec.rb +0 -35
  34. data/spec/lib/latitude_validator_spec.rb +0 -31
  35. data/spec/lib/longitude_validator_spec.rb +0 -31
  36. data/spec/lib/mac_address_validator_spec.rb +0 -54
  37. data/spec/lib/name_validator_spec.rb +0 -39
  38. data/spec/lib/password_validator_spec.rb +0 -85
  39. data/spec/lib/phone_validator_spec.rb +0 -42
  40. data/spec/lib/sedol_validator_spec.rb +0 -31
  41. data/spec/lib/slug_validator_spec.rb +0 -41
  42. data/spec/lib/ssn_validator_spec.rb +0 -36
  43. data/spec/lib/url_validator_spec.rb +0 -106
  44. data/spec/lib/username_validator_spec.rb +0 -37
  45. data/spec/lib/uuid_validator_spec.rb +0 -157
  46. data/spec/spec_helper.rb +0 -12
@@ -8,14 +8,15 @@ Gem::Specification.new do |spec|
8
8
  spec.version = ActiveValidation::VERSION
9
9
  spec.authors = ["Juan Gomez"]
10
10
  spec.email = ["j.gomez@drexed.com"]
11
+
11
12
  spec.summary = %q{Gem for commonly used validators.}
12
13
  spec.description = %q{Validate commonly used attributes easily with ActiveValidation.}
13
14
  spec.homepage = "https://github.com/drexed/active_validation"
14
15
  spec.license = "MIT"
15
16
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
20
  spec.require_paths = ["lib"]
20
21
 
21
22
  spec.add_runtime_dependency "activemodel"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_validation"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -6,6 +6,10 @@ en:
6
6
  alpha_numeric: "is not a valid alpha-numeric characters"
7
7
  base64: "is not a valid Base64 encode"
8
8
  boolean: "is not a valid boolean"
9
+ coordinate:
10
+ coordinate: "is not a valid coordinate"
11
+ latitude: "is not a valid latitude"
12
+ longitude: "is not a valid longitude"
9
13
  credit_card: "is not a valid credit card"
10
14
  currency: "is not a valid currency"
11
15
  cusip: "is not a valid CUSIP"
@@ -16,8 +20,6 @@ en:
16
20
  ip: "is not a valid IP"
17
21
  isbn: "is not a valid ISBN"
18
22
  isin: "is not a valid ISIN"
19
- longitude: "is not a valid latitude"
20
- longitude: "is not a valid longitude"
21
23
  mac_address: "is not a valid MAC address"
22
24
  name: "is not a valid name"
23
25
  password: "is not a valid password"
@@ -41,6 +43,9 @@ en:
41
43
  ensure_valid_boolean_format_of:
42
44
  failure_message_for_should: "%{model} should ensure valid boolean format of attribute %{attr}"
43
45
  failure_message_for_should_not: "%{model} should not ensure valid boolean format of attribute %{attr}"
46
+ ensure_valid_coordinate_format_of:
47
+ failure_message_for_should: "%{model} should ensure valid coordinate format of attribute %{attr}"
48
+ failure_message_for_should_not: "%{model} should not ensure valid coordinate format of attribute %{attr}"
44
49
  ensure_valid_credit_card_format_of:
45
50
  failure_message_for_should: "%{model} should ensure valid credit card format of attribute %{attr}"
46
51
  failure_message_for_should_not: "%{model} should not ensure valid credit card format of attribute %{attr}"
@@ -71,12 +76,6 @@ en:
71
76
  ensure_valid_isin_format_of:
72
77
  failure_message_for_should: "%{model} should ensure valid ISIN format of attribute %{attr}"
73
78
  failure_message_for_should_not: "%{model} should not ensure valid ISIN format of attribute %{attr}"
74
- ensure_valid_latitude_format_of:
75
- failure_message_for_should: "%{model} should ensure valid latitude format of attribute %{attr}"
76
- failure_message_for_should_not: "%{model} should not ensure valid latitude format of attribute %{attr}"
77
- ensure_valid_longitude_format_of:
78
- failure_message_for_should: "%{model} should ensure valid longitude format of attribute %{attr}"
79
- failure_message_for_should_not: "%{model} should not ensure valid longitude format of attribute %{attr}"
80
79
  ensure_valid_mac_address_format_of:
81
80
  failure_message_for_should: "%{model} should ensure valid MAC address format of attribute %{attr}"
82
81
  failure_message_for_should_not: "%{model} should not ensure valid MAC address format of attribute %{attr}"
@@ -6,6 +6,7 @@ require 'active_validation/validators/alpha_validator'
6
6
  require 'active_validation/validators/alpha_numeric_validator'
7
7
  require 'active_validation/validators/base64_validator'
8
8
  require 'active_validation/validators/boolean_validator'
9
+ require 'active_validation/validators/coordinate_validator'
9
10
  require 'active_validation/validators/credit_card_validator'
10
11
  require 'active_validation/validators/currency_validator'
11
12
  require 'active_validation/validators/cusip_validator'
@@ -16,8 +17,6 @@ require 'active_validation/validators/imei_validator'
16
17
  require 'active_validation/validators/ip_validator'
17
18
  require 'active_validation/validators/isbn_validator'
18
19
  require 'active_validation/validators/isin_validator'
19
- require 'active_validation/validators/latitude_validator'
20
- require 'active_validation/validators/longitude_validator'
21
20
  require 'active_validation/validators/mac_address_validator'
22
21
  require 'active_validation/validators/name_validator'
23
22
  require 'active_validation/validators/password_validator'
@@ -35,6 +34,7 @@ if defined?(RSpec)
35
34
  require 'active_validation/matchers/ensure_valid_alpha_numeric_format_of'
36
35
  require 'active_validation/matchers/ensure_valid_base64_format_of'
37
36
  require 'active_validation/matchers/ensure_valid_boolean_format_of'
37
+ require 'active_validation/matchers/ensure_valid_coordinate_format_of'
38
38
  require 'active_validation/matchers/ensure_valid_credit_card_format_of'
39
39
  require 'active_validation/matchers/ensure_valid_currency_format_of'
40
40
  require 'active_validation/matchers/ensure_valid_cusip_format_of'
@@ -45,8 +45,6 @@ if defined?(RSpec)
45
45
  require 'active_validation/matchers/ensure_valid_ip_format_of'
46
46
  require 'active_validation/matchers/ensure_valid_isbn_format_of'
47
47
  require 'active_validation/matchers/ensure_valid_isin_format_of'
48
- require 'active_validation/matchers/ensure_valid_latitude_format_of'
49
- require 'active_validation/matchers/ensure_valid_longitude_format_of'
50
48
  require 'active_validation/matchers/ensure_valid_mac_address_format_of'
51
49
  require 'active_validation/matchers/ensure_valid_name_format_of'
52
50
  require 'active_validation/matchers/ensure_valid_password_format_of'
@@ -64,6 +62,7 @@ if defined?(Rails)
64
62
 
65
63
  module ActiveValidation
66
64
  class Railtie < ::Rails::Railtie
65
+
67
66
  initializer 'active_validation' do |app|
68
67
  ActiveValidation::Railtie.instance_eval do
69
68
  locales = locales_from(app.config.i18n.available_locales)
@@ -86,6 +85,7 @@ if defined?(Rails)
86
85
  array = Array(args || [])
87
86
  array.blank? ? '*' : array
88
87
  end
88
+
89
89
  end
90
90
  end
91
91
  end
@@ -1,16 +1,16 @@
1
- RSpec::Matchers.define :ensure_valid_latitude_format_of do |attribute|
1
+ RSpec::Matchers.define :ensure_valid_coordinate_format_of do |attribute|
2
2
  match do |model|
3
- model.send("#{attribute}=", 91)
3
+ model.send("#{attribute}=", [91, 181])
4
4
  model.valid?
5
5
 
6
6
  if model.errors.has_key?(attribute)
7
- model.errors[attribute].include?(I18n.t('active_validation.errors.messages.latitude'))
7
+ model.errors[attribute].include?(I18n.t('active_validation.errors.messages.coordinate.coordinate'))
8
8
  end
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
12
  I18n.t(
13
- 'active_validation.matchers.ensure_valid_latitude_format_of.failure_message_for_should',
13
+ 'active_validation.matchers.ensure_valid_coordinate_format_of.failure_message_for_should',
14
14
  attr: attribute.inspect,
15
15
  model: model.class.name
16
16
  )
@@ -18,7 +18,7 @@ RSpec::Matchers.define :ensure_valid_latitude_format_of do |attribute|
18
18
 
19
19
  failure_message_when_negated do |model|
20
20
  I18n.t(
21
- 'active_validation.matchers.ensure_valid_latitude_format_of.failure_message_for_should_not',
21
+ 'active_validation.matchers.ensure_valid_coordinate_format_of.failure_message_for_should_not',
22
22
  attr: attribute.inspect,
23
23
  model: model.class.name
24
24
  )
@@ -0,0 +1,38 @@
1
+ class CoordinateValidator < ActiveModel::EachValidator
2
+
3
+ def validate_each(record, attribute, value)
4
+ boundary = options.fetch(:boundary, :coordinate)
5
+ unless BOUNDARIES.include?(boundary)
6
+ raise ArgumentError,
7
+ "Unknown boundary: #{boundary.inspect}. Valid boundaries are: #{BOUNDARIES.map(&:inspect).join(', ')}"
8
+ end
9
+
10
+ unless value.present? && valid_boundary?(value)
11
+ record.errors[attribute] << (options[:message] || I18n.t("active_validation.errors.messages.coordinate.#{boundary}"))
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ BOUNDARIES = [:coordinate, :latitude, :longitude]
18
+
19
+ def valid_latitude?(value)
20
+ value >= -90 && value <= 90
21
+ end
22
+
23
+ def valid_longitude?(value)
24
+ value >= -180 && value <= 180
25
+ end
26
+
27
+ def valid_boundary?(value)
28
+ case options[:boundary]
29
+ when :latitude
30
+ valid_latitude?(value)
31
+ when :longitude
32
+ valid_longitude?(value)
33
+ else
34
+ valid_latitude?(value.first) && valid_longitude?(value.last)
35
+ end
36
+ end
37
+
38
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveValidation
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2015-02-25 00:00:00.000000000 Z
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -119,17 +119,22 @@ files:
119
119
  - ".gitignore"
120
120
  - ".rspec"
121
121
  - ".travis.yml"
122
+ - CODE_OF_CONDUCT.md
122
123
  - Gemfile
123
124
  - LICENSE.txt
124
125
  - README.md
125
126
  - Rakefile
126
127
  - active_validation.gemspec
128
+ - bin/console
129
+ - bin/rake
130
+ - bin/setup
127
131
  - config/locales/en.yml
128
132
  - lib/active_validation.rb
129
133
  - lib/active_validation/matchers/ensure_valid_alpha_format_of.rb
130
134
  - lib/active_validation/matchers/ensure_valid_alpha_numeric_format_of.rb
131
135
  - lib/active_validation/matchers/ensure_valid_base64_format_of.rb
132
136
  - lib/active_validation/matchers/ensure_valid_boolean_format_of.rb
137
+ - lib/active_validation/matchers/ensure_valid_coordinate_format_of.rb
133
138
  - lib/active_validation/matchers/ensure_valid_credit_card_format_of.rb
134
139
  - lib/active_validation/matchers/ensure_valid_currency_format_of.rb
135
140
  - lib/active_validation/matchers/ensure_valid_cusip_format_of.rb
@@ -140,8 +145,6 @@ files:
140
145
  - lib/active_validation/matchers/ensure_valid_ip_format_of.rb
141
146
  - lib/active_validation/matchers/ensure_valid_isbn_format_of.rb
142
147
  - lib/active_validation/matchers/ensure_valid_isin_format_of.rb
143
- - lib/active_validation/matchers/ensure_valid_latitude_format_of.rb
144
- - lib/active_validation/matchers/ensure_valid_longitude_format_of.rb
145
148
  - lib/active_validation/matchers/ensure_valid_mac_address_format_of.rb
146
149
  - lib/active_validation/matchers/ensure_valid_name_format_of.rb
147
150
  - lib/active_validation/matchers/ensure_valid_password_format_of.rb
@@ -156,6 +159,7 @@ files:
156
159
  - lib/active_validation/validators/alpha_validator.rb
157
160
  - lib/active_validation/validators/base64_validator.rb
158
161
  - lib/active_validation/validators/boolean_validator.rb
162
+ - lib/active_validation/validators/coordinate_validator.rb
159
163
  - lib/active_validation/validators/credit_card_validator.rb
160
164
  - lib/active_validation/validators/currency_validator.rb
161
165
  - lib/active_validation/validators/cusip_validator.rb
@@ -166,8 +170,6 @@ files:
166
170
  - lib/active_validation/validators/ip_validator.rb
167
171
  - lib/active_validation/validators/isbn_validator.rb
168
172
  - lib/active_validation/validators/isin_validator.rb
169
- - lib/active_validation/validators/latitude_validator.rb
170
- - lib/active_validation/validators/longitude_validator.rb
171
173
  - lib/active_validation/validators/mac_address_validator.rb
172
174
  - lib/active_validation/validators/name_validator.rb
173
175
  - lib/active_validation/validators/password_validator.rb
@@ -179,33 +181,6 @@ files:
179
181
  - lib/active_validation/validators/username_validator.rb
180
182
  - lib/active_validation/validators/uuid_validator.rb
181
183
  - lib/active_validation/version.rb
182
- - spec/lib/alpha_numeric_validator_spec.rb
183
- - spec/lib/alpha_validator_spec.rb
184
- - spec/lib/base64_validator_spec.rb
185
- - spec/lib/boolean_validator_spec.rb
186
- - spec/lib/credit_card_validator_spec.rb
187
- - spec/lib/currency_validator_spec.rb
188
- - spec/lib/cusip_validator_spec.rb
189
- - spec/lib/email_validator_spec.rb
190
- - spec/lib/equality_validator_spec.rb
191
- - spec/lib/hex_validator_spec.rb
192
- - spec/lib/imei_validator_spec.rb
193
- - spec/lib/ip_validator_spec.rb
194
- - spec/lib/isbn_validator_spec.rb
195
- - spec/lib/isin_validator_spec.rb
196
- - spec/lib/latitude_validator_spec.rb
197
- - spec/lib/longitude_validator_spec.rb
198
- - spec/lib/mac_address_validator_spec.rb
199
- - spec/lib/name_validator_spec.rb
200
- - spec/lib/password_validator_spec.rb
201
- - spec/lib/phone_validator_spec.rb
202
- - spec/lib/sedol_validator_spec.rb
203
- - spec/lib/slug_validator_spec.rb
204
- - spec/lib/ssn_validator_spec.rb
205
- - spec/lib/url_validator_spec.rb
206
- - spec/lib/username_validator_spec.rb
207
- - spec/lib/uuid_validator_spec.rb
208
- - spec/spec_helper.rb
209
184
  homepage: https://github.com/drexed/active_validation
210
185
  licenses:
211
186
  - MIT
@@ -226,35 +201,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
201
  version: '0'
227
202
  requirements: []
228
203
  rubyforge_project:
229
- rubygems_version: 2.4.6
204
+ rubygems_version: 2.4.8
230
205
  signing_key:
231
206
  specification_version: 4
232
207
  summary: Gem for commonly used validators.
233
- test_files:
234
- - spec/lib/alpha_numeric_validator_spec.rb
235
- - spec/lib/alpha_validator_spec.rb
236
- - spec/lib/base64_validator_spec.rb
237
- - spec/lib/boolean_validator_spec.rb
238
- - spec/lib/credit_card_validator_spec.rb
239
- - spec/lib/currency_validator_spec.rb
240
- - spec/lib/cusip_validator_spec.rb
241
- - spec/lib/email_validator_spec.rb
242
- - spec/lib/equality_validator_spec.rb
243
- - spec/lib/hex_validator_spec.rb
244
- - spec/lib/imei_validator_spec.rb
245
- - spec/lib/ip_validator_spec.rb
246
- - spec/lib/isbn_validator_spec.rb
247
- - spec/lib/isin_validator_spec.rb
248
- - spec/lib/latitude_validator_spec.rb
249
- - spec/lib/longitude_validator_spec.rb
250
- - spec/lib/mac_address_validator_spec.rb
251
- - spec/lib/name_validator_spec.rb
252
- - spec/lib/password_validator_spec.rb
253
- - spec/lib/phone_validator_spec.rb
254
- - spec/lib/sedol_validator_spec.rb
255
- - spec/lib/slug_validator_spec.rb
256
- - spec/lib/ssn_validator_spec.rb
257
- - spec/lib/url_validator_spec.rb
258
- - spec/lib/username_validator_spec.rb
259
- - spec/lib/uuid_validator_spec.rb
260
- - spec/spec_helper.rb
208
+ test_files: []
@@ -1,26 +0,0 @@
1
- RSpec::Matchers.define :ensure_valid_longitude_format_of do |attribute|
2
- match do |model|
3
- model.send("#{attribute}=", 181)
4
- model.valid?
5
-
6
- if model.errors.has_key?(attribute)
7
- model.errors[attribute].include?(I18n.t('active_validation.errors.messages.longitude'))
8
- end
9
- end
10
-
11
- failure_message do |model|
12
- I18n.t(
13
- 'active_validation.matchers.ensure_valid_longitude_format_of.failure_message_for_should',
14
- attr: attribute.inspect,
15
- model: model.class.name
16
- )
17
- end
18
-
19
- failure_message_when_negated do |model|
20
- I18n.t(
21
- 'active_validation.matchers.ensure_valid_longitude_format_of.failure_message_for_should_not',
22
- attr: attribute.inspect,
23
- model: model.class.name
24
- )
25
- end
26
- end
@@ -1,9 +0,0 @@
1
- class LatitudeValidator < ActiveModel::EachValidator
2
-
3
- def validate_each(record, attribute, value)
4
- unless value.present? && value >= -90 && value <= 90
5
- record.errors[attribute] << (options[:message] || I18n.t('active_validation.errors.messages.latitude'))
6
- end
7
- end
8
-
9
- end
@@ -1,9 +0,0 @@
1
- class LongitudeValidator < ActiveModel::EachValidator
2
-
3
- def validate_each(record, attribute, value)
4
- unless value.present? && value >= -180 && value <= 180
5
- record.errors[attribute] << (options[:message] || I18n.t('active_validation.errors.messages.longitude'))
6
- end
7
- end
8
-
9
- end
@@ -1,91 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AlphaNumericValidator do
4
-
5
- context "has a valid value" do
6
- let(:klass) do
7
- Class.new do
8
- include ActiveModel::Validations
9
- attr_accessor :title, :name
10
- validates :title, alpha_numeric: true
11
- end
12
- end
13
-
14
- subject { klass.new }
15
-
16
- it { should allow_value("Example").for(:title) }
17
- it { should allow_value("Example Title").for(:title) }
18
- it { should allow_value("Example1").for(:title) }
19
- it { should allow_value("Example 1").for(:title) }
20
-
21
- it { should_not allow_value('').for(:title) }
22
- it { should_not allow_value(' ').for(:title) }
23
- it { should_not allow_value(nil).for(:title) }
24
- it { should_not allow_value("Ex-ample").for(:title) }
25
- it { should_not allow_value("Ex-ample1").for(:title) }
26
- it { should_not allow_value("! \#$%\`|").for(:title) }
27
- it { should_not allow_value("<>@[]\`|").for(:title) }
28
-
29
- it { should ensure_valid_alpha_numeric_format_of(:title) }
30
- it { should_not ensure_valid_alpha_numeric_format_of(:name) }
31
- end
32
-
33
- context "with :strict option has a valid value" do
34
- let(:klass) do
35
- Class.new do
36
- include ActiveModel::Validations
37
- attr_accessor :title, :name
38
- validates :title, alpha_numeric: { strict: true }
39
- end
40
- end
41
-
42
- subject { klass.new }
43
-
44
- it { should allow_value("Example").for(:title) }
45
- it { should allow_value("Example1").for(:title) }
46
-
47
- it { should_not allow_value('').for(:title) }
48
- it { should_not allow_value(' ').for(:title) }
49
- it { should_not allow_value(nil).for(:title) }
50
- it { should_not allow_value("Example Title").for(:title) }
51
- it { should_not allow_value("Example 1").for(:title) }
52
- it { should_not allow_value("Ex-ample").for(:title) }
53
- it { should_not allow_value("Ex-ample1").for(:title) }
54
- it { should_not allow_value("! \#$%\`|").for(:title) }
55
- it { should_not allow_value("<>@[]\`|").for(:title) }
56
-
57
- it { should ensure_valid_alpha_numeric_format_of(:title) }
58
- it { should_not ensure_valid_alpha_numeric_format_of(:name) }
59
- end
60
-
61
- context "with case: :lower option has a valid value" do
62
- let(:klass) do
63
- Class.new do
64
- include ActiveModel::Validations
65
- attr_accessor :title, :name
66
- validates :title, alpha_numeric: { case: :lower }
67
- end
68
- end
69
-
70
- subject { klass.new }
71
-
72
- it { should allow_value("example1").for(:title) }
73
- it { should allow_value("example title 1").for(:title) }
74
-
75
- it { should_not allow_value('').for(:title) }
76
- it { should_not allow_value(' ').for(:title) }
77
- it { should_not allow_value(nil).for(:title) }
78
- it { should_not allow_value("Example").for(:title) }
79
- it { should_not allow_value("Example Title").for(:title) }
80
- it { should_not allow_value("Example 1").for(:title) }
81
- it { should_not allow_value("Example1").for(:title) }
82
- it { should_not allow_value("Ex-ample").for(:title) }
83
- it { should_not allow_value("Ex-ample1").for(:title) }
84
- it { should_not allow_value("! \#$%\`|").for(:title) }
85
- it { should_not allow_value("<>@[]\`|").for(:title) }
86
-
87
- it { should ensure_valid_alpha_numeric_format_of(:title) }
88
- it { should_not ensure_valid_alpha_numeric_format_of(:name) }
89
- end
90
-
91
- end