Sterling Rose Design Blog
assert_include Workaround
Authored by Dana Jones
May 21, 2009 13:51
7 Comments
Tags: testing Rails
Authored by Dana Jones
May 21, 2009 13:51
7 Comments
Tags: testing Rails
I’m not sure if there used to be an assert_include method or not (I’ve seen some references to it, but can’t find it anywhere in the Rails API), but I found a workaround.
I have a Color model, and I want the :index action to only show those colors whose deleted value is set to false (it’s more or less what the acts_as_paranoid plugin did/does). My test for the :index action looks like this:
There may be other ways to do this (and I certainly wel...
I have a Color model, and I want the :index action to only show those colors whose deleted value is set to false (it’s more or less what the acts_as_paranoid plugin did/does). My test for the :index action looks like this:
test "should get only colors that are not deleted" do
first_color = Color.create(:name => 'Blue', :deleted => false)
second_color = Color.create(:name => 'Red', :deleted => true)
get :index
assert_response :success
assert_not_nil assigns(:colors)
assert_equal true, assigns(:colors).include?(first_color)
assert_equal false, assigns(:colors).include?(second_color)
endThere may be other ways to do this (and I certainly wel...

