Sha256: 7ad9f5103e4f94369ca27bbd7b779d471a7c65e1df62d90aad5baa2811dff69f

Contents?: true

Size: 1.51 KB

Versions: 14

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

describe Azeroth::Decorator do
  describe 'yard' do
    describe '#as_json' do
      it 'simple example' do
        object = DummyModel.new(
          id: 100,
          first_name: 'John',
          last_name: 'Wick',
          favorite_pokemon: 'Arcanine'
        )

        decorator = DummyModel::Decorator.new(object)

        expect(decorator.as_json).to eq(
          'name' => 'John Wick',
          'age' => nil,
          'pokemon' => 'Arcanine'
        )
      end

      it 'complete example' do
        master = PokemonMaster.create(
          first_name: 'Ash',
          last_name: 'Ketchum',
          age: 10
        )

        master.create_favorite_pokemon(
          name: 'pikachu',
          nickname: 'Pikachu'
        )

        metapod = Pokemon.create(name: :metapod)

        master.pokemons.create(
          name: 'butterfree', previous_form: metapod
        )
        master.pokemons.create(name: 'squirtle')

        decorator = PokemonMaster::Decorator.new(master)

        expect(decorator.as_json).to eq(
          {
            'age' => 10,
            'name' => 'Ash Ketchum',
            'favorite_pokemon' => {
              'name' => 'pikachu',
              'nickname' => 'Pikachu'
            },
            'pokemons' => [{
              'name' => 'butterfree',
              'evolution_of' => 'metapod'
            }, {
              'name' => 'squirtle'
            }, {
              'name' => 'pikachu'
            }]
          }
        )
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
azeroth-1.0.0 spec/integration/yard/azeroth/decorator_spec.rb
azeroth-0.10.1 spec/integration/yard/azeroth/decorator_spec.rb
azeroth-0.10.0 spec/integration/yard/azeroth/decorator_spec.rb
azeroth-0.9.0 spec/integration/yard/azeroth/decorator_spec.rb
azeroth-0.8.2 spec/integration/yard/azeroth/decorator_spec.rb
azeroth-0.8.1 spec/integration/yard/azeroth/decorator_spec.rb
azeroth-0.8.0 spec/integration/yard/azeroth/decorator_spec.rb
azeroth-0.7.4 spec/integration/yard/azeroth/decorator_spec.rb
azeroth-0.7.3 spec/integration/yard/azeroth/decorator_spec.rb
azeroth-0.7.2 spec/integration/yard/azeroth/decorator_spec.rb
azeroth-0.7.1 spec/integration/yard/azeroth/decorator_spec.rb
azeroth-0.7.0 spec/integration/yard/azeroth/decorator_spec.rb
azeroth-0.6.5 spec/integration/yard/azeroth/decorator_spec.rb
azeroth-0.6.4 spec/integration/yard/azeroth/decorator_spec.rb