Changeset 5335 for platform/tdiary/spec

Show
Ignore:
Timestamp:
01/23/08 15:04:01 (11 months ago)
Author:
hsbt
Message:

platform/tdiary/spec/spec_helper.rb: add CGIFake class, @conf.mobile_agent? and @conf.bot?.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • platform/tdiary/spec/spec_helper.rb

    r5312 r5335  
    3939        class Config 
    4040 
    41                 attr_accessor :index, :html_title 
     41                attr_accessor :index, :html_title, :cgi 
    4242 
    4343                def initialize 
     44                        @cgi = CGIFake.new 
    4445                        @options = {} 
    4546                        @options2 = {} 
    4647                        @index = './' 
    4748                        @html_title = '' 
     49 
     50                        bot = ["bot", "spider", "antenna", "crawler", "moget", "slurp"] 
     51                        bot += @options['bot'] || [] 
     52                        @bot = Regexp::new( "(#{bot.uniq.join( '|' )})", true ) 
    4853                end 
    4954 
     
    6974                        end 
    7075                end 
     76 
     77                def mobile_agent? 
     78                        @cgi.mobile_agent? 
     79                end 
     80 
     81                def bot? 
     82                        @bot =~ @cgi.user_agent 
     83                end 
     84 
     85                def iphone? 
     86                        @cgi.iphone? 
     87                end 
     88                alias ipod? iphone? 
    7189        end 
    7290end 
    7391 
    74 def fake_plugin( name_sym, base=nil, &block ) 
     92class CGIFake 
     93        attr_accessor :user_agent 
     94         
     95        def initialize 
     96                @user_agent = "" 
     97        end 
     98         
     99        def mobile_agent? 
     100                self.user_agent =~ %r[(DoCoMo|J-PHONE|Vodafone|MOT-|UP\.Browser|DDIPOCKET|ASTEL|PDXGW|Palmscape|Xiino|sharp pda browser|Windows CE|L-mode|WILLCOM|SoftBank)]i 
     101        end 
     102 
     103        def iphone? 
     104                self.user_agent =~ /iPhone|iPod/ 
     105        end 
     106end 
     107 
     108 
     109def fake_plugin( name_sym, cgi=nil, base=nil, &block ) 
    75110        plugin = PluginFake.new 
    76111        yield plugin if block_given?