diff --git a/app/models/spf.rb b/app/models/spf.rb new file mode 100644 index 0000000..6a2e0cd --- /dev/null +++ b/app/models/spf.rb @@ -0,0 +1,8 @@ +class SPF < Record + validates :content, + format: { + with: /\A".*"\Z/, + message: 'SPF records should be enclosed in quotes' + } + +end diff --git a/test/factories/spf.rb b/test/factories/spf.rb new file mode 100644 index 0000000..633c97e --- /dev/null +++ b/test/factories/spf.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :spf, class: 'SPF' do + domain + name '' + content '"v=spf1 a:mail.example.com -all"' + end +end diff --git a/test/models/spf_text.rb b/test/models/spf_text.rb new file mode 100644 index 0000000..dffe12c --- /dev/null +++ b/test/models/spf_text.rb @@ -0,0 +1,36 @@ +require 'test_helper' + +class SPFTest < ActiveSupport::TestCase + + test 'saves' do + rec = build(:spf) + rec.valid? + + assert_empty rec.errors + assert rec.save + end + + [ + '""', + '"The quick brown fox"' + ].each { |spf| + test "valid content #{spf}" do + rec = build(:spf, content: spf) + rec.valid? + assert_empty rec.errors[:content], "#{spf.inspect} should be valid!" + end + } + + [ + '', + '"', + 'no quotes', + ].each { |spf| + test "invalid content #{spf}" do + rec = build(:spf, content: spf) + rec.valid? + assert_not_empty rec.errors[:content], "#{spf.inspect} should be invalid!" + end + } + +end