-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Problem:
I would like to be able to render partials with test track flags in them in view specs.
Details:
With devise, you can use their controller helpers in your view specs like:
RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, type: /controller|view/
endThis gives you access to their global setters and getters for user authentication. Thus if your view requires current_user you can set it up in your test.
Like devise, Test track also relies on methods that are globally accessible in rails rendering pipeline.
Work around
We have a work around where we monkey patch the test controller like this:
RSpec.configure do |config|
config.before(:suite) do
class ActionView::TestCase::TestController
include TestTrack::Controller
self.test_track_identity = :current_user # user, manager, ...
end
end
endProposed solution
I think it would be helpful if the test_track_rails_client were to expose a some sort of test helper module for this purpose. That way we could write something like:
RSpec.configure do |config|
config.include TestTrack::Test::ViewHelpers, type: :view
endOne small hitch is that the authorized user is currently configured at the controller level (self.test_track_identity). Devise doesn't have this problem because the define their "default scope" in an initializer:
Devise.setup do |config|
config.default_scope = :user
endA couple of ways we could handle this:
- Define a fake
test_track_visitorso that you can use the existing test helperstub_test_track_assignments ... - Move
self.test_track_identityinto an initializer. - Use a module builder like
RSpec.configure do |config|
config.include TestTrack::Test::ViewHelpers.for(:current_plan_manager), type: :view
end