Module: RailsStuff::RSpecHelpers::Groups::Request::ClassMethods
- Defined in:
- lib/rails_stuff/rspec_helpers/groups/request.rb
Instance Method Summary collapse
-
#init_session ⇒ Object
Perform simple request to initialize session.
-
#set_referer ⇒ Object
Adds ‘referer`, `referer_path` and `headers` with `let`.
- #with_csrf_protection! ⇒ Object
Instance Method Details
#init_session ⇒ Object
Perform simple request to initialize session. Useful for ‘change` matchers.
35 36 37 38 39 40 |
# 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 ⇒ Object
Adds ‘referer`, `referer_path` and `headers` with `let`. Requires `root_url`
24 25 26 27 28 29 30 31 |
# 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! ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 |