Skip to content

Commit

Permalink
Merge pull request #111 from omniauth/orm_specs
Browse files Browse the repository at this point in the history
Add missing ORM specs and fix bugs discovered
  • Loading branch information
pboling authored Mar 24, 2021
2 parents 9f55885 + 9b0454e commit a53dc1d
Show file tree
Hide file tree
Showing 33 changed files with 660 additions and 342 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
if: matrix.ruby == '2.7' && github.event_name != 'pull_request'
continue-on-error: ${{ matrix.allow_failures != 'false' }}
- name: Run tests
run: bundle exec rake test
run: bundle exec rake
- name: CodeClimate Post-build Notification
run: cc-test-reporter after-build
if: matrix.ruby == '2.7' && github.event_name != 'pull_request' && always()
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/pkg/
/spec/reports/
/tmp/
/rethinkdb_data

*.gem

Expand Down
8 changes: 8 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ Sequel/SaveChanges:

Lint/UselessMethodDefinition:
Enabled: false

RSpec/FilePath:
Include:
- spec
- spec_orms

RSpec/BeforeAfterAll:
Enabled: false
73 changes: 26 additions & 47 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-03-21 02:34:29 UTC using RuboCop version 1.11.0.
# on 2021-03-24 02:21:52 UTC using RuboCop version 1.11.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -13,25 +13,18 @@ Gemspec/RequiredRubyVersion:
Exclude:
- 'omniauth-identity.gemspec'

# Offense count: 1
# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
Lint/ConstantDefinitionInBlock:
Exclude:
- 'spec/omniauth/identity/models/active_record_spec.rb'

# Offense count: 1
# Configuration parameters: AllowComments.
Lint/EmptyClass:
Exclude:
- 'spec/omniauth/identity/secure_password_spec.rb'

# Offense count: 1
Lint/NestedMethodDefinition:
Lint/MissingSuper:
Exclude:
- 'lib/omniauth/identity/secure_password.rb'

# Offense count: 1
# Offense count: 2
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 30
Expand All @@ -40,14 +33,14 @@ Metrics/AbcSize:
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
# IgnoredMethods: refine
Metrics/BlockLength:
Max: 28
Max: 32

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 145

# Offense count: 7
# Offense count: 9
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 20
Expand Down Expand Up @@ -82,44 +75,25 @@ Naming/PredicateName:
- 'spec/**/*'
- 'lib/omniauth/identity/secure_password.rb'

# Offense count: 7
# Offense count: 6
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/omniauth/identity/model_spec.rb'
- 'spec/omniauth/strategies/identity_spec.rb'
- 'spec/support/shared_contexts/persistable_model.rb'

# Offense count: 1
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
- 'spec/omniauth/identity/model_spec.rb'
- 'spec/support/shared_contexts/instance_with_instance_methods.rb'

# Offense count: 3
RSpec/ExpectInHook:
Exclude:
- 'spec/omniauth/strategies/identity_spec.rb'

# Offense count: 8
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
# Include: **/*_spec*rb*, **/spec/**/*
RSpec/FilePath:
Exclude:
- 'spec/omniauth/identity/model_spec.rb'
- 'spec/omniauth/identity/models/active_record_spec.rb'
- 'spec/omniauth/identity/models/couch_potato_spec.rb'
- 'spec/omniauth/identity/models/mongoid_spec.rb'
- 'spec/omniauth/identity/models/no_brainer_spec.rb'
- 'spec/omniauth/identity/models/sequel_spec.rb'
- 'spec/omniauth/identity/secure_password_spec.rb'
- 'spec/omniauth/strategies/identity_spec.rb'

# Offense count: 1
RSpec/LeakyConstantDeclaration:
Exclude:
- 'spec/omniauth/identity/models/active_record_spec.rb'

# Offense count: 8
# Configuration parameters: .
# SupportedStyles: have_received, receive
Expand All @@ -135,13 +109,11 @@ RSpec/MultipleExpectations:
RSpec/MultipleMemoizedHelpers:
Max: 8

# Offense count: 44
# Offense count: 1
# Configuration parameters: IgnoreSharedExamples.
RSpec/NamedSubject:
Exclude:
- 'spec/omniauth/identity/model_spec.rb'
- 'spec/omniauth/identity/models/couch_potato_spec.rb'
- 'spec/omniauth/identity/models/mongoid_spec.rb'
- 'spec_orms/mongoid_spec.rb'

# Offense count: 12
RSpec/NestedGroups:
Expand All @@ -152,27 +124,28 @@ RSpec/StubbedMock:
Exclude:
- 'spec/omniauth/strategies/identity_spec.rb'

# Offense count: 22
# Offense count: 5
RSpec/SubjectStub:
Exclude:
- 'spec/omniauth/identity/model_spec.rb'
- 'spec/omniauth/identity/models/active_record_spec.rb'
- 'spec/omniauth/identity/models/couch_potato_spec.rb'
- 'spec/omniauth/identity/models/mongoid_spec.rb'
- 'spec/omniauth/identity/models/sequel_spec.rb'
- 'spec_orms/couch_potato_spec.rb'
- 'spec_orms/mongoid_spec.rb'
- 'spec_orms/nobrainer_spec.rb'

# Offense count: 4
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
- 'spec/omniauth/identity/model_spec.rb'
- 'spec/omniauth/strategies/identity_spec.rb'
- 'spec/support/shared_contexts/model_with_class_methods.rb'

# Offense count: 1
Rake/Desc:
Exclude:
- 'Rakefile'

# Offense count: 7
# Offense count: 10
Style/Documentation:
Exclude:
- '**/*.md'
Expand All @@ -184,24 +157,30 @@ Style/Documentation:
- 'lib/omniauth/identity/secure_password.rb'
- 'spec/omniauth/identity/secure_password_spec.rb'

# Offense count: 5
# Offense count: 4
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/omniauth/identity/model.rb'
- 'lib/omniauth/identity/secure_password.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/IfUnlessModifier:
Exclude:
- 'lib/omniauth/strategies/identity.rb'

# Offense count: 1
# Configuration parameters: AllowedMethods.
# AllowedMethods: respond_to_missing?
Style/OptionalBooleanParameter:
Exclude:
- 'lib/omniauth/identity/model.rb'

# Offense count: 1
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
# IgnoredPatterns: (?-mix:^\#)
Layout/LineLength:
Max: 123
Max: 138
4 changes: 4 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# frozen_string_literal: true

SimpleCov.start do
add_filter '/.github/'
add_filter '/coverage/'
add_filter '/rethinkdb_data/'
add_filter '/spec/'
add_filter '/spec_orms/'
add_filter '/vendor/bundle/'
end
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.0.7] - 2021-03-23

### Fixed

- \[ActiveRecord\] Fixed [#110](https://github.com/omniauth/omniauth-identity/issues/110) which prevented `OmniAuth::Identity::Models::ActiveRecord`-based records from saving.
- \[CouchPotato\] Fixed `OmniAuth::Identity::Models::CouchPotato`'s `#save`.
- \[Sequel\] Fixed `OmniAuth::Identity::Models::Sequel`'s `#save`.
- \[Model\] Only define `::create`, `#save`, and `#persisted?` when not already defined.
- \[Model\] Restore original `info` functionality which set `name` based on `first_name`, `last_name`, or `nickname`

### Changed

- Upgraded to a newer `OmniAuth::Identity::SecurePassword` ripped from [Rails 6-1-stable](https://github.com/rails/rails/blob/6-1-stable/activemodel/lib/active_model/secure_password.rb)
- Aeons ago the original was ripped from Rails 3.1, and frozen in time.
While writing specs, it was discovered to be incompatible with this gem's Sequel adapter.
- Specs validate that the new version does work.
In any case, the ripped version is only used when the `has_secure_password` macro is not yet defined in the class.

### Added

- New specs to cover real use cases and implementations of each ORM model adapter that ships with the gem:
- ActiveRecord (Polyglot - Many Relational Databases)
- Sequel (Polyglot - Many Relational Databases)
- CouchPotato (CouchDB)
- Mongoid (MongoDB)
- NoBrainer (RethinkDB)

## [3.0.6] - 2021-03-20

### Fixed
Expand Down
13 changes: 9 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ group :documentation do
end

group :development, :test do
# ORMs
if ruby_version < Gem::Version.new('2.5.0')
gem 'activerecord', '~> 5' # rails 5 works with Ruby 2.4
gem 'activerecord', '~> 5', require: false # rails 5 works with Ruby 2.4
else
gem 'activerecord', '~> 6' # rails 6 requires Ruby 2.5 or later
gem 'activerecord', '~> 6', require: false # rails 6 requires Ruby 2.5 or later
end
gem 'anonymous_active_record', '~> 1', require: false
gem 'couch_potato', github: 'langalex/couch_potato', require: false
gem 'mongoid', '~> 7', require: false
gem 'mongoid-rspec', github: 'mongoid/mongoid-rspec', require: false
gem 'nobrainer', '~> 0', require: false
gem 'sequel', '~> 5', require: false

if ruby_version >= Gem::Version.new('2.4')
# No need to run byebug / pry on earlier versions
Expand All @@ -44,12 +51,10 @@ group :development, :test do
gem 'simplecov', '~> 0.21', platform: :mri
end

gem 'couch_potato', github: 'langalex/couch_potato'
gem 'growl'
gem 'guard'
gem 'guard-bundler'
gem 'guard-rspec'
gem 'mongoid-rspec', github: 'mongoid/mongoid-rspec'
gem 'rb-fsevent'
end

Expand Down
60 changes: 52 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ Just include `OmniAuth::Identity::Models::Sequel` mixin, and specify
whatever else you will need.

```ruby
class SequelTestIdentity < Sequel::Model
include OmniAuth::Identity::Models::Sequel
class SequelTestIdentity < Sequel::Model(:identities)
include ::OmniAuth::Identity::Models::Sequel
auth_key :email
# whatever else you want!
end
Expand All @@ -108,8 +108,8 @@ fields that you will need.

```ruby
class Identity
include Mongoid::Document
include OmniAuth::Identity::Models::Mongoid
include ::Mongoid::Document
include ::OmniAuth::Identity::Models::Mongoid

field :email, type: String
field :name, type: String
Expand All @@ -124,8 +124,9 @@ fields that you will need.

```ruby
class Identity
include CouchPotato::Persistence
include OmniAuth::Identity::Models::CouchPotatoModule
# NOTE: CouchPotato::Persistence must be included before OmniAuth::Identity::Models::CouchPotatoModule
include ::CouchPotato::Persistence
include ::OmniAuth::Identity::Models::CouchPotatoModule

property :email
property :password_digest
Expand All @@ -147,8 +148,8 @@ fields that you will need.

```ruby
class Identity
include NoBrainer::Document
include OmniAuth::Identity::Models::NoBrainer
include ::NoBrainer::Document
include ::OmniAuth::Identity::Models::NoBrainer

auth_key :email
end
Expand Down Expand Up @@ -265,6 +266,49 @@ option :locate_conditions, ->(req) { { model.auth_key => req['auth_key'] } }

Please contribute some documentation if you have the gumption! The maintainer's time is limited, and sometimes the authors of PRs with new options don't update the _this_ readme. 😭

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am ‘Added some feature’`)
4. Push to the branch (`git push origin my-new-feature`)
5. Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
- NOTE: In order to run *all* the tests you will need to have the following databases installed, configured, and running.
1. [RethinkDB](https://rethinkdb.com), an open source, real-time, web database, [installed](https://rethinkdb.com/docs/install/) and [running](https://rethinkdb.com/docs/start-a-server/), e.g.
```bash
brew install rethinkdb
rethinkdb
```
2. [MongoDB](https://docs.mongodb.com/manual/administration/install-community/)
```bash
brew tap mongodb/brew
brew install [email protected]
mongod --config /usr/local/etc/mongod.conf
```
3. [CouchDB](https://couchdb.apache.org) (download the .app)
To run all tests on all databases:
```bash
bundle exec rake
```
To run a specific DB:
```bash
# CouchDB / CouchPotato
bundle exec rspec spec spec_orms --tag 'couchdb'
# ActiveRecord and Sequel, as they both use the in-memory SQLite driver.
bundle exec rspec spec spec_orms --tag 'sqlite3'
# NOTE - mongoid and nobrainer specs can't be isolated with "tag" because it still loads everything,
# and the two libraries are fundamentally incompatible.
# MongoDB / Mongoid
bundle exec rspec spec_orms/mongoid_spec.rb
# RethinkDB / NoBrainer
bundle exec rspec spec_orms/nobrainer_spec.rb
```
6. Create new Pull Request

## License

MIT License. See LICENSE for details.
Expand Down
Loading

0 comments on commit a53dc1d

Please sign in to comment.