Sha256: 8f76f90cb5e73fa7b019bf4061f377f3f5c6836937be49833a5afd8f96ea3d8a

Contents?: true

Size: 1.58 KB

Versions: 2

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'

shared_examples_for 'a tagged model' do

  # clazz must be defined by the calling file

  let(:model) { clazz.new }


  it 'has tags' do
    expect(model).to respond_to(:tags)
  end

  it 'can change its tags' do
    expect(model).to respond_to(:tags=)

    model.tags = :some_tags
    expect(model.tags).to eq(:some_tags)
    model.tags = :some_other_tags
    expect(model.tags).to eq(:some_other_tags)
  end


  describe 'abstract instantiation' do

    context 'a new tagged object' do

      let(:model) { clazz.new }


      it 'starts with no tags' do
        expect(model.tags).to eq([])
      end

      it 'starts with no inherited tags' do
        expect(model.applied_tags).to eq([])
      end

      it 'starts with no tags at all' do
        expect(model.all_tags).to eq([])
      end

    end

  end

  it 'has applied tags' do
    expect(model).to respond_to(:applied_tags)
  end

  it 'inherits its applied tags from its ancestors' do
    all_parent_tags = [:parent_tag_1, :parent_tag_2, :grandparent_tag_1]
    parent = double(:all_tags => all_parent_tags)

    model.parent_model = parent

    expect(model.applied_tags).to match_array(all_parent_tags)
  end

  it 'knows all of its applicable tags' do
    all_parent_tags = [:parent_tag_1, :parent_tag_2, :grandparent_tag_1]
    own_tags = [:tag_1, :tag_2]

    parent = double(:all_tags => all_parent_tags)

    model.parent_model = parent
    model.tags = own_tags

    expect(model.all_tags).to match_array(all_parent_tags + own_tags)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cuke_modeler-1.0.1 spec/unit/shared/tagged_models_unit_specs.rb
cuke_modeler-1.0.0 spec/unit/shared/tagged_models_unit_specs.rb