forest-rails
forest-rails copied to clipboard
Rspec on Smart Actions
Expected behavior
I should be able to write request specs on my Forest Smart Actions.
Actual behavior
Running into issues with ForestLiana Authentication I guess...
Failure Logs
Context
- Package Version: 2.8.0
- Rails Version: 4.2.10
- Database Dialect: PG
- Database Version: PostgreSQL 9.6.6
Hi @lucasgerard, can you detail your request with anything that could give more context (pieces of code for example)?
Thank you.
+1
I know it's not the best practice, but my work around I current have is having all my forest controllers inherit from a base controller, and then in that base controller I have
module Forest
class BaseController < ForestLiana::SmartActionsController
# ...
skip_before_action :reject_unauthorized_ip if Rails.env.test?
skip_before_action :smart_action_pre_perform_checks if Rails.env.test?
skip_before_action :authenticate_user_from_jwt if Rails.env.test?
# ...
end
end
and now I can test my controllers normally with rspec just making sure i pass the correct params needed to fulfill my actions.
@jordanell It's probably a bit safer to skip the actions in a before
hook in RSpec:
before do
allow_any_instance_of(Forest::CustomersController).to receive(:reject_unauthorized_ip)
allow_any_instance_of(Forest::CustomersController).to receive(:authenticate_user_from_jwt)
allow_any_instance_of(Forest::CustomersController).to receive(:check_permission_for_smart_route)
end
Then you don't need to change the behaviour of production code.