ama_validators 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c9614a52d7db2277d72016cb12ce7d2a37f2243
|
4
|
+
data.tar.gz: c16272215b974ab584d9d5ddb2d581d5627219a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52ef9dcddbebe180317a6fee81b162309927cca12217e2029ee51200c660de39a8b5eb97bc51d54ee5086813ea3172a96aad4b663054bfcbbf839c5a4b840610
|
7
|
+
data.tar.gz: 82a782460d95064be8a77a1a96806c5178079988de3eeab5d9719f348bb49b70a8f02d63729aad1d946bbbd1f16d484af58ac4b408743d9a594ccd4226bf8979
|
@@ -3,12 +3,14 @@
|
|
3
3
|
|
4
4
|
class ProvinceValidator < ActiveModel::EachValidator
|
5
5
|
def validate_each(object, attribute, value)
|
6
|
-
provinces = PROV_STATE[object.send(options[:country])]
|
6
|
+
provinces = PROV_STATE[object.send(options[:country]).to_sym]
|
7
7
|
if !provinces.try(:include?, value)
|
8
|
-
object.errors[attribute] << (options[:message] || 'Province/State
|
8
|
+
object.errors[attribute] << (options[:message] || 'Province/State should be in selected country.')
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
COUNTRIES = { canada: 'Canada', usa: 'United States of America', mexico: 'Mexico' }
|
13
|
+
|
12
14
|
PROV_STATE = {
|
13
15
|
canada: ['Alberta', 'British Columbia', 'Manitoba', 'New Brunswick', 'Newfoundland', 'Nova Scotia',
|
14
16
|
'Northwest Territories', 'Nunavut', 'Ontario', 'Prince Edward Island', 'Saskatchewan',
|
@@ -11,6 +11,15 @@ describe ProvinceValidator do
|
|
11
11
|
|
12
12
|
subject { Validatable.new({ country: country, province: province }) }
|
13
13
|
|
14
|
+
context 'province is in selected country as a string' do
|
15
|
+
let(:country) { 'canada' }
|
16
|
+
let(:province) { 'Alberta' }
|
17
|
+
|
18
|
+
it 'is valid' do
|
19
|
+
expect(subject).to be_valid
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
14
23
|
context 'province is in selected country' do
|
15
24
|
let(:country) { :canada }
|
16
25
|
let(:province) { 'Alberta' }
|