Created
March 9, 2017 01:27
-
-
Save jturkel/5aea783a05dbfc2b345132580e78921c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', '5.0.2' | |
gem 'goldiloader' | |
gem 'sqlite3' | |
gem 'minitest' | |
end | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'logger' | |
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :blogs, force: true do |t| | |
end | |
create_table :posts, force: true do |t| | |
t.integer :blog_id | |
end | |
end | |
ActiveRecord::Base.belongs_to_required_by_default = true | |
class Blog < ActiveRecord::Base | |
has_many :posts | |
end | |
class Post < ActiveRecord::Base | |
belongs_to :blog | |
end | |
class BugTest < defined?(Minitest::Test) ? Minitest::Test : MiniTest::Unit::TestCase | |
def test_belongs_to_validation | |
blog = Blog.create! | |
post = Post.new | |
assert !post.valid? | |
post.blog = blog | |
assert post.valid? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment