Displaying 2 results from an estimated 2 matches for "subdomain_id".
2012 Nov 08
1
validates_uniqueness_of(*attr_names) w scope not working in unit test
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-PV5Ro7/Mr...
2011 Dec 05
2
How to bypass a create record after validation wo error ?
...I wrote a UserValidator class to check the uniqueness of the email
field
# if no user registered w this email, then no error , can proceed to
create
User.where(:email => self.email).empty? # no error
# if a user is already registered w this email,
target_subdomain = Subdomain.find(self.subdomain_id)
unless target_subdomain.members.where(;email => self;email).empty?
record.errors[:email] << "is already a member" # error
else # user is not a not a member of this subdomain....
existing_user = User.where(:email => self.email).first # get
existing user r...