impressionist/spec/controllers/widgets_controller_spec.rb

104 lines
2.8 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe WidgetsController do
before do
@widget = Widget.find(1)
allow(Widget).to receive(:find).and_return(@widget)
end
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
end
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
end
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
end
context "impressionist unique options" do
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
end
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
get :show, params: { id: 2 }
expect(Impression.all.size).to eq 13
get :index
expect(Impression.all.size).to eq 14
end
end
2015-04-21 10:21:47 +00:00
context "Impresionist unique params options" do
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
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
end