Topic: assert assigns() not working

This one really has me scratching my head.  In a functional test, I'm trying to verify whether the variable @email_test_button_disabled was set to true or false.  I put verbose puts statements in my controller, and I positively verified it's being set by printing the assigns via assigns.keys.sort.each {|key| puts key}.  It's there!  Yet, assert assigns(:email_test_button_disabled) nor assert assigns['email_test_button_disabled'] detect it.  WTH!?  Ideas anyone?  It's annoying to run into some weird roadblock just about every day.  Hopefully I'll get over the hump soon.

thanks,
brian

BrewControl.com - Brewery and Brewpub management powered by RoR

Re: assert assigns() not working

Are you calling the assert after you call the controller action (get/post)? does the @email_test_button_disabled change at any point in the action? Does assigns(:email_test_button_disabled) return false or nil?

Please post the code as there may be something influencing this.

Railscasts - Free Ruby on Rails Screencasts

Re: assert assigns() not working

Here is my test function:

def test_index_3
  get :index, {}, { :company_id => 3, :user_id => 1 }
  assert_response :success
  assert_template 'index'
  assert assigns(:email_settings)
  assigns.keys.sort.each { |key| puts "'#{key}'" }
  assert assigns(:email_test_button_disabled)  <==  Says <false> is not true
  assert_false :email_test_button_disabled
  assert flash.empty?
end

The controller either sets it to true or false.

thanks,
brian

BrewControl.com - Brewery and Brewpub management powered by RoR

Re: assert assigns() not working

Can you post the controller action too?

Are you certain the @email_test_button_disabled is set to true in the controller? If it is "false" it will act as you are describing. If you are just trying to see if it is set or not, try this:

assert !assigns(:email_test_button_disabled).nil?

Railscasts - Free Ruby on Rails Screencasts

Re: assert assigns() not working

If it is "false" it will act as you are describing

(I don't think it should)  I tried the line of code that you posted, and it worked.  IMO, that is a bug in assigns().  The word assigns is not ambiguous.  I assigned a variable, and assigns() returned false.  Thanks, though.  1 more facet to put in my pocket...

brian

BrewControl.com - Brewery and Brewpub management powered by RoR

Re: assert assigns() not working

It's not a bug, it is just "assigns" behaves differently than what you expect. It doesn't return a true/false value, but the value of the instance variable. If you set "@foo = 'bar'" in the controller then "assigns(:foo)" would return "bar".

Railscasts - Free Ruby on Rails Screencasts

Re: assert assigns() not working

I fell into the twilight zone, and just made it back out.  Thanks for the help.

brian

Last edited by bkrahmer (2007-01-27 03:15:22)

BrewControl.com - Brewery and Brewpub management powered by RoR