From 7774accb6ccec083eaf66c892e9e22f6d8bdc431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 4 Jul 2010 17:22:57 +0200 Subject: [PATCH] Remove data_mapper support. Devise 1.1.0 will be released soon. This new version will support activerecord and mongoid as default ORMs. From now on, Devise will prefer ORM extensions as gems since this is the best way to handle dependencies. For example, to allow Devise to work with Datamapper, it requires at least activemodel, dm-rails and dm-timestamps. If the ORM support comes from Devise gem, we cannot add dm-rails and dm-timestamps as dependencies, relying on the developer and documentation to find these out and install them. Other ORMs may still be added to Devise, as long as they are supported by the community, extend Devise test suite to have all tests passing and they necessarily use ActiveModel::Validations. --- CHANGELOG.rdoc | 2 +- Gemfile | 12 +-- Gemfile.lock | 114 ---------------------- lib/devise/orm/data_mapper.rb | 97 ------------------ lib/generators/devise/templates/devise.rb | 5 +- test/models/validatable_test.rb | 2 - test/orm/data_mapper.rb | 10 -- test/rails_app/app/data_mapper/admin.rb | 12 --- test/rails_app/app/data_mapper/shim.rb | 2 - test/rails_app/app/data_mapper/user.rb | 23 ----- 10 files changed, 5 insertions(+), 274 deletions(-) delete mode 100644 lib/devise/orm/data_mapper.rb delete mode 100644 test/orm/data_mapper.rb delete mode 100644 test/rails_app/app/data_mapper/admin.rb delete mode 100644 test/rails_app/app/data_mapper/shim.rb delete mode 100644 test/rails_app/app/data_mapper/user.rb diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index b036f396..24925f9a 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -38,7 +38,7 @@ * E-mails now use any template available in the filesystem. Easy to create multipart e-mails * E-mails asks headers_for in the model to set the proper headers * Allow to specify haml in devise_views - * Compatibility with Datamapper and Mongoid + * Compatibility with Mongoid * Make config.devise available on config/application.rb * TokenAuthenticatable now works with HTTP Basic Auth * Allow :unlock_strategy to be :none and add :lock_strategy which can be :failed_attempts or none. Setting those values to :none means that you want to handle lock and unlocking by yourself diff --git a/Gemfile b/Gemfile index 1cc9ba70..887a8aef 100644 --- a/Gemfile +++ b/Gemfile @@ -20,14 +20,4 @@ group :mongoid do gem "mongo" gem "mongoid", :git => "git://github.com/durran/mongoid.git" gem "bson_ext" -end - -group :data_mapper do - gem 'dm-core', '~> 1.0.0', :git => 'git://github.com/datamapper/dm-core' - gem 'dm-migrations', '~> 1.0.0', :git => 'git://github.com/datamapper/dm-migrations' - gem 'dm-sqlite-adapter', '~> 1.0.0', :git => 'git://github.com/datamapper/dm-sqlite-adapter' - gem 'dm-validations', '~> 1.0.0', :git => 'git://github.com/datamapper/dm-validations' - gem 'dm-serializer', '~> 1.0.0', :git => 'git://github.com/datamapper/dm-serializer' - gem 'dm-timestamps', '~> 1.0.0', :git => 'git://github.com/datamapper/dm-timestamps' - gem 'dm-rails', '~> 1.0.0', :git => 'git://github.com/datamapper/dm-rails' -end +end \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 601b29cd..26acb566 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,82 +1,3 @@ -GIT - remote: git://github.com/datamapper/dm-core - revision: 40ff12e - specs: - dm-core (1.0.0) - addressable (~> 2.1) - extlib (~> 0.9.15) - dm-core (1.0.0) - addressable (~> 2.1) - extlib (~> 0.9.15) - -GIT - remote: git://github.com/datamapper/dm-migrations - revision: c72ba40 - specs: - dm-migrations (1.0.0) - dm-core (~> 1.0.0) - dm-migrations (1.0.0) - dm-core (~> 1.0.0) - -GIT - remote: git://github.com/datamapper/dm-rails - revision: 8bf64e7 - specs: - dm-rails (1.0.0) - actionpack (~> 3.0.0.beta3) - activesupport (~> 3.0.0.beta3) - dm-active_model (~> 1.0.0) - dm-core (~> 1.0.0) - railties (~> 3.0.0.beta3) - dm-rails (1.0.0) - actionpack (~> 3.0.0.beta3) - activesupport (~> 3.0.0.beta3) - dm-active_model (~> 1.0.0) - dm-core (~> 1.0.0) - railties (~> 3.0.0.beta3) - -GIT - remote: git://github.com/datamapper/dm-serializer - revision: 1f0f617 - specs: - dm-serializer (1.0.0) - dm-core (~> 1.0.0) - fastercsv (~> 1.5.3) - json_pure (~> 1.4.3) - dm-serializer (1.0.0) - dm-core (~> 1.0.0) - fastercsv (~> 1.5.3) - json_pure (~> 1.4.3) - -GIT - remote: git://github.com/datamapper/dm-sqlite-adapter - revision: 2a8562b - specs: - dm-sqlite-adapter (1.0.0) - dm-do-adapter (~> 1.0.0) - do_sqlite3 (~> 0.10.2) - dm-sqlite-adapter (1.0.0) - dm-do-adapter (~> 1.0.0) - do_sqlite3 (~> 0.10.2) - -GIT - remote: git://github.com/datamapper/dm-timestamps - revision: 791bad7 - specs: - dm-timestamps (1.0.0) - dm-core (~> 1.0.0) - dm-timestamps (1.0.0) - dm-core (~> 1.0.0) - -GIT - remote: git://github.com/datamapper/dm-validations - revision: c793091 - specs: - dm-validations (1.0.0) - dm-core (~> 1.0.0) - dm-validations (1.0.0) - dm-core (~> 1.0.0) - GIT remote: git://github.com/durran/mongoid.git revision: 79b4d37 @@ -179,8 +100,6 @@ GEM specs: abstract (1.0.0) abstract (1.0.0) - addressable (2.1.2) - addressable (2.1.2) arel (0.4.0) activesupport (>= 3.0.0.beta) arel (0.4.0) @@ -195,38 +114,12 @@ GEM builder (2.1.2) columnize (0.3.1) columnize (0.3.1) - data_objects (0.10.2) - addressable (~> 2.1) - data_objects (0.10.2) - addressable (~> 2.1) - dm-active_model (1.0.0) - activemodel (~> 3.0.0.beta3) - dm-core (~> 1.0.0) - dm-active_model (1.0.0) - activemodel (~> 3.0.0.beta3) - dm-core (~> 1.0.0) - dm-do-adapter (1.0.0) - data_objects (~> 0.10.1) - dm-core (~> 1.0.0) - dm-do-adapter (1.0.0) - data_objects (~> 0.10.1) - dm-core (~> 1.0.0) - do_sqlite3 (0.10.2) - data_objects (= 0.10.2) - do_sqlite3 (0.10.2) - data_objects (= 0.10.2) erubis (2.6.6) abstract (>= 1.0.0) erubis (2.6.6) abstract (>= 1.0.0) - extlib (0.9.15) - extlib (0.9.15) - fastercsv (1.5.3) - fastercsv (1.5.3) i18n (0.4.1) i18n (0.4.1) - json_pure (1.4.3) - json_pure (1.4.3) linecache (0.43) linecache (0.43) mail (2.2.5) @@ -300,13 +193,6 @@ PLATFORMS DEPENDENCIES bcrypt-ruby bson_ext - dm-core (~> 1.0.0)! - dm-migrations (~> 1.0.0)! - dm-rails (~> 1.0.0)! - dm-serializer (~> 1.0.0)! - dm-sqlite-adapter (~> 1.0.0)! - dm-timestamps (~> 1.0.0)! - dm-validations (~> 1.0.0)! mocha mongo mongoid! diff --git a/lib/devise/orm/data_mapper.rb b/lib/devise/orm/data_mapper.rb deleted file mode 100644 index aa3a27a7..00000000 --- a/lib/devise/orm/data_mapper.rb +++ /dev/null @@ -1,97 +0,0 @@ -module Devise - module Orm - module DataMapper - module Hook - def devise_modules_hook! - extend Schema - include Compatibility - yield - return unless Devise.apply_schema - devise_modules.each { |m| send(m) if respond_to?(m, true) } - end - end - - module Schema - include Devise::Schema - - SCHEMA_OPTIONS = { - :null => :required, - :limit => :length - } - - # Tell how to apply schema methods. This automatically maps :limit to - # :length and :null to :required. - def apply_devise_schema(name, type, options={}) - SCHEMA_OPTIONS.each do |old_key, new_key| - next unless options.key?(old_key) - options[new_key] = options.delete(old_key) - end - - options.delete(:default) if options[:default].nil? - property name, type, options - end - end - - module Compatibility - extend ActiveSupport::Concern - - module ClassMethods - # Hooks for confirmable - def before_create(*args) - wrap_hook(:before, :create, *args) - end - - def after_create(*args) - wrap_hook(:after, :create, *args) - end - - def before_save(*args) - wrap_hook(:before, :save, *args) - end - - def wrap_hook(action, method, *args) - options = args.extract_options! - - args.each do |callback| - send action, method, callback - class_eval <<-METHOD, __FILE__, __LINE__ + 1 - def #{callback} - super if #{options[:if] || true} - end - METHOD - end - end - - # Add ActiveRecord like finder - def find(*args) - case args.first - when :first, :all - send(args.shift, *args) - else - get(*args) - end - end - end - - def changed? - dirty? - end - - def save(options=nil) - if options.is_a?(Hash) && options[:validate] == false - save! - else - super() - end - end - - def update_attributes(*args) - update(*args) - end - end - end - end -end - -DataMapper::Model.append_extensions(Devise::Models) -DataMapper::Model.append_extensions(Devise::Orm::DataMapper::Hook) diff --git a/lib/generators/devise/templates/devise.rb b/lib/generators/devise/templates/devise.rb index 6031ba7c..bfcd8149 100644 --- a/lib/generators/devise/templates/devise.rb +++ b/lib/generators/devise/templates/devise.rb @@ -9,8 +9,9 @@ Devise.setup do |config| # config.mailer = "Devise::Mailer" # ==> ORM configuration - # Load and configure the ORM. Supports :active_record (default), :mongoid - # (bson_ext recommended) and :data_mapper (experimental). + # Load and configure the ORM. Supports :active_record (default) and + # :mongoid (bson_ext recommended) by default. Other ORMs may be + # available as additional gems. require 'devise/orm/<%= options[:orm] %>' # ==> Configuration for any authentication mechanism diff --git a/test/models/validatable_test.rb b/test/models/validatable_test.rb index 16a2b0f1..a1df1901 100644 --- a/test/models/validatable_test.rb +++ b/test/models/validatable_test.rb @@ -1,8 +1,6 @@ require 'test_helper' class ValidatableTest < ActiveSupport::TestCase - extend Devise::TestSilencer if [:mongoid, :data_mapper].include?(DEVISE_ORM) - test 'should require email to be set' do user = new_user(:email => nil) assert user.invalid? diff --git a/test/orm/data_mapper.rb b/test/orm/data_mapper.rb deleted file mode 100644 index 2f042a5d..00000000 --- a/test/orm/data_mapper.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'rails/test_help' - -DataMapper.auto_migrate! - -class ActiveSupport::TestCase - setup do - User.all.destroy! - Admin.all.destroy! - end -end diff --git a/test/rails_app/app/data_mapper/admin.rb b/test/rails_app/app/data_mapper/admin.rb deleted file mode 100644 index 1703b515..00000000 --- a/test/rails_app/app/data_mapper/admin.rb +++ /dev/null @@ -1,12 +0,0 @@ -class Admin - include DataMapper::Resource - - property :id, Serial - property :username, String - - devise :database_authenticatable, :registerable, :timeoutable, :recoverable - - def self.create!(*args) - create(*args) - end -end diff --git a/test/rails_app/app/data_mapper/shim.rb b/test/rails_app/app/data_mapper/shim.rb deleted file mode 100644 index 66f12cdb..00000000 --- a/test/rails_app/app/data_mapper/shim.rb +++ /dev/null @@ -1,2 +0,0 @@ -module Shim -end diff --git a/test/rails_app/app/data_mapper/user.rb b/test/rails_app/app/data_mapper/user.rb deleted file mode 100644 index cbe2a598..00000000 --- a/test/rails_app/app/data_mapper/user.rb +++ /dev/null @@ -1,23 +0,0 @@ -class User - include DataMapper::Resource - - extend Devise::Orm::DataMapper::Schema - include Devise::Orm::DataMapper::Compatibility - - property :id, Serial - property :username, String - - devise :database_authenticatable, :confirmable, :lockable, :recoverable, - :registerable, :rememberable, :timeoutable, :token_authenticatable, - :trackable, :validatable - - timestamps :at - - def self.create!(*args) - create(*args) - end - - def self.destroy_all - all.destroy - end -end