2009-11-16 14:28:52 -08:00
|
|
|
require 'rubygems'
|
2010-10-08 11:46:41 -07:00
|
|
|
require 'bundler/setup'
|
|
|
|
Bundler.require(:default)
|
|
|
|
require 'supermodel' # shouldn't Bundler do this already?
|
2010-10-05 10:09:37 -07:00
|
|
|
require 'active_support/all'
|
2010-07-20 16:00:22 -07:00
|
|
|
require 'matchers'
|
2010-04-13 21:02:39 +08:00
|
|
|
require 'cancan/matchers'
|
2009-11-16 14:28:52 -08:00
|
|
|
|
2010-10-05 10:09:37 -07:00
|
|
|
RSpec.configure do |config|
|
2009-11-16 14:28:52 -08:00
|
|
|
config.mock_with :rr
|
2010-10-08 11:46:41 -07:00
|
|
|
config.before(:each) do
|
|
|
|
Project.delete_all
|
|
|
|
Category.delete_all
|
|
|
|
end
|
2009-11-16 14:28:52 -08:00
|
|
|
end
|
2009-11-26 09:29:53 -08:00
|
|
|
|
|
|
|
class Ability
|
|
|
|
include CanCan::Ability
|
2010-05-21 13:41:24 -07:00
|
|
|
|
2009-11-26 09:29:53 -08:00
|
|
|
def initialize(user)
|
|
|
|
end
|
|
|
|
end
|
2009-12-13 11:39:02 -08:00
|
|
|
|
2010-10-08 11:46:41 -07:00
|
|
|
class Category < SuperModel::Base
|
|
|
|
has_many :projects
|
|
|
|
end
|
2010-09-03 14:00:46 -07:00
|
|
|
|
2010-10-08 11:46:41 -07:00
|
|
|
class Project < SuperModel::Base
|
|
|
|
belongs_to :category
|
2010-09-03 14:00:46 -07:00
|
|
|
|
2010-08-06 23:24:04 -07:00
|
|
|
class << self
|
|
|
|
protected
|
2010-07-21 11:45:26 -07:00
|
|
|
|
2010-08-06 23:24:04 -07:00
|
|
|
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
|
2010-05-25 14:02:26 +04:00
|
|
|
end
|
2010-08-06 23:24:04 -07:00
|
|
|
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
|
2010-05-25 14:02:26 +04:00
|
|
|
end
|
2010-05-25 12:14:01 +04:00
|
|
|
end
|