Skip to content

Instantly share code, notes, and snippets.

@gdeglin
Last active September 23, 2015 06:24
Show Gist options
  • Save gdeglin/a32541807ba366d57c57 to your computer and use it in GitHub Desktop.
Save gdeglin/a32541807ba366d57c57 to your computer and use it in GitHub Desktop.
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'rack', github: 'rack/rack'
gem 'sprockets', github: 'rails/sprockets'
gem 'sprockets-rails', github: 'rails/sprockets-rails'
gem 'sass-rails', github: 'rails/sass-rails'
gem 'pg'
end
require 'active_record'
require 'minitest/autorun'
require 'logger'
#
ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'test',insert_returning: false)
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :users, force: true do |t|
t.string :name
end
create_table :profiles, force: true do |t|
t.integer :user_id
end
end
class User < ActiveRecord::Base
has_one :profile
after_save do |user|
user.create_profile
end
end
class Profile < ActiveRecord::Base
belongs_to :user
end
class BugTest < Minitest::Test
def test_association
user = User.create()
assert Profile.first.user_id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment