sepastian-mongoid-paranoia-rails4 0.0.1.alpha
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.
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/.travis.yml +20 -0
- data/Gemfile +10 -0
- data/LICENSE +22 -0
- data/README.md +68 -0
- data/Rakefile +13 -0
- data/lib/mongoid-paranoia.rb +1 -0
- data/lib/mongoid/paranoia.rb +137 -0
- data/lib/mongoid/paranoia/monkey_patches.rb +95 -0
- data/lib/mongoid/validatable/uniqueness_including_deleted_validator.rb +38 -0
- data/mongoid-paranoia-rails4.gemspec +23 -0
- data/spec/app/models/address.rb +69 -0
- data/spec/app/models/appointment.rb +7 -0
- data/spec/app/models/author.rb +6 -0
- data/spec/app/models/fish.rb +8 -0
- data/spec/app/models/paranoid_phone.rb +25 -0
- data/spec/app/models/paranoid_post.rb +33 -0
- data/spec/app/models/person.rb +190 -0
- data/spec/app/models/phone.rb +11 -0
- data/spec/app/models/tag.rb +6 -0
- data/spec/app/models/title.rb +4 -0
- data/spec/mongoid/nested_attributes_spec.rb +164 -0
- data/spec/mongoid/paranoia_spec.rb +730 -0
- data/spec/mongoid/scoping_spec.rb +55 -0
- data/spec/mongoid/validatable/uniqueness_spec.rb +58 -0
- data/spec/spec_helper.rb +81 -0
- metadata +140 -0
@@ -0,0 +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
|
+
criteria.selector.should 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
|
+
criteria.selector.should 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
|
+
criteria.selector.should 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
|
+
criteria.selector.should eq({ "fresh" => true })
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mongoid::Validatable::UniquenessValidator 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_including_deleted => true)
|
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
|
+
new_post.should 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
|
+
new_post.should be_valid
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when the field is not unique" do
|
46
|
+
|
47
|
+
let(:new_post) do
|
48
|
+
ParanoidPost.new(title: "testing")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns false" do
|
52
|
+
new_post.should_not be_valid
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,81 @@
|
|
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, consistency: :strong)
|
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 and clear the identity map before each spec.
|
60
|
+
config.before(:each) do
|
61
|
+
Mongoid.purge!
|
62
|
+
Mongoid::IdentityMap.clear
|
63
|
+
end
|
64
|
+
|
65
|
+
# On travis we are creating many different databases on each test run. We
|
66
|
+
# drop the database after the suite.
|
67
|
+
config.after(:suite) do
|
68
|
+
if ENV["CI"]
|
69
|
+
Mongoid::Threaded.sessions[:default].drop
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Filter out MongoHQ specs if we can't connect to it.
|
74
|
+
config.filter_run_excluding(config: ->(value){
|
75
|
+
return true if value == :mongohq && !mongohq_connectable?
|
76
|
+
})
|
77
|
+
end
|
78
|
+
|
79
|
+
ActiveSupport::Inflector.inflections do |inflect|
|
80
|
+
inflect.singular("address_components", "address_component")
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sepastian-mongoid-paranoia-rails4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.alpha
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sebastian Gassner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activemodel
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 4.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 4.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sepastian-mongoid-rails4
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 4.0.0.alpha
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 4.0.0.alpha
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.11'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.11'
|
62
|
+
description: Mongoid fork with support for Rails 4, for gem development. When releasing
|
63
|
+
a gem, the gem can only depend on other released gems, not on github sources or
|
64
|
+
paths. Mongoid has not yet released a gem supporting Rails 4. This gem is just a
|
65
|
+
packaged version of the mongoid master branch, filling the gap until a release of
|
66
|
+
mongoid with support for Rails 4.
|
67
|
+
email:
|
68
|
+
- sebastian.gassner@gmail.com
|
69
|
+
executables: []
|
70
|
+
extensions: []
|
71
|
+
extra_rdoc_files: []
|
72
|
+
files:
|
73
|
+
- .gitignore
|
74
|
+
- .rspec
|
75
|
+
- .travis.yml
|
76
|
+
- Gemfile
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- lib/mongoid-paranoia.rb
|
81
|
+
- lib/mongoid/paranoia.rb
|
82
|
+
- lib/mongoid/paranoia/monkey_patches.rb
|
83
|
+
- lib/mongoid/validatable/uniqueness_including_deleted_validator.rb
|
84
|
+
- mongoid-paranoia-rails4.gemspec
|
85
|
+
- spec/app/models/address.rb
|
86
|
+
- spec/app/models/appointment.rb
|
87
|
+
- spec/app/models/author.rb
|
88
|
+
- spec/app/models/fish.rb
|
89
|
+
- spec/app/models/paranoid_phone.rb
|
90
|
+
- spec/app/models/paranoid_post.rb
|
91
|
+
- spec/app/models/person.rb
|
92
|
+
- spec/app/models/phone.rb
|
93
|
+
- spec/app/models/tag.rb
|
94
|
+
- spec/app/models/title.rb
|
95
|
+
- spec/mongoid/nested_attributes_spec.rb
|
96
|
+
- spec/mongoid/paranoia_spec.rb
|
97
|
+
- spec/mongoid/scoping_spec.rb
|
98
|
+
- spec/mongoid/validatable/uniqueness_spec.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
homepage: https://github.com/sepastian/mongoid-paranoia
|
101
|
+
licenses: []
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>'
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.3.1
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project: sepastian-mongoid-paranoia-rails4
|
120
|
+
rubygems_version: 1.8.23
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: A fork of the mongoid master branch, supporting Rails 4.
|
124
|
+
test_files:
|
125
|
+
- spec/app/models/address.rb
|
126
|
+
- spec/app/models/appointment.rb
|
127
|
+
- spec/app/models/author.rb
|
128
|
+
- spec/app/models/fish.rb
|
129
|
+
- spec/app/models/paranoid_phone.rb
|
130
|
+
- spec/app/models/paranoid_post.rb
|
131
|
+
- spec/app/models/person.rb
|
132
|
+
- spec/app/models/phone.rb
|
133
|
+
- spec/app/models/tag.rb
|
134
|
+
- spec/app/models/title.rb
|
135
|
+
- spec/mongoid/nested_attributes_spec.rb
|
136
|
+
- spec/mongoid/paranoia_spec.rb
|
137
|
+
- spec/mongoid/scoping_spec.rb
|
138
|
+
- spec/mongoid/validatable/uniqueness_spec.rb
|
139
|
+
- spec/spec_helper.rb
|
140
|
+
has_rdoc:
|