Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- describe User do
- before(:each) do
- @attr = {
- :name => "Example User",
- :email => "user@example.com",
- :password => "foobar",
- :password_confirmation => "foobar"
- }
- end
- it "should create a new instance given valid attributes" do
- User.create!(@attr)
- end
- it "should require a name" do
- no_name_user = User.new(@attr.merge(:name => "")) # variable that merges the @attr and sets the :name to be blank
- no_name_user.should_not be_valid # the "no_name_user" should not be valid since the @attr is merged to blank
- end
- it "should reject names that are too long" do
- long_name = "a" * 51
- long_name_user = User.new(@attr.merge(:name => long_name))
- long_name_user.should_not be_valid
- end
- it "should accept valid email addresses" do
- addresses = %w[user@foo.com THE_USER@foo.bar.org first.last@foo.jp]
- addresses.each do |address|
- valid_email_user = User.new(@attr.merge(:email => address))
- valid_email_user.should be_valid
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement