What do these before filters do? Here''s an example:
Say I have a before_filter called "find_my_record" since my edit,
show,
delete, and update all call @user = User.find(params[:id])
before_filter :find_my_record, :only=>[:edit, :update, :show, :delete]
...
def edit
end
def delete
@user.destroy
end
protected
def find_my_record
@user = User.find(params[:id])
end
Then I have a functional test that looks like this:
def test_edit
get :edit, {:id=>1}
assert_response :success
assert_not_nil assigns(:user) # this should be filled in if the before
filter ran.
end
Basically, it all comes down to what your before_filter is actually doing.
If it redirects certain users away, write a test helper that does that.
def test_should_not_let_normal_users_delete
get :delete, {:id=>1} # note no session passed in
assert_response :redirected
assert_equal flash[:notice], "You do not have access to that
feature."
end
def test_should_let_admins_delete
get :delete, {:id=>1}, {:user => 1} # should get this from a fixture
instead of hard-coding
assert_response :redirected
assert_equal flash[:notice], "Record deleted successfully."
end
Does that help?
On 7/3/07, Mark
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> Hi,
>
> On certain controllers I have various before filters, is there anything
> I can put in my functional tests to make sure these before filters are
> run?
>
> Thanks,
> Mark
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---