[rspec-devel] [ rspec-Bugs-7353 ] has_many :through bug?

noreply at rubyforge.org noreply at rubyforge.org
Tue Dec 19 03:05:02 EST 2006


Bugs item #7353, was opened at 2006-12-19 08:05
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=7353&group_id=797

Category: rails plugin
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Dallas Pool (codeninja)
Assigned to: Nobody (None)
Summary: has_many :through bug?

Initial Comment:
class Project < ActiveRecord::Base
  has_many :project_users
  has_many :users, :through=>:project_users  
end

class User < ActiveRecord::Base
  has_many :project_users
  has_many :projects, :through=> :project_users
end

class ProjectUser < ActiveRecord::Base
  belongs_to :project
  belongs_to :users
end



##spec##
context "The Project Model" do
  fixtures :projects, :users, :project_users

  specify "should associate to a user" do
    project = Project.find(1) #passes
    project.should_have(2).users #passes
    project.users.should_include users(:admin) #fails
  end
end


##errors##
1)
'The Project Model should associate to a user' FAILED
[#<ProjectUser:0x37d1ff8 @attributes={"project_id"=>"1", "id"=>"1", "user_id"=>"1"}>, 

#<ProjectUser:0x37d1e48 @attributes={"project_id"=>"1", "id"=>"2", "user_id"=>"2"}>] 

should include #<User:0x37cd1
f8 @attributes={"salt"=>"daed2d80790f1a28cb24d0dbcf9b61ae6b83490a", "updated_at"=>nil, "crypted_password"=>"27038ea45242931b85f8ef1bf115118ccbb2d301", "is_developer"=>"0", "is_client"=>"0", "is_admin"
=>"1", "remember_token_expires_at"=>nil, "id"=>"1", "remember_token"=>nil, "login"=>"admin_test", "created_at"=>nil, "email"=>"admin_test at gmail.com"}>
./spec/models/project_spec.rb:20:



it appears that when product.users is referenced that rspec is looking at product.product_users and not at the actual Users table. Investigating this via console reveals that product.users returns an array of users.... what gives?

It would be great if I could get an email about this.

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=7353&group_id=797


More information about the rspec-devel mailing list