adding model adapter files in proper location with loading behavior
This commit is contained in:
parent
f8760b7149
commit
4c5ba09f4c
9
Gemfile
9
Gemfile
|
@ -1,10 +1,13 @@
|
||||||
source "http://rubygems.org"
|
source "http://rubygems.org"
|
||||||
gemspec
|
|
||||||
|
|
||||||
case ENV["MODEL_ADAPTER"]
|
case ENV["MODEL_ADAPTER"]
|
||||||
|
when nil, "active_record"
|
||||||
|
gem "activerecord", :require => "active_record"
|
||||||
|
when "data_mapper"
|
||||||
|
gem "dm-core", "~> 1.0.2"
|
||||||
when "mongoid"
|
when "mongoid"
|
||||||
gem "bson_ext", "~> 1.1"
|
gem "bson_ext", "~> 1.1"
|
||||||
gem "mongoid", "~> 2.0.0.beta.19"
|
gem "mongoid", "~> 2.0.0.beta.19"
|
||||||
when "data_mapper"
|
|
||||||
gem "dm-core", "~> 1.0.2"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
gemspec
|
||||||
|
|
|
@ -2,8 +2,10 @@ require 'cancan/ability'
|
||||||
require 'cancan/rule'
|
require 'cancan/rule'
|
||||||
require 'cancan/controller_resource'
|
require 'cancan/controller_resource'
|
||||||
require 'cancan/controller_additions'
|
require 'cancan/controller_additions'
|
||||||
require 'cancan/active_record_additions'
|
|
||||||
require 'cancan/mongoid_additions'
|
|
||||||
require 'cancan/exceptions'
|
require 'cancan/exceptions'
|
||||||
require 'cancan/query'
|
require 'cancan/query'
|
||||||
require 'cancan/inherited_resource'
|
require 'cancan/inherited_resource'
|
||||||
|
|
||||||
|
require 'cancan/model_adapters/active_record_adapter' if defined? ActiveRecord
|
||||||
|
require 'cancan/model_adapters/data_mapper_adapter' if defined? DataMapper
|
||||||
|
require 'cancan/model_adapters/mongoid_adapter' if defined? Mongoid
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
require 'dm-core'
|
|
||||||
|
|
||||||
module CanCan
|
module CanCan
|
||||||
module Ability
|
module Ability
|
||||||
# could use alias_method_chain, but it's not worth adding activesupport as a gem dependency
|
# could use alias_method_chain, but it's not worth adding activesupport as a gem dependency
|
|
@ -1,6 +1,5 @@
|
||||||
if ENV["MODEL_ADAPTER"] == "data_mapper"
|
if ENV["MODEL_ADAPTER"] == "data_mapper"
|
||||||
require "spec_helper"
|
require "spec_helper"
|
||||||
require 'cancan/data_mapper_additions'
|
|
||||||
|
|
||||||
describe CanCan::DataMapperAdditions do
|
describe CanCan::DataMapperAdditions do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
if ENV["MODEL_ADAPTER"] == "mongoid"
|
if ENV["MODEL_ADAPTER"] == "mongoid"
|
||||||
require 'mongoid' # require mongoid first so MongoidAdditions are loaded
|
|
||||||
require "spec_helper"
|
require "spec_helper"
|
||||||
|
|
||||||
class MongoidCategory
|
class MongoidCategory
|
||||||
|
@ -35,7 +34,7 @@ if ENV["MODEL_ADAPTER"] == "mongoid"
|
||||||
end
|
end
|
||||||
|
|
||||||
Mongoid.configure do |config|
|
Mongoid.configure do |config|
|
||||||
config.master = Mongo::Connection.new('127.0.0.1', 27017).db("cancan_mongoid_additions_spec")
|
config.master = Mongo::Connection.new('127.0.0.1', 27017).db("cancan_mongoid_spec")
|
||||||
end
|
end
|
||||||
|
|
||||||
describe CanCan::MongoidAdditions do
|
describe CanCan::MongoidAdditions do
|
||||||
|
@ -50,7 +49,6 @@ if ENV["MODEL_ADAPTER"] == "mongoid"
|
||||||
it "should not raise an error for ActiveRecord models" do
|
it "should not raise an error for ActiveRecord models" do
|
||||||
@model_class = Class.new(Project)
|
@model_class = Class.new(Project)
|
||||||
stub(@model_class).scoped { :scoped_stub }
|
stub(@model_class).scoped { :scoped_stub }
|
||||||
@model_class.send(:include, CanCan::ActiveRecordAdditions)
|
|
||||||
@ability = Object.new
|
@ability = Object.new
|
||||||
@ability.extend(CanCan::Ability)
|
@ability.extend(CanCan::Ability)
|
||||||
|
|
||||||
|
@ -60,7 +58,7 @@ if ENV["MODEL_ADAPTER"] == "mongoid"
|
||||||
}.should_not raise_error
|
}.should_not raise_error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Mongoid defined" do
|
context "Mongoid defined" do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@model_class = MongoidProject
|
@model_class = MongoidProject
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'bundler/setup'
|
require 'bundler/setup'
|
||||||
|
|
||||||
Bundler.require(:default)
|
Bundler.require(:default)
|
||||||
|
|
||||||
require 'supermodel' # shouldn't Bundler do this already?
|
require 'supermodel' # shouldn't Bundler do this already?
|
||||||
require 'active_support/all'
|
require 'active_support/all'
|
||||||
require 'matchers'
|
require 'matchers'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user