mongoid_paranoia 0.4.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/lib/mongoid/paranoia/version.rb +1 -1
- data/lib/mongoid/paranoia.rb +21 -31
- metadata +6 -63
- data/perf/scope.rb +0 -65
- data/spec/app/models/address.rb +0 -71
- data/spec/app/models/appointment.rb +0 -7
- data/spec/app/models/author.rb +0 -6
- data/spec/app/models/fish.rb +0 -8
- data/spec/app/models/paranoid_phone.rb +0 -25
- data/spec/app/models/paranoid_post.rb +0 -65
- data/spec/app/models/person.rb +0 -21
- data/spec/app/models/phone.rb +0 -11
- data/spec/app/models/relations.rb +0 -247
- data/spec/app/models/tag.rb +0 -6
- data/spec/app/models/title.rb +0 -4
- data/spec/mongoid/configuration_spec.rb +0 -19
- data/spec/mongoid/document_spec.rb +0 -21
- data/spec/mongoid/nested_attributes_spec.rb +0 -164
- data/spec/mongoid/paranoia_spec.rb +0 -887
- data/spec/mongoid/scoping_spec.rb +0 -55
- data/spec/mongoid/validatable/uniqueness_spec.rb +0 -74
- data/spec/spec_helper.rb +0 -43
@@ -1,55 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Mongoid::Criteria::Scopable do
|
4
|
-
|
5
|
-
context "when the document is paranoid" do
|
6
|
-
|
7
|
-
context "when calling a class method" do
|
8
|
-
|
9
|
-
let(:criteria) do
|
10
|
-
Fish.fresh
|
11
|
-
end
|
12
|
-
|
13
|
-
it "includes the deleted_at criteria in the selector" do
|
14
|
-
expect(criteria.selector).to eq({
|
15
|
-
"deleted_at" => nil, "fresh" => true
|
16
|
-
})
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "when chaining a class method to unscoped" do
|
21
|
-
|
22
|
-
let(:criteria) do
|
23
|
-
Fish.unscoped.fresh
|
24
|
-
end
|
25
|
-
|
26
|
-
it "does not include the deleted_at in the selector" do
|
27
|
-
expect(criteria.selector).to eq({ "fresh" => true })
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "when chaining a class method to deleted" do
|
32
|
-
|
33
|
-
let(:criteria) do
|
34
|
-
Fish.deleted.fresh
|
35
|
-
end
|
36
|
-
|
37
|
-
it "includes the deleted_at $ne criteria in the selector" do
|
38
|
-
expect(criteria.selector).to eq({
|
39
|
-
"deleted_at" => { "$ne" => nil }, "fresh" => true
|
40
|
-
})
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "when chaining a where to unscoped" do
|
45
|
-
|
46
|
-
let(:criteria) do
|
47
|
-
Fish.unscoped.where(fresh: true)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "includes no default scoping information in the selector" do
|
51
|
-
expect(criteria.selector).to eq({ "fresh" => true })
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "Paranoia uniqueness scoped validator" do
|
4
|
-
describe "#valid?" do
|
5
|
-
context "when the document is a root document" do
|
6
|
-
context "when the document is paranoid" do
|
7
|
-
before do
|
8
|
-
ParanoidPost.validates(:title, uniqueness: { conditions: -> { ParanoidPost.where(deleted_at: nil) } })
|
9
|
-
end
|
10
|
-
|
11
|
-
after do
|
12
|
-
ParanoidPost.reset_callbacks(:validate)
|
13
|
-
end
|
14
|
-
|
15
|
-
let!(:post) do
|
16
|
-
ParanoidPost.create(title: "testing")
|
17
|
-
end
|
18
|
-
|
19
|
-
context "when the field is unique" do
|
20
|
-
|
21
|
-
let(:new_post) do
|
22
|
-
ParanoidPost.new(title: "test")
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns true" do
|
26
|
-
expect(new_post).to be_valid
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "when the field is unique for non soft deleted docs" do
|
31
|
-
|
32
|
-
before do
|
33
|
-
post.delete!
|
34
|
-
end
|
35
|
-
|
36
|
-
let(:new_post) do
|
37
|
-
ParanoidPost.new(title: "testing")
|
38
|
-
end
|
39
|
-
|
40
|
-
it "returns true" do
|
41
|
-
expect(new_post).to be_valid
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "when the field is not unique for soft deleted docs" do
|
46
|
-
|
47
|
-
before do
|
48
|
-
post = ParanoidPost.create(title: "test")
|
49
|
-
post.delete
|
50
|
-
end
|
51
|
-
|
52
|
-
let(:new_post) do
|
53
|
-
ParanoidPost.new(title: "test")
|
54
|
-
end
|
55
|
-
|
56
|
-
it "returns true" do
|
57
|
-
expect(new_post).to be_valid
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "when the field is not unique" do
|
62
|
-
|
63
|
-
let(:new_post) do
|
64
|
-
ParanoidPost.new(title: "testing")
|
65
|
-
end
|
66
|
-
|
67
|
-
it "returns false" do
|
68
|
-
expect(new_post).not_to be_valid
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
-
|
4
|
-
require 'mongoid'
|
5
|
-
require 'mongoid/paranoia'
|
6
|
-
require 'rspec'
|
7
|
-
|
8
|
-
# When testing locally we use the database named mongoid_test. However when
|
9
|
-
# tests are running in parallel on Travis we need to use different database
|
10
|
-
# names for each process running since we do not have transactions and want a
|
11
|
-
# clean slate before each spec run.
|
12
|
-
def database_id
|
13
|
-
'mongoid_paranoia_test'
|
14
|
-
end
|
15
|
-
|
16
|
-
# Set the database that the spec suite connects to.
|
17
|
-
Mongoid.configure do |config|
|
18
|
-
config.belongs_to_required_by_default = false
|
19
|
-
config.connect_to(database_id)
|
20
|
-
end
|
21
|
-
|
22
|
-
RSpec.configure do |config|
|
23
|
-
|
24
|
-
# Drop all collections
|
25
|
-
config.before(:each) do
|
26
|
-
Mongoid.purge!
|
27
|
-
end
|
28
|
-
|
29
|
-
config.before(:all) do
|
30
|
-
Mongoid.logger.level = Logger::INFO
|
31
|
-
Mongo::Logger.logger.level = Logger::INFO
|
32
|
-
end
|
33
|
-
|
34
|
-
config.after(:all) do
|
35
|
-
Mongoid.purge!
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
ActiveSupport::Inflector.inflections do |inflect|
|
40
|
-
inflect.singular('address_components', 'address_component')
|
41
|
-
end
|
42
|
-
|
43
|
-
Dir[File.join(File.dirname(__FILE__), 'app/models/*.rb')].each{ |f| require f }
|