Created
October 8, 2015 22:14
-
-
Save daniloisr/3268f2fe1511ff15d806 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 'activerecord' | |
gem 'sqlite3' | |
end | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'logger' | |
# Ensure backward compatibility with Minitest 4 | |
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :users, force: true do |t| | |
end | |
create_table :contact_infos, force: true do |t| | |
t.references :user | |
t.string :name | |
end | |
end | |
class User < ActiveRecord::Base | |
has_one :contact_info | |
accepts_nested_attributes_for :contact_info | |
end | |
class ContactInfo < ActiveRecord::Base | |
belongs_to :user | |
validates :name, presence: true | |
end | |
class BugTest < Minitest::Test | |
def test_association_validation | |
user = User.new({ contact_info_attributes: {}}) | |
assert(user.valid?, user.errors.full_messages) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment