Skip to content

Commit

Permalink
Ensure that polymorphic associations does not require a klass to exis…
Browse files Browse the repository at this point in the history
…ts [#84 status:resolved]
  • Loading branch information
josevalim committed Jun 5, 2009
1 parent cfbf8fb commit f824ea5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Expand Up @@ -32,7 +32,10 @@ def source_exists?
reflection.source_reflection rescue false
end

# Polymorphic associations does not have a klass.
#
def klass_exists?
return true if @options[:polymorphic]
reflection.klass rescue nil
end

Expand Down
6 changes: 6 additions & 0 deletions remarkable_activerecord/spec/association_matcher_spec.rb
Expand Up @@ -15,6 +15,7 @@ def define_and_validate(options={})
@model = define_model :project, columns do
belongs_to :company, options
belongs_to :unknown
belongs_to :accountable, :polymorphic => true
end

belong_to :company
Expand Down Expand Up @@ -145,6 +146,11 @@ def define_and_validate(options={})
it { should_not define_and_validate(:association_columns => { :association_count => :integer }).counter_cache(:association_count) }
end

describe "with polymorphic option" do
before(:each){ define_and_validate(:model_columns => {:accountable_id => :integer, :accountable_type => :string}) }
it { should belong_to(:accountable).polymorphic }
end

create_optional_boolean_specs(:readonly, self)
create_optional_boolean_specs(:validate, self)
create_optional_boolean_specs(:autosave, self) if RAILS_VERSION =~ /^2.3/
Expand Down

0 comments on commit f824ea5

Please sign in to comment.