Skip to content

@steveklabnik /test.rb
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Test case for issue 1629
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
@steveklabnik

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.