Add extract controller logic for bypassing impression to bot? method

This commit is contained in:
Ross Kaffenberger 2012-03-20 16:57:20 -04:00
parent 594889a3db
commit 3a64d4b9ab
3 changed files with 34 additions and 4 deletions

View File

@ -41,10 +41,7 @@ module ImpressionistController
private
def bypass
Impressionist::Bots::WILD_CARDS.each do |wild_card|
return true if request.user_agent and request.user_agent.downcase.include? wild_card
end
Impressionist::Bots::LIST.include? request.user_agent
Impressionist::Bots.bot?(request.user_agent)
end
def unique_instance?(impressionable, unique_opts)

View File

@ -1,5 +1,11 @@
module Impressionist
module Bots
def self.bot?(user_agent = nil)
return false if user_agent.nil?
WILD_CARDS.any? { |wc| user_agent.downcase.include?(wc) } || LIST.include?(user_agent)
end
WILD_CARDS = ["bot","yahoo","slurp","google","msn","crawler"]
LIST = ["<a href='http://www.unchaos.com/'> UnChaos </a> From Chaos To Order Hybrid Web Search Engine.(vadim_gonchar@unchaos.com)",

View File

@ -0,0 +1,27 @@
require 'spec_helper'
describe Impressionist::Bots do
describe "self.bot?" do
it "is true if user_agent is matches wild card" do
Impressionist::Bots.bot?("google.com bot").should be_true
end
it "is true if user_agent is on bot list" do
Impressionist::Bots.bot?("A-Online Search").should be_true
end
it "is false if user_agent is blank" do
Impressionist::Bots.bot?("").should be_false
Impressionist::Bots.bot?(nil).should be_false
end
it "is false if user_agent is safe" do
Impressionist::Bots.bot?('127.0.0.1').should be_false
end
it "is false if user_agent not given" do
Impressionist::Bots.bot?.should be_false
end
end
end