diff --git a/Gemfile b/Gemfile index 4e1c66e..e65ee88 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/lib/cancan.rb b/lib/cancan.rb index 1238cf5..03a5086 100644 --- a/lib/cancan.rb +++ b/lib/cancan.rb @@ -2,8 +2,10 @@ require 'cancan/ability' 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 diff --git a/lib/cancan/active_record_additions.rb b/lib/cancan/model_adapters/active_record_adapter.rb similarity index 100% rename from lib/cancan/active_record_additions.rb rename to lib/cancan/model_adapters/active_record_adapter.rb diff --git a/lib/cancan/data_mapper_additions.rb b/lib/cancan/model_adapters/data_mapper_adapter.rb similarity index 99% rename from lib/cancan/data_mapper_additions.rb rename to lib/cancan/model_adapters/data_mapper_adapter.rb index 679f5af..0723b4d 100644 --- a/lib/cancan/data_mapper_additions.rb +++ b/lib/cancan/model_adapters/data_mapper_adapter.rb @@ -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 diff --git a/lib/cancan/mongoid_additions.rb b/lib/cancan/model_adapters/mongoid_adapter.rb similarity index 100% rename from lib/cancan/mongoid_additions.rb rename to lib/cancan/model_adapters/mongoid_adapter.rb diff --git a/spec/cancan/model_adapters/data_mapper_adapter_spec.rb b/spec/cancan/model_adapters/data_mapper_adapter_spec.rb index 4abe8ba..c7d6c55 100644 --- a/spec/cancan/model_adapters/data_mapper_adapter_spec.rb +++ b/spec/cancan/model_adapters/data_mapper_adapter_spec.rb @@ -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 diff --git a/spec/cancan/model_adapters/mongoid_adapter_spec.rb b/spec/cancan/model_adapters/mongoid_adapter_spec.rb index 66bb568..2a6d937 100644 --- a/spec/cancan/model_adapters/mongoid_adapter_spec.rb +++ b/spec/cancan/model_adapters/mongoid_adapter_spec.rb @@ -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 @@ if ENV["MODEL_ADAPTER"] == "mongoid" 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 @@ if ENV["MODEL_ADAPTER"] == "mongoid" 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 @@ if ENV["MODEL_ADAPTER"] == "mongoid" }.should_not raise_error end end - + context "Mongoid defined" do before(:each) do @model_class = MongoidProject diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index da6b77b..421855e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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'