-
Notifications
You must be signed in to change notification settings - Fork 90
Mongoid 6 & 7 and rails 5.1, 5.2 & 6.0 upgrade #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ritxi
wants to merge
15
commits into
thetron:master
Choose a base branch
from
ritxi:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8b28b6b
Refactor #alias_method_chain implementation with ruby's native #prepend
e9da5aa
remove resolver parameter from resolve_token_collisions lookup resolv…
fbb61df
Upgrade mongoid version
1796f59
Ensure non mongoid_token exceptions are cought and tokens regenerated
30537c3
Remove older ruby versions
b256286
Make code climate reporting work
4520306
Make exception assertion compatible with mongo 2.4
6f1b7f9
Gem autoload using zeitwerk
46aa33a
Update mongo version
606c5a8
Use new :expect syntax
c27cbf5
Add appraisals
f86f7c4
Use more ruby naming convention duplicate_token_error?
d53a1f8
Ensure collisions to work on mongodb 2.6. 3.0 and 4.0
9e04f9c
Fix rubocop errors
8b0b106
Update README
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ | |
| Gemfile.lock | ||
| pkg/* | ||
| .DS_Store | ||
| gemfiles/*.gemfile.lock | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,20 @@ | ||
| language: ruby | ||
|
|
||
| rvm: | ||
| - 1.9.3 | ||
| - 2.0.0 | ||
| - 2.1.0 | ||
| - 2.1.1 | ||
|
|
||
| gemfile: | ||
| - Gemfile | ||
| matrix: | ||
| include: | ||
| - rvm: 2.5.7 | ||
| gemfile: gemfiles/mongoid_7.gemfile | ||
| - rvm: 2.5.7 | ||
| gemfile: gemfiles/mongoid_6.gemfile | ||
| - rvm: 2.5.7 | ||
| gemfile: gemfiles/mongoid_6_rails_5.1.gemfile | ||
|
|
||
| services: | ||
| - mongodb | ||
|
|
||
| env: | ||
| - CODECLIMATE_REPO_TOKEN=b216164ab66da464aa02fe5b862811ba0526c8dc7ea291ebe53056be4b6b5e1f | ||
|
|
||
| script: "bundle exec rspec" | ||
| script: | ||
| - bundle exec rspec | ||
| - bundle exec codeclimate-test-reporter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| appraise 'mongoid-7' do | ||
| gem 'mongoid', '~> 7.0' | ||
| end | ||
|
|
||
| appraise 'mongoid-6' do | ||
| gem 'mongoid', '~> 6.0' | ||
| end | ||
|
|
||
| appraise 'mongoid-6-rails-5.1' do | ||
| gem 'mongoid', '~> 6.0' | ||
| gem 'rails', '~> 5.1' | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # This file was generated by Appraisal | ||
|
|
||
| source "http://rubygems.org" | ||
|
|
||
| gem "mongoid", "~> 6.0" | ||
|
|
||
| group :test do | ||
| gem "codeclimate-test-reporter", require: nil | ||
| gem "database_cleaner" | ||
| gem "mongoid-rspec" | ||
| gem "rspec" | ||
| end | ||
|
|
||
| gemspec path: "../" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # This file was generated by Appraisal | ||
|
|
||
| source "http://rubygems.org" | ||
|
|
||
| gem "mongoid", "~> 6.0" | ||
| gem "rails", "~> 5.1" | ||
|
|
||
| group :test do | ||
| gem "codeclimate-test-reporter", require: nil | ||
| gem "database_cleaner" | ||
| gem "mongoid-rspec" | ||
| gem "rspec" | ||
| end | ||
|
|
||
| gemspec path: "../" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # This file was generated by Appraisal | ||
|
|
||
| source "http://rubygems.org" | ||
|
|
||
| gem "mongoid", "~> 7.0" | ||
|
|
||
| group :test do | ||
| gem "codeclimate-test-reporter", require: nil | ||
| gem "database_cleaner" | ||
| gem "mongoid-rspec" | ||
| gem "rspec" | ||
| end | ||
|
|
||
| gemspec path: "../" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,39 @@ | ||
| require 'mongoid/token/collisions' | ||
| # frozen_string_literal: true | ||
|
|
||
| module Mongoid | ||
| module Token | ||
| module SafeOperationsHandler | ||
| def insert(options = {}) | ||
| safe_operation { super(options) } | ||
| end | ||
|
|
||
| def upsert(options = {}) | ||
| safe_operation { super(options) } | ||
| end | ||
|
|
||
| def safe_operation(&block) | ||
| resolve_token_collisions { with(write: { w: 1 }, &block) } | ||
| end | ||
| end | ||
|
|
||
| class CollisionResolver | ||
| attr_accessor :create_new_token | ||
| attr_reader :klass | ||
| attr_reader :field_name | ||
| attr_reader :retry_count | ||
|
|
||
| def initialize(klass, field_name, retry_count) | ||
| @create_new_token = Proc.new {|doc|} | ||
| @create_new_token = proc { |doc| } | ||
| @klass = klass | ||
| @field_name = field_name | ||
| @retry_count = retry_count | ||
| klass.send(:include, Mongoid::Token::Collisions) | ||
| alias_method_with_collision_resolution(:insert) | ||
| alias_method_with_collision_resolution(:upsert) | ||
| klass.send(:prepend, SafeOperationsHandler) | ||
| end | ||
|
|
||
| def create_new_token_for(document) | ||
| @create_new_token.call(document) | ||
| end | ||
|
|
||
| private | ||
| def alias_method_with_collision_resolution(method) | ||
| handler = self | ||
| klass.send(:define_method, :"#{method.to_s}_with_#{handler.field_name}_safety") do |method_options = {}| | ||
| self.resolve_token_collisions handler do | ||
| with(:safe => true).send(:"#{method.to_s}_without_#{handler.field_name}_safety", method_options) | ||
| end | ||
| end | ||
| klass.alias_method_chain method.to_sym, :"#{handler.field_name}_safety" | ||
| end | ||
| end | ||
| end | ||
| end |
7 changes: 4 additions & 3 deletions
7
lib/mongoid/token/exceptions.rb → ...ngoid/token/collision_retries_exceeded.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bundler/OrderedGems: Gems should be sorted in an alphabetical order within their section of the Gemfile. Gem database_cleaner should appear before rspec.