Erwin
2012-Nov-08 15:27 UTC
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/Mrj4@public.gmane.org", 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-PV5Ro7/Mrj4@public.gmane.org", 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-PV5Ro7/Mrj4@public.gmane.org", password:
"UkZaHWcy", password_confirmation:
"UkZaHWcy")> user = FactoryGirl.build(:user, subdomain_id: @coocoo[:id], email:
"user.doe-PV5Ro7/Mrj4@public.gmane.org", 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
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/UqU8HJOSg0AJ.
For more options, visit https://groups.google.com/groups/opt_out.
Erwin
2012-Nov-08 16:05 UTC
Re: validates_uniqueness_of(*attr_names) w scope not working in unit test
[SOLVED] weird environment => weird behaviour I had a duplicated copy of my User model file still in my models folder ... filename was user_copy.. but containing a User class def.. I guess running in the console, the first user model file was used , but in unit test , the copy was used ... need a break .. tea time ! not tea party ! Le jeudi 8 novembre 2012 16:27:29 UTC+1, Erwin a écrit :> > 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/Mrj4@public.gmane.org", 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-PV5Ro7/Mrj4@public.gmane.org", 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-PV5Ro7/Mrj4@public.gmane.org", password: "UkZaHWcy", password_confirmation: > "UkZaHWcy") > > user = FactoryGirl.build(:user, subdomain_id: @coocoo[:id], email: " > user.doe-PV5Ro7/Mrj4@public.gmane.org", 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 > > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/F8S8GP61tK4J. For more options, visit https://groups.google.com/groups/opt_out.
Apparently Analagous Threads
- RegExp does not match
- How to modify the template path for ActionMailer used in a Ruby script ?
- Using a nonstandard foreign key
- [Rails 3.2.5] Rails: unit test fixture_path : fixture_file_upload cannot find the file ...
- Trouble with rspec and FactoryGirl Sequence