<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -9,7 +9,7 @@ module Remarkable
         optionals :uniq, :readonly, :validate, :autosave, :polymorphic, :counter_cache, :default =&gt; true
 
         collection_assertions :association_exists?, :macro_matches?, :through_exists?, :source_exists?,
-                              :join_table_exists?, :foreign_key_exists?, :polymorphic_exists?,
+                              :klass_exists?, :join_table_exists?, :foreign_key_exists?, :polymorphic_exists?,
                               :counter_cache_exists?, :options_match?
 
         protected
@@ -32,6 +32,10 @@ module Remarkable
             reflection.source_reflection rescue false
           end
 
+          def klass_exists?
+            reflection.klass rescue nil
+          end
+
           # has_and_belongs_to_many only works if the tables are in the same
           # database, so we always look for the table in the subject connection.
           #
@@ -74,11 +78,18 @@ module Remarkable
             @reflection ||= subject_class.reflect_on_association(@association.to_sym)
           end
 
-          # Rescue nil to avoid raising errors in invalid through associations
+          def subject_table_name
+            subject_class.table_name.to_s
+          end
+
           def reflection_class_name
             reflection.class_name.to_s rescue nil
           end
 
+          def reflection_table_name
+            reflection.klass.table_name.to_s rescue nil
+          end
+
           def reflection_foreign_key
             reflection.primary_key_name.to_s
           end
@@ -107,9 +118,9 @@ module Remarkable
             elsif reflection.macro == :has_and_belongs_to_many
               reflection.options[:join_table]
             elsif reflection.macro == :belongs_to
-              subject_class.table_name
+              subject_table_name
             else
-              reflection.klass.table_name
+              reflection_table_name
             end
           end
 
@@ -132,14 +143,14 @@ module Remarkable
             if @subject &amp;&amp; reflection
               options.merge!(
                 :actual_macro         =&gt; Remarkable.t(reflection.macro, :scope =&gt; matcher_i18n_scope, :default =&gt; reflection.macro.to_s),
-                :subject_table        =&gt; subject_class.table_name.inspect,
-                :reflection_table     =&gt; reflection.klass.table_name.inspect,
+                :subject_table        =&gt; subject_table_name.inspect,
+                :reflection_table     =&gt; reflection_table_name.inspect,
                 :foreign_key_table    =&gt; foreign_key_table.inspect,
                 :polymorphic_column   =&gt; reflection_foreign_key.sub(/_id$/, '_type').inspect,
                 :counter_cache_column =&gt; reflection.counter_cache_column.to_s.inspect,
                 :join_table           =&gt; reflection.options[:join_table].inspect,
                 :foreign_key          =&gt; reflection_foreign_key.inspect
-              ) rescue nil # rescue to allow specs to run properly
+              )
             end
 
             options</diff>
      <filename>remarkable_activerecord/lib/remarkable_activerecord/matchers/association_matcher.rb</filename>
    </modified>
    <modified>
      <diff>@@ -53,10 +53,11 @@ en:
         has_one: have one
         description: &quot;{{macro}} {{associations}}&quot;
         expectations:
-          association_exists: &quot;{{subject_name}} records {{macro}} {{association}}, got no association&quot;
+          association_exists: &quot;{{subject_name}} records {{macro}} {{association}}, but the association does not exist&quot;
           macro_matches: &quot;{{subject_name}} records {{macro}} {{association}}, got {{subject_name}} records {{actual_macro}} {{association}}&quot;
           through_exists: &quot;{{subject_name}} records {{macro}} {{association}} through {{through}}, through association does not exist&quot;
           source_exists: &quot;{{subject_name}} records {{macro}} {{association}} through {{through}}, source association does not exist&quot;
+          klass_exists: &quot;{{subject_name}} records {{macro}} {{association}}, but the association class does not exist&quot;
           join_table_exists: &quot;join table {{join_table}} to exist, but does not&quot;
           foreign_key_exists: &quot;foreign key {{foreign_key}} to exist on {{foreign_key_table}}, but does not&quot;
           polymorphic_exists: &quot;{{subject_table}} to have {{polymorphic_column}} as column, but does not&quot;</diff>
      <filename>remarkable_activerecord/locale/en.yml</filename>
    </modified>
    <modified>
      <diff>@@ -9,10 +9,12 @@ describe 'association_matcher' do
     def define_and_validate(options={})
       columns = options.delete(:association_columns) || { :projects_count =&gt; :integer }
       define_model :company, columns
+      define_model :super_company, columns
 
       columns = options.delete(:model_columns) || { :company_id =&gt; :integer, :company_type =&gt; :string }
       @model = define_model :project, columns do
         belongs_to :company, options
+        belongs_to :unknown
       end
 
       belong_to :company
@@ -47,7 +49,7 @@ describe 'association_matcher' do
         define_and_validate
         matcher = belong_to('whatever')
         matcher.matches?(@model)
-        matcher.failure_message.should == 'Expected Project records belong to whatever, got no association'
+        matcher.failure_message.should == 'Expected Project records belong to whatever, but the association does not exist'
       end
 
       it 'should set macro_matches? message' do
@@ -57,6 +59,13 @@ describe 'association_matcher' do
         matcher.failure_message.should == 'Expected Project records have one company, got Project records belong to company'
       end
 
+      it 'should set klass_exists? message' do
+        define_and_validate
+        matcher = belong_to('unknown')
+        matcher.matches?(@model)
+        matcher.failure_message.should == 'Expected Project records belong to unknown, but the association class does not exist'
+      end
+
       it 'should set foreign_key_exists? message' do
         matcher = define_and_validate(:model_columns =&gt; {})
         matcher.matches?(@model)
@@ -93,6 +102,7 @@ describe 'association_matcher' do
         before(:each){ define_and_validate }
 
         it { should belong_to(:company) }
+        it { should_not belong_to(:unknown) }
         it { should_not belong_to(:project) }
         it { should_not have_one(:company) }
         it { should_not have_many(:company) }
@@ -158,6 +168,7 @@ describe 'association_matcher' do
         m.foreign_key = :company_id
       end
 
+      should_not_belong_to :unknown
       should_not_belong_to :project
       should_not_have_one  :company
       should_not_have_many :companies
@@ -174,6 +185,7 @@ describe 'association_matcher' do
     # Defines a model, create a validation and returns a raw matcher
     def define_and_validate(options={})
       define_model :label
+      define_model :super_label
 
       columns = options.delete(:association_columns) || [ :label_id, :project_id ]
       create_table(options.delete(:association_table) || :labels_projects) do |table|
@@ -209,7 +221,7 @@ describe 'association_matcher' do
         define_and_validate
         matcher = have_and_belong_to_many('whatever')
         matcher.matches?(@model)
-        matcher.failure_message.should == 'Expected Project records have and belong to many whatever, got no association'
+        matcher.failure_message.should == 'Expected Project records have and belong to many whatever, but the association does not exist'
       end
 
       it 'should set macro_matches? message' do
@@ -365,7 +377,7 @@ describe 'association_matcher' do
         define_and_validate
         matcher = have_many('whatever')
         matcher.matches?(@model)
-        matcher.failure_message.should == 'Expected Project records have many whatever, got no association'
+        matcher.failure_message.should == 'Expected Project records have many whatever, but the association does not exist'
       end
 
       it 'should set macro_matches? message' do
@@ -503,6 +515,7 @@ describe 'association_matcher' do
       @model = define_model :project, options.delete(:model_columns) || {} do
         has_many :project_managers unless options.delete(:skip_through)
         has_one  :manager, options
+        has_one  :unknown
       end
 
       have_one :manager
@@ -524,7 +537,14 @@ describe 'association_matcher' do
         define_and_validate
         matcher = have_one('whatever')
         matcher.matches?(@model)
-        matcher.failure_message.should == 'Expected Project records have one whatever, got no association'
+        matcher.failure_message.should == 'Expected Project records have one whatever, but the association does not exist'
+      end
+
+      it 'should set klass_exists? message' do
+        define_and_validate
+        matcher = have_one('unknown')
+        matcher.matches?(@model)
+        matcher.failure_message.should == 'Expected Project records have one unknown, but the association class does not exist'
       end
 
       it 'should set macro_matches? message' do
@@ -571,6 +591,7 @@ describe 'association_matcher' do
         before(:each){ define_and_validate }
 
         it { should have_one(:manager) }
+        it { should_not have_one(:unknown) }
         it { should_not belong_to(:manager) }
         it { should_not have_many(:managers) }
         it { should_not have_and_belong_to_many(:managers) }
@@ -635,6 +656,7 @@ describe 'association_matcher' do
         m.through = :project_managers
       end
 
+      should_not_have_one :unknown
       should_not_have_one :manager, :validate =&gt; false
       should_not_have_one :manager, :through =&gt; :another_thing
     end</diff>
      <filename>remarkable_activerecord/spec/association_matcher_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -174,10 +174,11 @@ en:
         has_one: have one
         description: &quot;{{macro}} {{associations}}&quot;
         expectations:
-          association_exists: &quot;{{subject_name}} records {{macro}} {{association}}, got no association&quot;
+          association_exists: &quot;{{subject_name}} records {{macro}} {{association}}, but the association does not exist&quot;
           macro_matches: &quot;{{subject_name}} records {{macro}} {{association}}, got {{subject_name}} records {{actual_macro}} {{association}}&quot;
           through_exists: &quot;{{subject_name}} records {{macro}} {{association}} through {{through}}, through association does not exist&quot;
           source_exists: &quot;{{subject_name}} records {{macro}} {{association}} through {{through}}, source association does not exist&quot;
+          klass_exists: &quot;{{subject_name}} records {{macro}} {{association}}, but the association class does not exist&quot;
           join_table_exists: &quot;join table {{join_table}} to exist, but does not&quot;
           foreign_key_exists: &quot;foreign key {{foreign_key}} to exist on {{foreign_key_table}}, but does not&quot;
           polymorphic_exists: &quot;{{subject_table}} to have {{polymorphic_column}} as column, but does not&quot;</diff>
      <filename>remarkable_i18n/en.yml</filename>
    </modified>
    <modified>
      <diff>@@ -174,10 +174,11 @@ pt-BR:
         has_one: possuir um(a)
         description: &quot;{{macro}} {{associations}}&quot;
         expectations:
-          association_exists: &quot;{{subject_name}} pudesse {{macro}} {{association}}, obtive nenhuma associa&#231;&#227;o&quot;
+          association_exists: &quot;{{subject_name}} pudesse {{macro}} {{association}}, mas associa&#231;&#227;o n&#227;o existe&quot;
           macro_matches: &quot;{{subject_name}} pudesse {{macro}} {{association}}, obtive que {{subject_name}} deve {{actual_macro}} {{association}}&quot;
           through_exists: &quot;{{subject_name}} pudesse {{macro}} {{association}} atrav&#233;s de {{through}}, obtive que \&quot;through_association\&quot; n&#227;o existe&quot;
           source_exists: &quot;{{subject_name}} pudesse {{macro}} {{association}} atrav&#233;s de {{through}}, obtive que \&quot;source association\&quot; n&#227;o existe&quot;
+          klass_exists: &quot;{{subject_name}} records {{macro}} {{association}}, mas a classe da associa&#231;&#227;o n&#227;o existe&quot;
           join_table_exists: &quot;tabela de jun&#231;&#227;o {{join_table}} existisse, mas n&#227;o existe&quot;
           foreign_key_exists: &quot;chave estrangeira {{foreign_key}} existisse em {{foreign_key_table}}, mas n&#227;o existe&quot;
           polymorphic_exists: &quot;{{subject_table}} tivesse {{polymorphic_column}} como coluna, mas n&#227;o tem&quot;</diff>
      <filename>remarkable_i18n/pt-BR.yml</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>33cb6808b5af1b42d2d3bfde0a45d744a0101e8c</id>
    </parent>
  </parents>
  <author>
    <name>Jos&#233; Valim</name>
    <email>jose.valim@gmail.com</email>
  </author>
  <url>http://github.com/carlosbrando/remarkable/commit/456d8f279c63da86b6716ec0515d80f8f9cd9afd</url>
  <id>456d8f279c63da86b6716ec0515d80f8f9cd9afd</id>
  <committed-date>2009-06-04T07:32:05-07:00</committed-date>
  <authored-date>2009-06-04T07:32:05-07:00</authored-date>
  <message>Ensure the association class exists on association matchers.</message>
  <tree>ad42311b1c9a7aa08e1706e4543caedf33d2f4ef</tree>
  <committer>
    <name>Jos&#233; Valim</name>
    <email>jose.valim@gmail.com</email>
  </committer>
</commit>
