Skip to content

Instantly share code, notes, and snippets.

@jonasschneider
Created January 30, 2010 19:56
Show Gist options
  • Save jonasschneider/290695 to your computer and use it in GitHub Desktop.
Save jonasschneider/290695 to your computer and use it in GitHub Desktop.
$ rails -v
Rails 2.3.5
$ rails bugtest
$ cd bugtest
$ script/generate model Project name:string
$ cat app/models/project.rb
class Project < ActiveRecord::Base
has_and_belongs_to_many :users
end
$ script/generate model User name:string
$ cat app/models/user.rb
class User < ActiveRecord::Base
has_and_belongs_to_many :projects
end
$ script/generate migration CreateProjectsUsers
class CreateProjectsUsers < ActiveRecord::Migration
def self.up
create_table :projects_users, :id => false do |t|
t.integer :project_id
t.integer :user_id
end
end
def self.down
drop_table :projects_users
end
end
$ rake db:test:prepare
$ cat bug_test.rb
require "test/test_helper"
class BugTest < ActiveSupport::TestCase
def test_bug
rails = Project.create :name => "Rails"
js = rails.users.build :name => "JS"
js.save!
assert_equal [js], rails.users
assert_equal [rails], js.projects
end
end
$ ruby bug_test.rb
Loaded suite bug_test
Started
F
Finished in 0.33 seconds.
1) Failure:
test_bug(BugTest) [bug_test.rb:8]:
<[#<User id: 980190963, name: "JS", created_at: "2010-01-30 19:52:34", updated_at: "2010-01-30 19:52:34">]> ex
pected but was
<[]>.
1 tests, 1 assertions, 1 failures, 0 errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment