cancan/spec/spec_helper.rb

55 lines
1022 B
Ruby
Raw Normal View History

2009-11-16 22:28:52 +00:00
require 'rubygems'
require 'bundler'
Bundler.require(:default, :test)
require 'active_support/all'
2010-07-20 23:00:22 +00:00
require 'matchers'
2010-04-13 13:02:39 +00:00
require 'cancan/matchers'
2009-11-16 22:28:52 +00:00
RSpec.configure do |config|
2009-11-16 22:28:52 +00:00
config.mock_with :rr
end
class Ability
include CanCan::Ability
2010-05-21 20:41:24 +00:00
def initialize(user)
end
end
# Generic class to mimic a model
class Project
attr_accessor :name
def initialize(attributes = {})
@name = attributes[:name]
end
def attributes=(attributes)
@name = attributes[:name] if attributes[:name]
end
class << self
protected
def sanitize_sql(hash_cond)
case hash_cond
when Hash
sanitize_hash(hash_cond).join(' AND ')
when Array
hash_cond.shift.gsub('?'){"#{hash_cond.shift.inspect}"}
when String then hash_cond
end
end
def 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
end
2010-05-25 08:14:01 +00:00
end