public

Rails 3.1: HasManyThrough Bug

  • Download Gist
rails310-has-many-through-bug.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
require "sqlite3"
#gem "rails", "~> 3.0.10"
#gem "rails", "3.1.0"
gem "rails", "3.1.1.rc1"
 
require "logger"
require "active_record"
require "test/unit"
 
puts "Active Record #{ActiveRecord::VERSION::STRING}"
 
ActiveRecord::Base.logger = Logger.new(STDOUT)
 
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
 
ActiveRecord::Schema.define do
create_table "people", :force => true do |t|
t.string "project_id"
t.string "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end
 
create_table "projects", :force => true do |t|
t.string "name"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end
 
create_table "users", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
end
 
class Project < ActiveRecord::Base
belongs_to :user
has_many :users, :through => :people
end
 
class Person < ActiveRecord::Base
belongs_to :project
belongs_to :user
end
 
class User < ActiveRecord::Base
has_many :people
has_many :projects, :through => :people
end
 
class HasManyThrough < Test::Unit::TestCase
 
def test_user_projects_build_assigns_project_to_user
user = User.create(:name => "Francesc")
project = user.projects.build
assert !project.user.nil?
end
 
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.