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

Results by cookie #79

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Results by cookie #79

wants to merge 14 commits into from

Conversation

mkcode
Copy link
Contributor

@mkcode mkcode commented Oct 13, 2015

Hi @deski - Following up on our discussion in #78

This PR adds info from the peek cookie as discussed. It does not save Peek results unless the peek cookie is enabled. Always sets the cookie if peek is enabled.

In the case Peek was not enabled for a request, and is toggled on, Peek::Views with a data-defer-to are hidden and a refresh message is displayed:

screen shot 2015-10-12 at 8 41 31 pm

@dewski
Copy link
Member

dewski commented Oct 13, 2015

Thanks for opening this up! I'll take a look at this over the next few days.

end

test "does not save results if the peek cookie is not set" do
assert_not_called(Peek.adapter, :save) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be an assertion here that the cookie isn't set.

@dewski
Copy link
Member

dewski commented Oct 31, 2015

Thanks for being patient with me, I gave this a round of review. Let me know what you think.

@dewski dewski mentioned this pull request Oct 31, 2015
@mkcode
Copy link
Contributor Author

mkcode commented Oct 31, 2015

Great feedback. I'll fix this up.

@mkcode
Copy link
Contributor Author

mkcode commented Nov 2, 2015

Hi @dewski - I updated this branch according to your feedback.

I changed the the name of the cookie test from peek_enabled to peek_bar_visible: https://github.com/peek/peek/pull/79/files#diff-5fa9351cd8e19ee995f9f3c600861393R14 in response to this comment: #79 (comment). We can't reuse peek_enabled for this, because it is in a global context, while the payload flag is per request. peek_bar_visible is a better name for this now, but that can change if you like.

This test could be better: https://github.com/peek/peek/pull/79/files#diff-d89c7ee11ab586df930a3fb679d46386R10. It is redundant with the other tests now and is actually testing if the request is saved. Ideally, this would be testing that Peek._request_id is set, but I could not figure out how to test for this without mocking, because it is cleared after the request. Deleting that test works for me.

@dewski
Copy link
Member

dewski commented Nov 2, 2015

We can't reuse peek_enabled for this, because it is in a global context, while the payload flag is per request. peek_bar_visible is a better name for this now, but that can change if you like.

Could you clarify what you mentioned here? I'd like to have peek_enabled? be the one source for determining if the bar is to be displayed and tracked. If it's disabled it won't render the view and after the request it won't save the payload. Since both methods are in the same controller they should be able to call one another.

end

test "the request id is set" do
test "the request id is set when the peek cookie is set" do
assert_empty Peek.adapter.requests
get '/'
assert_not_empty Peek.adapter.requests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the test case changed here at all, just need to update the test body:

assert_empty Peek.request_id
get '/'
refute_empty Peek.request_id

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! Will update this.

@mkcode
Copy link
Contributor Author

mkcode commented Nov 2, 2015

Could you clarify what you mentioned here?

Sure. peek_enabled is meant to be overridden in descendant controllers. From the readme:

class ApplicationController < ActionController::Base
  def peek_enabled?
    current_user.staff?
  end
end

If we were to reuse peek_enabled, users would need to add a test for the cookie in their peek_enabled? in order to get the benefits of this PR. I see peek_enabled as the place to lock down which users should have access to peek.

Perhaps this is the behavior you would like, which would make this behavior opt-in and we should add this info to the README. It was my intention to turn this behavior on by default, because its zero-cognitive-load on the user and I cannot think of a case where a user would need the results when the bar is not visible.

Either way works!

@mkcode
Copy link
Contributor Author

mkcode commented Nov 2, 2015

peek_enabled? would need to look like this if we were to reuse it:

class ApplicationController < ActionController::Base
  def peek_enabled?
    return false unless peek_bar_visible?
    current_user.staff?
  end
end

@mkcode
Copy link
Contributor Author

mkcode commented Nov 23, 2015

Hi @dewski - Hoping we can resolve this soon. What are your thoughts on #79 (comment) ?

@@ -68,4 +77,5 @@ do ($ = jQuery) ->

$ ->
if peekEnabled()
setPeekEnabledCookie(true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't set the peek=true cookie for every request as it will ignore the user's preference if they've set it to false.

@@ -20,7 +20,10 @@ class Railtie < ::Rails::Engine

initializer 'peek.persist_request_data' do
ActiveSupport::Notifications.subscribe('process_action.action_controller') do
Peek.adapter.save
|_, _, _, _, payload|
if payload[:peek_bar_visible]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update this to check if payload[:peek_enabled].

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

Successfully merging this pull request may close these issues.

None yet

2 participants