On Mon, Sep 8, 2008 at 7:49 PM, Eric Harris-Braun <[EMAIL PROTECTED]> wrote:
> Hi folks,
>
> I'm hoping for a bit of help on best-practices for skipping a
> before_filter when running a particular step. Specifically the
> authentication filter. What happens is that the post (see code below)
> returns a redirect response to the login page triggered by the of my
> authentication filter, rather than the contents of what I'd like to be
> testing.
>
> How do people handle temporarily turning of this kind of thing that's
> not relevant to the test? Temporarily I've just put an unless RAILS_ENV
> == 'test' after it, but obviouly that won't work for the specs that
> actually test that before filter!
Hi Eric,
Story Runner and Cucumber both hook into rails through
ActionController::Integration::Session which, as far as I know, offers
no hooks the likes of which you are looking for.
The get, post, put and delete methods are not the same as those in
rails functional tests or rspec controller specs because they do not
target a specific controller - they actually go through routing - so
there is no way to get a handle on the controller on which you want to
bypass the filter.
For me, this is as it should be. The idea behind automating scenarios
is to run through the stack, including routing. Even when we bypass
routing and controllers and go directly to models, we're still going
from the outside of the model layer - not to its internals.
That said, if you still want to do this and control when it happens, I
*think* you could do something like this:
class ApplicationController
def self.skipping_authentication
alias_method :orig_authenticate, :authenticate
def authenticate; true; end
yield
alias_method :authenticate, :orig_authenticate
end
end
ApplicationController.skipping_authentication do
post "/entry", :record => @params
end
I have not tested it in a story. It might not work. But it might :)
I did try the concept out outside of rails/stories/etc:
http://gist.github.com/9597
That'll output this:
BAR
bar
HTH,
David
> Thanks for any help!
>
> -Eric
>
> Given "$field in new entry is $field_value" do |field,field_value|
> @params ||= {}
> @params[field.intern] = field_value
> end
>
> When "submitting the new entry" do
> post "/entry", :record => @params
> end
>
> Then "should include confirmation: $message" do |message|
> response.should have_text(/#{message}/)
> end
>
> --
> He who is content with his lot probably has a lot.
> _______________________________________________
> rspec-users mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users