FEATURE: Track user profile views.

This commit is contained in:
Guo Xiang Tan
2015-09-14 15:51:17 +08:00
parent f41bcafe8d
commit 7acc93b2a0
10 changed files with 129 additions and 5 deletions

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe UsersController do
describe '.show' do
let!(:user) { log_in }
let(:user) { log_in }
it 'returns success' do
xhr :get, :show, username: user.username, format: :json
@ -31,6 +31,30 @@ describe UsersController do
expect(response).to be_forbidden
end
describe "user profile views" do
let(:other_user) { Fabricate(:user) }
it "should track a user profile view for a signed in user" do
UserProfileView.expects(:add).with(other_user.user_profile.id, request.remote_ip, user.id)
xhr :get, :show, username: other_user.username
end
it "should not track a user profile view for a user viewing his own profile" do
UserProfileView.expects(:add).never
xhr :get, :show, username: user.username
end
it "should track a user profile view for an anon user" do
UserProfileView.expects(:add).with(other_user.user_profile.id, request.remote_ip, nil)
xhr :get, :show, username: other_user.username
end
it "skips tracking" do
UserProfileView.expects(:add).never
xhr :get, :show, { username: user.username, skip_track_visit: true }
end
end
context "fetching a user by external_id" do
before { user.create_single_sign_on_record(external_id: '997', last_payload: '') }