Sha256: 7d922e89172599c2076c462e98153fd8e6874f5298af8f5f453abdd2f3f21ea1

Contents?: true

Size: 1.77 KB

Versions: 2

Compression:

Stored size: 1.77 KB

Contents

require 'spec_helper'

describe Banyan::CategoryGroup do
  let(:category_group) { FactoryGirl.create(:banyan_category_group) }
  subject { category_group }

  it                        { should be_valid }
  its(:children)            { should be_empty }
  its(:group_categorizable) { should be_nil }

  context "with banyan group model created" do
    let(:banyan_group_model) { FactoryGirl.create :banyan_group_model }
    before { subject.group_categorizable = banyan_group_model; subject.save }

    its(:group_categorizable) { should eql(banyan_group_model) }
    it "should be visible by banyan group model" do
      banyan_group_model.category_groups.should include(subject)
    end
  end

  context "with children" do
    let(:subcategory) { FactoryGirl.create :banyan_category_group }
    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_group.tag }

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

    context "when explicitly set" do
      let(:tag_name) { 'foobar' }
      let(:category_group) { FactoryGirl.create(:banyan_category_group, :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_group_spec.rb
banyan-1.0.1 spec/banyan/banyan_category_group_spec.rb