module RailsStuff::RSpecHelpers::Groups::Request::ClassMethods
Public Instance Methods
init_session()
click to toggle source
Perform simple request to initialize session. Useful for `change` matchers.
# File lib/rails_stuff/rspec_helpers/groups/request.rb, line 35 def init_session before do path = defined?(init_session_path) ? init_session_path : '/' get(path) end end
set_referer()
click to toggle source
Adds `referer`, `referer_path` and `headers` with `let`. Requires `root_url`
Calls superclass method
# File lib/rails_stuff/rspec_helpers/groups/request.rb, line 24 def set_referer let(:referer) { root_url.sub(%r{/$}, referer_path) } let(:referer_path) { '/test_referer' } let(:headers) do headers = {Referer: referer} defined?(super) ? super().merge(headers) : headers end end
with_csrf_protection!()
click to toggle source
# File lib/rails_stuff/rspec_helpers/groups/request.rb, line 42 def with_csrf_protection! around do |ex| begin old = ActionController::Base.allow_forgery_protection ActionController::Base.allow_forgery_protection = true ex.run ensure ActionController::Base.allow_forgery_protection = old end end let(:csrf_response) do path = defined?(csrf_response_path) ? csrf_response_path : '/' get(path) && response.body end let(:csrf_param) { csrf_response.match(/meta name="csrf-param" content="([^"]*)"/)[1] } let(:csrf_token) { csrf_response.match(/<meta name="csrf-token" content="([^"]*)"/)[1] } end