commit
69b01ca270
|
@ -41,10 +41,7 @@ module ImpressionistController
|
||||||
private
|
private
|
||||||
|
|
||||||
def bypass
|
def bypass
|
||||||
Impressionist::Bots::WILD_CARDS.each do |wild_card|
|
Impressionist::Bots.bot?(request.user_agent)
|
||||||
return true if request.user_agent and request.user_agent.downcase.include? wild_card
|
|
||||||
end
|
|
||||||
Impressionist::Bots::LIST.include? request.user_agent
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def unique_instance?(impressionable, unique_opts)
|
def unique_instance?(impressionable, unique_opts)
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
module Impressionist
|
module Impressionist
|
||||||
module Bots
|
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"]
|
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)",
|
LIST = ["<a href='http://www.unchaos.com/'> UnChaos </a> From Chaos To Order Hybrid Web Search Engine.(vadim_gonchar@unchaos.com)",
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue