Sha256: fb6186e7e5f9480ec1b0b90d99c4881ce1ec4ee7f0edb521dec794e10d964410
Contents?: true
Size: 976 Bytes
Versions: 1
Compression:
Stored size: 976 Bytes
Contents
require 'spec_helper' RSpec.describe Serialism::Serializer, type: :model do let(:subject) do Class.new(Serialism::Serializer) do attributes :id, :computed def computed "computed by serializer - #{object.id}" end end end describe '.attributes' do it 'should allow attributes to be set and retrieved' do subject.attributes(:a, :b) expect(subject.attributes).to eq([:a, :b]) end end describe '#render' do let(:item) do item_class = Struct.new(:id, :computed) item_class.new(1, "'computed' defined in item") end it 'should prefer attribute implementations in the serializer' do values = subject.new(item).render expect(values[:computed]).to eq 'computed by serializer - 1' end it 'should use attribute implementation in object if not defined explicitly in serializer' do values = subject.new(item).render expect(values[:id]).to eq 1 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
serialism-0.2.0 | spec/lib/serialism/serializer_spec.rb |