mongoid_paranoia 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,55 +1,55 @@
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
+ 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 +1,74 @@
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
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 CHANGED
@@ -1,80 +1,73 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
-
4
- MODELS = File.join(File.dirname(__FILE__), "app/models")
5
- $LOAD_PATH.unshift(MODELS)
6
-
7
- require "mongoid"
8
- require "mongoid/paranoia"
9
- require "rspec"
10
-
11
- # These environment variables can be set if wanting to test against a database
12
- # that is not on the local machine.
13
- ENV["MONGOID_SPEC_HOST"] ||= "localhost"
14
- ENV["MONGOID_SPEC_PORT"] ||= "27017"
15
-
16
- # These are used when creating any connection in the test suite.
17
- HOST = ENV["MONGOID_SPEC_HOST"]
18
- PORT = ENV["MONGOID_SPEC_PORT"].to_i
19
-
20
- # Moped.logger.level = Logger::DEBUG
21
- # Mongoid.logger.level = Logger::DEBUG
22
-
23
- # When testing locally we use the database named mongoid_test. However when
24
- # tests are running in parallel on Travis we need to use different database
25
- # names for each process running since we do not have transactions and want a
26
- # clean slate before each spec run.
27
- def database_id
28
- "mongoid_test"
29
- end
30
-
31
- # Can we connect to MongoHQ from this box?
32
- def mongohq_connectable?
33
- ENV["MONGOHQ_REPL_PASS"].present?
34
- end
35
-
36
- # Set the database that the spec suite connects to.
37
- Mongoid.configure do |config|
38
- config.connect_to(database_id)
39
- end
40
-
41
- # Autoload every model for the test suite that sits in spec/app/models.
42
- Dir[ File.join(MODELS, "*.rb") ].sort.each do |file|
43
- name = File.basename(file, ".rb")
44
- autoload name.camelize.to_sym, name
45
- end
46
-
47
- module Rails
48
- class Application
49
- end
50
- end
51
-
52
- module MyApp
53
- class Application < Rails::Application
54
- end
55
- end
56
-
57
- RSpec.configure do |config|
58
-
59
- # Drop all collections
60
- config.before(:each) do
61
- Mongoid.purge!
62
- end
63
-
64
- # On travis we are creating many different databases on each test run. We
65
- # drop the database after the suite.
66
- config.after(:suite) do
67
- if ENV["CI"]
68
- Mongoid::Threaded.sessions[:default].drop
69
- end
70
- end
71
-
72
- # Filter out MongoHQ specs if we can't connect to it.
73
- config.filter_run_excluding(config: ->(value){
74
- return true if value == :mongohq && !mongohq_connectable?
75
- })
76
- end
77
-
78
- ActiveSupport::Inflector.inflections do |inflect|
79
- inflect.singular("address_components", "address_component")
80
- end
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
+ Dir[File.join(File.dirname(__FILE__), "app/models/*.rb")].each{ |f| require f }
8
+
9
+ # These environment variables can be set if wanting to test against a database
10
+ # that is not on the local machine.
11
+ ENV["MONGOID_SPEC_HOST"] ||= "localhost"
12
+ ENV["MONGOID_SPEC_PORT"] ||= "27017"
13
+
14
+ # These are used when creating any connection in the test suite.
15
+ HOST = ENV["MONGOID_SPEC_HOST"]
16
+ PORT = ENV["MONGOID_SPEC_PORT"].to_i
17
+
18
+ # Moped.logger.level = Logger::DEBUG
19
+ # Mongoid.logger.level = Logger::DEBUG
20
+
21
+ # When testing locally we use the database named mongoid_test. However when
22
+ # tests are running in parallel on Travis we need to use different database
23
+ # names for each process running since we do not have transactions and want a
24
+ # clean slate before each spec run.
25
+ def database_id
26
+ "mongoid_test"
27
+ end
28
+
29
+ # Can we connect to MongoHQ from this box?
30
+ def mongohq_connectable?
31
+ ENV["MONGOHQ_REPL_PASS"].present?
32
+ end
33
+
34
+ # Set the database that the spec suite connects to.
35
+ Mongoid.configure do |config|
36
+ config.connect_to(database_id)
37
+ end
38
+
39
+ module Rails
40
+ class Application
41
+ end
42
+ end
43
+
44
+ module MyApp
45
+ class Application < Rails::Application
46
+ end
47
+ end
48
+
49
+ RSpec.configure do |config|
50
+
51
+ # Drop all collections
52
+ config.before(:each) do
53
+ Mongoid.purge!
54
+ end
55
+
56
+ config.before(:all) do
57
+ Mongoid.logger.level = Logger::INFO
58
+ Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5?
59
+ end
60
+
61
+ config.after(:all) do
62
+ Mongoid.purge!
63
+ end
64
+
65
+ # Filter out MongoHQ specs if we can't connect to it.
66
+ config.filter_run_excluding(config: ->(value){
67
+ return true if value == :mongohq && !mongohq_connectable?
68
+ })
69
+ end
70
+
71
+ ActiveSupport::Inflector.inflections do |inflect|
72
+ inflect.singular("address_components", "address_component")
73
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_paranoia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
@@ -9,22 +9,36 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-11 00:00:00.000000000 Z
12
+ date: 2015-09-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ! '>'
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '3'
20
+ version: '4'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ! '>'
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '3'
27
+ version: '4'
28
+ - !ruby/object:Gem::Dependency
29
+ name: mongoid-compatibility
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
28
42
  description: There may be times when you don't want documents to actually get deleted
29
43
  from the database, but "flagged" as deleted. Mongoid provides a Paranoia module
30
44
  to give you just that.
@@ -39,6 +53,7 @@ files:
39
53
  - README.md
40
54
  - lib/mongoid-paranoia.rb
41
55
  - lib/mongoid/paranoia.rb
56
+ - lib/mongoid/paranoia/configuration.rb
42
57
  - lib/mongoid/paranoia/monkey_patches.rb
43
58
  - lib/mongoid/paranoia/version.rb
44
59
  - lib/mongoid_paranoia.rb
@@ -51,8 +66,10 @@ files:
51
66
  - spec/app/models/paranoid_post.rb
52
67
  - spec/app/models/person.rb
53
68
  - spec/app/models/phone.rb
69
+ - spec/app/models/relations.rb
54
70
  - spec/app/models/tag.rb
55
71
  - spec/app/models/title.rb
72
+ - spec/mongoid/configuration_spec.rb
56
73
  - spec/mongoid/document_spec.rb
57
74
  - spec/mongoid/nested_attributes_spec.rb
58
75
  - spec/mongoid/paranoia_spec.rb
@@ -69,36 +86,37 @@ require_paths:
69
86
  - lib
70
87
  required_ruby_version: !ruby/object:Gem::Requirement
71
88
  requirements:
72
- - - ! '>='
89
+ - - ">="
73
90
  - !ruby/object:Gem::Version
74
91
  version: '0'
75
92
  required_rubygems_version: !ruby/object:Gem::Requirement
76
93
  requirements:
77
- - - ! '>='
94
+ - - ">="
78
95
  - !ruby/object:Gem::Version
79
96
  version: '0'
80
97
  requirements: []
81
98
  rubyforge_project:
82
- rubygems_version: 2.2.1
99
+ rubygems_version: 2.4.5.1
83
100
  signing_key:
84
101
  specification_version: 4
85
102
  summary: Paranoid documents
86
103
  test_files:
87
104
  - perf/scope.rb
88
- - spec/app/models/address.rb
89
- - spec/app/models/appointment.rb
90
105
  - spec/app/models/author.rb
91
- - spec/app/models/fish.rb
106
+ - spec/app/models/title.rb
107
+ - spec/app/models/appointment.rb
108
+ - spec/app/models/address.rb
92
109
  - spec/app/models/paranoid_phone.rb
93
- - spec/app/models/paranoid_post.rb
110
+ - spec/app/models/fish.rb
94
111
  - spec/app/models/person.rb
95
112
  - spec/app/models/phone.rb
113
+ - spec/app/models/paranoid_post.rb
96
114
  - spec/app/models/tag.rb
97
- - spec/app/models/title.rb
98
- - spec/mongoid/document_spec.rb
99
- - spec/mongoid/nested_attributes_spec.rb
115
+ - spec/app/models/relations.rb
116
+ - spec/spec_helper.rb
100
117
  - spec/mongoid/paranoia_spec.rb
101
- - spec/mongoid/scoping_spec.rb
102
118
  - spec/mongoid/validatable/uniqueness_spec.rb
103
- - spec/spec_helper.rb
104
- has_rdoc:
119
+ - spec/mongoid/nested_attributes_spec.rb
120
+ - spec/mongoid/document_spec.rb
121
+ - spec/mongoid/configuration_spec.rb
122
+ - spec/mongoid/scoping_spec.rb