Guest User

Untitled

a guest
Dec 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. ## size.rb
  2.  
  3. after_create :add_size_to_products_in_category
  4.  
  5.  
  6. protected
  7. def add_size_to_products_in_category
  8. self.category.products.each do |product|
  9. product.sizes << self
  10. end
  11. end
  12.  
  13.  
  14. ## size_spec.rb
  15. let(:category) { FactoryGirl.build :category }
  16. let(:size) { FactoryGirl.build :size }
  17. let(:product) { FactoryGirl.build :product }
  18.  
  19. it "should add size to all products" do
  20. product.save.should be_true
  21. sizes = product.sizes.count
  22. size = Size.new :name => "Another size", :category => category
  23. size.save.should be_true
  24. product.sizes.count.should eql(sizes + 1) # fails here saying it gets 0 expecting 1
  25. end
Add Comment
Please, Sign In to add comment