2007-07-14 18:35:51 +00:00
|
|
|
require File.dirname(__FILE__) + '/../test_helper'
|
|
|
|
|
|
|
|
class UserTest < Test::Unit::TestCase
|
2008-09-02 16:49:13 -04:00
|
|
|
fixtures :all
|
2007-07-14 18:35:51 +00:00
|
|
|
|
|
|
|
should_have_many :posts
|
2007-11-28 20:04:36 +00:00
|
|
|
should_have_many :dogs
|
2008-01-21 15:06:05 +00:00
|
|
|
|
2008-08-31 12:14:16 -04:00
|
|
|
should_have_many :friendships
|
|
|
|
should_have_many :friends
|
|
|
|
|
2008-09-17 16:16:41 -04:00
|
|
|
should_have_one :address
|
2008-09-17 12:32:44 -07:00
|
|
|
should_have_one :address, :dependent => :destroy
|
2008-02-28 21:40:42 +00:00
|
|
|
|
2008-05-01 13:49:29 +00:00
|
|
|
should_have_indices :email, :name, [:email, :name]
|
|
|
|
should_have_index :age
|
|
|
|
|
2008-07-29 17:08:16 -04:00
|
|
|
should_have_named_scope :old, :conditions => "age > 50"
|
|
|
|
should_have_named_scope :eighteen, :conditions => { :age => 18 }
|
2008-08-31 12:14:16 -04:00
|
|
|
|
2008-07-29 17:21:38 -04:00
|
|
|
should_have_named_scope 'recent(5)', :limit => 5
|
|
|
|
should_have_named_scope 'recent(1)', :limit => 1
|
|
|
|
should_have_named_scope 'recent_via_method(7)', :limit => 7
|
|
|
|
|
|
|
|
context "when given an instance variable" do
|
|
|
|
setup { @count = 2 }
|
|
|
|
should_have_named_scope 'recent(@count)', :limit => 2
|
|
|
|
end
|
2008-07-29 17:08:16 -04:00
|
|
|
|
2007-07-14 18:35:51 +00:00
|
|
|
should_not_allow_values_for :email, "blah", "b lah"
|
|
|
|
should_allow_values_for :email, "a@b.com", "asdf@asdf.com"
|
|
|
|
should_ensure_length_in_range :email, 1..100
|
|
|
|
should_ensure_value_in_range :age, 1..100
|
|
|
|
should_protect_attributes :password
|
2007-10-31 13:47:37 +00:00
|
|
|
should_have_class_methods :find, :destroy
|
2007-10-31 13:50:08 +00:00
|
|
|
should_have_instance_methods :email, :age, :email=, :valid?
|
2007-11-23 15:18:28 +00:00
|
|
|
should_have_db_columns :name, :email, :age
|
|
|
|
should_have_db_column :id, :type => "integer", :primary => true
|
2008-08-31 12:14:16 -04:00
|
|
|
should_have_db_column :email, :type => "string", :default => nil, :precision => nil, :limit => 255,
|
2007-11-23 15:18:28 +00:00
|
|
|
:null => true, :primary => false, :scale => nil, :sql_type => 'varchar(255)'
|
2008-01-21 15:06:05 +00:00
|
|
|
should_require_acceptance_of :eula
|
2008-05-29 16:48:39 -07:00
|
|
|
should_require_unique_attributes :email, :scoped_to => :name
|
2008-08-31 12:14:16 -04:00
|
|
|
|
2008-06-19 17:23:45 +01:00
|
|
|
should_ensure_length_is :ssn, 9, :message => "Social Security Number is not the right length"
|
|
|
|
should_only_allow_numeric_values_for :ssn
|
2008-06-26 17:15:17 -04:00
|
|
|
|
2008-06-24 15:50:38 -04:00
|
|
|
should_have_readonly_attributes :name
|
2008-09-03 20:37:28 -04:00
|
|
|
|
|
|
|
should_fail do
|
|
|
|
should_protect_attributes :name, :age
|
|
|
|
end
|
2007-07-14 18:35:51 +00:00
|
|
|
end
|