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.
  • Loading branch information
tute committed May 5, 2015
1 parent b5d4faf commit 049e71c
Show file tree
Hide file tree
Showing 81 changed files with 302 additions and 1,404 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-orms.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-orms/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-orms extension

====
## Installation

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

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

- 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 365c10
16 changes: 11 additions & 5 deletions doorkeeper-orms.gemspec
Expand Up @@ -10,17 +10,23 @@ Gem::Specification.new do |s|
s.authors = ["jasl"]
s.email = ["jasl9187@hotmail.com"]
s.homepage = "http://github.com/doorkeeper-gem/doorkeeper-orms"
s.summary = "Doorkeeper with extracted ORM specifics, including mongoid 2-4 and mongo_mapper."
s.description = "Doorkeeper with extracted ORM specifics, including mongoid 2-4 and mongo_mapper"
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 "rails", ">= 3.1"
s.add_dependency "doorkeeper", "~> 2.2.0"

s.add_development_dependency "rspec-rails", "~> 2.99.0"
s.add_development_dependency "factory_girl", "~> 4.4.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
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'
2 changes: 1 addition & 1 deletion lib/doorkeeper-orms/version.rb
@@ -1,3 +1,3 @@
module DoorkeeperOrms
VERSION = "0.0.1"
VERSION = "3.0.0"
end
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
9 changes: 4 additions & 5 deletions lib/doorkeeper/orm/mongo_mapper/access_grant.rb
@@ -1,6 +1,9 @@
module Doorkeeper
class AccessGrant
include MongoMapper::Document

include AccessGrantMixin

safe
timestamps!

Expand All @@ -9,14 +12,10 @@ class AccessGrant
key :resource_owner_id, ObjectId
key :application_id, ObjectId
key :token, String
key :scopes, String
key :expires_in, Integer
key :redirect_uri, String
key :revoked_at, DateTime
key :scopes, String

def scopes=(value)
write_attribute :scopes, value if value.present?
end

def self.create_indexes
ensure_index :token, unique: true
Expand Down

0 comments on commit 049e71c

Please sign in to comment.