robzolkos
5/19/2011 - 2:17 AM

spec for organisations, categories, products

spec for organisations, categories, products

  it "association test should work for organisations, categories, products" do
    @orga = Factory.create(:organisation, :id=>1, :title=>"abc")
    @orgb = Factory.create(:organisation, :id=>2, :title=>"abc")
  
    @cata = Factory.create(:category, :title=>"design")
    @catb = Factory.create(:category, :title=>"web design")
    @catc = Factory.build(:category,  :title=>"web")
 
    @product1 = Factory.create(:product, :id=>1, :title=>"xxx", :categories=>[@cata, @catb], :organisation=>@orga)
    @product2 = Factory.create(:product, :id=>2, :title=>"yyy", :categories=>[@catc, @cata], :organisation=>@orga)
    @product3 = Factory.create(:product, :id=>3, :title=>"zzz", :categories=>[@catb], :organisation=>@orgb)
  
    @cata.products.size.should == 2
    @catb.products.size.should == 2
  
    @product1.categories.should == [@cata, @catb]
    @product2.categories.should == [@catc, @cata]
  
    @orga.products.size.should == 2
    @orga.categories.size.should == 3
  end