Last active
August 29, 2015 14:05
-
-
Save NikitaAvvakumov/3db3848deae0a3444a03 to your computer and use it in GitHub Desktop.
Spec for proposed validator for legacy province codes, OSRA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Validator is here: https://gist.github.com/adc8cb0de0c6fa12dfb1.git | |
require 'rails_helper' | |
describe LegacyCodeMatchesProvinceValidator do | |
let(:test_class) do | |
Class.new do | |
include ActiveModel::Validations | |
attr_accessor :name | |
attr_accessor :code | |
validates_with LegacyCodeMatchesProvinceValidator | |
end | |
end | |
subject(:test_province) { test_class.new } | |
it 'passes when legacy code matches province name' do | |
[['Damascus & Rif Dimashq', 11], | |
['Aleppo', 12], | |
['Homs', 13], | |
['Hama', 14], | |
['Latakia', 15], | |
['Deir Al-Zor', 16], | |
['Daraa', 17], | |
['Idlib', 18], | |
['Ar Raqqah', 19], | |
['Al Ḥasakah', 20], | |
['Tartous', 21], | |
['Al-Suwayada', 22], | |
['Al-Quneitera', 23], | |
['Outside Syria', 29]].each do |pair| | |
test_province.name = pair[0] | |
test_province.code = pair[1] | |
expect(test_province).to be_valid | |
end | |
end | |
it 'fails when legacy code does not match province name' do | |
[['Damascus & Rif Dimashq', 12], ['Aleppo', 13], ['Homs', 14], ['Hama', 11]].each do |pair| | |
test_province.name = pair[0] | |
test_province.code = pair[1] | |
expect(test_province).not_to be_valid | |
end | |
end | |
it 'passes when province name is not one of original 14' do | |
[['New Province', 11], ['Newer Province', 77], ['Newest Province', 1024]].each do |pair| | |
test_province.name = pair[0] | |
test_province.code = pair[1] | |
expect(test_province).to be_valid | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@PurityControl: fixed the validator name.
['New Province', 11]
is valid here because 'New Province' is not an existing province name. However, it will fail the uniqueness validation on thecode
attribute, which won't allow new province records to reuse existing codes.