Permalink
Browse files

Loading and passing some tests with mongo_mapper

  • Loading branch information...
1 parent c89ad7e commit 84b4d59948ad944373ea7b7ee7cc7bdec016822d @kbighorse kbighorse committed Oct 12, 2011
Showing with 10,487 additions and 10 deletions.
  1. +1 −1 .gitignore
  2. +1 −0 Gemfile
  3. +9 −2 Gemfile.lock
  4. +5 −0 lib/sorcery.rb
  5. +19 −2 lib/sorcery/model.rb
  6. +70 −0 lib/sorcery/model/adapters/mongo_mapper.rb
  7. +4 −0 spec/rails3_mongo_mapper/.gitignore
  8. +1 −0 spec/rails3_mongo_mapper/.rspec
  9. +15 −0 spec/rails3_mongo_mapper/Gemfile
  10. +158 −0 spec/rails3_mongo_mapper/Gemfile.lock
  11. +11 −0 spec/rails3_mongo_mapper/Rakefile
  12. +108 −0 spec/rails3_mongo_mapper/app/controllers/application_controller.rb
  13. +2 −0 spec/rails3_mongo_mapper/app/helpers/application_helper.rb
  14. +25 −0 spec/rails3_mongo_mapper/app/mailers/sorcery_mailer.rb
  15. +7 −0 spec/rails3_mongo_mapper/app/models/authentication.rb
  16. +5 −0 spec/rails3_mongo_mapper/app/models/user.rb
  17. +14 −0 spec/rails3_mongo_mapper/app/views/layouts/application.html.erb
  18. +17 −0 spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.html.erb
  19. +9 −0 spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.text.erb
  20. +17 −0 spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.html.erb
  21. +9 −0 spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.text.erb
  22. +16 −0 spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.html.erb
  23. +8 −0 spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.text.erb
  24. +4 −0 spec/rails3_mongo_mapper/config.ru
  25. +51 −0 spec/rails3_mongo_mapper/config/application.rb
  26. +13 −0 spec/rails3_mongo_mapper/config/boot.rb
  27. +5 −0 spec/rails3_mongo_mapper/config/environment.rb
  28. +30 −0 spec/rails3_mongo_mapper/config/environments/development.rb
  29. 0 spec/rails3_mongo_mapper/config/environments/in_memory.rb
  30. +49 −0 spec/rails3_mongo_mapper/config/environments/production.rb
  31. +35 −0 spec/rails3_mongo_mapper/config/environments/test.rb
  32. +7 −0 spec/rails3_mongo_mapper/config/initializers/backtrace_silencers.rb
  33. +10 −0 spec/rails3_mongo_mapper/config/initializers/inflections.rb
  34. +5 −0 spec/rails3_mongo_mapper/config/initializers/mime_types.rb
  35. +2 −0 spec/rails3_mongo_mapper/config/initializers/mongo.rb
  36. +7 −0 spec/rails3_mongo_mapper/config/initializers/secret_token.rb
  37. +8 −0 spec/rails3_mongo_mapper/config/initializers/session_store.rb
  38. +5 −0 spec/rails3_mongo_mapper/config/locales/en.yml
  39. +59 −0 spec/rails3_mongo_mapper/config/routes.rb
  40. +23 −0 spec/rails3_mongo_mapper/db/schema.rb
  41. +7 −0 spec/rails3_mongo_mapper/db/seeds.rb
  42. 0 spec/rails3_mongo_mapper/lib/tasks/.gitkeep
  43. +26 −0 spec/rails3_mongo_mapper/public/404.html
  44. +26 −0 spec/rails3_mongo_mapper/public/422.html
  45. +26 −0 spec/rails3_mongo_mapper/public/500.html
  46. 0 spec/rails3_mongo_mapper/public/favicon.ico
  47. BIN spec/rails3_mongo_mapper/public/images/rails.png
  48. +2 −0 spec/rails3_mongo_mapper/public/javascripts/application.js
  49. +965 −0 spec/rails3_mongo_mapper/public/javascripts/controls.js
  50. +974 −0 spec/rails3_mongo_mapper/public/javascripts/dragdrop.js
  51. +1,123 −0 spec/rails3_mongo_mapper/public/javascripts/effects.js
  52. +6,001 −0 spec/rails3_mongo_mapper/public/javascripts/prototype.js
  53. +175 −0 spec/rails3_mongo_mapper/public/javascripts/rails.js
  54. +5 −0 spec/rails3_mongo_mapper/public/robots.txt
  55. 0 spec/rails3_mongo_mapper/public/stylesheets/.gitkeep
  56. +6 −0 spec/rails3_mongo_mapper/script/rails
  57. +130 −0 spec/rails3_mongo_mapper/spec/controller_spec.rb
  58. +2 −0 spec/rails3_mongo_mapper/spec/spec.opts
  59. +27 −0 spec/rails3_mongo_mapper/spec/spec_helper.orig.rb
  60. +55 −0 spec/rails3_mongo_mapper/spec/spec_helper.rb
  61. +9 −0 spec/rails3_mongo_mapper/spec/user_activation_spec.rb
  62. +8 −0 spec/rails3_mongo_mapper/spec/user_activity_logging_spec.rb
  63. +8 −0 spec/rails3_mongo_mapper/spec/user_brute_force_protection_spec.rb
  64. +8 −0 spec/rails3_mongo_mapper/spec/user_oauth_spec.rb
  65. +8 −0 spec/rails3_mongo_mapper/spec/user_remember_me_spec.rb
  66. +8 −0 spec/rails3_mongo_mapper/spec/user_reset_password_spec.rb
  67. +37 −0 spec/rails3_mongo_mapper/spec/user_spec.rb
  68. 0 spec/rails3_mongo_mapper/vendor/plugins/.gitkeep
  69. +7 −5 spec/rails3_mongoid/Gemfile.lock
View
@@ -37,7 +37,7 @@ pkg
#
# For TextMate
#*.tmproj
-#tmtags
+tmtags
#
# For emacs:
#*~
View
@@ -4,6 +4,7 @@ source "http://rubygems.org"
# gem "activesupport", ">= 2.3.5"
gem 'oauth', "~> 0.4.4"
gem 'oauth2', "~> 0.5.1"
+gem 'mongo_mapper'
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
View
@@ -43,7 +43,7 @@ GEM
faraday (0.7.4)
addressable (~> 2.2.6)
multipart-post (~> 1.1.0)
- rack (< 2, >= 1.1.0)
+ rack (>= 1.1.0, < 2)
git (1.2.5)
hike (1.2.1)
i18n (0.6.0)
@@ -61,6 +61,10 @@ GEM
mime-types (1.16)
mongo (1.3.1)
bson (>= 1.3.1)
+ mongo_mapper (0.9.2)
+ activemodel (~> 3.0)
+ activesupport (~> 3.0)
+ plucky (~> 0.3.8)
mongoid (2.2.0)
activemodel (~> 3.0)
mongo (~> 1.3)
@@ -71,6 +75,8 @@ GEM
oauth2 (0.5.1)
faraday (~> 0.7.4)
multi_json (~> 1.0.3)
+ plucky (0.3.8)
+ mongo (~> 1.3)
polyglot (0.3.2)
rack (1.3.3)
rack-cache (1.0.3)
@@ -127,7 +133,7 @@ GEM
sprockets (2.0.0)
hike (~> 1.2)
rack (~> 1.0)
- tilt (!= 1.3.0, ~> 1.1)
+ tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.4)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
@@ -148,6 +154,7 @@ DEPENDENCIES
bundler (~> 1.0.0)
jeweler (~> 1.5.2)
json (>= 1.5.1)
+ mongo_mapper
mongoid (~> 2.0)
oauth (~> 0.4.4)
oauth2 (~> 0.5.1)
View
@@ -5,6 +5,7 @@ module Model
module Adapters
autoload :ActiveRecord, 'sorcery/model/adapters/active_record'
autoload :Mongoid, 'sorcery/model/adapters/mongoid'
+ autoload :MongoMapper, 'sorcery/model/adapters/mongo_mapper'
end
module Submodules
autoload :UserActivation, 'sorcery/model/submodules/user_activation'
@@ -77,6 +78,10 @@ module Internal
end
end
+ if defined?(MongoMapper)
+ MongoMapper::Document.send(:plugin, Sorcery::Model::Adapters::MongoMapper)
+ end
+
require 'sorcery/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
require 'sorcery/sinatra' if defined?(Sinatra)
end
View
@@ -3,8 +3,8 @@ module Sorcery
# It should be included into the ORM base class.
# In the case of Rails this is usually ActiveRecord (actually, in that case, the plugin does this automatically).
#
- # When included it defines a single method: 'activate_sorcery!' which when called adds the other capabilities
- # to the class.
+ # When included it defines a single method: 'authenticates_with_sorcery!'
+ # which when called adds the other capabilities to the class.
# This method is also the place to configure the plugin in the Model layer.
module Model
def self.included(klass)
@@ -24,6 +24,9 @@ def authenticates_with_sorcery!
::Sorcery::Controller::Config.user_config.tap{|blk| blk.call(@sorcery_config) if blk}
init_mongoid_support! if defined?(Mongoid) and self.ancestors.include?(Mongoid::Document)
+ if defined?(MongoMapper) and self.ancestors.include?(MongoMapper::Document)
+ init_mongo_mapper_support!
+ end
init_orm_hooks!
@@ -62,6 +65,20 @@ def init_mongoid_support!
end
end
+ # defines mongo_mapper fields on the model class,
+ def init_mongo_mapper_support!
+ self.class_eval do
+ sorcery_config.username_attribute_names.each do |username|
+ key username, String
+ end
+ email_attribute = sorcery_config.email_attribute_name
+ username_attributes = sorcery_config.username_attribute_names
+ key sorcery_config.email_attribute_name, String unless username_attributes.include?(email_attribute)
+ key sorcery_config.crypted_password_attribute_name, String
+ key sorcery_config.salt_attribute_name, String
+ end
+ end
+
# add virtual password accessor and ORM callbacks.
def init_orm_hooks!
self.class_eval do
@@ -0,0 +1,70 @@
+module Sorcery
+ module Model
+ module Adapters
+ module MongoMapper
+ extend ActiveSupport::Concern
+
+ included do
+ include Sorcery::Model
+ end
+
+ module InstanceMethods
+ def increment(attr)
+ self.inc(attr,1)
+ end
+ end
+
+ module ClassMethods
+ def find_by_credentials(credentials)
+ @sorcery_config.username_attribute_names.each do |attribute|
+ @user = where(attribute => credentials[0]).first
+ break if @user
+ end
+ @user
+ end
+
+ # def find_by_provider_and_uid(provider, uid)
+ # @user_klass ||= ::Sorcery::Controller::Config.user_class.to_s.constantize
+ # where(@user_klass.sorcery_config.provider_attribute_name => provider, @user_klass.sorcery_config.provider_uid_attribute_name => uid).first
+ # end
+
+ def find_by_id(id)
+ find(id)
+ end
+
+ # def find_by_activation_token(token)
+ # where(sorcery_config.activation_token_attribute_name => token).first
+ # end
+ #
+ # def find_by_remember_me_token(token)
+ # where(sorcery_config.remember_me_token_attribute_name => token).first
+ # end
+ #
+ # def find_by_username(username)
+ # query = sorcery_config.username_attribute_names.map {|name| {name => username}}
+ # where(query).first
+ # end
+ #
+ # def transaction(&blk)
+ # tap(&blk)
+ # end
+ #
+ # def find_by_sorcery_token(token_attr_name, token)
+ # where(token_attr_name => token).first
+ # end
+ #
+ # def find_by_email(email)
+ # where(sorcery_config.email_attribute_name => email).first
+ # end
+ #
+ # def get_current_users
+ # config = sorcery_config
+ # where(config.last_activity_at_attribute_name.ne => nil) \
+ # .any_of({config.last_logout_at_attribute_name => nil},{config.last_activity_at_attribute_name.gt => config.last_logout_at_attribute_name}) \
+ # .and(config.last_activity_at_attribute_name.gt => config.activity_timeout.seconds.ago.utc.to_s(:db)).order_by([:_id,:asc])
+ # end
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,4 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/**/*
@@ -0,0 +1 @@
+--colour
@@ -0,0 +1,15 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.3'
+gem "sorcery", '>= 0.1.0', :path => '../../../'
+gem "mongo_mapper"
+gem "bson_ext", "~> 1.3"
+
+group :development, :test do
+ gem "rspec", "~> 2.5.0"
+ gem 'rspec-rails', "~> 2.5.0"
+ gem 'ruby-debug19'
+ gem 'simplecov', '>= 0.3.8', :require => false # Will install simplecov-html as a dependency
+ gem 'timecop'
+ gem 'pry'
+end
@@ -0,0 +1,158 @@
+PATH
+ remote: ../../../
+ specs:
+ sorcery (0.7.0)
+ bcrypt-ruby (~> 3.0.0)
+ oauth (~> 0.4.4)
+ oauth (~> 0.4.4)
+ oauth2 (~> 0.5.1)
+ oauth2 (~> 0.5.1)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.3)
+ actionpack (= 3.0.3)
+ mail (~> 2.2.9)
+ actionpack (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.13)
+ rack-test (~> 0.5.6)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ activesupport (3.0.3)
+ addressable (2.2.6)
+ archive-tar-minitar (0.5.2)
+ arel (2.0.10)
+ bcrypt-ruby (3.0.1)
+ bson (1.4.0)
+ bson_ext (1.4.0)
+ builder (2.1.2)
+ coderay (0.9.8)
+ columnize (0.3.4)
+ diff-lcs (1.1.3)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ faraday (0.7.5)
+ addressable (~> 2.2.6)
+ multipart-post (~> 1.1.3)
+ rack (>= 1.1.0, < 2)
+ i18n (0.6.0)
+ linecache19 (0.5.12)
+ ruby_core_source (>= 0.1.4)
+ mail (2.2.19)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ method_source (0.6.6)
+ ruby_parser (~> 2.0.5)
+ mime-types (1.16)
+ mongo (1.4.0)
+ bson (= 1.4.0)
+ mongo_mapper (0.9.2)
+ activemodel (~> 3.0)
+ activesupport (~> 3.0)
+ plucky (~> 0.3.8)
+ multi_json (1.0.3)
+ multipart-post (1.1.3)
+ oauth (0.4.5)
+ oauth2 (0.5.1)
+ faraday (~> 0.7.4)
+ multi_json (~> 1.0.3)
+ plucky (0.3.8)
+ mongo (~> 1.3)
+ polyglot (0.3.2)
+ pry (0.9.6.2)
+ coderay (~> 0.9.8)
+ method_source (~> 0.6.5)
+ ruby_parser (~> 2.0.5)
+ slop (~> 2.1.0)
+ rack (1.2.4)
+ rack-mount (0.6.14)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.3)
+ actionmailer (= 3.0.3)
+ actionpack (= 3.0.3)
+ activerecord (= 3.0.3)
+ activeresource (= 3.0.3)
+ activesupport (= 3.0.3)
+ bundler (~> 1.0)
+ railties (= 3.0.3)
+ railties (3.0.3)
+ actionpack (= 3.0.3)
+ activesupport (= 3.0.3)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.9.2)
+ rspec (2.5.0)
+ rspec-core (~> 2.5.0)
+ rspec-expectations (~> 2.5.0)
+ rspec-mocks (~> 2.5.0)
+ rspec-core (2.5.2)
+ rspec-expectations (2.5.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.5.0)
+ rspec-rails (2.5.0)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.5.0)
+ ruby-debug-base19 (0.11.25)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby_core_source (>= 0.1.4)
+ ruby-debug19 (0.11.6)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby-debug-base19 (>= 0.11.19)
+ ruby_core_source (0.1.5)
+ archive-tar-minitar (>= 0.5.2)
+ ruby_parser (2.0.6)
+ sexp_processor (~> 3.0)
+ sexp_processor (3.0.7)
+ simplecov (0.5.3)
+ multi_json (~> 1.0.3)
+ simplecov-html (~> 0.5.3)
+ simplecov-html (0.5.3)
+ slop (2.1.0)
+ thor (0.14.6)
+ timecop (0.3.5)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.30)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bson_ext (~> 1.3)
+ mongo_mapper
+ pry
+ rails (= 3.0.3)
+ rspec (~> 2.5.0)
+ rspec-rails (~> 2.5.0)
+ ruby-debug19
+ simplecov (>= 0.3.8)
+ sorcery (>= 0.1.0)!
+ timecop
@@ -0,0 +1,11 @@
+require 'rake'
+require 'rspec/core/rake_task'
+
+desc 'Default: Run all specs for a specific rails version.'
+task :default => :spec
+
+desc "Run all specs for a specific rails version"
+RSpec::Core::RakeTask.new(:spec) do |t|
+ t.pattern = '**/*_spec.rb'
+ t.rspec_opts = ["--options #{File.dirname(__FILE__)}/spec/spec.opts"]
+end
Oops, something went wrong.

0 comments on commit 84b4d59

Please sign in to comment.