Sha256: b1ce60ee792260edf0e56ebf98707e794d118c4359ac92f7c49a9542f026b9a4

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require "spec_helper"

require "support/have_persisted_matcher"
require "support/object_store_setup"
require "support/seed_data_setup"
require "terrestrial"

require "terrestrial/configurations/conventional_configuration"

RSpec.describe "Config override" do
  include_context "object store setup"
  include_context "seed data setup"

  let(:user) { object_store[:users].where(id: "users/1").first }

  context "with an object that has private fields" do
    let(:user_serializer) {
      ->(object) {
        object.to_h.merge(
          first_name: "I am a custom serializer",
          last_name: "and i don't care about facts",
        )
      }
    }

    before do
      mappings
        .setup_mapping(:users) { |users|
          users.serializer(user_serializer)
        }
    end

    context "when saving the object" do
      it "uses the custom serializer" do
        user.first_name = "This won't work"
        user.last_name = "because the serialzer is weird"

        object_store[:users].save(user)

        expect(datastore).to have_persisted(:users, hash_including(
          id: user.id,
          first_name: "I am a custom serializer",
          last_name: "and i don't care about facts",
        ))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
terrestrial-0.5.0 spec/custom_serializers_spec.rb