Sha256: 1d36965c4cee9c7d25adbde45a0e313c667985cb4ec4a41d490c3295cd134737

Contents?: true

Size: 1.48 KB

Versions: 19

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Azeroth::DummyDecorator do
  subject(:decorator) { described_class.new(object) }

  let(:model)  { build(:dummy_model) }
  let(:object) { model }

  describe '#as_json' do
    context 'when object is just a model' do
      let(:expected_json) do
        {
          favorite_game: 'pokemon',
          favorite_pokemon: 'squirtle',
          first_name: 'dummy',
          id: model.id,
          last_name: 'bot',
          age: 21
        }.stringify_keys
      end

      it 'object.as_json' do
        expect(decorator.as_json).to eq(expected_json)
      end
    end

    context 'when object is an array' do
      let(:object) { [model, other_model] }

      let(:other_model) do
        build(
          :dummy_model,
          first_name: 'dum',
          age: 65,
          favorite_pokemon: :bulbasaur
        )
      end

      let(:expected_json) do
        [
          {
            favorite_game: 'pokemon',
            favorite_pokemon: 'squirtle',
            first_name: 'dummy',
            id: model.id,
            last_name: 'bot',
            age: 21
          }, {
            favorite_game: 'pokemon',
            favorite_pokemon: 'bulbasaur',
            first_name: 'dum',
            id: other_model.id,
            last_name: 'bot',
            age: 65
          }
        ].map(&:stringify_keys)
      end

      it 'object.as_json' do
        expect(decorator.as_json).to eq(expected_json)
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
azeroth-1.0.0 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.10.1 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.10.0 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.9.0 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.8.2 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.8.1 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.8.0 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.7.4 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.7.3 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.7.2 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.7.1 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.7.0 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.6.5 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.6.4 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.6.3 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.6.2 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.6.1 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.6.0 spec/lib/azeroth/dummy_decorator_spec.rb
azeroth-0.5.0 spec/lib/azeroth/dummy_decorator_spec.rb