Sha256: 318165268720de7e0ad36fade65c046a4be4233422d9b2c4c6da9795cafc6fc1
Contents?: true
Size: 1.79 KB
Versions: 3
Compression:
Stored size: 1.79 KB
Contents
require 'spec_helper' describe Gutentag::Tag, :type => :model do describe '.find_by_name' do it "returns a tag with the same name" do existing = Gutentag::Tag.create! :name => 'pancakes' expect(Gutentag::Tag.find_by_name('pancakes')).to eq(existing) end it "returns a tag with the same normalised name" do existing = Gutentag::Tag.create! :name => 'pancakes' expect(Gutentag::Tag.find_by_name('Pancakes')).to eq(existing) end it "otherwise returns nil" do expect(Gutentag::Tag.find_by_name('pancakes')).to be_nil end end describe '.find_or_create' do it "returns a tag with the same name" do existing = Gutentag::Tag.create! :name => 'pancakes' expect(Gutentag::Tag.find_or_create('pancakes')).to eq(existing) end it "returns a tag with the same normalised name" do existing = Gutentag::Tag.create! :name => 'pancakes' expect(Gutentag::Tag.find_or_create('Pancakes')).to eq(existing) end it "creates a new tag if no matches exist" do expect(Gutentag::Tag.find_or_create('pancakes')).to be_persisted end end describe '#name' do before :each do allow(Gutentag::TagName).to receive(:call).and_return('waffles') end it "normalises the provided name" do expect(Gutentag::TagName).to receive(:call).with('Pancakes'). and_return('waffles') Gutentag::Tag.create!(:name => 'Pancakes') end it "saves the normalised name" do expect(Gutentag::Tag.create!(:name => 'Pancakes').name).to eq('waffles') end end describe '#valid?' do it "ignores case when enforcing uniqueness" do Gutentag::Tag.create! :name => 'pancakes' tag = Gutentag::Tag.create(:name => 'Pancakes') expect(tag.errors[:name].length).to eq(1) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
gutentag-0.8.0 | spec/models/gutentag/tag_spec.rb |
gutentag-0.7.0 | spec/models/gutentag/tag_spec.rb |
gutentag-0.6.0 | spec/models/gutentag/tag_spec.rb |