2009-11-16 22:28:52 +00:00
|
|
|
require 'rubygems'
|
|
|
|
require 'spec'
|
|
|
|
require 'active_support'
|
|
|
|
require 'active_record'
|
|
|
|
require 'action_controller'
|
|
|
|
require 'action_view'
|
2010-07-20 23:00:22 +00:00
|
|
|
require 'matchers'
|
2010-04-13 12:59:50 +00:00
|
|
|
require 'cancan'
|
2010-04-13 13:02:39 +00:00
|
|
|
require 'cancan/matchers'
|
2009-11-16 22:28:52 +00:00
|
|
|
|
|
|
|
Spec::Runner.configure do |config|
|
|
|
|
config.mock_with :rr
|
|
|
|
end
|
2009-11-26 17:29:53 +00:00
|
|
|
|
|
|
|
class Ability
|
|
|
|
include CanCan::Ability
|
2010-05-21 20:41:24 +00:00
|
|
|
|
2009-11-26 17:29:53 +00:00
|
|
|
def initialize(user)
|
|
|
|
end
|
|
|
|
end
|
2009-12-13 19:39:02 +00:00
|
|
|
|
2010-07-20 20:20:01 +00:00
|
|
|
# this class helps out in testing nesting and SQL conditions
|
2009-12-13 19:39:02 +00:00
|
|
|
class Person
|
2010-05-25 08:14:01 +00:00
|
|
|
def self.sanitize_sql(hash_cond)
|
|
|
|
case hash_cond
|
2010-05-25 10:02:26 +00:00
|
|
|
when Hash
|
|
|
|
sanitize_hash(hash_cond).join(' AND ')
|
2010-05-25 08:14:01 +00:00
|
|
|
when Array
|
|
|
|
hash_cond.shift.gsub('?'){"#{hash_cond.shift.inspect}"}
|
|
|
|
when String then hash_cond
|
|
|
|
end
|
|
|
|
end
|
2010-05-25 10:02:26 +00:00
|
|
|
|
|
|
|
def self.sanitize_hash(hash)
|
|
|
|
hash.map do |name, value|
|
|
|
|
if Hash === value
|
|
|
|
sanitize_hash(value).map{|cond| "#{name}.#{cond}"}
|
|
|
|
else
|
|
|
|
"#{name}=#{value}"
|
|
|
|
end
|
|
|
|
end.flatten
|
|
|
|
end
|
2010-05-25 08:14:01 +00:00
|
|
|
end
|