Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Test case for issue 1629

View test.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
unless File.exists?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'sqlite3'
GEMFILE
 
system 'bundle'
end
 
require 'bundler'
Bundler.setup(:default)
 
require 'active_record'
require 'minitest/autorun'
require 'logger'
 
# 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 do |t|
end
 
create_table :addresses do |t|
t.integer :addressable_id
t.string :addressable_type
end
 
class User < ActiveRecord::Base
has_one :address, :as => :addressable
accepts_nested_attributes_for :address
end
 
class Address < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
validates_associated :addressable
end
 
class BugTest < MiniTest::Unit::TestCase
def test_polymorphic_nested_attributes
u = User.new({:address => Address.new})
assert u.save
end
end
end
Owner

This test passes because we have validates_associated, if we had validates_presence_of it would fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.