#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#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
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)>'--
You received this message because you are subscribed to a topic in the Google Groups "rspec" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rspec/0m457NKBWFE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
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.
Adding before(:example) hook to clear the cache seems to fix the problem. Is it the right way to go?RSpec.describe "Addresses", type: :request dolet(:user) { create(:user) }let!(:address) { create(:address, shop: user.shop)}let(:headers) { valid_headers(user.username) }before(:example) { Rails.cache.clear }
config.cache_store = :null_storeRails.cache.clearit 'updates the modified attributes' do
expect(address.reload.street).to eq 'new fancy street'
endTo unsubscribe from this group and all its topics, send an email to rspec+unsubscribe@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
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.
--
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 rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/ef16f471-582d-479f-88d0-28f58be65634%40googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "rspec" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rspec/0m457NKBWFE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/dejalu-217-6799f603-4dc3-400f-baf2-ab4fac66a9f2%40jonrowe.co.uk.