I'm using ruby 1.9.2 and rails 3.2.2.
I have a 'domain' model (domain.rb):
class Domain < ActiveRecord::Base
attr_accessible :url
belongs_to :user
VALID_DOMAIN_REGEX = /^[a-z0-9\-\.]+\.[a-z]{2,}$/i
validates :url, presence:true,
format: { with: VALID_DOMAIN_REGEX },
uniqueness: { case_sensitive: false }
end
And a test asserting that a duplicate domain should not be valid:
require 'spec_helper'
describe Domain do
before do
@domain = FactoryGirl.create(:domain)
end
subject { @domain }
describe "when domain url is already taken" do
before do
domain_with_same_url = @domain.dup
domain_with_same_url.url = @domain.url.upcase
domain_with_same_url.save
end
it { should_not be_valid }
end
end
The test keeps failing:
1) Domain when domain url is already taken Failure/Error: it { should_not be_valid } expected valid? to return false, got true # ./spec/models/domain_spec.rb:31:in `block (3 levels) in '