I'm using ActiveModel Serializers gem with Rails API and I tried to enable 
caching on `Address` following the docs of AMS 
<https://github.com/rails-api/active_model_serializers/blob/v0.10.6/docs/general/caching.md>
 
as follows:

#serializers/address_serializer.rb


# frozen_string_literal: true


class AddressSerializer < ActiveModel::Serializer
  cache key: 'address', expires_in: 3.hours


  attributes :city,
             :id,
             :latitude,
             :longitude,
             :modified_by,
             :postal_code,
             :region,
             :street,
             :updated_at


  belongs_to :shop
end



But with this in place the previously passing request spec failed:

#spec/requests/address_spec.rb


require 'rails_helper'


RSpec.describe "Addresses", type: :request do
  let(:user)     { create(:user) }
  let!(:address) { create(:address, shop: user.shop)}
  let(:headers)  { valid_headers(user.username) }


describe 'PATCH /shops/:shop_identifer/address' do
    let(:valid_params) do
      ams_json(
        Address,
        city: address.city,
        postal_code: address.postal_code,
        street: 'new fancy street',
        modified_by: address.modified_by,
        shop: address.shop,
        id: address.id
      )
    end


    before { patch "/shops/#{address.shop.identifier}/address", params: 
valid_params, headers: headers }


    it 'returns status code 204' do
      expect(response).to have_http_status(204)
    end


    it 'updates the modified attributes' do
      updated = Address.find(address.id)
      expect(updated.street).to eq 'new fancy street'
    end
  end
end



with error:

1) Addresses PATCH /shops/:shop_identifer/address updates the modified 
attributes 

 Failure/Error: expect(updated.street).to eq 'new fancy street' 

 

 expected: "new fancy street" 

 got: "7285 Dicki Circle" 

 (compared using ==) 

 # ./spec/requests/addresses_spec.rb:42:in `block (3 levels) in <top 
(required)>'


What am I missing? Thank you.


-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/90835c10-2133-4acb-9619-34fc01f368c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to