Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add view spec helpers (similar to devise) #107

Open
RowanMcDonald opened this issue May 19, 2020 · 0 comments
Open

Add view spec helpers (similar to devise) #107

RowanMcDonald opened this issue May 19, 2020 · 0 comments

Comments

@RowanMcDonald
Copy link
Contributor

RowanMcDonald commented May 19, 2020

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/
end

This 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
end

Proposed 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
end

One 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
end

A couple of ways we could handle this:

  1. Define a fake test_track_visitor so that you can use the existing test helper stub_test_track_assignments ...
  2. Move self.test_track_identity into an initializer.
  3. Use a module builder like
RSpec.configure do |config|
  config.include TestTrack::Test::ViewHelpers.for(:current_plan_manager), type: :view
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant