Sha256: ed1da6ca249f58c6990e7c1c978ab693dc063d0863615d40ae75f2b4eab05deb

Contents?: true

Size: 1.63 KB

Versions: 6

Compression:

Stored size: 1.63 KB

Contents

require 'spec_helper'

RSpec.describe Yaks::Mapper::ClassMethods do
  subject(:mapper_class) do
    Class.new do
      extend Yaks::Mapper::ClassMethods
      attributes :foo, :bar
      link :some_rel, 'http://some_link'
      has_one :thing
      has_many :thingies
    end
  end

  describe 'attributes' do
    it 'should allow setting them' do
      expect( mapper_class.attributes ).to eq [
        Yaks::Mapper::Attribute.new(:foo),
        Yaks::Mapper::Attribute.new(:bar)
      ]
    end

    describe 'with inheritance' do
      let(:child_class) do
        Class.new(mapper_class) do
          attributes :baz
        end
      end

      let(:grandchild_class) do
        Class.new(child_class)
      end

      it 'should inherit attributes from the parent' do
        expect(child_class.attributes).to eq [
          Yaks::Mapper::Attribute.new(:foo),
          Yaks::Mapper::Attribute.new(:bar),
          Yaks::Mapper::Attribute.new(:baz)
        ]
      end

      it 'should create a valid config' do
        expect(grandchild_class.config).to be_a Yaks::Mapper::Config
      end

      it 'should not alter the parent' do
        expect(mapper_class.attributes).to eq [
          Yaks::Mapper::Attribute.new(:foo),
          Yaks::Mapper::Attribute.new(:bar),
        ]
      end
    end
  end

  it 'should register links' do
    expect(mapper_class.config.links).to eq [
      Yaks::Mapper::Link.new(:some_rel, 'http://some_link', {})
    ]
  end

  it 'should register associations' do
    expect(mapper_class.config.associations).to eq [
      Yaks::Mapper::HasOne.new(name: :thing),
      Yaks::Mapper::HasMany.new(name: :thingies)
    ]
  end

end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
yaks-0.6.0.alpha.1 spec/unit/yaks/mapper/class_methods_spec.rb
yaks-html-0.6.0.alpha yaks/spec/unit/yaks/mapper/class_methods_spec.rb
yaks-0.6.0.alpha yaks/spec/unit/yaks/mapper/class_methods_spec.rb
yaks-0.5.0 spec/unit/yaks/mapper/class_methods_spec.rb
yaks-0.4.4 spec/unit/yaks/mapper/class_methods_spec.rb
yaks-0.4.3 spec/unit/yaks/mapper/class_methods_spec.rb