Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #7 from bmarini/v-0-9-support

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

0 notes on commit 692b245

Please sign in to comment.
Something went wrong with that request. Please try again.