Sha256: 953ad5055428e9ca49eb5a3d006e13c24caf38527a23a60b43eb26f5a9e54ef2

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

require 'spec_helper'

describe Banyan::Category do
  let(:category) { FactoryGirl.create(:banyan_category) }
  subject { category }

  it                                 { should be_valid }
  its(:children)                     { should be_empty }
  its(:banyan_model_categorizations) { should be_empty }

  context "with banyan model created" do
    let(:banyan_model) { FactoryGirl.create :banyan_model }
    before { subject.banyan_model_categorizations << banyan_model }

    its(:banyan_model_categorizations) { should include(banyan_model) }
    it "should be visible by banyan model" do
      banyan_model.categories.should include(subject)
    end
  end

  context "with children" do
    let(:subcategory) { FactoryGirl.create :banyan_category }
    before { subject.children << subcategory }

    its(:children) { should include(subcategory) }
    it "should be visible from subcategory" do
      subcategory.parent.should eql(subject)
    end
  end

  context "in different language" do
    before do
      @default_language = I18n.locale
      @default_name = subject.name
      I18n.locale = :es
    end
    after { I18n.locale = @default_locale }

    its(:name) { should eql(@default_name) }
    it "should be able to change name" do
      subject.name = "test"
      subject.name.should eql("test")
      I18n.locale = @default_locale
      subject.name.should eql(@default_name)
    end
  end

  context "#tag" do
    subject { category.tag }

    context "when not explicitly set" do
      it { should eq(category.name) }
    end

    context "when explicitly set" do
      let(:tag_name) { 'foobar' }
      let(:category) { FactoryGirl.create(:banyan_category, :tag => tag_name) }

      it { should eq(tag_name) }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
banyan-1.1.1 spec/banyan/banyan_category_spec.rb
banyan-1.0.1 spec/banyan/banyan_category_spec.rb