diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2017-09-09 17:37:13 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2017-09-09 17:37:13 +0200 |
commit | 5de07c194e85fa74e7d7f2be12e99cb9acad3ccc (patch) | |
tree | fc58dc46aba60b898afec89a1cb5b451da07d236 /spec/contact_spec.rb | |
parent | 032d46f65ac3bbfe5c05f96e6b68d0dfe2a4aa3d (diff) | |
download | norsk-urskog-registrations-5de07c194e85fa74e7d7f2be12e99cb9acad3ccc.tar.gz norsk-urskog-registrations-5de07c194e85fa74e7d7f2be12e99cb9acad3ccc.tar.bz2 norsk-urskog-registrations-5de07c194e85fa74e7d7f2be12e99cb9acad3ccc.zip |
Validate postcode properly.
Don't accept invalid postcodes, or postcodes containing invalid chars.
Diffstat (limited to 'spec/contact_spec.rb')
-rw-r--r-- | spec/contact_spec.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/contact_spec.rb b/spec/contact_spec.rb new file mode 100644 index 0000000..980626b --- /dev/null +++ b/spec/contact_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Contact do + let(:params) { create_contact_params } + + it "rejects empty postcodes" do + params.delete('postcode') + @contact = Contact.new(params) + expect(@contact.valid?).to be(false) + end + + it "rejects too short postcodes" do + params['postcode'] = '123' + @contact = Contact.new(params) + expect(@contact.valid?).to be(false) + end + + it "rejects too long postcodes" do + params['postcode'] = '12345' + @contact = Contact.new(params) + expect(@contact.valid?).to be(false) + end + + it "rejects postcodes wiht invalid chars" do + params['postcode'] = '123s' + @contact = Contact.new(params) + expect(@contact.valid?).to be(false) + end +end |