I'm using rspec, rails, guard and sorcery for my authentication and testing.
I have a test that is testing the length of an email. I want to reject emails that are too long. Here is the test I wrote for spec/models/user_spec.rb
require 'spec_helper'
describe User do
before(:each) do
@attr = { :email => "[email protected]", :password => "password", :password_confirmation => "password" }
end
it "should reject emails that are too long" do
long_email = "a" * 101 + "gmail.com"
long_email = User.new (@attr.merge(:email => long_email))
long_email.should_not be_valid
end
Here is the model validations I have in place:
class User < ActiveRecord::Base
authenticates_with_sorcery!
attr_accessible :email, :password, :password_confirmation
validates_presence_of :password, :on => :create
validates :password, :confirmation => true,
:length => { :within => 6..100 }
email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, :presence => true,
:format => { :with => email_regex },
:uniqueness => {:case_sensitive => false},
:length => { :within => 5..100 }
end
I'm a noob with this stuff, so any help would be greatly appreciated. The test is green right now, it goes red if I change the line to long_email.should be_valid. Thanks in advance!