Issues with Tests

Test Code:

def setup
@controller = SettingsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new

@request.session[:user_id] = User.find(1)
@request.session[:time_of_last_action] = (Time.now - 30*60)
end

def test_turn_wysiwyg_off
post ‘index’, {:settings => {:wysiwyg => 0}}
assert_equal(nil, session[:user_id].settings)
assert_equal(false, session[:user_id].settings.wysiwyg,
‘Session was not updated’)
assert_equal(false, UserSetting.find(1).wysiwyg, ‘Database was not
updated’)

assert_equal ‘Your settings have been successfully updated’,
flash[:notice]
end

=========================================================================

Action Code:

def index
if request.post?
if (session[:user_id].settings.update_attributes(params[:settings]))
if(session[:user_id].settings.save)
flash[:notice] = ‘Your settings have been successfully updated’
else
flash[:notice] = ‘Your settings could not be updated’
end
end
end
@settings = session[:user_id].settings
end

============================================================================

The action passes when tested manually.
It appears as though I don’t have access to any changes to the session

Does any one know how to make the magic happen?

Keynan P. wrote:

end
else
It appears as though I don’t have access to any changes to the session

Does any one know how to make the magic happen?

You haven’t told us which assert you think is supposed to be failing and
why.

If you want to track the changes to the session object, you can just
print out its contents in your code and see if things are getting set as
they should be.


Michael W.

Keynan P. wrote:

the purpose of the first assert is to print the session in the fail
message

all the assertions fail.

the assigns hash seems to be working but information from session and
flash does not change with the request

In Ruby false != 0


Michael W.

the purpose of the first assert is to print the session in the fail
message

all the assertions fail.

the assigns hash seems to be working but information from session and
flash does not change with the request

actually the problem was a security filter was interupting.

p.s. in rails checkboxes 0 is submited and false is stored in the model
attribute