Advertisement
Guest User

Untitled

a guest
Aug 1st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.03 KB | None | 0 0
  1. describe User do
  2.  
  3.   before(:each) do
  4.     @attr = {
  5.       :name => "Example User",
  6.       :email => "user@example.com",
  7.       :password => "foobar",
  8.       :password_confirmation => "foobar"
  9.     }
  10.   end
  11.  
  12.   it "should create a new instance given valid attributes" do
  13.     User.create!(@attr)
  14.   end
  15.  
  16.   it "should require a name" do
  17.     no_name_user = User.new(@attr.merge(:name => "")) # variable that merges the @attr and sets the :name to be blank
  18.     no_name_user.should_not be_valid # the "no_name_user" should not be valid since the @attr is merged to blank
  19.   end
  20.  
  21.   it "should reject names that are too long" do
  22.     long_name = "a" * 51
  23.     long_name_user = User.new(@attr.merge(:name => long_name))
  24.     long_name_user.should_not be_valid
  25.   end
  26.  
  27.   it "should accept valid email addresses" do
  28.     addresses = %w[user@foo.com THE_USER@foo.bar.org first.last@foo.jp]
  29.     addresses.each do |address|
  30.       valid_email_user = User.new(@attr.merge(:email => address))
  31.       valid_email_user.should be_valid
  32.     end
  33.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement