Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## size.rb
- after_create :add_size_to_products_in_category
- protected
- def add_size_to_products_in_category
- self.category.products.each do |product|
- product.sizes << self
- end
- end
- ## size_spec.rb
- let(:category) { FactoryGirl.build :category }
- let(:size) { FactoryGirl.build :size }
- let(:product) { FactoryGirl.build :product }
- it "should add size to all products" do
- product.save.should be_true
- sizes = product.sizes.count
- size = Size.new :name => "Another size", :category => category
- size.save.should be_true
- product.sizes.count.should eql(sizes + 1) # fails here saying it gets 0 expecting 1
- end
Add Comment
Please, Sign In to add comment