mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Spec the AddressSerializer before changing it
This commit is contained in:
40
spec/serializers/api/address_serializer_spec.rb
Normal file
40
spec/serializers/api/address_serializer_spec.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
# 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 "updates even when database wasn't changed" do
|
||||
expect {
|
||||
address.first_name = "Nick"
|
||||
}.to change {
|
||||
serializer.to_json
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user