title: Rails class naming collision
body: <p>In my rails application I have the following:</p>
  
  <ol>
  <li><p><code>Post</code> model</p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
    # ...
  end
  </code></pre></li>
  <li><p><code>Post</code> model inside such a module</p>
  
  <pre><code># lib/my_module/models.rb
  module MyModule
    module Models
      class AbstractTable &lt; ActiveRecord::Base
        self.abstract_class = true
      end
  
      class Comment &lt; AbstractTable
        belogs_to :post
      end
  
      class Post &lt; AbstractTable
        has_many :comments
      end
    end
  end
  </code></pre></li>
  </ol>
  
  <p>Both <code>Post</code> models have different set of fields and are connected to different databases: </p>
  
  <ol>
  <li><code>Post</code> -> Postgresql adapter</li>
  <li><code>MyModule::Models::Post</code> -> SQLite adapter</li>
  </ol>
  
  <p><strong>Sometimes</strong> (depending on a seed value), when running test suite, I get a super strange constant (?) collition: in places, where original <code>Post</code> constant is mentioned (on a create/update operations) I get error that it lacks fields from <code>MyModule::Models::Post</code>, while in places, where <code>MyModule::Models::Post</code> is mentioned – I get an error that the model lacks attributes from origin <code>Post</code>.</p>
  
  <p>Additional clues:</p>
  
  <ol>
  <li>I only use <code>MyModule::Models::Post</code> inside the <code>MyModule</code> scope, calling <code>Models::Post</code>,</li>
  <li>I never use <code>MyModule::Models::Post</code> outside the lib.</li>
  <li>All "different" models are kept in a single file, <code>lib/my_module/models.rb</code></li>
  <li>If I login to a <code>pry</code> session for a failing spec, before the line where ruby brags about <code>MyModule::Models::Post</code> not having fields it should have (but fields from <code>Post</code> instead): calling <code>MyModule::Models::Post</code> returns me exact original <code>Post</code> model class!</li>
  </ol>
  
  <p><strong>What am I missing? Is this an rspec problem? Am I messing up with convention or something?</strong></p>
  
  <p><strong>Update 1</strong>. I tried to split <code>Models</code> module, putting every additional model into a separate file. No luck – same errors</p>
  
  <p><strong>Update 2</strong>. Another thought was: since <code>Comment</code> model is defined before <code>Post</code>, Ruby tries to load original <code>Post</code> first. Still, moving the <code>Post</code> model up didn't help.</p>
  
  <p><strong>Update 3</strong>. RSpec had <a href="https://github.com/rspec/rspec-mocks/commit/1e3f431e522d61b9b8df06e01c6bbcfff0e0981a" rel="nofollow">this</a> commit. Still, updating Gemfile's <code>rspec-mock</code> to point from github didn't help.</p>