Permalink
Browse files

adding model adapter files in proper location with loading behavior

  • Loading branch information...
1 parent f8760b7 commit 4c5ba09f4cdda1788b230802e20df34854826928 @ryanb committed Dec 29, 2010
View
@@ -1,10 +1,13 @@
source "http://rubygems.org"
-gemspec
case ENV["MODEL_ADAPTER"]
+when nil, "active_record"
+ gem "activerecord", :require => "active_record"
+when "data_mapper"
+ gem "dm-core", "~> 1.0.2"
when "mongoid"
gem "bson_ext", "~> 1.1"
gem "mongoid", "~> 2.0.0.beta.19"
-when "data_mapper"
- gem "dm-core", "~> 1.0.2"
end
+
+gemspec
View
@@ -2,8 +2,10 @@
require 'cancan/rule'
require 'cancan/controller_resource'
require 'cancan/controller_additions'
-require 'cancan/active_record_additions'
-require 'cancan/mongoid_additions'
require 'cancan/exceptions'
require 'cancan/query'
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 Ability
# 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"
require "spec_helper"
- require 'cancan/data_mapper_additions'
describe CanCan::DataMapperAdditions do
before(:each) do
@@ -1,5 +1,4 @@
if ENV["MODEL_ADAPTER"] == "mongoid"
- require 'mongoid' # require mongoid first so MongoidAdditions are loaded
require "spec_helper"
class MongoidCategory
@@ -35,7 +34,7 @@ def sanitize_hash(hash)
end
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
describe CanCan::MongoidAdditions do
@@ -50,7 +49,6 @@ def sanitize_hash(hash)
it "should not raise an error for ActiveRecord models" do
@model_class = Class.new(Project)
stub(@model_class).scoped { :scoped_stub }
- @model_class.send(:include, CanCan::ActiveRecordAdditions)
@ability = Object.new
@ability.extend(CanCan::Ability)
@@ -60,7 +58,7 @@ def sanitize_hash(hash)
}.should_not raise_error
end
end
-
+
context "Mongoid defined" do
before(:each) do
@model_class = MongoidProject
View
@@ -1,6 +1,8 @@
require 'rubygems'
require 'bundler/setup'
+
Bundler.require(:default)
+
require 'supermodel' # shouldn't Bundler do this already?
require 'active_support/all'
require 'matchers'

0 comments on commit 4c5ba09

Please sign in to comment.