Skip to content

Instantly share code, notes, and snippets.

@jdudek jdudek/user_spec.rb
Created Nov 24, 2010

Embed
What would you like to do?
Test validations in ActiveRecord
require 'spec_helper'
module ActiveModel
class Errors
def error_names
@_error_names ||= { }
end
def add_with_save_names(attribute, message = nil, options = {})
message ||= :invalid
if message.is_a?(Proc)
message = message.call
end
error_names[attribute] ||= []
error_names[attribute] << message
add_without_save_names(attribute, message, options)
end
alias_method_chain :add, :save_names
end
end
describe User do
it "should not allow to short name" do
u = User.new(:name => "a")
u.valid?
puts u.errors.error_names
u.errors.error_names[:name].should include(:too_short)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.