2013-07-06 19:20:35 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe WidgetsController do
|
2020-07-20 13:35:41 +00:00
|
|
|
before do
|
2013-07-06 19:20:35 +00:00
|
|
|
@widget = Widget.find(1)
|
2020-07-20 13:35:41 +00:00
|
|
|
allow(Widget).to receive(:find).and_return(@widget)
|
2013-07-06 19:20:35 +00:00
|
|
|
end
|
|
|
|
|
2020-07-20 13:35:41 +00:00
|
|
|
it "logs impression at the per action level" do
|
|
|
|
get :show, params: { id: 1 }
|
|
|
|
expect(Impression.all.size).to eq 12
|
|
|
|
|
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(Impression.all.size).to eq 13
|
|
|
|
|
|
|
|
get :new
|
|
|
|
|
|
|
|
expect(Impression.all.size).to eq 13
|
2013-07-06 19:20:35 +00:00
|
|
|
end
|
|
|
|
|
2020-07-20 13:35:41 +00:00
|
|
|
it "does not log impression when user-agent is in wildcard list" do
|
|
|
|
request.env['HTTP_USER_AGENT'] = 'somebot'
|
|
|
|
|
|
|
|
get :show, params: { id: 1 }
|
|
|
|
expect(Impression.all.size).to eq 11
|
2013-07-06 19:20:35 +00:00
|
|
|
end
|
|
|
|
|
2020-07-20 13:35:41 +00:00
|
|
|
it "does not log impression when user-agent is in the bot list" do
|
|
|
|
request.env['HTTP_USER_AGENT'] = 'Acoon Robot v1.50.001'
|
|
|
|
|
|
|
|
get :show, params: { id: 1 }
|
|
|
|
expect(Impression.all.size).to eq 11
|
2013-07-06 19:20:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "impressionist unique options" do
|
2020-07-20 13:35:41 +00:00
|
|
|
it "logs unique impressions at the per action level" do
|
|
|
|
get :show, params: { id: 1 }
|
|
|
|
expect(Impression.all.size).to eq 12
|
|
|
|
get :show, params: { id: 2 }
|
|
|
|
expect(Impression.all.size).to eq 13
|
|
|
|
get :show, params: { id: 2 }
|
|
|
|
expect(Impression.all.size).to eq 13
|
|
|
|
get :index
|
|
|
|
expect(Impression.all.size).to eq 14
|
2013-07-06 19:20:35 +00:00
|
|
|
end
|
|
|
|
|
2020-07-20 13:35:41 +00:00
|
|
|
it "logs unique impressions only once per id" do
|
|
|
|
get :show, params: { id: 1 }
|
|
|
|
expect(Impression.all.size).to eq 12
|
|
|
|
get :show, params: { id: 2 }
|
|
|
|
expect(Impression.all.size).to eq 13
|
2013-07-06 19:20:35 +00:00
|
|
|
|
2020-07-20 13:35:41 +00:00
|
|
|
get :show, params: { id: 2 }
|
|
|
|
expect(Impression.all.size).to eq 13
|
2013-07-06 19:20:35 +00:00
|
|
|
|
2020-07-20 13:35:41 +00:00
|
|
|
get :index
|
|
|
|
expect(Impression.all.size).to eq 14
|
2013-07-06 19:20:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-21 10:21:47 +00:00
|
|
|
context "Impresionist unique params options" do
|
2020-07-20 13:35:41 +00:00
|
|
|
it "logs unique impressions at the per action and params level" do
|
|
|
|
get :show, params: { id: 1 }
|
|
|
|
expect(Impression.all.size).to eq 12
|
|
|
|
|
|
|
|
get :show, params: { id: 2, checked: true }
|
|
|
|
expect(Impression.all.size).to eq 13
|
|
|
|
|
|
|
|
get :show, params: { id: 2, checked: false }
|
|
|
|
expect(Impression.all.size).to eq 14
|
|
|
|
|
|
|
|
get :index
|
|
|
|
expect(Impression.all.size).to eq 15
|
2015-04-21 10:21:47 +00:00
|
|
|
end
|
|
|
|
|
2020-07-20 13:35:41 +00:00
|
|
|
it "does not log impression for same params and same id" do
|
|
|
|
get :show, params: { id: 1 }
|
|
|
|
expect(Impression.all.size).to eq 12
|
|
|
|
|
|
|
|
get :show, params: { id: 1 }
|
|
|
|
expect(Impression.all.size).to eq 12
|
|
|
|
|
|
|
|
get :show, params: { id: 1, checked: true }
|
|
|
|
expect(Impression.all.size).to eq 13
|
|
|
|
|
|
|
|
get :show, params: { id: 1, checked: false }
|
|
|
|
expect(Impression.all.size).to eq 14
|
|
|
|
|
|
|
|
get :show, params: { id: 1, checked: true }
|
|
|
|
expect(Impression.all.size).to eq 14
|
|
|
|
|
|
|
|
get :show, params: { id: 1, checked: false }
|
|
|
|
expect(Impression.all.size).to eq 14
|
|
|
|
|
|
|
|
get :show, params: { id: 1 }
|
|
|
|
expect(Impression.all.size).to eq 14
|
|
|
|
|
|
|
|
get :show, params: { id: 2 }
|
|
|
|
expect(Impression.all.size).to eq 15
|
2015-04-21 10:21:47 +00:00
|
|
|
end
|
|
|
|
end
|
2013-07-06 19:20:35 +00:00
|
|
|
end
|