tracks debate visits from the controller

This commit is contained in:
rgarcia
2015-09-09 14:39:31 +02:00
parent cdc914de0d
commit e555126331
3 changed files with 26 additions and 3 deletions

View File

@@ -13,6 +13,7 @@ class DebatesController < ApplicationController
@debates = @debates.page(params[:page]).for_render.send("sort_by_#{@order}")
@tag_cloud = Debate.tag_counts.order(taggings_count: :desc, name: :asc).limit(20)
set_debate_votes(@debates)
ahoy.track_visit
end
def show
@@ -23,6 +24,7 @@ class DebatesController < ApplicationController
@all_visible_comments = @root_comments + @comments
set_comment_flags(@all_visible_comments)
ahoy.track_visit
end
def new

View File

@@ -34,9 +34,6 @@ class Debate < ActiveRecord::Base
scope :sort_by_most_commented, -> { order(comments_count: :desc) }
scope :sort_by_random, -> { order("RANDOM()") }
# Ahoy setup
visitable # Ahoy will automatically assign visit_id on create
def likes
cached_votes_up
end

View File

@@ -11,6 +11,30 @@ describe DebatesController do
SimpleCaptcha.always_pass = @original_captcha_pass_value
end
describe 'GET show' do
it 'should create an ahoy visit' do
debate = create(:debate)
sign_in create(:user)
get :show, id: debate.id
expect(Visit.count).to eq 1
expect(Visit.first.landing_page).to eq debate_url(debate)
end
end
describe 'GET index' do
it 'should create an ahoy visit' do
debate = create(:debate)
sign_in create(:user)
get :index
expect(Visit.count).to eq 1
expect(Visit.first.landing_page).to eq debates_url
end
end
describe 'POST create' do
it 'should create an ahoy event' do