Sha256: f47509a060070dc21f3adc0878457362b30f328c60d19823a505efca1326298f

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require "spec_helper"

RSpec.describe "Adding and removing tags" do
  let(:article)  { Article.create }
  let(:pancakes) { Gutentag::Tag.create :name => "pancakes" }

  it "stores new tags" do
    article.tags << pancakes

    expect(article.tags.reload).to eq([pancakes])
  end

  it "removes existing tags" do
    article.tags << pancakes

    article.tags.delete pancakes

    expect(article.tags.reload).to eq([])
  end

  it "removes taggings when an article is deleted" do
    article.tags << pancakes

    article.destroy

    expect(Gutentag::Tagging.where(
      :taggable_type => "Article", :taggable_id => article.id
    ).count).to be_zero
  end

  it "removes taggings when a tag is deleted" do
    article.tags << pancakes

    pancakes.destroy

    expect(Gutentag::Tagging.where(:tag_id => pancakes.id).count).to be_zero
  end

  it "should have a mean tag cloud" do
    gorillas = Gutentag::Tag.create(:name => "gorillas")
    another_article = Article.create

    article.tags << pancakes
    expect(Gutentag::Tag.by_weight.first).to eq(pancakes)

    article.tags << gorillas
    another_article.tags << gorillas
    expect(Gutentag::Tag.by_weight.first).to eq(gorillas)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gutentag-2.6.2 spec/acceptance/tags_spec.rb
gutentag-2.6.1 spec/acceptance/tags_spec.rb
gutentag-2.6.0 spec/acceptance/tags_spec.rb
gutentag-2.5.4 spec/acceptance/tags_spec.rb
gutentag-2.5.3 spec/acceptance/tags_spec.rb