Skip to content

Instantly share code, notes, and snippets.

@nerdinand
Created March 24, 2015 21:52
Show Gist options
  • Save nerdinand/7665496e2b6d26619781 to your computer and use it in GitHub Desktop.
Save nerdinand/7665496e2b6d26619781 to your computer and use it in GitHub Desktop.
require 'bundler'
Bundler.setup(:default)
require 'pg'
require_relative 'lib/active_record'
require 'minitest/autorun'
require 'logger'
require 'byebug'
ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'test123')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :hosts, force: true do |t|
end
create_table :links, force: true do |t|
t.integer :host_id
t.integer :page_id
end
create_table :pages, force: true do |t|
end
end
class Host < ActiveRecord::Base
has_many :links
has_many :pages, through: :links
end
class Link < ActiveRecord::Base
belongs_to :host
belongs_to :page
end
class Page < ActiveRecord::Base
has_many :links
has_many :hosts, through: :links
end
class BugTest < Minitest::Test
def test_hmt
host = Host.new
page = Page.new
host.pages.include? page
refute host.pages.include?(page)
host.pages << page
assert host.pages.include?(page)
host.pages.delete page
refute host.pages.include?(page)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment