Skip to content

Instantly share code, notes, and snippets.

@r38y
Created September 25, 2012 21:52
Show Gist options
  • Save r38y/3784696 to your computer and use it in GitHub Desktop.
Save r38y/3784696 to your computer and use it in GitHub Desktop.
# passes (from different app)
it "should associate with a location with location_ids" do
location = create(:location)
vendor = create(:vendor, location_ids: [location.id])
vendor.reload
vendor.locations.should include(location)
end
# fails
it "should associate with a category with category_ids" do
category = create(:category)
drawing = create(:drawing, category_ids: [category.id])
drawing.reload
drawing.categories.should include(category)
end
# passes
it "should associate with a category with category_ids" do
category = create(:category)
drawing = create(:drawing)
drawing.category_ids = [category.id]
drawing.save
drawing.reload
drawing.categories.should include(category)
end
@jamesarosen
Copy link

What about drawing.categories(true).should include(category)?

@r38y
Copy link
Author

r38y commented Sep 25, 2012

Doesn't help. The reason I went down this trail is selecting categories with a checkbox wasn't working when creating the drawing so I created these tests to help me figure it out. Watching the logs, nothing gets inserted into the db when creating but it does on update. Thanks though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment