Skip to content

Commit

Permalink
Merge branch 'fix-prevent-load-of-mongoid-adapter-with-rails-6'
Browse files Browse the repository at this point in the history
When I use a version of Ruby and a version of Rails that are not
compatible with the use of Monogoid
I want to be able to run the test suite as usual
Even if it means not loading the Mongoid adapter code
Because I am not using it anyway
  • Loading branch information
gonzalo-bulnes committed Aug 20, 2019
2 parents d7cf181 + 13dc9eb commit ad3a592
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ gemfile:
- gemfiles/ruby_1.9.3_rails_3.2.gemfile
rvm:
- "1.9.3"
- "2.2.2"
- "2.6.3"
- ruby-head
matrix:
allow_failures:
Expand All @@ -18,7 +18,7 @@ matrix:
gemfile: gemfiles/rails_5_devise_4.gemfile
- rvm: 1.9.3
gemfile: gemfiles/rails_4_devise_3.gemfile
- rvm: 2.2.2
- rvm: 2.6.3
gemfile: gemfiles/ruby_1.9.3_rails_3.2.gemfile
- rvm: ruby-head
gemfile: gemfiles/rails_4_devise_3.gemfile
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ Simple Token Authentication
[![Gem Version](https://badge.fury.io/rb/simple_token_authentication.svg)](http://badge.fury.io/rb/simple_token_authentication)
[![Build Status](https://travis-ci.org/gonzalo-bulnes/simple_token_authentication.svg?branch=master)](https://travis-ci.org/gonzalo-bulnes/simple_token_authentication)
[![Code Climate](https://codeclimate.com/github/gonzalo-bulnes/simple_token_authentication.svg)](https://codeclimate.com/github/gonzalo-bulnes/simple_token_authentication)
[![Dependency Status](https://gemnasium.com/gonzalo-bulnes/simple_token_authentication.svg)](https://gemnasium.com/gonzalo-bulnes/simple_token_authentication)
[![security](https://hakiri.io/github/gonzalo-bulnes/simple_token_authentication/master.svg)](https://hakiri.io/github/gonzalo-bulnes/simple_token_authentication/master)
[![Security](https://hakiri.io/github/gonzalo-bulnes/simple_token_authentication/master.svg)](https://hakiri.io/github/gonzalo-bulnes/simple_token_authentication/master)
[![Inline docs](http://inch-ci.org/github/gonzalo-bulnes/simple_token_authentication.svg?branch=master)](http://inch-ci.org/github/gonzalo-bulnes/simple_token_authentication)

Token authentication support has been removed from [Devise][devise] for security reasons. In [this gist][original-gist], Devise's [José Valim][josevalim] explains how token authentication should be performed in order to remain safe.
Expand Down
23 changes: 15 additions & 8 deletions lib/simple_token_authentication/adapters/mongoid_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
require 'mongoid'
require 'simple_token_authentication/adapter'
if Module.const_defined?('ActiveModel') &&
ActiveModel.const_defined?('Serializers') &&
ActiveModel::Serializers.const_defined?('Xml')
# As far as I know Mongoid doesn't support Rails 6
# Please let me know if this isn't true when you read it!

module SimpleTokenAuthentication
module Adapters
class MongoidAdapter
extend SimpleTokenAuthentication::Adapter
require 'mongoid'
require 'simple_token_authentication/adapter'

def self.base_class
::Mongoid::Document
module SimpleTokenAuthentication
module Adapters
class MongoidAdapter
extend SimpleTokenAuthentication::Adapter

def self.base_class
::Mongoid::Document
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
require 'spec_helper'
require 'simple_token_authentication/adapters/mongoid_adapter'
if Module.const_defined?('ActiveModel') &&
ActiveModel.const_defined?('Serializers') &&
ActiveModel::Serializers.const_defined?('Xml')
# As far as I know Mongoid doesn't support Rails 6
# Please let me know if this isn't true when you read it!

describe 'SimpleTokenAuthentication::Adapters::MongoidAdapter' do
require 'spec_helper'
require 'simple_token_authentication/adapters/mongoid_adapter'

before(:each) do
stub_const('Mongoid', Module.new)
stub_const('Mongoid::Document', double())
describe 'SimpleTokenAuthentication::Adapters::MongoidAdapter' do

@subject = SimpleTokenAuthentication::Adapters::MongoidAdapter
end
before(:each) do
stub_const('Mongoid', Module.new)
stub_const('Mongoid::Document', double())

@subject = SimpleTokenAuthentication::Adapters::MongoidAdapter
end

it_behaves_like 'an adapter'
it_behaves_like 'an adapter'

describe '.base_class' do
describe '.base_class' do

it 'is Mongoid::Document', private: true do
expect(@subject.base_class).to eq Mongoid::Document
it 'is Mongoid::Document', private: true do
expect(@subject.base_class).to eq Mongoid::Document
end
end
end
end
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

require 'action_controller'
require 'active_record'
require 'mongoid'
require 'active_support'

require 'simple_token_authentication'
Expand Down

0 comments on commit ad3a592

Please sign in to comment.