Compare commits

...

1 Commits

Author SHA1 Message Date
jibees
abf9c4e438 Revert "Cache address JSON to avoid database queries" 2022-11-15 11:05:54 +01:00
2 changed files with 2 additions and 42 deletions

View File

@@ -1,8 +1,8 @@
# frozen_string_literal: true
class Api::AddressSerializer < ActiveModel::Serializer
cached
delegate :cache_key, to: :object
# cached
# delegate :cache_key, to: :object
attributes :id, :zipcode, :city, :state_name, :state_id,
:phone, :firstname, :lastname, :address1, :address2, :city, :country_id,

View File

@@ -1,40 +0,0 @@
# frozen_string_literal: true
require 'spec_helper'
describe Api::AddressSerializer do
subject(:serializer) { described_class.new(address) }
let(:address) { build(:address) }
describe "#country_name" do
it "provides the country's name" do
address.country.name = "Australia"
expect(serializer.country_name).to eq "Australia"
end
end
describe "#state_name" do
it "provides the state's abbreviation" do
address.state.abbr = "Vic"
expect(serializer.state_name).to eq "Vic"
end
end
describe "caching" do
it "updates with the record" do
expect {
address.update!(first_name: "Nick")
}.to change {
serializer.to_json
}
end
it "uses stored result when database wasn't changed" do
expect {
address.first_name = "Nick"
}.to_not change {
serializer.to_json
}
end
end
end