Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/controllers/faqs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class FaqsController < ApplicationController
include AhoyTracking
skip_before_action :authenticate_user!, only: [ :index, :show ]
before_action :set_faq, only: [ :show, :edit, :update, :destroy ]

Expand All @@ -8,10 +9,12 @@ def index
@faqs = faqs.search_by_params(params.to_unsafe_h.slice("query", "published"))
.by_position
.page(params[:page])
track_index_intent(Faq, @faqs, params)
end

def show
authorize! @faq
track_view(@faq)
end

def new
Expand Down
32 changes: 32 additions & 0 deletions spec/requests/faqs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,38 @@
let!(:unpublished_faq) { create(:faq, question: "Unpublished FAQ", answer: "Unpublished FAQ Body") }
let!(:public_faq) { create(:faq, :published, question: "Public FAQ", answer: "Public FAQ Body", publicly_visible: true) }

describe "Ahoy tracking" do
before { sign_in admin }

describe "GET /index" do
it "tracks a search event when a query param is present" do
expect(Analytics::AhoyTracker).to receive(:track_index_intent).with(
anything, Faq, params: anything, result_count: anything
)

get faqs_path, params: { query: "Published" }
end

it "calls track_index_intent even without search params" do
expect(Analytics::AhoyTracker).to receive(:track_index_intent).with(
anything, Faq, params: anything, result_count: anything
)

get faqs_path
end
end

describe "GET /show" do
it "tracks a view event" do
expect(Analytics::AhoyTracker).to receive(:track).with(
anything, :view, published_faq
)

get faq_path(published_faq)
end
end
end

describe "GET /index" do
context "as an admin" do
before { sign_in admin }
Expand Down