-
Notifications
You must be signed in to change notification settings - Fork 165
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
Mongoid paranoia support #273
Open
johnnyshields
wants to merge
7
commits into
mongoid:master
Choose a base branch
from
tablecheck:mongoid-paranoia-support
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 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c3abb37
Mongoid paranoia support
johnnyshields 837c8ee
Rework specs
johnnyshields 4bfd30d
Add specs
johnnyshields 7b27669
Update rubocop.yml
johnnyshields 339beda
Revert to old code
johnnyshields a9b73d9
Merge branch 'mongoid-paranoia-support' of github.com:tablecheck/mong…
johnnyshields 930ae90
Revert last commit
johnnyshields 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 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,20 @@ | ||
--- | ||
name: Rubocop | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
env: | ||
CI: true | ||
TESTOPTS: '-v' | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Ruby 3.2 | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: 3.2 | ||
bundler-cache: true | ||
- name: Run Rubocop | ||
run: bundle exec rubocop --parallel |
This file contains 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 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 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 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 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 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,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class Agent | ||
include Mongoid::Document | ||
include Mongoid::Slug | ||
include Mongoid::Paranoia | ||
|
||
field :name | ||
slug :name, permanent: true | ||
end |
This file contains 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 @@ | ||
# frozen_string_literal: true | ||
|
||
Mongoid::Slug.use_paranoia = true | ||
class SecretAgent | ||
include Mongoid::Document | ||
include Mongoid::Slug | ||
include Mongoid::Paranoia | ||
|
||
field :name | ||
slug :name, permanent: true | ||
end | ||
Mongoid::Slug.use_paranoia = false |
This file contains 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,46 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe Mongoid::Slug do | ||
context 'when paranoia support is not enabled' do | ||
let!(:doc) { Agent.create(name: 'Garbo') } | ||
|
||
it 'does not delete the slug when the document is destroyed' do | ||
expect(doc.slug).to eq 'garbo' | ||
doc.destroy | ||
expect(Agent.unscoped.find(doc._id).slug).to eq 'garbo' | ||
end | ||
end | ||
|
||
context 'when paranoia support is enabled' do | ||
let!(:doc) { SecretAgent.create(name: 'Alaric') } | ||
|
||
around do |example| | ||
Mongoid::Slug.use_paranoia = true | ||
example.run | ||
ensure | ||
Mongoid::Slug.use_paranoia = false | ||
end | ||
|
||
it 'deletes the slug when the document is destroyed' do | ||
expect(doc.slug).to eq 'alaric' | ||
doc.destroy | ||
# TODO: This case should be nil. | ||
expect(SecretAgent.unscoped.find(doc._id).slug).to eq doc._id.to_s | ||
doc.restore | ||
expect(SecretAgent.unscoped.find(doc._id).slug).to eq 'alaric' | ||
end | ||
|
||
it 'deletes the slug when deleted document is saved' do | ||
expect(doc.slug).to eq 'alaric' | ||
doc.deleted_at = Time.current | ||
doc.save! | ||
expect(SecretAgent.unscoped.find(doc._id).slug).to eq nil | ||
# TODO: This case should re-set the slug. | ||
doc.deleted_at = nil | ||
doc.save! | ||
expect(SecretAgent.unscoped.find(doc._id).slug).to eq nil | ||
end | ||
end | ||
end |
This file contains 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
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.
You probably want to make a separate integration test that uses a different Gemfile for mongoid_paranoia to make sure it works without.
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.
ok good point. same thought crossed my mind.