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