From 1023636ed3e3c0ada96e3b845b1c456cf9f4e5f1 Mon Sep 17 00:00:00 2001 From: Shenouda Bertel Date: Mon, 31 May 2010 22:21:25 +0300 Subject: [PATCH] Initial import --- .gitignore | 2 + MIT-LICENSE | 20 ++++ README | 27 +++++ Rakefile | 51 +++++++++ init.rb | 4 + install.rb | 6 + lib/tasks/wurfl_store_tasks.rake | 23 ++++ lib/wurfl_store.rb | 30 +++++ lib/wurfl_store/cache_initializer.rb | 47 ++++++++ lib/wurfl_store/filter.rb | 12 ++ lib/wurfl_store/view.rb | 24 ++++ lib/wurfl_store/wurfl/wurfl_load.rb | 121 ++++++++++++++++++++ lib/wurfl_store/wurfl/wurflhandset.rb | 154 ++++++++++++++++++++++++++ nbproject/private/config.properties | 0 nbproject/private/private.properties | 1 + nbproject/private/rake-d.txt | 14 +++ nbproject/project.properties | 7 ++ nbproject/project.xml | 16 +++ spec/spec_helper.rb | 9 ++ spec/wurfl_store_spec.rb | 31 ++++++ uninstall.rb | 1 + 21 files changed, 600 insertions(+) create mode 100755 .gitignore create mode 100755 MIT-LICENSE create mode 100755 README create mode 100755 Rakefile create mode 100755 init.rb create mode 100755 install.rb create mode 100755 lib/tasks/wurfl_store_tasks.rake create mode 100755 lib/wurfl_store.rb create mode 100755 lib/wurfl_store/cache_initializer.rb create mode 100755 lib/wurfl_store/filter.rb create mode 100755 lib/wurfl_store/view.rb create mode 100755 lib/wurfl_store/wurfl/wurfl_load.rb create mode 100755 lib/wurfl_store/wurfl/wurflhandset.rb create mode 100644 nbproject/private/config.properties create mode 100644 nbproject/private/private.properties create mode 100644 nbproject/private/rake-d.txt create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100755 spec/spec_helper.rb create mode 100755 spec/wurfl_store_spec.rb create mode 100755 uninstall.rb diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..c44c3e3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +pkg/* +nbproject/*.gitignore diff --git a/MIT-LICENSE b/MIT-LICENSE new file mode 100755 index 0000000..b47e962 --- /dev/null +++ b/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2010 mobiThought + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README b/README new file mode 100755 index 0000000..eb4f059 --- /dev/null +++ b/README @@ -0,0 +1,27 @@ +WurflStore : Wurfl Redis Store +============ + +Wurfl Redis Store + +Installation +============ + +Install the gem from gemcutter: + + sudo gem install wurfl_store + +Special Thanks +============== + +WurflStore was inspired and based on wurfl_store . Many thanks to the authors and contributors. + + +Feedback +======== + +Send Feedback and questions to: sbertel at mobithought.com + + +More will Coming Soon, Wait for MobiThought + +Copyright (c) 2010 Shenouda Bertel, MobiThought, released under the MIT license diff --git a/Rakefile b/Rakefile new file mode 100755 index 0000000..3073918 --- /dev/null +++ b/Rakefile @@ -0,0 +1,51 @@ +require 'rubygems' +require 'rake' +require 'rake/testtask' +require 'rake/rdoctask' +require 'rake/gempackagetask' + +desc 'Default: run unit tests.' +task :default => :test + +desc 'Test the wurfl_store plugin.' +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.libs << 'test' + t.pattern = 'test/**/*_test.rb' + t.verbose = true +end + +desc 'Generate documentation for the wurfl_store gem.' +Rake::RDocTask.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'WurflStore' + rdoc.options << '--line-numbers' << '--inline-source' + rdoc.rdoc_files.include('README') + rdoc.rdoc_files.include('lib/**/*.rb') +end + +PKG_FILES = FileList[ '[a-zA-Z]*', 'generators/**/*', 'lib/**/*', 'test/**/*' ] + +spec = Gem::Specification.new do |s| + s.name = "wurfl_store" + s.version = "0.1.0" + s.authors = ["Shenouda Bertel"] + s.description = "Wurfl Redis Store" + s.email = "sbertel@mobithought.com" + s.homepage = "http://mobithought.com/" + s.files = PKG_FILES.to_a + s.require_paths = ["lib"] + s.rubyforge_project = "wurfl_store" + s.rubygems_version = "1.3.6" + s.summary = "Wurfl Redis Store" + s.platform = Gem::Platform::RUBY + s.add_dependency('redis-store') + s.add_dependency('nokogiri') + s.has_rdoc = false + s.extra_rdoc_files = ["README"] +end + +desc 'Turn this plugin into a gem.' +Rake::GemPackageTask.new(spec) do |pkg| + pkg.gem_spec = spec +end diff --git a/init.rb b/init.rb new file mode 100755 index 0000000..56cdac1 --- /dev/null +++ b/init.rb @@ -0,0 +1,4 @@ +require 'wurfl_store' +ActionController::Base.send(:include, WurflStore::Filter) +ActionView::Base.send(:include, WurflStore::View) +WurflStore.init \ No newline at end of file diff --git a/install.rb b/install.rb new file mode 100755 index 0000000..c768495 --- /dev/null +++ b/install.rb @@ -0,0 +1,6 @@ +# Create necessary directory for wurfl.xml/pstore if it doesn't already exist. +puts 'Creating wurfl directory at' + Rails.root.join('tmp', 'wurfl') +FileUtils.mkdir_p(Rails.root.join('tmp', 'wurfl')) + +FileUtils.cd(Rails.root) +'rake wurfl:update' \ No newline at end of file diff --git a/lib/tasks/wurfl_store_tasks.rake b/lib/tasks/wurfl_store_tasks.rake new file mode 100755 index 0000000..0b5e2a7 --- /dev/null +++ b/lib/tasks/wurfl_store_tasks.rake @@ -0,0 +1,23 @@ +namespace :wurfl do + desc "Download the latest wurfl.xml.gz and unpack it." + task :update do + require Pathname.new(File.dirname(__FILE__)).join('..', 'wurfl_store', 'wurfl', 'wurfl_load') + + FileUtils.mkdir_p(Rails.root.join('tmp', 'wurfl')) + FileUtils.cd(Rails.root.join('tmp', 'wurfl')) + + return_code = `wget -N -- http://downloads.sourceforge.net/project/wurfl/WURFL/latest/wurfl-latest.xml.gz`.to_i + raise 'Failed to download wurfl-latest.xml.gz' unless return_code == 0 + + return_code = `gunzip -c wurfl-latest.xml.gz > wurfl.xml`.to_i + raise 'Failed to unzip wurfl-latest.xml.gz' unless return_code == 0 + end + + desc "Load the latest XML file into the cache." + task :cache_update do + require Pathname.new(File.dirname(__FILE__)).join('..', 'wurfl_store', 'cache_initializer') + require Rails.root.join('config', 'environment.rb') + puts 'This can take a minute or two. Be patient.' + WurflStore::CacheInitializer.refresh_cache + end +end diff --git a/lib/wurfl_store.rb b/lib/wurfl_store.rb new file mode 100755 index 0000000..bbbfc2e --- /dev/null +++ b/lib/wurfl_store.rb @@ -0,0 +1,30 @@ +require 'wurfl_store/cache_initializer' +require 'wurfl_store/view' +require 'wurfl_store/filter' +require 'rubygems' +require 'activesupport' +require 'redis-store' + +module WurflStore + attr_accessor :cache + def self.cache + @cache + end + + def self.init + @cache = ActiveSupport::Cache.lookup_store(:redis_store) + # determine if the cache has been initialized with the wurfl + CacheInitializer.initialize_cache if WurflStore.cache.read('wurfl_initialized').nil? + end + + def self.get_handset(user_agent) + return nil if user_agent.nil? + CacheInitializer.cache_initialized? + user_agent.slice!(250..-1) + handset = @cache.read(user_agent.tr(' ', '')) + chopped_user_agent = user_agent.chop + return nil if chopped_user_agent.empty? + return self.get_handset(chopped_user_agent) if handset.nil? + return handset + end +end \ No newline at end of file diff --git a/lib/wurfl_store/cache_initializer.rb b/lib/wurfl_store/cache_initializer.rb new file mode 100755 index 0000000..42bcb8f --- /dev/null +++ b/lib/wurfl_store/cache_initializer.rb @@ -0,0 +1,47 @@ +require Pathname.new(File.dirname(__FILE__)).join('wurfl', 'wurfl_load') + +module WurflStore + module CacheInitializer + def self.load_wurfl + wurfl_loader = WurflLoader.new + path_to_wurfl = Rails.root.join('tmp', 'wurfl', 'wurfl.xml') + unless path_to_wurfl.exist? + puts 'Could not find wurfl.xml. Have you run rake wurfl:update yet?' + Process.exit + end + return wurfl_loader.load_wurfl(path_to_wurfl) + end + + def self.cache_initialized? + return true if WurflStore.cache.read('wurfl_initialized') + initialize_cache + loop do + break if WurflStore.cache.read('wurfl_initialized') + sleep(0.1) + end + return true + end + + def self.initialize_cache + # Prevent more than one process from trying to initialize the cache. + return unless WurflStore.cache.write('wurfl_initializing', true, :unless_exist => true) + + WurflStore.cache.write('wurfl_initialized', false) + # Proceed to initialize the cache. + xml_to_cache + WurflStore.cache.write('wurfl_initializing', false) + end + + def self.xml_to_cache + handsets, fallbacks = load_wurfl + handsets.each_value do |handset| + WurflStore.cache.write(handset.user_agent.tr(' ', ''), handset) + end + WurflStore.cache.write('wurfl_initialized', true) + end + + def self.refresh_cache + xml_to_cache + end + end +end diff --git a/lib/wurfl_store/filter.rb b/lib/wurfl_store/filter.rb new file mode 100755 index 0000000..e70c12e --- /dev/null +++ b/lib/wurfl_store/filter.rb @@ -0,0 +1,12 @@ +module WurflStore + module Filter + + def set_wurfl + return unless session[:handset_checked].nil? + handset = WurflStore.get_handset(request.headers['HTTP_USER_AGENT']) + session[:handset_agent] = handset.user_agent unless handset.nil? + session[:handset_checked] = true + end + + end +end \ No newline at end of file diff --git a/lib/wurfl_store/view.rb b/lib/wurfl_store/view.rb new file mode 100755 index 0000000..63da4b0 --- /dev/null +++ b/lib/wurfl_store/view.rb @@ -0,0 +1,24 @@ +module WurflStore + module View + + def handset + WurflStore.get_handset(session[:handset_agent]) + end + + def handset_capability(capability) + return nil if handset.nil? + capability = handset[capability] + return nil if capability.nil? + case capability.strip + when /^d+$/ + capability = capability.to_i + when /^true$/i + capability = true + when /^false$/i + capability = false + end + return capability + end + + end +end \ No newline at end of file diff --git a/lib/wurfl_store/wurfl/wurfl_load.rb b/lib/wurfl_store/wurfl/wurfl_load.rb new file mode 100755 index 0000000..8aeb89d --- /dev/null +++ b/lib/wurfl_store/wurfl/wurfl_load.rb @@ -0,0 +1,121 @@ +require Pathname.new(File.dirname(__FILE__)).join('wurflhandset') +require 'rubygems' +require 'nokogiri' + +# Modified to use nokogiri. GREATLY increased speed. +# $Id: wurflloader.rb,v 1.1 2003/11/23 12:26:05 zevblut Exp $ +# Authors: Zev Blut (zb@ubit.com) +# Copyright (c) 2003, Ubiquitous Business Technology (http://ubit.com) +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# +# * Neither the name of the WURFL nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +class WurflLoader + def initialize + @handsets = Hash::new + @fallbacks = Hash::new + end + + def load_wurfl(wurflfile) + file = File.new(wurflfile) + doc = Nokogiri::XML::Document.parse file + + # read counter + rcount = 0 + + # iterate over all of the devices in the file + doc.xpath("wurfl/devices/device").each do |element| + + rcount += 1 + hands = nil # the reference to the current handset + if element.attributes["id"].to_s == "generic" + # setup the generic Handset + element.attributes["user_agent"] = "generic" + if @handsets.key?("generic") then + hands = @handsets["generic"] + puts "Updating the generic handset at count #{rcount}" if @verbose + else + # the generic handset has not been created. Make it + hands = WurflHandset::new "generic","generic" + @handsets["generic"] = hands + @fallbacks["generic"] = Array::new + puts "Made the generic handset at count #{rcount}" if @verbose + end + + else + # Setup an actual handset + + # check if handset already exists. + wurflid = element.attributes["id"].to_s + if @handsets.key?(wurflid) + # Must have been created by someone who named it as a fallback earlier. + hands = @handsets[wurflid] + else + hands = WurflHandset::new "","" + end + hands.wurfl_id = wurflid + hands.user_agent = element.attributes["user_agent"].to_s + hands.user_agent = 'generic' if hands.user_agent.empty? + + # get the fallback and copy it's values into this handset's hashtable + fallb = element.attributes["fall_back"].to_s + + # for tracking of who has fallbacks + if !@fallbacks.key?(fallb) + @fallbacks[fallb] = Array::new + end + @fallbacks[fallb]<< hands.user_agent + + # Now set the handset to the proper fallback reference + if !@handsets.key?(fallb) + # We have a fallback that does not exist yet, create the reference. + @handsets[fallb] = WurflHandset::new "","" + end + hands.fallback = @handsets[fallb] + end + + # now copy this handset's specific capabilities into it's hashtable + element.xpath("./*/capability").each do |el2| + hands[el2.attributes["name"].to_s] = el2.attributes["value"].to_s + end + @handsets[hands.wurfl_id] = hands + + # Do some error checking + if hands.wurfl_id.nil? + puts "a handset with a nil id at #{rcount}" + elsif hands.user_agent.nil? + puts "a handset with a nil agent at #{rcount}" + end + end + return @handsets, @fallbacks + end + +end \ No newline at end of file diff --git a/lib/wurfl_store/wurfl/wurflhandset.rb b/lib/wurfl_store/wurfl/wurflhandset.rb new file mode 100755 index 0000000..be6ec08 --- /dev/null +++ b/lib/wurfl_store/wurfl/wurflhandset.rb @@ -0,0 +1,154 @@ +# Copyright (c) 2003, Ubiquitous Business Technology (http://ubit.com) +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# +# * Neither the name of the WURFL nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# $Id: wurflhandset.rb,v 1.1 2003/11/23 12:26:05 zevblut Exp $ +# Authors: Zev Blut (zb@ubit.com) + +=begin +A class that represents a handset based on information taken from the WURFL. +=end +class WurflHandset + + extend Enumerable + + attr_accessor :wurfl_id, :user_agent, :fallback + + # Constructor + # Parameters: + # wurfl_id: is the WURFL ID of the handset + # useragent: is the user agent of the handset + # fallback: is the fallback handset that this handset + # uses for missing details. + def initialize (wurfl_id,useragent,fallback=nil) + # A hash to hold keys and values specific to this handset + @capabilityhash = Hash::new + @wurfl_id = wurfl_id.to_s + @user_agent = useragent.to_s + @fallback = fallback + end + + # Hash accessor + # Parameters: + # key: the WURFL key whose value is desired + # Returns: + # The value of the key, nil if the handset does not have the key. + def [] (key) + # Check if the handset actually has the key + if @capabilityhash.key?(key) + return @capabilityhash[key] + else + # The handset does not so check if the fallback handset does + # Note: that this is actually a recursive call. + if @fallback != nil + return @fallback[key] + end + end + # if it gets this far then no one has the key + return nil + end + + # like the above accessor, but also to know who the value + # comes from + # Returns: + # the value and the id of the handset from which the value was obtained + def get_value_and_owner(key) + return @capabilityhash[key],@wurfl_id if @capabilityhash.key?(key) + return @fallback.get_value_and_owner(key) if @fallback != nil + return nil,nil + end + + # Setter, A method to set a key and value of the handset. + def []= (key,val) + @capabilityhash[key] = val.to_s + end + + # A Method to iterate over all of the keys and values that the handset has. + # Note: this will abstract the hash iterator to handle all the lower level + # calls for the fallback values. + def each + keys = self.keys + keys.each do |key| + # here is the magic that gives us the key and value of the handset + # all the way up to the fallbacks end. + # Call the pass block with the key and value passed + yield key, self[key] + end + end + + # A method to get all of the keys that the handset has. + def keys + # merge the unique keys of the handset and it's fallback + return @capabilityhash.keys | @fallback.keys if @fallback != nil + # no fallback so just return the handset's keys + return @capabilityhash.keys + end + + # A method to do a simple equality check against two handsets. + # Parameter: + # other: Is the another WurflHandset to check against. + # Returns: + # true if the two handsets are equal in all values. + # false if they are not exactly equal in values, id and user agent. + # Note: for a more detailed comparison, use the compare method. + def ==(other) + return false if other.nil? || other.class != WurflHandset + if (self.wurfl_id == other.wurfl_id) && (self.user_agent == other.user_agent) + other.each do |key,value| + return false if value != self[key] + end + return true + end + return false + end + + # A method to compare a handset's values against another handset. + # Parameters: + # other: is the another WurflHandset to compare against + # Returns: + # An array of the different values. + # Each entry in the Array is an Array of three values. + # The first value is the key in which both handsets have different values. + # The second is the other handset's value for the key. + # The third is the handset id from where the other handset got it's value. + def compare(other) + differences = Array.new + self.keys.each do |key| + oval,oid = other.get_value_and_owner(key) + if @capabilityhash[key].to_s != oval.to_s + differences<< [key,oval,oid] + end + end + return differences + end + +end diff --git a/nbproject/private/config.properties b/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties new file mode 100644 index 0000000..b4b4584 --- /dev/null +++ b/nbproject/private/private.properties @@ -0,0 +1 @@ +platform.active=Ruby_1 diff --git a/nbproject/private/rake-d.txt b/nbproject/private/rake-d.txt new file mode 100644 index 0000000..e530b28 --- /dev/null +++ b/nbproject/private/rake-d.txt @@ -0,0 +1,14 @@ +clobber= +clobber_package=Remove package products +clobber_rdoc=Remove rdoc products +default=Default: run unit tests. +gem=Build the gem file wurfl_store-0.1.0.gem +package=Build all the packages +pkg= +pkg/wurfl_store-0.1.0= +pkg/wurfl_store-0.1.0.gem= +rdoc=Build the rdoc HTML Files +rdoc/index.html= +repackage=Force a rebuild of the package files +rerdoc=Force a rebuild of the RDOC files +test=Run tests diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..3ed0f87 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,7 @@ +javac.classpath= +main.file= +platform.active=Ruby_0 +source.encoding=UTF-8 +spec.src.dir=spec +src.dir=lib +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..553628e --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,16 @@ + + + org.netbeans.modules.ruby.rubyproject + + + wurfl_store + + + + + + + + + + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100755 index 0000000..297d7f0 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,9 @@ +begin + require File.dirname(__FILE__) + '/../../../../spec/spec_helper' +rescue LoadError + puts "You need to install rspec in your base app" + exit +end + +plugin_spec_dir = File.dirname(__FILE__) +ActiveRecord::Base.logger = Logger.new(plugin_spec_dir + "/debug.log") \ No newline at end of file diff --git a/spec/wurfl_store_spec.rb b/spec/wurfl_store_spec.rb new file mode 100755 index 0000000..d01cf1b --- /dev/null +++ b/spec/wurfl_store_spec.rb @@ -0,0 +1,31 @@ +require File.dirname(__FILE__) + '/spec_helper' + +describe WurflStore do + describe 'wurfl_store base' do + before(:all) do + WurflStore.cache.delete('wurfl_initialized') + WurflStore.cache.delete('wurfl_initializing') + end + + it 'should load the wurfl into the cache if it is not present' do + WurflStore.init + assert WurflStore.cache.read('wurfl_initialized') + end + + it 'should return that the cache is initialized' do + assert WurflStore::CacheInitializer.cache_initialized? + end + + it 'should have cached the generic handset' do + WurflStore.cache.read('generic').should_not be_nil + end + + it 'should return nil given an invalid handset' do + WurflStore.get_handset('A Fake Handset').should be_nil + end + + it 'should return a valid handset given a UA that can be truncated to a valid UA' do + WurflStore.get_handset('Nokia 30 foobaloo').should_not be_nil + end + end +end \ No newline at end of file diff --git a/uninstall.rb b/uninstall.rb new file mode 100755 index 0000000..9738333 --- /dev/null +++ b/uninstall.rb @@ -0,0 +1 @@ +# Uninstall hook code here