Rails 3.2.8
Very strange , it works in dv mode console , but not in a unit test
class User < ActiveRecord::Base
belongs_to :subdomain
validates_uniqueness_of :email, :scope => :subdomain_id
class UserTest < ActiveSupport::TestCase
def initialize_user
@booboo = FactoryGirl.create(:subdomain, name: “booboo”)
@coocoo = FactoryGirl.create(:subdomain, name: “coocoo”)
FactoryGirl.create(:user, subdomain_id: @booboo[:id], email: “user.doe@acme.com”, password: “UkZaHWcy”, password_confirmation: “UkZaHWcy”)
end
def teardown
User.delete_all
Subdomain.delete_all
end
test “should_save_user_with_duplicated_email_in_another_scoped_subdomain” do
user = FactoryGirl.build(:user, subdomain_id: @coocoo[:id], email: “user.doe@acme.com”, password: “UkZaHWcy”, password_confirmation: “UkZaHWcy”)
assert user.save # failing @messages={:email=>[“has already been taken”]}
end
Now in console
@booboo = FactoryGirl.create(:subdomain, name: “booboo”)
@coocoo = FactoryGirl.create(:subdomain, name: “coocoo”)
FactoryGirl.create(:user, subdomain_id: @booboo[:id], email: "user.doe@acme.com", password: "UkZaHWcy", password_confirmation: "UkZaHWcy")
user = FactoryGirl.build(:user, subdomain_id: @coocoo[:id], email: "user.doe@acme.com", password: "UkZaHWcy", password_confirmation: "UkZaHWcy")
user.save
COMMIT
=> true
why do the same Model have different behaviors in test mode and dev mode ? any clue ?
thanks for feedback