Module: SimpleCrud::RSpec::Helpers::Requests
- Included in:
- SimpleCrud::RSpec::Helpers
- Defined in:
- lib/simple_crud/rspec/helpers/requests.rb
Overview
Request params and format helpers shared by every action example.
Instance Method Summary collapse
-
#body_params(attrs) ⇒ Object
Wraps a request body under the model's strong-params key when params_key is configured (nested strong params), else passes it flat.
-
#record_param(action, record, not_found: false) ⇒ Object
The params that identify a record for the given action, using the configured finder_key when the action has a custom finder.
- #request_format(action) ⇒ Object
-
#route_params ⇒ Object
Extra params (e.g. a parent slug) added to every request, for nested resources like /projects/:project_slug/tasks.
-
#unprocessable_status ⇒ Object
:unprocessable_entity was renamed :unprocessable_content in Rack 3.1.
- #with_route_params(attrs) ⇒ Object
Instance Method Details
#body_params(attrs) ⇒ Object
Wraps a request body under the model's strong-params key when params_key is configured (nested strong params), else passes it flat.
38 39 40 41 |
# File 'lib/simple_crud/rspec/helpers/requests.rb', line 38 def body_params(attrs) key = params_key key ? { key => attrs } : attrs end |
#record_param(action, record, not_found: false) ⇒ Object
The params that identify a record for the given action, using the configured finder_key when the action has a custom finder.
30 31 32 33 34 |
# File 'lib/simple_crud/rspec/helpers/requests.rb', line 30 def record_param(action, record, not_found: false) key = check_finder(action) ? finder_key : :id value = not_found ? "nonexistent-#{key}" : record.public_send(key) { key => value } end |
#request_format(action) ⇒ Object
14 15 16 |
# File 'lib/simple_crud/rspec/helpers/requests.rb', line 14 def request_format(action) check_html(action) ? :html : :json end |
#route_params ⇒ Object
Extra params (e.g. a parent slug) added to every request, for nested resources like /projects/:project_slug/tasks.
20 21 22 |
# File 'lib/simple_crud/rspec/helpers/requests.rb', line 20 def route_params resolve(setting(:route_params)) end |
#unprocessable_status ⇒ Object
:unprocessable_entity was renamed :unprocessable_content in Rack 3.1. Resolve the current Rack's canonical symbol for 422.
10 11 12 |
# File 'lib/simple_crud/rspec/helpers/requests.rb', line 10 def unprocessable_status Rack::Utils::SYMBOL_TO_STATUS_CODE.invert[422] end |
#with_route_params(attrs) ⇒ Object
24 25 26 |
# File 'lib/simple_crud/rspec/helpers/requests.rb', line 24 def with_route_params(attrs) route_params.merge(attrs) end |