2009-11-16 22:28:52 +00:00
|
|
|
require 'rubygems'
|
2010-10-08 18:46:41 +00:00
|
|
|
require 'bundler/setup'
|
2010-12-29 23:01:49 +00:00
|
|
|
|
2010-10-08 18:46:41 +00:00
|
|
|
Bundler.require(:default)
|
2010-12-29 23:01:49 +00:00
|
|
|
|
2010-10-08 18:46:41 +00:00
|
|
|
require 'supermodel' # shouldn't Bundler do this already?
|
2010-10-05 17:09:37 +00:00
|
|
|
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
|
|
|
|
2010-10-05 17:09:37 +00:00
|
|
|
RSpec.configure do |config|
|
2011-10-04 22:02:59 +00:00
|
|
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
|
|
config.filter_run :focus => true
|
|
|
|
config.run_all_when_everything_filtered = true
|
2009-11-16 22:28:52 +00:00
|
|
|
config.mock_with :rr
|
2010-10-08 18:46:41 +00:00
|
|
|
config.before(:each) do
|
|
|
|
Project.delete_all
|
|
|
|
Category.delete_all
|
|
|
|
end
|
2011-11-09 16:38:19 +00:00
|
|
|
config.extend WithModel if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record"
|
2009-11-16 22:28:52 +00:00
|
|
|
end
|
2009-11-26 17:29:53 +00:00
|
|
|
|
2013-01-03 12:16:30 +00:00
|
|
|
# Working around CVE-2012-5664 requires us to convert all ID params
|
|
|
|
# to strings. Let's switch to using string IDs in tests, otherwise
|
|
|
|
# SuperModel and/or RR will fail (as strings are not fixnums).
|
|
|
|
|
|
|
|
module SuperModel
|
|
|
|
class Base
|
|
|
|
def generate_id
|
|
|
|
object_id.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
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-10-08 18:46:41 +00:00
|
|
|
class Category < SuperModel::Base
|
|
|
|
has_many :projects
|
|
|
|
end
|
2010-09-03 21:00:46 +00:00
|
|
|
|
2012-01-05 21:21:11 +00:00
|
|
|
module Sub
|
|
|
|
class Project < SuperModel::Base
|
|
|
|
belongs_to :category
|
|
|
|
attr_accessor :category # why doesn't SuperModel do this automatically?
|
|
|
|
|
|
|
|
def self.respond_to?(method, include_private = false)
|
|
|
|
if method.to_s == "find_by_name!" # hack to simulate ActiveRecord
|
|
|
|
true
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-10-08 18:46:41 +00:00
|
|
|
class Project < SuperModel::Base
|
|
|
|
belongs_to :category
|
2011-03-16 06:37:05 +00:00
|
|
|
attr_accessor :category # why doesn't SuperModel do this automatically?
|
2011-05-20 03:37:36 +00:00
|
|
|
|
|
|
|
def self.respond_to?(method, include_private = false)
|
|
|
|
if method.to_s == "find_by_name!" # hack to simulate ActiveRecord
|
|
|
|
true
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
2010-05-25 08:14:01 +00:00
|
|
|
end
|