Skip to content

Commit

Permalink
Extend doorkeeper 3 with its extracted ORMs
Browse files Browse the repository at this point in the history
doorkeeper 3 has not been released yet, and will be when its ORMs are
successfully extracted and tested into this project.

This PR extends doorkeeper with the ORM specifics for mongoid and
mongomapper.

To test it, it loads doorkeeper as a submodule, copy its test suite into
this project, configures the ORMs according to the matrix defined in
`.travis.yml` file, and run the test suite with each.

Renames project from `doorkeeper-orm` to `doorkeeper-mongodb`.
  • Loading branch information
tute committed May 5, 2015
1 parent b5d4faf commit f4687f7
Show file tree
Hide file tree
Showing 84 changed files with 329 additions and 1,429 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,3 +12,4 @@ spec/generators/tmp
.rvmrc
*.swp
.idea
spec
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "doorkeeper"]
path = doorkeeper
url = https://github.com/doorkeeper-gem/doorkeeper.git
3 changes: 3 additions & 0 deletions .hound.yml
Expand Up @@ -4,3 +4,6 @@ LineLength:

StringLiterals:
Enabled: false

TrailingBlankLines:
Enabled: true
39 changes: 34 additions & 5 deletions .travis.yml
@@ -1,12 +1,41 @@
language: ruby
sudo: false
cache: bundler

rvm:
- 1.9.3
- 2.0
- 2.1
- 2.2

env:
- orm=mongoid2
- orm=mongoid3
- orm=mongoid4
- orm=mongo_mapper
- rails=3.2.0
- rails=4.1.0
- rails=4.2.0

gemfile:
- Gemfile
- gemfiles/Gemfile.mongoid2.rb
- gemfiles/Gemfile.mongoid3.rb
- gemfiles/Gemfile.mongoid4.rb
- gemfiles/Gemfile.mongo_mapper.rb

services:
- mongodb

matrix:
exclude:
- env: rails=3.2.0
rvm: 2.2

- gemfile: gemfiles/Gemfile.mongoid2.rb
env: rails=4.1.0
- gemfile: gemfiles/Gemfile.mongoid2.rb
env: rails=4.2.0

- gemfile: gemfiles/Gemfile.mongoid3.rb
env: rails=4.1.0
- gemfile: gemfiles/Gemfile.mongoid3.rb
env: rails=4.2.0

- gemfile: gemfiles/Gemfile.mongoid4.rb
env: rails=3.2.0
45 changes: 45 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,45 @@
# Contributing

We love pull requests from everyone. By participating in this project, you agree
to abide by the thoughtbot [code of conduct].

[code of conduct]: https://thoughtbot.com/open-source-code-of-conduct

Fork, then clone the repo:

git clone git@github.com:your-username/doorkeeper-mongodb.git

Set up Ruby dependencies via Bundler

bundle install

Make sure the tests pass:

rake

Make your change.
Write tests.
Follow our [style guide][style].
Make the tests pass:

[style]: https://github.com/thoughtbot/guides/tree/master/style

rake

Write a [good commit message][commit].
Push to your fork.
[Submit a pull request][pr].

[commit]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
[pr]: https://github.com/doorkeeper-gem/doorkeeper-mongodb/compare/

If [Hound] catches style violations,
fix them.

[hound]: https://houndci.com

Wait for us.
We try to at least comment on pull requests within one business day.
We may suggest changes.

Thank you for your contribution!
28 changes: 4 additions & 24 deletions Gemfile
@@ -1,28 +1,8 @@
source "https://rubygems.org"
ENV['rails'] ||= '4.2.0'

gem 'doorkeeper', github: 'jasl/doorkeeper', branch: 'extract-orm-specifics'
source 'https://rubygems.org'

# Defaults. For supported versions check .travis.yml
ENV['orm'] ||= 'mongoid4'
ENV['rails'] ||= ENV['orm'] == 'mongoid4' ? '~> 4.1.2' : '~> 3.2.13'

gem 'rails', ENV['rails']

case ENV['orm']
when 'active_record'
gem 'activerecord'

when 'mongoid2'
gem 'mongoid', '~> 2'

when 'mongoid3'
gem 'mongoid', '~> 3'

when 'mongoid4'
gem 'mongoid', '~> 4'

when 'mongo_mapper'
gem 'mongo_mapper', '~> 0'
end
gem 'rails', "~> #{ENV['rails']}"
gem "doorkeeper"

gemspec
58 changes: 48 additions & 10 deletions README.md
@@ -1,16 +1,54 @@
# Doorkeeper bundle
# doorkeeper-mongodb extension

====
## Installation

Doorkeeper's extracted ORM specifics.
doorkeeper-mongodb provides doorkeeper support to MongoMapper, Mongoid 2, 3 and 4.
To start using it, add to your Gemfile:

including:
``` ruby
gem 'doorkeeper-mongodb'
```

- Mongoid2
- Mongoid3
- Mongoid4
- Mongo mapper
Run [doorkeeper’s installation generator]:

### License
rails generate doorkeeper:install

MIT.
[doorkeeper’s installation generator]: https://github.com/doorkeeper-gem/doorkeeper#installation

This will install the doorkeeper initializer into
`config/initializers/doorkeeper.rb`.

Set the ORM configuration:

``` ruby
Doorkeeper.configure do
orm :mongoid2 # or :mongoid3, :mongoid4, :mongo_mapper
end
```

### Mongoid indexes

Make sure you create indexes for doorkeeper models. You can do this either by
running `rake db:mongoid:create_indexes` or (if you're using Mongoid 2) by
adding `autocreate_indexes: true` to your `config/mongoid.yml`


### MongoMapper indexes

Generate the `db/indexes.rb` file and create indexes for the doorkeeper models:

rails generate doorkeeper:mongo_mapper:indexes
rake db:index


## Tests

To run tests, clone this repository and run `rake`. It will copy and run
doorkeeper’s original test suite, after configuring the ORM according to the
variables defined in `.travis.yml` file.


---

Please refer to https://github.com/doorkeeper-gem/doorkeeper for instructions on
doorkeeper’s project.
38 changes: 21 additions & 17 deletions Rakefile
@@ -1,24 +1,28 @@
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end

require 'bundler/setup'
require 'rspec/core/rake_task'

require 'rdoc/task'
desc 'Default: run specs.'
task :default => :spec

RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'DoorkeeperOrms'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('lib/**/*.rb')
task :load_doorkeeper do
`git submodule init`
`git submodule update`
`cp -r doorkeeper/spec .`
`bundle exec rspec`
end

Bundler::GemHelper.install_tasks
RSpec::Core::RakeTask.new(:spec) do |config|
config.verbose = false
end

desc "Run all specs"
RSpec::Core::RakeTask.new(:spec)
Rake::Task["spec"].enhance [:load_doorkeeper]

desc 'Default: run specs.'
task :default => :spec
namespace :doorkeeper do
desc "Install doorkeeper in dummy app"
task :install do
cd 'spec/dummy'
system 'bundle exec rails g doorkeeper:install --force'
end
end

Bundler::GemHelper.install_tasks
1 change: 1 addition & 0 deletions doorkeeper
Submodule doorkeeper added at 0b0031
32 changes: 32 additions & 0 deletions doorkeeper-mongodb.gemspec
@@ -0,0 +1,32 @@
$:.push File.expand_path("../lib", __FILE__)

# Maintain your gem's version:
require "doorkeeper-mongodb/version"

# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "doorkeeper-mongodb"
s.version = DoorkeeperMongodb::VERSION
s.authors = ["jasl"]
s.email = ["jasl9187@hotmail.com"]
s.homepage = "http://github.com/doorkeeper-gem/doorkeeper-mongodb"
s.summary = "Doorkeeper mongoid 2, 3, 4 and mongo_mapper ORMs"
s.description = "Doorkeeper mongoid 2, 3, 4 and mongo_mapper ORMs"
s.license = "MIT"

s.files = Dir["lib/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
s.test_files = Dir["spec/**/*"]

s.add_dependency "doorkeeper", "~> 2.2.0"

s.add_development_dependency "sqlite3", "~> 1.3.5"
s.add_development_dependency "rspec-rails", "~> 3.2.0"
s.add_development_dependency "capybara", "~> 2.3.0"
s.add_development_dependency "generator_spec", "~> 0.9.0"
s.add_development_dependency "factory_girl", "~> 4.5.0"
s.add_development_dependency "timecop", "~> 0.7.0"
s.add_development_dependency "database_cleaner", "~> 1.3.0"
s.add_development_dependency "rspec-activemodel-mocks", "~> 1.0.0"
s.add_development_dependency "bcrypt-ruby", "~> 3.0.1"
s.add_development_dependency "pry", "~> 0.10.0"
end
26 changes: 0 additions & 26 deletions doorkeeper-orms.gemspec

This file was deleted.

8 changes: 8 additions & 0 deletions gemfiles/Gemfile.common.rb
@@ -0,0 +1,8 @@
ENV['rails'] ||= '4.2.0'

source 'https://rubygems.org'

gem 'rails', "~> #{ENV['rails']}"
gem "doorkeeper"

gemspec path: '../'
5 changes: 5 additions & 0 deletions gemfiles/Gemfile.mongo_mapper.rb
@@ -0,0 +1,5 @@
gemfile = 'gemfiles/Gemfile.common.rb'
instance_eval IO.read(gemfile), gemfile

gem 'mongo_mapper'
gem 'bson_ext'
5 changes: 5 additions & 0 deletions gemfiles/Gemfile.mongoid2.rb
@@ -0,0 +1,5 @@
gemfile = 'gemfiles/Gemfile.common.rb'
instance_eval IO.read(gemfile), gemfile

gem 'mongoid', '~> 2'
gem 'bson_ext'
4 changes: 4 additions & 0 deletions gemfiles/Gemfile.mongoid3.rb
@@ -0,0 +1,4 @@
gemfile = 'gemfiles/Gemfile.common.rb'
instance_eval IO.read(gemfile), gemfile

gem 'mongoid', '~> 3'
4 changes: 4 additions & 0 deletions gemfiles/Gemfile.mongoid4.rb
@@ -0,0 +1,4 @@
gemfile = 'gemfiles/Gemfile.common.rb'
instance_eval IO.read(gemfile), gemfile

gem 'mongoid', '~> 4'
6 changes: 4 additions & 2 deletions lib/doorkeeper_bundle.rb → lib/doorkeeper-mongodb.rb
@@ -1,7 +1,9 @@
require 'doorkeeper/orm/mongo_mapper'
require 'doorkeeper-mongodb/version'

require 'doorkeeper/orm/mongoid2'
require 'doorkeeper/orm/mongoid3'
require 'doorkeeper/orm/mongoid4'
require 'doorkeeper/orm/mongo_mapper'

module DoorkeeperOrms
module DoorkeeperMongodb
end
3 changes: 3 additions & 0 deletions lib/doorkeeper-mongodb/version.rb
@@ -0,0 +1,3 @@
module DoorkeeperMongodb
VERSION = "3.0.0"
end
3 changes: 0 additions & 3 deletions lib/doorkeeper-orms/version.rb

This file was deleted.

8 changes: 8 additions & 0 deletions lib/doorkeeper/orm/mongo_mapper.rb
Expand Up @@ -6,6 +6,14 @@ def self.initialize_models!
require 'doorkeeper/orm/mongo_mapper/access_token'
require 'doorkeeper/orm/mongo_mapper/application'
end

def self.initialize_application_owner!
require 'doorkeeper/models/concerns/ownership'

Doorkeeper::Application.send :include, Doorkeeper::Models::Ownership
end

def self.check_requirements!(_config); end
end
end
end

0 comments on commit f4687f7

Please sign in to comment.