Sha256: 413ca57171f856fd89e67ea397f8188f02beb4a7247ab2f33666de037851df0b
Contents?: true
Size: 1.82 KB
Versions: 1
Compression:
Stored size: 1.82 KB
Contents
# frozen_string_literal: true 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.normaliser).to receive(:call).and_return("waffles") end it "normalises the provided name" do allow(Gutentag.normaliser).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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gutentag-1.0.0 | spec/models/gutentag/tag_spec.rb |