Sam Joseph
2005-Oct-20 12:47 UTC
strange difference between test and development databases
Hi All, So I have this function in my user class: def isAdmin @admin = Group.find_by_handle(''admin'') return self.groups.include?(@admin) end which works fine on the devel database, but not on the test database. I''ve run "rake clone_structure_to_test", so the db''s should be identical (the important tables here being users, groups and groups_users) but for some reason the function fails on the test db. See console output below showing be trying to debug the difference: Can anyone think what might be causing this difference in behaviour? D:\user\Code\ruby\prometheus>ruby script\console test Loading test environment.>> user = User.find(1000006)=> #<User:0x3777ca8 @attributes={"salt"=>"7f8b036f9b647d46d22abdbfc8113f44a88f9889", "seclevel"=>"0", "pwexpires"=>nil, "deleted_at"=>nil, "username"=>"adminbob ", "org_id"=>nil, "url"=>nil, "id"=>"1000006", "lastname"=>nil, "firstname"=>nil, "addeddate"=>"2001-01-01 00:00:00", "phone"=>nil, "lastlogin"=>"2005-10-20 21: 33:32", "picture"=>nil, "bio"=>nil, "reason"=>nil, "photo_id"=>nil, "password"=>"ef94c16f6c124a4e84cc215c164767bfa25f6e92", "position"=>nil, "email"=>"srjoseph@ hawaii.edu", "previouslastlogin"=>nil}>>> user.groups=> [#<Group:0x3773bf8 @attributes={"name"=>"ADMIN", "role"=>"admin", "id"=>"6", "group_id"=>"1000006", "added_at"=>"2005-10-18 06:48:55", "user_id"=>"1000006", "parent_id"=>nil, "approved_at"=>"2005-10-18 06:48:55"}>]>> @admin = Group.find_by_handle(''admin'')=> #<Group:0x376f8a8 @attributes={"name"=>"ADMIN", "id"=>"1000006", "parent_id"=>nil}>>> user.groups.include?(@admin)=> false>> exitD:\user\Code\ruby\prometheus>ruby script\console Loading development environment.>> user = User.find(343)=> #<User:0x37820d0 @attributes={"salt"=>nil, "seclevel"=>"1000", "pwexpires"=>nil, "deleted_at"=>nil, "username"=>"srjoseph", "org_id"=>"0", "url"=>"", "id"=>" 343", "lastname"=>"Joseph", "firstname"=>"Sam", "addeddate"=>"0000-00-00 00:00:00", "phone"=>"n/a", "lastlogin"=>"2005-10-20 18:54:46", "picture"=>nil, "bio"=>" ", "reason"=>nil, "photo_id"=>"87", "password"=>"41259f88156755fb", "position"=>"disCourse developer", "email"=>"srjoseph-MsMAYOsy5kY3uPMLIKxrzw@public.gmane.org", "previouslastlogin"=>"200 5-10-20 18:49:03"}>>> user.groups=> [#<Group:0x377e050 @attributes={"name"=>"ADMIN", "role"=>nil, "id"=>"5", "group_id"=>"5", "added_at"=>"2005-10-18 06:48:55", "user_id"=>"343", "parent_id"=>n il, "approved_at"=>"2005-10-18 06:48:55"}>]>> @admin = Group.find_by_handle(''admin'')=> #<Group:0x3779d00 @attributes={"name"=>"ADMIN", "id"=>"5", "parent_id"=>nil}>>> user.groups.include?(@admin)=> true>> exitMany thanks in advance. CHEERS> SAM
Sam Joseph
2005-Oct-21 07:21 UTC
Re: strange difference between test and development databases
Still no idea why this doesn''t work, but I found a way round by adjusting the function to: def isAdmin @names = groups.collect{|g| g.name} return @names.include?(''ADMIN'') end so this now checks explicitly for a group named "ADMIN" rather than checking if the admin group appears in the user groups. Any insights on why the former approach fails in some instances gratefully accepted. CHEERS> SAM Sam Joseph wrote:>Hi All, > >So I have this function in my user class: > >def isAdmin >@admin = Group.find_by_handle(''admin'') >return self.groups.include?(@admin) >end > >which works fine on the devel database, but not on the test database. >I''ve run "rake clone_structure_to_test", so the db''s should be identical >(the important tables here being users, groups and groups_users) but for >some reason the function fails on the test db. See console output below >showing be trying to debug the difference: > >Can anyone think what might be causing this difference in behaviour? > >D:\user\Code\ruby\prometheus>ruby script\console test >Loading test environment. > > >>>user = User.find(1000006) >>> >>> >=> #<User:0x3777ca8 >@attributes={"salt"=>"7f8b036f9b647d46d22abdbfc8113f44a88f9889", >"seclevel"=>"0", "pwexpires"=>nil, "deleted_at"=>nil, "username"=>"adminbob >", "org_id"=>nil, "url"=>nil, "id"=>"1000006", "lastname"=>nil, >"firstname"=>nil, "addeddate"=>"2001-01-01 00:00:00", "phone"=>nil, >"lastlogin"=>"2005-10-20 21: >33:32", "picture"=>nil, "bio"=>nil, "reason"=>nil, "photo_id"=>nil, >"password"=>"ef94c16f6c124a4e84cc215c164767bfa25f6e92", "position"=>nil, >"email"=>"srjoseph@ >hawaii.edu", "previouslastlogin"=>nil}> > > >>>user.groups >>> >>> >=> [#<Group:0x3773bf8 @attributes={"name"=>"ADMIN", "role"=>"admin", >"id"=>"6", "group_id"=>"1000006", "added_at"=>"2005-10-18 06:48:55", >"user_id"=>"1000006", >"parent_id"=>nil, "approved_at"=>"2005-10-18 06:48:55"}>] > > >>>@admin = Group.find_by_handle(''admin'') >>> >>> >=> #<Group:0x376f8a8 @attributes={"name"=>"ADMIN", "id"=>"1000006", >"parent_id"=>nil}> > > >>>user.groups.include?(@admin) >>> >>> >=> false > > >>>exit >>> >>> > >D:\user\Code\ruby\prometheus>ruby script\console >Loading development environment. > > >>>user = User.find(343) >>> >>> >=> #<User:0x37820d0 @attributes={"salt"=>nil, "seclevel"=>"1000", >"pwexpires"=>nil, "deleted_at"=>nil, "username"=>"srjoseph", >"org_id"=>"0", "url"=>"", "id"=>" >343", "lastname"=>"Joseph", "firstname"=>"Sam", "addeddate"=>"0000-00-00 >00:00:00", "phone"=>"n/a", "lastlogin"=>"2005-10-20 18:54:46", >"picture"=>nil, "bio"=>" >", "reason"=>nil, "photo_id"=>"87", "password"=>"41259f88156755fb", >"position"=>"disCourse developer", "email"=>"srjoseph-MsMAYOsy5kY3uPMLIKxrzw@public.gmane.org", >"previouslastlogin"=>"200 >5-10-20 18:49:03"}> > > >>>user.groups >>> >>> >=> [#<Group:0x377e050 @attributes={"name"=>"ADMIN", "role"=>nil, >"id"=>"5", "group_id"=>"5", "added_at"=>"2005-10-18 06:48:55", >"user_id"=>"343", "parent_id"=>n >il, "approved_at"=>"2005-10-18 06:48:55"}>] > > >>>@admin = Group.find_by_handle(''admin'') >>> >>> >=> #<Group:0x3779d00 @attributes={"name"=>"ADMIN", "id"=>"5", >"parent_id"=>nil}> > > >>>user.groups.include?(@admin) >>> >>> >=> true > > >>>exit >>> >>> > >Many thanks in advance. > >CHEERS> SAM > > > > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > > >