title: Rspec model methods return nil when created by let
body: <p>Ok, so this may seem like a total newbie ask, but when I create an instance of my model with <code>let</code>, for some reason all of the getter methods on it return nil. Here's my example:</p>
  
  <p><strong>Model:</strong></p>
  
  <pre class="lang-ruby prettyprint-override"><code>class Parcel &lt; ActiveRecord::Base
    extend UUIDHelper
  
    serialize :address, ActiveRecord::Coders::Hstore
  
    self.rgeo_factory_generator = RGeo::Geographic.spherical_factory srid: 3785
  
    attr_accessible :address, :area_poly, :id, :lonlat, :municipal_id
  end
  </code></pre>
  
  <p><strong>Spec:</strong></p>
  
  <pre class="lang-ruby prettyprint-override"><code>require 'spec_helper'
  require 'street_address'
  
  describe Parcel do
    let(:geo_factory) { RGeo::Geographic.spherical_factory(srid: 3785)}
    let(:point1) {geo_factory.point(-72.9229165, 41.3096987)}
    let(:point2) {geo_factory.point(-72.9229169, 41.3096987)}
    let(:point3) {geo_factory.point(-72.9229169, 41.3096983)}
    let(:point4) {geo_factory.point(-72.9229165, 41.3096983)}
    let(:line_string) {geo_factory.line_string([point1,point2,point3,point4])}
    let(:polygon) {geo_factory.polygon(line_string)}
    let(:parcel) { Parcel.create(
        municipal_id: 'abc123',
        area_poly: polygon,
        #lonlat: polygon.centroid,
        address: StreetAddress::US.parse('55 Whitney Ave New Haven, CT 06510').as_json
    )}
  
    it "#municipal_id should not be nil" do
      parcel.municipal_id.nil? should_not be_true
    end
  end
  </code></pre>
  
  <p>(the #longlat attribute is commented out because calling the <code>.centroid</code> method on a spherically defined polygon in RGeo is a no-no. Getting the right projection, while on my list of to-dos, is not relevant to this question)
  And the spec fails like so:</p>
  
  <pre><code>expected: non-true value
    got: #&lt;Parcel id: nil, municipal_id: nil, address: {}, created_at: nil, updated_at: nil, area_poly: nil, lonlat: nil&gt;
  </code></pre>
  
  <p>FWIW, here's the Rspec log:</p>
  
  <pre><code>Connecting to database specified by database.yml
     (0.1ms)  BEGIN
     (7.2ms)  SELECT * FROM geometry_columns WHERE f_table_name='parcels'
     (0.1ms)  SAVEPOINT active_record_1
    SQL (4.2ms)  INSERT INTO "parcels" ("address", "area_poly", "created_at", "id", "lonlat",     "municipal_id", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7)  [["address", "\"number\"=&gt;\"55\",\"street\"=&gt;\"Whitney\",\"street_type\"=&gt;\"Ave\",\"unit\"=&gt;NULL,\"unit_prefix\"=&gt;NULL,\"suffix\"=&gt;NULL,\"prefix\"=&gt;NULL,\"city\"=&gt;\"New Haven\",\"state\"=&gt;\"CT\",\"postal_code\"=&gt;\"06510\",\"postal_code_ext\"=&gt;NULL"], ["area_poly", #&lt;RGeo::Geographic::SphericalPolygonImpl:0x80b773e0 "POLYGON ((-72.9229165 41.3096987, -72.9229169 41.3096987, -72.9229169 41.3096983, -72.9229165 41.3096983, -72.9229165 41.3096987))"&gt;], ["created_at", Mon, 02 Jun 2014 11:59:51 UTC +00:00], ["id", nil], ["lonlat", nil], ["municipal_id", "abc123"], ["updated_at", Mon, 02 Jun 2014 11:59:51 UTC +00:00]]
     (0.1ms)  RELEASE SAVEPOINT active_record_1
     (0.1ms)  ROLLBACK
  </code></pre>
  
  <p>For reference, I can successfully run <code>Parcel.create</code> in a Rails console, and get instance variables to return non-nil values</p>
  
  <p>I'm running rails 3.2, using postgres 9.3 with postgis 2, and heavily relying on activerecord-postgis-adaptor, RGeo, activerecord-postgres-hstore, among other gems.</p>
  
  <p>Any thoughts?</p>