Sha256: cabb9ccd8019c21e438c6cb28c52938be91fcaffb383fbf6a2bc8f987e0f5ad7

Contents?: true

Size: 1.7 KB

Versions: 5

Compression:

Stored size: 1.7 KB

Contents

require 'spec_helper'

describe Gutentag::Tag do
  describe '.find_by_name' do
    it "returns a tag with the same name" do
      existing = Gutentag::Tag.create! :name => 'pancakes'

      Gutentag::Tag.find_by_name('pancakes').should == existing
    end

    it "returns a tag with the same normalised name" do
      existing = Gutentag::Tag.create! :name => 'pancakes'

      Gutentag::Tag.find_by_name('Pancakes').should == existing
    end

    it "otherwise returns nil" do
      Gutentag::Tag.find_by_name('pancakes').should be_nil
    end
  end

  describe '.find_or_create' do
    it "returns a tag with the same name" do
      existing = Gutentag::Tag.create! :name => 'pancakes'

      Gutentag::Tag.find_or_create('pancakes').should == existing
    end

    it "returns a tag with the same normalised name" do
      existing = Gutentag::Tag.create! :name => 'pancakes'

      Gutentag::Tag.find_or_create('Pancakes').should == existing
    end

    it "creates a new tag if no matches exist" do
      Gutentag::Tag.find_or_create('pancakes').should be_persisted
    end
  end

  describe '#name' do
    before :each do
      Gutentag::TagName.stub :normalise => 'waffles'
    end

    it "normalises the provided name" do
      Gutentag::TagName.should_receive(:normalise).with('Pancakes').
        and_return('waffles')

      Gutentag::Tag.create!(:name => 'Pancakes')
    end

    it "saves the normalised name" do
      Gutentag::Tag.create!(:name => 'Pancakes').name.should == 'waffles'
    end
  end

  describe '#valid?' do
    it "ignores case when enforcing uniqueness" do
      Gutentag::Tag.create! :name => 'pancakes'

      Gutentag::Tag.create(:name => 'Pancakes').should have(1).error_on(:name)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gutentag-0.5.0 spec/models/gutentag/tag_spec.rb
gutentag-0.4.0 spec/models/gutentag/tag_spec.rb
gutentag-0.3.0 spec/models/gutentag/tag_spec.rb
gutentag-0.2.2 spec/models/gutentag/tag_spec.rb
gutentag-0.2.1 spec/models/gutentag/tag_spec.rb