I am testing an update via assert_equal and it does not seem to work. I have this fixture: bob1: id: 1000001 login: bob glogin: bob-pbC8P9QkocYAvxtiuMwx3w@public.gmane.org session_token: 77a38 Here is my test method: class Guser < ActiveRecord::Base def self.update_token(glogin, login, stoken) u=find(:first, :conditions=>["glogin = ? AND login = ?", glogin, login]) return nil if u.nil? if u.session_token != stoken u.session_token = stoken u.save return u end #nil end end Here is where I call the method, where I match the ''glogin'' and ''login'' column values and if they match I want to update the session token. require File.dirname(__FILE__) + ''/../test_helper'' class GuserTest < ActiveSupport::TestCase self.use_instantiated_fixtures = true fixtures :users def test_match_login assert_equal @bob1, Guser.update_token("bob-pbC8P9QkocYAvxtiuMwx3w@public.gmane.org", "bob", "77a38") end The first time even if there is no record in the database it inserts and gives a success message: 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips Then I run it again by changing the method argument like this to update the sesison token assert_equal @bob1, Guser.update_token("bob-pbC8P9QkocYAvxtiuMwx3w@public.gmane.org", "bob", "77a138") It still gives a success message: 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips The new value of session token is never updated in the table column from ''77a38'' to ''77a38'' . Can you please tell me how to update the sesison token if my glogin and login fields are found to match -- View this message in context: http://old.nabble.com/assert_equal-Test---how-to-test-updates-tp27424657p27424657.html Sent from the RubyOnRails Users mailing list archive at Nabble.com. -- 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I meant it does not update the value from ''77a38'' to ''77a138'' vihrao wrote:> > I am testing an update via assert_equal and it does not seem to work. > > I have this fixture: > bob1: > id: 1000001 > login: bob > glogin: bob-pbC8P9QkocYAvxtiuMwx3w@public.gmane.org > session_token: 77a38 > > Here is my test method: > class Guser < ActiveRecord::Base > def self.update_token(glogin, login, stoken) > u=find(:first, :conditions=>["glogin = ? AND login = ?", glogin, > login]) > return nil if u.nil? > if u.session_token != stoken > u.session_token = stoken > u.save > return u > end > #nil > end > end > > Here is where I call the method, where I match the ''glogin'' and ''login'' > column values and if they match I want to update the session token. > > require File.dirname(__FILE__) + ''/../test_helper'' > class GuserTest < ActiveSupport::TestCase > self.use_instantiated_fixtures = true > fixtures :users > def test_match_login > assert_equal @bob1, Guser.update_token("bob-pbC8P9QkocYAvxtiuMwx3w@public.gmane.org", "bob", > "77a38") > end > > The first time even if there is no record in the database it inserts and > gives a success message: > 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips > > Then I run it again by changing the method argument like this to update > the sesison token > assert_equal @bob1, Guser.update_token("bob-pbC8P9QkocYAvxtiuMwx3w@public.gmane.org", "bob", "77a138") > It still gives a success message: 1 tests, 1 assertions, 0 failures, 0 > errors, 0 skips > > The new value of session token is never updated in the table column from > ''77a38'' to ''77a38'' . Can you please tell me how to update the sesison > token if my glogin and login fields are found to match > > > > >-- View this message in context: http://old.nabble.com/assert_equal-Test---how-to-test-updates-tp27424657p27424772.html Sent from the RubyOnRails Users mailing list archive at Nabble.com. -- 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 2, 5:55 pm, vihrao <vih...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Then I run it again by changing the method argument like this to update the > sesison token > assert_equal @bob1, Guser.update_token("b...-pbC8P9QkocYAvxtiuMwx3w@public.gmane.org", "bob", "77a138") > It still gives a success message: 1 tests, 1 assertions, 0 failures, 0 > errors, 0 skips > > The new value of session token is never updated in the table column from > ''77a38'' to ''77a38'' . Can you please tell me how to update the sesison token > if my glogin and login fields are found to matchassert_equal uses the == method to compare the two objects, and == on activerecord doesn''t compare attributes: it only compares the id of the object (ie do the compared objects represent the same row in the database) Fred -- 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. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 2, 5:55 pm, vihrao <vih...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Then I run it again by changing the method argument like this to update > the > sesison token > assert_equal @bob1, Guser.update_token("b...-pbC8P9QkocYAvxtiuMwx3w@public.gmane.org", "bob", > "77a138") > It still gives a success message: 1 tests, 1 assertions, 0 failures, 0 > errors, 0 skips > > The new value of session token is never updated in the table column from > ''77a38'' to ''77a138'' . Can you please tell me how to update the sesison > token > if my glogin and login fields are found to matchassert_equal uses the == method to compare the two objects, and == on activerecord doesn''t compare attributes: it only compares the id of the object (ie do the compared objects represent the same row in the database) Fred -- Thank you. To perform an update I have to find if the existing attribute(database column) value is equal to new value that I pass, and then overwrite it if it does not match. How can I test this situation - can you please tell me? -- View this message in context: http://old.nabble.com/assert_equal-Test---how-to-test-updates-tp27424657p27426161.html Sent from the RubyOnRails Users mailing list archive at Nabble.com. -- 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. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
assert_equal uses the == method to compare the two objects, and == on activerecord doesn''t compare attributes: it only compares the id of the object (ie do the compared objects represent the same row in the database) Fred -- That is why I had this issue. I had two fixtures users.yml and gusers.yml. Both had ''bob'' defined with same record ID. Now users.yml was referred by user controller and gusers.yml was referred by gusers controller. However when I did assert_equal using gusers it pulled the record from the users model instead of gusers model. I could not understand that behavior. When I changed the gusers.yml ''bob'' to ''bob1'' it pulled the record from the correct gusers model. This tell me that we have make sure IDs are unique across fixtures from different models. That is confusing each model has to have its own space. -- View this message in context: http://old.nabble.com/assert_equal-Test---how-to-test-updates-tp27424657p27430836.html Sent from the RubyOnRails Users mailing list archive at Nabble.com. -- 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 3, 4:21 am, vihrao <vih...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> assert_equal uses the == method to compare the two objects, and == on > activerecord doesn''t compare attributes: it only compares the id of > the object (ie do the compared objects represent the same row in the > database) >A small addition: it obviously also compares class and there''s some fiddly stuff around handling the cases of unsaved objects> > -- > That is why I had this issue. I had two fixtures users.yml and gusers.yml. > Both had ''bob'' defined with same record ID. Now users.yml was referred by > user controller and gusers.yml was referred by gusers controller. However > when I did assert_equal using gusers it pulled the record from the users > model instead of gusers model. I could not understand that behavior. > When I changed the gusers.yml ''bob'' to ''bob1'' it pulled the record from the > correct gusers model. > > This tell me that we have make sure IDs are unique across fixtures from > different models. That is confusing each model has to have its own space.if you are using instantiated fixtures, then yes, each fixture needs its own label, but no one does that any more. If you want the bob fixture from users write users(:bob) and for the other one gusers (:bob) Fred> > -- > View this message in context:http://old.nabble.com/assert_equal-Test---how-to-test-updates-tp27424... > Sent from the RubyOnRails Users mailing list archive at Nabble.com.-- 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. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.