Files
railsgoat/spec/models/user_spec.rb
T
chrismo 4ccdca8984 Fixed model specs, some of which I broke.
There's a fight here between DatabaseCleaner strategies - simpler to use
the default :transaction for model specs, but Capybara lives in a
different world where different connections are in play and
:transactions don't work. So, while introducing the more cumbersome
(though with more control) DatabaseCleaner gem and its truncation
strategy, I forgot to make sure the model specs had the fixtures present
that they depend on. This is fixed up now.

The user spec for invalid email was also failing - the regex there is
not savvy enough to handle rejecting two @ signs, so I made the invalid
value something still invalid to get it passing -- real regex validation
of email is ... impossible, so we'll roll with this and move on.
2013-10-02 17:53:12 -05:00

37 lines
762 B
Ruby

require 'spec_helper.rb'
describe User do
before(:all) do
UserFixture.reset_all_users
DatabaseCleaner.strategy = :transaction
end
after(:all) do
DatabaseCleaner.strategy = :truncation
end
it "can be instantiated" do
User.new.should be_an_instance_of(User)
end
it "should require a email" do
User.new(:email => "").should_not be_valid
end
it "should require valid email" do
User.new(:email => "@gmail.com").should_not be_valid
end
it "should require unique email" do
user = User.all.first
User.new(:email => user.email).should_not be_valid
end
it "name can be updated" do
new_name = "Bobby"
user = User.all.first
user.first_name = new_name
user.save!
User.all.first.first_name.should == new_name
end
end