Sha256: e74e191202eb284474d87bf9cb4b26830d4f9a219ee7546e69a9204a4e9ec7ea

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

require 'spec_helper'

describe Mongoid::TagCollectible::Tagged do
  let(:instance) { Namespaced::TestTagged.create! }
  describe 'tag_class' do
    it 'defines tag_class' do
      expect(instance.class.tag_class).to eq(Namespaced::TestTaggedTag)
    end
  end
  describe 'rename_tag' do
    context "doesn't match an existing tag" do
      it 'is the same' do
        old_tags = instance.class.all.map(&:tags)
        instance.class.rename_tag! 'Yellow', 'yellow'
        expect(instance.class.all.map(&:tags)).to eq old_tags
      end
    end
    context 'matches an existing tag' do
      it 'is different' do
        instance.tags = %w(Yellow Mellow)
        instance.save!
        old_tags = instance.class.all.map(&:tags)
        instance.class.rename_tag! 'Yellow', 'Blue'
        expect(instance.class.all.map(&:tags)).not_to eq old_tags
        expect(instance.reload.tags).to include 'Blue'
        expect(instance.tags).to include 'Mellow'
        expect(instance.tags).not_to include 'Yellow'
      end
    end
  end
  describe 'remove_tag!' do
    it 'deletes tag' do
      instance.tags = %w(Yellow Mellow)
      instance.save!
      instance.class.remove_tag!('Yellow')
      expect(instance.class.find(instance.id).tags).to eq(['Mellow'])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-tag-collectible-0.2.0 spec/mongoid-tag-collectible/namespaced_tagged_spec.rb