Skip to content

Commit a53dc1d

Browse files
authored
Merge pull request #111 from omniauth/orm_specs
Add missing ORM specs and fix bugs discovered
2 parents 9f55885 + 9b0454e commit a53dc1d

33 files changed

+660
-342
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
if: matrix.ruby == '2.7' && github.event_name != 'pull_request'
4949
continue-on-error: ${{ matrix.allow_failures != 'false' }}
5050
- name: Run tests
51-
run: bundle exec rake test
51+
run: bundle exec rake
5252
- name: CodeClimate Post-build Notification
5353
run: cc-test-reporter after-build
5454
if: matrix.ruby == '2.7' && github.event_name != 'pull_request' && always()

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/pkg/
1212
/spec/reports/
1313
/tmp/
14+
/rethinkdb_data
1415

1516
*.gem
1617

.rubocop.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ Sequel/SaveChanges:
3232

3333
Lint/UselessMethodDefinition:
3434
Enabled: false
35+
36+
RSpec/FilePath:
37+
Include:
38+
- spec
39+
- spec_orms
40+
41+
RSpec/BeforeAfterAll:
42+
Enabled: false

.rubocop_todo.yml

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2021-03-21 02:34:29 UTC using RuboCop version 1.11.0.
3+
# on 2021-03-24 02:21:52 UTC using RuboCop version 1.11.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -13,25 +13,18 @@ Gemspec/RequiredRubyVersion:
1313
Exclude:
1414
- 'omniauth-identity.gemspec'
1515

16-
# Offense count: 1
17-
# Configuration parameters: AllowedMethods.
18-
# AllowedMethods: enums
19-
Lint/ConstantDefinitionInBlock:
20-
Exclude:
21-
- 'spec/omniauth/identity/models/active_record_spec.rb'
22-
2316
# Offense count: 1
2417
# Configuration parameters: AllowComments.
2518
Lint/EmptyClass:
2619
Exclude:
2720
- 'spec/omniauth/identity/secure_password_spec.rb'
2821

2922
# Offense count: 1
30-
Lint/NestedMethodDefinition:
23+
Lint/MissingSuper:
3124
Exclude:
3225
- 'lib/omniauth/identity/secure_password.rb'
3326

34-
# Offense count: 1
27+
# Offense count: 2
3528
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
3629
Metrics/AbcSize:
3730
Max: 30
@@ -40,14 +33,14 @@ Metrics/AbcSize:
4033
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
4134
# IgnoredMethods: refine
4235
Metrics/BlockLength:
43-
Max: 28
36+
Max: 32
4437

4538
# Offense count: 1
4639
# Configuration parameters: CountComments, CountAsOne.
4740
Metrics/ClassLength:
4841
Max: 145
4942

50-
# Offense count: 7
43+
# Offense count: 9
5144
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
5245
Metrics/MethodLength:
5346
Max: 20
@@ -82,44 +75,25 @@ Naming/PredicateName:
8275
- 'spec/**/*'
8376
- 'lib/omniauth/identity/secure_password.rb'
8477

85-
# Offense count: 7
78+
# Offense count: 6
8679
# Configuration parameters: Prefixes.
8780
# Prefixes: when, with, without
8881
RSpec/ContextWording:
8982
Exclude:
90-
- 'spec/omniauth/identity/model_spec.rb'
9183
- 'spec/omniauth/strategies/identity_spec.rb'
84+
- 'spec/support/shared_contexts/persistable_model.rb'
9285

9386
# Offense count: 1
9487
# Configuration parameters: Max.
9588
RSpec/ExampleLength:
9689
Exclude:
97-
- 'spec/omniauth/identity/model_spec.rb'
90+
- 'spec/support/shared_contexts/instance_with_instance_methods.rb'
9891

9992
# Offense count: 3
10093
RSpec/ExpectInHook:
10194
Exclude:
10295
- 'spec/omniauth/strategies/identity_spec.rb'
10396

104-
# Offense count: 8
105-
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
106-
# Include: **/*_spec*rb*, **/spec/**/*
107-
RSpec/FilePath:
108-
Exclude:
109-
- 'spec/omniauth/identity/model_spec.rb'
110-
- 'spec/omniauth/identity/models/active_record_spec.rb'
111-
- 'spec/omniauth/identity/models/couch_potato_spec.rb'
112-
- 'spec/omniauth/identity/models/mongoid_spec.rb'
113-
- 'spec/omniauth/identity/models/no_brainer_spec.rb'
114-
- 'spec/omniauth/identity/models/sequel_spec.rb'
115-
- 'spec/omniauth/identity/secure_password_spec.rb'
116-
- 'spec/omniauth/strategies/identity_spec.rb'
117-
118-
# Offense count: 1
119-
RSpec/LeakyConstantDeclaration:
120-
Exclude:
121-
- 'spec/omniauth/identity/models/active_record_spec.rb'
122-
12397
# Offense count: 8
12498
# Configuration parameters: .
12599
# SupportedStyles: have_received, receive
@@ -135,13 +109,11 @@ RSpec/MultipleExpectations:
135109
RSpec/MultipleMemoizedHelpers:
136110
Max: 8
137111

138-
# Offense count: 44
112+
# Offense count: 1
139113
# Configuration parameters: IgnoreSharedExamples.
140114
RSpec/NamedSubject:
141115
Exclude:
142-
- 'spec/omniauth/identity/model_spec.rb'
143-
- 'spec/omniauth/identity/models/couch_potato_spec.rb'
144-
- 'spec/omniauth/identity/models/mongoid_spec.rb'
116+
- 'spec_orms/mongoid_spec.rb'
145117

146118
# Offense count: 12
147119
RSpec/NestedGroups:
@@ -152,27 +124,28 @@ RSpec/StubbedMock:
152124
Exclude:
153125
- 'spec/omniauth/strategies/identity_spec.rb'
154126

155-
# Offense count: 22
127+
# Offense count: 5
156128
RSpec/SubjectStub:
157129
Exclude:
158-
- 'spec/omniauth/identity/model_spec.rb'
159130
- 'spec/omniauth/identity/models/active_record_spec.rb'
160-
- 'spec/omniauth/identity/models/couch_potato_spec.rb'
161-
- 'spec/omniauth/identity/models/mongoid_spec.rb'
131+
- 'spec/omniauth/identity/models/sequel_spec.rb'
132+
- 'spec_orms/couch_potato_spec.rb'
133+
- 'spec_orms/mongoid_spec.rb'
134+
- 'spec_orms/nobrainer_spec.rb'
162135

163136
# Offense count: 4
164137
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
165138
RSpec/VerifiedDoubles:
166139
Exclude:
167-
- 'spec/omniauth/identity/model_spec.rb'
168140
- 'spec/omniauth/strategies/identity_spec.rb'
141+
- 'spec/support/shared_contexts/model_with_class_methods.rb'
169142

170143
# Offense count: 1
171144
Rake/Desc:
172145
Exclude:
173146
- 'Rakefile'
174147

175-
# Offense count: 7
148+
# Offense count: 10
176149
Style/Documentation:
177150
Exclude:
178151
- '**/*.md'
@@ -184,24 +157,30 @@ Style/Documentation:
184157
- 'lib/omniauth/identity/secure_password.rb'
185158
- 'spec/omniauth/identity/secure_password_spec.rb'
186159

187-
# Offense count: 5
160+
# Offense count: 4
188161
# Configuration parameters: MinBodyLength.
189162
Style/GuardClause:
190163
Exclude:
191164
- 'lib/omniauth/identity/model.rb'
192165
- 'lib/omniauth/identity/secure_password.rb'
193166

167+
# Offense count: 1
168+
# Cop supports --auto-correct.
169+
Style/IfUnlessModifier:
170+
Exclude:
171+
- 'lib/omniauth/strategies/identity.rb'
172+
194173
# Offense count: 1
195174
# Configuration parameters: AllowedMethods.
196175
# AllowedMethods: respond_to_missing?
197176
Style/OptionalBooleanParameter:
198177
Exclude:
199178
- 'lib/omniauth/identity/model.rb'
200179

201-
# Offense count: 1
180+
# Offense count: 4
202181
# Cop supports --auto-correct.
203182
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
204183
# URISchemes: http, https
205184
# IgnoredPatterns: (?-mix:^\#)
206185
Layout/LineLength:
207-
Max: 123
186+
Max: 138

.simplecov

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# frozen_string_literal: true
22

33
SimpleCov.start do
4+
add_filter '/.github/'
5+
add_filter '/coverage/'
6+
add_filter '/rethinkdb_data/'
47
add_filter '/spec/'
8+
add_filter '/spec_orms/'
59
add_filter '/vendor/bundle/'
610
end

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [Unreleased]
1010

11+
## [3.0.7] - 2021-03-23
12+
13+
### Fixed
14+
15+
- \[ActiveRecord\] Fixed [#110](https://github.com/omniauth/omniauth-identity/issues/110) which prevented `OmniAuth::Identity::Models::ActiveRecord`-based records from saving.
16+
- \[CouchPotato\] Fixed `OmniAuth::Identity::Models::CouchPotato`'s `#save`.
17+
- \[Sequel\] Fixed `OmniAuth::Identity::Models::Sequel`'s `#save`.
18+
- \[Model\] Only define `::create`, `#save`, and `#persisted?` when not already defined.
19+
- \[Model\] Restore original `info` functionality which set `name` based on `first_name`, `last_name`, or `nickname`
20+
21+
### Changed
22+
23+
- 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)
24+
- Aeons ago the original was ripped from Rails 3.1, and frozen in time.
25+
While writing specs, it was discovered to be incompatible with this gem's Sequel adapter.
26+
- Specs validate that the new version does work.
27+
In any case, the ripped version is only used when the `has_secure_password` macro is not yet defined in the class.
28+
29+
### Added
30+
31+
- New specs to cover real use cases and implementations of each ORM model adapter that ships with the gem:
32+
- ActiveRecord (Polyglot - Many Relational Databases)
33+
- Sequel (Polyglot - Many Relational Databases)
34+
- CouchPotato (CouchDB)
35+
- Mongoid (MongoDB)
36+
- NoBrainer (RethinkDB)
37+
1138
## [3.0.6] - 2021-03-20
1239

1340
### Fixed

Gemfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@ group :documentation do
1717
end
1818

1919
group :development, :test do
20+
# ORMs
2021
if ruby_version < Gem::Version.new('2.5.0')
21-
gem 'activerecord', '~> 5' # rails 5 works with Ruby 2.4
22+
gem 'activerecord', '~> 5', require: false # rails 5 works with Ruby 2.4
2223
else
23-
gem 'activerecord', '~> 6' # rails 6 requires Ruby 2.5 or later
24+
gem 'activerecord', '~> 6', require: false # rails 6 requires Ruby 2.5 or later
2425
end
26+
gem 'anonymous_active_record', '~> 1', require: false
27+
gem 'couch_potato', github: 'langalex/couch_potato', require: false
28+
gem 'mongoid', '~> 7', require: false
29+
gem 'mongoid-rspec', github: 'mongoid/mongoid-rspec', require: false
30+
gem 'nobrainer', '~> 0', require: false
31+
gem 'sequel', '~> 5', require: false
2532

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

47-
gem 'couch_potato', github: 'langalex/couch_potato'
4854
gem 'growl'
4955
gem 'guard'
5056
gem 'guard-bundler'
5157
gem 'guard-rspec'
52-
gem 'mongoid-rspec', github: 'mongoid/mongoid-rspec'
5358
gem 'rb-fsevent'
5459
end
5560

README.md

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ Just include `OmniAuth::Identity::Models::Sequel` mixin, and specify
9393
whatever else you will need.
9494

9595
```ruby
96-
class SequelTestIdentity < Sequel::Model
97-
include OmniAuth::Identity::Models::Sequel
96+
class SequelTestIdentity < Sequel::Model(:identities)
97+
include ::OmniAuth::Identity::Models::Sequel
9898
auth_key :email
9999
# whatever else you want!
100100
end
@@ -108,8 +108,8 @@ fields that you will need.
108108

109109
```ruby
110110
class Identity
111-
include Mongoid::Document
112-
include OmniAuth::Identity::Models::Mongoid
111+
include ::Mongoid::Document
112+
include ::OmniAuth::Identity::Models::Mongoid
113113

114114
field :email, type: String
115115
field :name, type: String
@@ -124,8 +124,9 @@ fields that you will need.
124124

125125
```ruby
126126
class Identity
127-
include CouchPotato::Persistence
128-
include OmniAuth::Identity::Models::CouchPotatoModule
127+
# NOTE: CouchPotato::Persistence must be included before OmniAuth::Identity::Models::CouchPotatoModule
128+
include ::CouchPotato::Persistence
129+
include ::OmniAuth::Identity::Models::CouchPotatoModule
129130

130131
property :email
131132
property :password_digest
@@ -147,8 +148,8 @@ fields that you will need.
147148

148149
```ruby
149150
class Identity
150-
include NoBrainer::Document
151-
include OmniAuth::Identity::Models::NoBrainer
151+
include ::NoBrainer::Document
152+
include ::OmniAuth::Identity::Models::NoBrainer
152153

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

266267
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. 😭
267268

269+
## Contributing
270+
271+
1. Fork it
272+
2. Create your feature branch (`git checkout -b my-new-feature`)
273+
3. Commit your changes (`git commit -am ‘Added some feature’`)
274+
4. Push to the branch (`git push origin my-new-feature`)
275+
5. Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
276+
- NOTE: In order to run *all* the tests you will need to have the following databases installed, configured, and running.
277+
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.
278+
```bash
279+
brew install rethinkdb
280+
rethinkdb
281+
```
282+
2. [MongoDB](https://docs.mongodb.com/manual/administration/install-community/)
283+
```bash
284+
brew tap mongodb/brew
285+
brew install mongodb-community@4.4
286+
mongod --config /usr/local/etc/mongod.conf
287+
```
288+
3. [CouchDB](https://couchdb.apache.org) (download the .app)
289+
To run all tests on all databases:
290+
```bash
291+
bundle exec rake
292+
```
293+
To run a specific DB:
294+
```bash
295+
# CouchDB / CouchPotato
296+
bundle exec rspec spec spec_orms --tag 'couchdb'
297+
298+
# ActiveRecord and Sequel, as they both use the in-memory SQLite driver.
299+
bundle exec rspec spec spec_orms --tag 'sqlite3'
300+
301+
# NOTE - mongoid and nobrainer specs can't be isolated with "tag" because it still loads everything,
302+
# and the two libraries are fundamentally incompatible.
303+
304+
# MongoDB / Mongoid
305+
bundle exec rspec spec_orms/mongoid_spec.rb
306+
307+
# RethinkDB / NoBrainer
308+
bundle exec rspec spec_orms/nobrainer_spec.rb
309+
```
310+
6. Create new Pull Request
311+
268312
## License
269313

270314
MIT License. See LICENSE for details.

0 commit comments

Comments
 (0)