diff --git a/Gemfile b/Gemfile index 191923f..f57af48 100644 --- a/Gemfile +++ b/Gemfile @@ -1,31 +1,29 @@ source :rubygems -source 'http://gems.github.com/' - -gem "rails" - group :test do gem "test-unit", "~> 2.0.9" - gem "webrat", "~> 0.7.0" + gem "webrat", "~> 0.7.2" gem "mocha", "~> 0.9.8", :require => false end group :default do - gem "webrat", "~> 0.7.0" + gem "rails", "~> 3.0.7" + gem "webrat", "~> 0.7.2" - gem "bcrypt-ruby", :require => "bcrypt" - gem "oauth2" - gem "warden", ">= 0.10.7" - gem 'mongo_mapper', '>= 0.8.4' + gem 'mongo_mapper', '0.9.0' gem 'sugar-high', '~> 0.3.4' gem 'devise', '>= 1.1.1' gem 'rails3-generators', '>= 0.13.0' - gem 'jnunemaker-validatable', '~> 1.8.1' gem 'bson_ext', '>= 1.0.9' - + + gem 'rake', '0.8.7' gem "orm_adapter" - gem "omniauth" - + gem "oa-oauth", '~> 0.2.0', :require => "omniauth/oauth" + gem "oa-openid", '~> 0.2.0', :require => "omniauth/openid" + + platforms :mri_18 do + gem "SystemTimer" + end end diff --git a/Rakefile b/Rakefile index ecaeac0..aaec182 100644 --- a/Rakefile +++ b/Rakefile @@ -4,14 +4,11 @@ require 'rake' require 'bundler' Bundler::GemHelper.install_tasks - require 'rake/testtask' require 'rake/rdoctask' require File.join(File.dirname(__FILE__), 'lib', 'mm-devise', 'version') desc 'Run Devise tests using MongoMapper. Specify path to devise with DEVISE_PATH' - - Rake::TestTask.new(:test) do |test| ENV['DEVISE_ORM'] ||= 'mongo_mapper' ENV['DEVISE_PATH'] ||= File.join(File.dirname(__FILE__), '../devise') @@ -27,56 +24,5 @@ Rake::TestTask.new(:test) do |test| test.verbose = true end -desc 'Default: run tests for all ORMs.' -task :default => :tests - -=begin -desc 'Default: run tests for all MongoMapper ORM setups.' -task :default => :pre_commit - -desc 'Run Devise tests for all MongoMapper ORM setups.' -task :pre_commit do - Dir[File.join(File.dirname(__FILE__), 'test', 'orm', '*.rb')].each do |file| - orm = File.basename(file).split(".").first - ENV['DEVISE_PATH'] ||= File.expand_path('../devise') - system "rake test DEVISE_ORM=#{orm} DEVISE_PATH=#{ENV['DEVISE_PATH']}" - end -end - - -task :test - -desc 'Generate documentation for dm-devise.' -Rake::RDocTask.new(:rdoc) do |rdoc| - rdoc.rdoc_dir = 'rdoc' - rdoc.title = 'mm-devise #{version}' - rdoc.options << '--line-numbers' << '--inline-source' - rdoc.rdoc_files.include('README.rdoc') - rdoc.rdoc_files.include('lib/**/*.rb') -end - -begin - require 'jeweler' - Jeweler::Tasks.new do |gem| - gem.name = "mm-devise" - gem.version = MongoMapper::Devise::VERSION.dup - gem.summary = %Q{Support for using MongoMapper ORM with devise} - gem.description = %Q{dm-devise adds MongoMapper support to devise (http://github.com/plataformatec/devise) for authentication support for Rails} - gem.email = "jmorgan@morgancreative.net" - gem.homepage = "http://github.com/kristianmandrup/mm-devise" - gem.authors = ["Kristian Mandrup"] - gem.add_dependency 'mongo_mapper', '>= 0.8.4' - gem.add_dependency 'bson', '>= 1.0.9' - gem.add_dependency 'rails3-generators', '>= 0.13.0' - gem.add_dependency 'jnunemaker-validatable', '>= 1.8.1' - gem.add_dependency 'devise', '>= 1.1.1' - gem.add_dependency 'sugar-high', '~> 0.3.0' - gem.add_dependency 'warden', '>= 0.10.7' - gem.add_dependency 'bcrypt-ruby', '>= 2.1.2' - # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings - end - Jeweler::GemcutterTasks.new -rescue LoadError - puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" -end -=end \ No newline at end of file +desc 'Default: run tests for MongoMapper' +task :default => :test diff --git a/lib/devise/orm/mongo_mapper.rb b/lib/devise/orm/mongo_mapper.rb index 38ef1ea..4b93021 100644 --- a/lib/devise/orm/mongo_mapper.rb +++ b/lib/devise/orm/mongo_mapper.rb @@ -1,26 +1,37 @@ -require 'mongo_mapper' -require 'devise/orm/mongo_mapper/compatibility' -require 'devise/orm/mongo_mapper/schema' -require 'devise/orm/mongo_mapper/date_time' -require 'devise/orm/mongo_mapper/mm-validations' +require 'orm_adapter/adapters/mongo_mapper' module Devise module Orm module MongoMapper + extend ActiveSupport::Concern + + included do + extend Devise::Models + extend Devise::Orm::MongoMapper::Hook + end + module Hook def devise_modules_hook! extend Schema - include Compatibility - include Validatable yield return unless Devise.apply_schema devise_modules.each { |m| send(m) if respond_to?(m, true) } - end + end + end + + module Schema + include Devise::Schema + + # Tell how to apply schema methods + def apply_devise_schema(name, type, options={}) + type = Time if type == DateTime + key(name, type, options) + end + end + end end end -MongoMapper::Document.append_extensions(Devise::Models) -MongoMapper::Document.append_extensions(Devise::Orm::MongoMapper::Hook) - +MongoMapper::Document.plugin Devise::Orm::MongoMapper diff --git a/lib/devise/orm/mongo_mapper/compatibility.rb b/lib/devise/orm/mongo_mapper/compatibility.rb deleted file mode 100644 index 6ab1993..0000000 --- a/lib/devise/orm/mongo_mapper/compatibility.rb +++ /dev/null @@ -1,89 +0,0 @@ -module Devise - module Orm - module MongoMapper - module Compatibility - extend ActiveSupport::Concern - - extend ActiveSupport::Concern - extend ActiveModel::Naming - - include ActiveModel::Serializers::Xml - include ActiveModel::Serializers::JSON - - def to_xml(options = {}, &block) - options[:except] ||= [] - options[:except] << :_id - - super options do |b| - b.id self.id - block.call(b) if block_given? - end - end - - - 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| - callback_method = :"#{callback}_callback_wrap" - send action, method, callback_method - class_eval <<-METHOD, __FILE__, __LINE__ + 1 - def #{callback_method} - #{callback} 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 - where(:'_id' => args.first).first - end - end - end - - # def changed? - # dirty? - # end -=begin - def save(options=nil) - if options.is_a?(Hash) && options[:validate] == false - save! - else - super() - end - end - - def update_attribute(name, value) - update_attributes(name => value) - end - # - # def update_attributes(*args) - # update(*args) - # end -=end - def invalid? - !valid? - end - end - end - end -end \ No newline at end of file diff --git a/lib/devise/orm/mongo_mapper/date_time.rb b/lib/devise/orm/mongo_mapper/date_time.rb deleted file mode 100644 index a0b2a24..0000000 --- a/lib/devise/orm/mongo_mapper/date_time.rb +++ /dev/null @@ -1,14 +0,0 @@ -class Date - unless method_defined?(:gmtime) - delegate :gmtime, :to => :to_time - end - - def utc - Time.zone.parse("#{hour.to_i - zone.to_i}:#{min}:#{sec}") - # self.to_datetime.new_offset(0) - end - - def to_i - to_time.utc.to_i - end -end diff --git a/lib/devise/orm/mongo_mapper/mm-validations.rb b/lib/devise/orm/mongo_mapper/mm-validations.rb deleted file mode 100644 index b712d95..0000000 --- a/lib/devise/orm/mongo_mapper/mm-validations.rb +++ /dev/null @@ -1,91 +0,0 @@ -require 'validatable' - -module Validatable - # Monkey-patch Validatable::Errors to support generation of error message from - # a Symbol. - class Errors - @@default_error_messages = {} - - # Holds a hash with all the default error messages that can be replaced by your own copy or localizations. - def self.default_error_messages=(default_error_messages) - @@default_error_messages = default_error_messages - end - - def self.default_error_message(key, field, *values) - field = field.to_s.humanize - @@default_error_messages[key] % [field, *values].flatten - end - - # original add before monkey-patch - # def add(attribute, message) #:nodoc: - # errors[attribute.to_sym] = [] if errors[attribute.to_sym].nil? - # errors[attribute.to_sym] << message - # end - - alias_method :original_add, :add - - # If the message is a Symbol, allow +default_error_message+ to generate - # the message, including translation. - def add(field_name, message) - if message.kind_of?(Symbol) - message = self.class.default_error_message(message, field_name) - end - fld_name = field_name.to_sym - errors[fld_name] = [] if errors[fld_name].nil? - original_add(fld_name, message) unless errors[fld_name].include?(message) - end - end -end - -module Validatable - class ValidatesPresenceOf < ValidationBase #:nodoc: - def message(instance) - super || "can't be blank" - end - end -end - -module Validatable - class ValidatesLengthOf < ValidationBase #:nodoc: - def message(instance) - min = !within.nil? ? within.first : minimum - max = !within.nil? ? within.last : maximum - super || "must be between #{min} and #{max} characters long" - end - end -end - - -# Default error messages consistent with ActiveModel messages and devise -# expectations. -Validatable::Errors.default_error_messages = { - :absent => 'must be absent', - :inclusion => 'is not included in the list', - :exclusion => 'is reserved', - :invalid => 'is invalid', - :confirmation => " doesn't match confirmation", - :accepted => 'must be accepted', - :nil => 'must not be nil', - :empty => "can't be empty", - :blank => "can't be blank", - :length_between => 'must be between %s and %s characters long', - :too_long => 'is too long (maximum is %s characters)', - :too_short => 'is too short (minimum is %s characters)', - :wrong_length => 'is the wrong length (should be %s characters)', - :taken => 'has already been taken', - :not_a_number => 'is not a number', - :not_an_integer => 'must be an integer', - :greater_than => 'must be greater than %s', - :greater_than_or_equal_to => 'must be greater than or equal to ', - :equal_to => 'must be equal to %s', - :not_equal_to => 'must not be equal to %s', - :less_than => 'must be less than %s', - :less_than_or_equal_to => 'must be less than or equal to %s', - :value_between => 'must be between %s and %s', - :odd => 'must be odd', - :even => 'must be even', - :primitive => 'must be of type %s', - :not_found => 'not found', - :already_confirmed => 'was already confirmed', - :not_locked => 'was not locked' -} diff --git a/lib/devise/orm/mongo_mapper/schema.rb b/lib/devise/orm/mongo_mapper/schema.rb deleted file mode 100644 index 3907299..0000000 --- a/lib/devise/orm/mongo_mapper/schema.rb +++ /dev/null @@ -1,86 +0,0 @@ -module MongoMapper - class ValidationUtil - class << self - attr_accessor :counter - - def inc_counter - @counter ||= 0 - @counter += 1 - end - end - end -end - -module Devise - module Orm - module MongoMapper - 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) - if :null == old_key - # :required is opposite of :null - options[new_key] = !options.delete(old_key) - else - options[new_key] = options.delete(old_key) - end - end - - options.delete(:default) if options[:default].nil? - required_option = options.delete(:required) - length_option = options.delete(:length) - - type = Time if type == DateTime - - key name, type, options - - counter = ::MongoMapper::ValidationUtil.inc_counter - - handle_email(name, counter) if name == :email - handle_length(name, counter, length_option) if length_option - handle_required(name, counter) if required_option - end - - protected - - def make_key prefix, name, counter - "#{prefix}_#{name}_#{counter}" - end - - def handle_required name, counter - key = make_key :presence, name, counter - validates_presence_of name.to_sym, :key => key - end - - def handle_email name, counter - key = make_key :unique, name, counter - validates_uniqueness_of name.to_sym, :key => key - end - - def handle_length name, counter, length_option - key = make_key :length, name, counter - options = case length_option - when Fixnum - {:maximum => length_option} - when Hash - length_option - else - raise ArgumentError, "length validation option must be either a Fixnum or Hash" - end - options[:key] = key - - validates_length_of name.to_sym, options - end - end - end - end -end diff --git a/lib/devise/orm/mongo_mapper_active_model.rb b/lib/devise/orm/mongo_mapper_active_model.rb deleted file mode 100644 index e41db21..0000000 --- a/lib/devise/orm/mongo_mapper_active_model.rb +++ /dev/null @@ -1,68 +0,0 @@ -require 'mongo_mapper' -require 'devise/orm/mongo_mapper/compatibility' -require 'devise/orm/mongo_mapper/schema' -require 'devise/orm/mongo_mapper/date_time' - -module Devise - module Orm - module MongoMapper - module Hook - def devise_modules_hook! - extend Schema - include ActiveModel::Validations - include ActiveModelCompatibility - include Compatibility - #class << self; attr_reader :descendants; end; - - def self.validates_uniqueness_of(*fields) - validates_with UniquenessValidator, _merge_attributes(fields) - end - - yield - return unless Devise.apply_schema - devise_modules.each { |m| send(m) if respond_to?(m, true) } - end - end - - # http://github.com/jkaramon/mongomapper/blob/rails3/lib/mongo_mapper/plugins/validations.rb - # ============================================================== - # validates_each in mongo_mapper should work just fine! - # ============================================================== - - # class UniquenessValidator < ActiveModel::EachValidator - # def validate_each(target, attribute, value) - # resource = ::DataMapper.repository(target.repository.name) { target.model.first(attribute => value) } - # if resource.nil? || (target.saved? && resource.key == target.key) - # return true - # else - # target.errors.add(attribute, :taken) - # return false - # end - # end - # end - - module ActiveModelCompatibility - # include ActiveModel::Validations does not make save check valid?. - # This may not be the best solution, but it seems to work. Note that - # Compatibility is included after this module; its #save method handles - # the :validate => false option. - def save(*args) - retval = valid? && super(*args) - assert_save_successful(:save, retval) - retval - end - end - end - end -end - -MongoMapper::Document.append_extensions(Devise::Models) -MongoMapper::Document.append_extensions(Devise::Orm::MongoMapper::Hook) - - -# module MongoMapper -# module Document -# extend ::Devise::Models -# extend ::Devise::Orm::MongoMapper::Hook -# end -# end diff --git a/mm-devise.gemspec b/mm-devise.gemspec index 1149676..8106b6b 100644 --- a/mm-devise.gemspec +++ b/mm-devise.gemspec @@ -1,104 +1,23 @@ -# Generated by jeweler -# DO NOT EDIT THIS FILE DIRECTLY -# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command # -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) +require "mm-devise/version" Gem::Specification.new do |s| - s.name = %q{mm-devise} - s.version = "1.1.10" + s.name = "mm-devise" + s.version = MongoMapper::Devise::VERSION + s.date = "2011-01-11" + s.summary = %Q{Support for using MongoMapper ORM with devise} + s.description = %Q{dm-devise adds MongoMapper support to devise (http://github.com/plataformatec/devise) for authentication support for Rails} + s.email = "jmorgan@morgancreative.net" + s.homepage = "http://github.com/kristianmandrup/mm-devise" + s.authors = ["Kristian Mandrup"] + s.files = Dir.glob("lib/**/*") + %w(Changelog.txt mm-devise.gemspec Gemfile LICENSE Rakefile README.markdown) + s.test_files = Dir.glob("test/**/*") - s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= - s.authors = ["Kristian Mandrup"] - s.date = %q{2011-01-11} - s.description = %q{dm-devise adds MongoMapper support to devise (http://github.com/plataformatec/devise) for authentication support for Rails} - s.email = %q{jmorgan@morgancreative.net} - s.extra_rdoc_files = [ - "LICENSE", - "README.markdown" - ] - s.files = [ - ".document", - ".gitignore", - "Gemfile", - "LICENSE", - "README.markdown", - "Rakefile", - "lib/devise/orm/mongo_mapper.rb", - "lib/devise/orm/mongo_mapper/compatibility.rb", - "lib/devise/orm/mongo_mapper/date_time.rb", - "lib/devise/orm/mongo_mapper/mm-validations.rb", - "lib/devise/orm/mongo_mapper/schema.rb", - "lib/devise/orm/mongo_mapper_active_model.rb", - "lib/generators/mongo_mapper/devise_generator.rb", - "lib/mm-devise/version.rb", - "mm-devise.gemspec", - "test/mongo_mapper/compatibility_test.rb", - "test/orm/mongo_mapper.rb", - "test/orm/mongo_mapper_active_model.rb", - "test/overrides/mm_validations_test.rb", - "test/overrides/mongo_mapper_test.rb", - "test/rails_app/app/mongo_mapper/admin.rb", - "test/rails_app/app/mongo_mapper/shim.rb", - "test/rails_app/app/mongo_mapper/user.rb", - "test/rails_app/app/mongo_mapper_active_model/admin.rb", - "test/rails_app/app/mongo_mapper_active_model/user.rb", - "test/rails_app/config/application.rb", - "test/rails_app/config/environment.rb", - "test/test_helper.rb" - ] - s.homepage = %q{http://github.com/kristianmandrup/mm-devise} - s.rdoc_options = ["--charset=UTF-8"] - s.require_paths = ["lib"] - s.rubygems_version = %q{1.3.7} - s.summary = %q{Support for using MongoMapper ORM with devise} - s.test_files = [ - "test/mongo_mapper/compatibility_test.rb", - "test/orm/mongo_mapper.rb", - "test/orm/mongo_mapper_active_model.rb", - "test/overrides/mm_validations_test.rb", - "test/overrides/mongo_mapper_test.rb", - "test/rails_app/app/mongo_mapper/admin.rb", - "test/rails_app/app/mongo_mapper/shim.rb", - "test/rails_app/app/mongo_mapper/user.rb", - "test/rails_app/app/mongo_mapper_active_model/admin.rb", - "test/rails_app/app/mongo_mapper_active_model/user.rb", - "test/rails_app/config/application.rb", - "test/rails_app/config/environment.rb", - "test/test_helper.rb" - ] + s.add_dependency 'mongo_mapper', '>= 0.9.0' + s.add_dependency 'devise', '>= 1.1.1' + s.add_dependency 'rails3-generators', '>= 0.13.0' + s.add_dependency 'sugar-high', '~> 0.3.0' + s.add_dependency "SystemTimer", "~> 1.2" if RUBY_VERSION < "1.9" - if s.respond_to? :specification_version then - current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION - s.specification_version = 3 - - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_runtime_dependency(%q, [">= 0.8.4"]) - s.add_runtime_dependency(%q, [">= 1.0.9"]) - s.add_runtime_dependency(%q, [">= 0.13.0"]) - s.add_runtime_dependency(%q, [">= 1.8.1"]) - s.add_runtime_dependency(%q, [">= 1.1.1"]) - s.add_runtime_dependency(%q, ["~> 0.3.0"]) - s.add_runtime_dependency(%q, [">= 0.10.7"]) - s.add_runtime_dependency(%q, [">= 2.1.2"]) - else - s.add_dependency(%q, [">= 0.8.4"]) - s.add_dependency(%q, [">= 1.0.9"]) - s.add_dependency(%q, [">= 0.13.0"]) - s.add_dependency(%q, [">= 1.8.1"]) - s.add_dependency(%q, [">= 1.1.1"]) - s.add_dependency(%q, ["~> 0.3.4"]) - s.add_dependency(%q, [">= 0.10.7"]) - s.add_dependency(%q, [">= 2.1.2"]) - end - else - s.add_dependency(%q, [">= 0.8.4"]) - s.add_dependency(%q, [">= 1.0.9"]) - s.add_dependency(%q, [">= 0.13.0"]) - s.add_dependency(%q, [">= 1.8.1"]) - s.add_dependency(%q, [">= 1.1.1"]) - s.add_dependency(%q, ["~> 0.3.0"]) - s.add_dependency(%q, [">= 0.10.7"]) - s.add_dependency(%q, [">= 2.1.2"]) - end end - diff --git a/test/orm/mongo_mapper.rb b/test/orm/mongo_mapper.rb index 00530fc..a344eba 100644 --- a/test/orm/mongo_mapper.rb +++ b/test/orm/mongo_mapper.rb @@ -1,30 +1,10 @@ -require 'rails/test_help' +MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017) +MongoMapper.database = "devise-test-suite" +MongoMapper.database.collections.each { |c| c.drop_indexes } class ActiveSupport::TestCase setup do - User.destroy_all - Admin.destroy_all - end -end - -module MongoMapper - module Validate - class ValidationErrors - - # ActiveModel prepends field names in +#full_messages+, and so the - # expected result of calling errors[field_name] will not include the - # field name in the message. However, DM expects the field name to be - # included in the original message. Assuming that the field name will - # begin the message, just strip it out (plus the following space) for - # testing purposes. This has no effect on #full_messages. - - # def [](property_name) - # if property_errors = errors[property_name.to_sym] - # property_errors.collect do |message| - # message[(property_name.to_s.length + 1)..-1] - # end - # end - # end - end + User.collection.remove + Admin.collection.remove end end diff --git a/test/orm/mongo_mapper_active_model.rb b/test/orm/mongo_mapper_active_model.rb deleted file mode 100644 index e94ad98..0000000 --- a/test/orm/mongo_mapper_active_model.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'rails/test_help' - -class ActiveSupport::TestCase - setup do - User.destroy_all - Admin.destroy_all - end -end diff --git a/test/overrides/mm_validations_test.rb b/test/overrides/mm_validations_test.rb deleted file mode 100644 index ca657a3..0000000 --- a/test/overrides/mm_validations_test.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'test_helper' - -# See data_mapper_test.rb in this folder for what this file is doing. -if DEVISE_ORM == :mongo_mapper - - class ValidatableTest < ActiveSupport::TestCase - undef test_should_require_a_password_with_minimum_of_6_characters - - # DataMapper uses a :value_between error message when given a minimum and - # maximum; ActiveModel shows either the :too_long or :too_short message. - test 'should require a password with minimum of 6 characters' do - user = new_user(:password => '12345', :password_confirmation => '12345') - assert user.invalid? - # assert_equal 'is too short (minimum is 6 characters)', user.errors[:password].join - assert_equal 'must be between 6 and 20 characters long', user.errors[:password].join - end - - undef test_should_require_a_password_with_maximum_of_20_characters_long - - # Same issue as previous test - test 'should require a password with maximum of 20 characters long' do - user = new_user(:password => 'x'*21, :password_confirmation => 'x'*21) - assert user.invalid? - # assert_equal 'is too long (maximum is 20 characters)', user.errors[:password].join - assert_equal 'must be between 6 and 20 characters long', user.errors[:password].join - end - - end - - class AuthenticationOthersTest < ActionController::IntegrationTest - - undef test_registration_in_xml_format_works_when_recognizing_path - - # DM's validates_confirmation_of requires the confirmation field to be present, - # while ActiveModel by default skips the confirmation test if the confirmation - # value is nil. This test takes advantage of AM's behavior, so just add the - # :password_confirmation value. - test 'registration in xml format works when recognizing path' do - assert_nothing_raised do - # post user_registration_path(:format => 'xml', :user => {:email => "test@example.com", :password => "invalid"} ) - post user_registration_path(:format => 'xml', :user => {:email => "test@example.com", :password => "invalid", :password_confirmation => "invalid"} ) - end - end - end - -end diff --git a/test/overrides/mongo_mapper_test.rb b/test/overrides/mongo_mapper_test.rb deleted file mode 100644 index 369e159..0000000 --- a/test/overrides/mongo_mapper_test.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'test_helper' - -# This file contains test cases that override devise tests, in the cases that -# the difference is values from DM versus those expected by devise is not -# particularly important and getting DM to pass the original devise tests would -# be difficult. -# -# This file contains tests shared by both data_mapper and -# data_mapper_active_model ORM setups. -# Tests specific to the data_mapper orm which uses dm-validations are in dm_validations_test.rb -# Tests specific to the data_mapper_active_model orm which uses ActiveModel -# validations would be in active_model_test.rb, but there aren't any (I would -# be rather surprised if there ever were any). -# -# For each test, an explanation is given as to why I chose to override the test, -# and the original assertion is commented above the DM-specific assertion. - -class TrackableHooksTest < ActionController::IntegrationTest - - undef test_current_and_last_sign_in_timestamps_are_updated_on_each_sign_in - - # DataMapper uses a DateTime type where ActiveRecord uses Time. The test is - # that the tested properties are being set, so just check for kind_of?(DateTime) - # instead of kind_of?(Time) - test "current and last sign in timestamps are updated on each sign in" do - user = create_user - assert_nil user.current_sign_in_at - assert_nil user.last_sign_in_at - - sign_in_as_user - user.reload - - assert_kind_of Time, user.current_sign_in_at - assert_kind_of Time, user.last_sign_in_at - - assert_equal user.current_sign_in_at, user.last_sign_in_at - assert user.current_sign_in_at >= user.created_at - - visit destroy_user_session_path - new_time = 2.seconds.from_now - Time.stubs(:now).returns(new_time) - - sign_in_as_user - user.reload - assert user.current_sign_in_at > user.last_sign_in_at - end -end - diff --git a/test/rails_app/app/mongo_mapper/admin.rb b/test/rails_app/app/mongo_mapper/admin.rb index 9954911..e34d87e 100644 --- a/test/rails_app/app/mongo_mapper/admin.rb +++ b/test/rails_app/app/mongo_mapper/admin.rb @@ -2,11 +2,9 @@ class Admin include MongoMapper::Document + include Shim + include SharedAdmin - key :username, String - + key :remember_token, String timestamps! - - include SharedAdmin - include Shim end diff --git a/test/rails_app/app/mongo_mapper/shim.rb b/test/rails_app/app/mongo_mapper/shim.rb index 9b1b36c..cfbb9c8 100644 --- a/test/rails_app/app/mongo_mapper/shim.rb +++ b/test/rails_app/app/mongo_mapper/shim.rb @@ -1,21 +1,7 @@ -# Shim should be included after SharedUser / SharedAdmin module Shim - def self.included(klass) - klass.extend(ModelMethods) - end + extend ::ActiveSupport::Concern - module ModelMethods - # Override version in SharedUser which uses #find_by_email. - def find_for_facebook_oauth(access_token, signed_in_resource=nil) - data = ActiveSupport::JSON.decode(access_token.get('/me')) - user = signed_in_resource || User.first(:email => data["email"]) || User.new - user.update_with_facebook_oauth(access_token, data) - user.save - user - end - - def create!(*args) - create(*args) - end + included do + self.include_root_in_json = true end end diff --git a/test/rails_app/app/mongo_mapper/user.rb b/test/rails_app/app/mongo_mapper/user.rb index 19d1673..25c7d83 100644 --- a/test/rails_app/app/mongo_mapper/user.rb +++ b/test/rails_app/app/mongo_mapper/user.rb @@ -2,25 +2,10 @@ class User include MongoMapper::Document + include Shim + include SharedUser key :username, String key :facebook_token, String timestamps! - - include SharedUser - include Shim - - unless DEVISE_ORM == :mongo_mapper_active_model - before_validation :update_password_confirmation - - # DM's validates_confirmation_of requires the confirmation field to be present, - # while ActiveModel by default skips the confirmation test if the confirmation - # value is nil. This test takes advantage of AM's behavior, so just add the - # :password_confirmation value. - def update_password_confirmation - if self.password && self.password_confirmation.nil? - self.password_confirmation = self.password - end - end - end end diff --git a/test/rails_app/app/mongo_mapper_active_model/admin.rb b/test/rails_app/app/mongo_mapper_active_model/admin.rb deleted file mode 100644 index 226aee2..0000000 --- a/test/rails_app/app/mongo_mapper_active_model/admin.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'shared_admin' -require File.join(File.dirname(__FILE__), '../mongo_mapper/shim.rb') - -class Admin - include MongoMapper::Document - - key :username, String - timestamps! - - include SharedAdmin - include Shim - -end diff --git a/test/rails_app/app/mongo_mapper_active_model/user.rb b/test/rails_app/app/mongo_mapper_active_model/user.rb deleted file mode 100644 index 315cf35..0000000 --- a/test/rails_app/app/mongo_mapper_active_model/user.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'shared_user' -require File.join(File.dirname(__FILE__), '../mongo_mapper/shim.rb') - -class User - include MongoMapper::Document - - key :username, String - key :facebook_token, String - timestamps! - - include SharedUser - include Shim -end diff --git a/test/test_helper.rb b/test/test_helper.rb index ad8daaf..159cfc0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,19 +8,20 @@ require "rails/test_help" require "orm/#{DEVISE_ORM}" -MongoMapper.connection = Mongo::Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost') -MongoMapper.database = 'mm-devise-db' - I18n.load_path << "#{DEVISE_PATH}/test/support/locale/en.yml" -require 'mocha' +require 'mocha' +require 'webrat' Webrat.configure do |config| config.mode = :rails config.open_error_files = false end -#Devise::Oauth.test_mode! - # Add support to load paths so we can overwrite broken webrat setup $:.unshift "#{DEVISE_PATH}/test/support" Dir["#{DEVISE_PATH}/test/support/**/*.rb"].each { |f| require f } + +# For generators +require "rails/generators/test_case" +require "generators/devise/install_generator" +require "generators/devise/views_generator"