Sha256: 30af0e0ab1e545affdda22b8fd181999e1667ecb1c62cacbef586eb0cbd99d0c

Contents?: true

Size: 1.48 KB

Versions: 10

Compression:

Stored size: 1.48 KB

Contents

require File.expand_path('../../spec_helper', __FILE__)

describe Tagtical::Tagging do
  before(:each) do
    clean_database!
    @klass = Tagtical::Tagging
    @tagging = @klass.new
  end
  subject { @tagging }

  describe "#before_create" do
    context "when no relevance set" do
      before do
        @tagging.relevance = nil
        @tagging.run_callbacks(:create)
      end
      its(:relevance) { should == @klass.default_relevance }
    end
    context "when relevance set" do
      before { @tagging.run_callbacks(:create) }
      its(:relevance) { should == @tagging.relevance }
    end
  end

  it "should sort by relevance" do
    @taggings = [3.454, 2.3, 6, 3.2].map { |relevance| @klass.new(:relevance => relevance) }
    @taggings.sort.map(&:relevance).should == [2.3, 3.2, 3.454, 6.0]
  end

  it "should not be valid with a invalid tag" do
    @tagging.taggable = TaggableModel.create(:name => "Bob Jones")
    @tagging.tag = Tagtical::Tag.new(:value => "") 

    @tagging.should_not be_valid

    if ActiveRecord::VERSION::MAJOR >= 3
      @tagging.errors[:tag_id].should == ["can't be blank"]
    else
      @tagging.errors[:tag_id].should == "can't be blank"
    end
  end

  it "should not create duplicate taggings" do
    @taggable = TaggableModel.create(:name => "Bob Jones")
    @tag = Tagtical::Tag.create(:value => "awesome")

    lambda {
      2.times { @klass.create(:taggable => @taggable, :tag => @tag, :context => 'tags') }
    }.should change(@klass, :count).by(1)
  end
  
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tagtical-1.3.1 spec/tagtical/tagging_spec.rb
tagtical-1.3.0 spec/tagtical/tagging_spec.rb
tagtical-1.2.0 spec/tagtical/tagging_spec.rb
tagtical-1.1.3 spec/tagtical/tagging_spec.rb
tagtical-1.1.2 spec/tagtical/tagging_spec.rb
tagtical-1.1.1 spec/tagtical/tagging_spec.rb
tagtical-1.1.0 spec/tagtical/tagging_spec.rb
tagtical-1.0.8 spec/tagtical/tagging_spec.rb
tagtical-1.0.7 spec/tagtical/tagging_spec.rb
tagtical-1.0.6 spec/tagtical/tagging_spec.rb