mongoid-minitest 0.1.5 → 1.0.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.
- checksums.yaml +4 -4
- data/.gitignore +18 -0
- data/.travis.yml +12 -0
- data/CHANGELOG.md +79 -2
- data/Gemfile +3 -0
- data/Gemfile.edge +6 -0
- data/{LICENSE → LICENSE.md} +1 -1
- data/README.md +46 -53
- data/Rakefile +13 -0
- data/lib/matchers/associations/associations.rb +20 -20
- data/lib/matchers/document/be_stored_in.rb +4 -4
- data/lib/matchers/document/document.rb +9 -7
- data/lib/matchers/document/have_field.rb +12 -13
- data/lib/matchers/document/have_index.rb +4 -4
- data/lib/matchers/matcher.rb +1 -3
- data/lib/mongoid-minitest.rb +2 -15
- data/mongoid-minitest.gemspec +28 -0
- data/test/matchers/associations_test.rb +32 -0
- data/test/matchers/document_test.rb +28 -0
- data/test/models/models.rb +48 -0
- data/test/test_helper.rb +15 -0
- metadata +49 -26
- data/lib/matchers/helpers.rb +0 -13
- data/lib/matchers/validations/acceptance.rb +0 -47
- data/lib/matchers/validations/associated.rb +0 -19
- data/lib/matchers/validations/confirmation.rb +0 -9
- data/lib/matchers/validations/exclusion.rb +0 -52
- data/lib/matchers/validations/format.rb +0 -65
- data/lib/matchers/validations/inclusion.rb +0 -52
- data/lib/matchers/validations/length.rb +0 -86
- data/lib/matchers/validations/presence.rb +0 -9
- data/lib/matchers/validations/uniqueness.rb +0 -64
- data/lib/matchers/validations/validations.rb +0 -91
- data/lib/mongoid-minitest/version.rb +0 -5
@@ -1,11 +1,11 @@
|
|
1
1
|
module Mongoid
|
2
2
|
module Matchers
|
3
3
|
class BeStoredInMatcher < Matcher
|
4
|
-
def initialize
|
4
|
+
def initialize collection_name
|
5
5
|
@collection_name = collection_name.to_s
|
6
6
|
end
|
7
7
|
|
8
|
-
def matches?
|
8
|
+
def matches? subject
|
9
9
|
class_of(subject).collection_name.to_s == @collection_name
|
10
10
|
end
|
11
11
|
|
@@ -14,8 +14,8 @@ module Mongoid
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def be_stored_in
|
18
|
-
BeStoredInMatcher.new
|
17
|
+
def be_stored_in collection_name
|
18
|
+
BeStoredInMatcher.new collection_name
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -2,8 +2,8 @@ module Mongoid
|
|
2
2
|
module Matchers
|
3
3
|
module Document
|
4
4
|
DOCUMENT = Mongoid::Document
|
5
|
-
PARANOIA = Mongoid::Paranoia
|
6
|
-
VERSIONING = Mongoid::Versioning
|
5
|
+
PARANOIA = Mongoid::Paranoia unless Mongoid::VERSION == '4.0.0'
|
6
|
+
VERSIONING = Mongoid::Versioning unless Mongoid::VERSION == '4.0.0'
|
7
7
|
TIMESTAMPS = Mongoid::Timestamps
|
8
8
|
|
9
9
|
class DocumentMatcher < Matcher
|
@@ -32,12 +32,14 @@ module Mongoid
|
|
32
32
|
DocumentMatcher.new DOCUMENT
|
33
33
|
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
unless Mongoid::VERSION == '4.0.0'
|
36
|
+
def be_paranoid
|
37
|
+
DocumentMatcher.new PARANOIA
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
40
|
+
def be_versioned
|
41
|
+
DocumentMatcher.new VERSIONING
|
42
|
+
end
|
41
43
|
end
|
42
44
|
|
43
45
|
def be_timestamped
|
@@ -2,34 +2,34 @@ module Mongoid
|
|
2
2
|
module Matchers
|
3
3
|
module Document
|
4
4
|
class HaveFieldMatcher < Matcher
|
5
|
-
def initialize
|
5
|
+
def initialize *fields
|
6
6
|
@fields = fields.collect(&:to_s)
|
7
7
|
end
|
8
8
|
|
9
|
-
def of_type
|
9
|
+
def of_type type
|
10
10
|
@type = type
|
11
11
|
self
|
12
12
|
end
|
13
13
|
|
14
|
-
def with_default_value
|
14
|
+
def with_default_value default
|
15
15
|
@default = default
|
16
16
|
self
|
17
17
|
end
|
18
18
|
|
19
|
-
def matches?
|
20
|
-
@klass = class_of
|
19
|
+
def matches? subject
|
20
|
+
@klass = class_of subject
|
21
21
|
@errors = []
|
22
22
|
|
23
23
|
@fields.each do |field|
|
24
|
-
if @klass.fields.include?
|
25
|
-
error =
|
24
|
+
if @klass.fields.include? field
|
25
|
+
error = ''
|
26
26
|
result_field = @klass.fields[field]
|
27
27
|
|
28
|
-
if check_type_with
|
28
|
+
if check_type_with result_field.type
|
29
29
|
error << " of type #{result_field.type.inspect}"
|
30
30
|
end
|
31
31
|
|
32
|
-
if check_default_with
|
32
|
+
if check_default_with result_field.default_val
|
33
33
|
error << " with default value of #{result_field.default_val.inspect}"
|
34
34
|
end
|
35
35
|
|
@@ -61,20 +61,19 @@ module Mongoid
|
|
61
61
|
|
62
62
|
private
|
63
63
|
|
64
|
-
def check_type_with
|
64
|
+
def check_type_with type
|
65
65
|
@type && type != @type
|
66
66
|
end
|
67
67
|
|
68
|
-
def check_default_with
|
68
|
+
def check_default_with default
|
69
69
|
!@default.nil? && !default.nil? && default != @default
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
def have_field
|
73
|
+
def have_field *fields
|
74
74
|
HaveFieldMatcher.new(*fields)
|
75
75
|
end
|
76
76
|
alias :have_fields :have_field
|
77
|
-
|
78
77
|
end
|
79
78
|
end
|
80
79
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Mongoid
|
2
2
|
module Matchers
|
3
3
|
class HaveIndexMatcher < Matcher
|
4
|
-
def initialize
|
4
|
+
def initialize *fields
|
5
5
|
@fields = fields.map(&:to_sym)
|
6
6
|
end
|
7
7
|
|
8
|
-
def matches?
|
9
|
-
@klass = class_of
|
8
|
+
def matches? subject
|
9
|
+
@klass = class_of subject
|
10
10
|
@klass.index_options.any? do |index, options|
|
11
11
|
index.keys == @fields
|
12
12
|
end
|
@@ -29,7 +29,7 @@ module Mongoid
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def have_index_for
|
32
|
+
def have_index_for *fields
|
33
33
|
HaveIndexMatcher.new(*fields)
|
34
34
|
end
|
35
35
|
end
|
data/lib/matchers/matcher.rb
CHANGED
data/lib/mongoid-minitest.rb
CHANGED
@@ -1,29 +1,16 @@
|
|
1
1
|
gem 'minitest'
|
2
|
-
require '
|
3
|
-
require 'minitest/spec'
|
4
|
-
require 'minitest/matchers'
|
5
|
-
|
2
|
+
require 'minitest-activemodel'
|
6
3
|
require 'matchers/matcher'
|
7
4
|
require 'matchers/document/document'
|
8
5
|
require 'matchers/document/have_field'
|
9
6
|
require 'matchers/document/be_stored_in'
|
10
7
|
require 'matchers/document/have_index'
|
11
|
-
require 'matchers/validations/validations'
|
12
|
-
require 'matchers/validations/presence'
|
13
|
-
require 'matchers/validations/uniqueness'
|
14
|
-
require 'matchers/validations/length'
|
15
|
-
require 'matchers/validations/format'
|
16
|
-
require 'matchers/validations/inclusion'
|
17
|
-
require 'matchers/validations/exclusion'
|
18
|
-
require 'matchers/validations/confirmation'
|
19
|
-
require 'matchers/validations/acceptance'
|
20
|
-
require 'matchers/validations/associated'
|
21
8
|
require 'matchers/associations/associations'
|
22
9
|
|
23
10
|
module Mongoid
|
24
11
|
module Matchers
|
25
12
|
include Document
|
26
|
-
include Validations
|
27
13
|
include Associations
|
14
|
+
include MiniTest::Matchers::ActiveModel
|
28
15
|
end
|
29
16
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'mongoid-minitest'
|
5
|
+
gem.version = '1.0.0'
|
6
|
+
|
7
|
+
gem.authors = ['Francesco Rodriguez', 'Sascha Wessel', 'Godfrey Chan', 'Ryan McGeary']
|
8
|
+
gem.email = ['lrodriguezsanc@gmail.com', 'ryan@mcgeary.org']
|
9
|
+
gem.description = %q{MiniTest matchers for Mongoid}
|
10
|
+
gem.summary = gem.description
|
11
|
+
gem.homepage = 'https://github.com/frodsan/mongoid-minitest'
|
12
|
+
gem.licenses = ['MIT']
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split "\n"
|
15
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename f }
|
16
|
+
gem.test_files = `git ls-files -- test/*`.split "\n"
|
17
|
+
gem.extra_rdoc_files = ['CHANGELOG.md', 'LICENSE.md', 'README.md']
|
18
|
+
gem.rdoc_options = ['--charset=UTF-8']
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
|
21
|
+
gem.required_ruby_version = '>= 1.9.3'
|
22
|
+
|
23
|
+
gem.add_dependency 'minitest', '~> 4.1'
|
24
|
+
gem.add_dependency 'minitest-matchers', '~> 1.2'
|
25
|
+
gem.add_dependency 'mongoid' , '>= 3'
|
26
|
+
gem.add_dependency 'minitest-activemodel', '~> 1.0'
|
27
|
+
gem.add_development_dependency 'rake'
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe "Associations" do
|
4
|
+
describe Person do
|
5
|
+
subject { Person }
|
6
|
+
|
7
|
+
it { must have_many(:pets).of_type(Pet).as_inverse_of(:owner) }
|
8
|
+
it { must have_one(:account).of_type(Account) }
|
9
|
+
it { must have_and_belong_to_many(:friends).of_type(Person) }
|
10
|
+
|
11
|
+
it { must embed_one(:profile) }
|
12
|
+
it { must embed_many(:sites) }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Pet do
|
16
|
+
subject { Pet }
|
17
|
+
|
18
|
+
it { must belong_to(:owner).of_type(Person) }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Account do
|
22
|
+
subject { Account }
|
23
|
+
|
24
|
+
it { must belong_to(:person).of_type(Person) }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe Site do
|
28
|
+
subject { Site }
|
29
|
+
|
30
|
+
it { must embedded_in(:person) }
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'Document' do
|
4
|
+
describe Person do
|
5
|
+
subject { Person }
|
6
|
+
|
7
|
+
it { must be_document }
|
8
|
+
it { must be_timestamped }
|
9
|
+
unless Mongoid::VERSION == '4.0.0'
|
10
|
+
it { must be_paranoid }
|
11
|
+
it { must be_versioned }
|
12
|
+
end
|
13
|
+
|
14
|
+
it { must be_stored_in(:people) }
|
15
|
+
|
16
|
+
it { must have_field(:name).of_type(String).with_default_value('me') }
|
17
|
+
it { must have_fields(:name, :login).of_type(String).with_default_value('me') }
|
18
|
+
|
19
|
+
it { must have_index_for(:name) }
|
20
|
+
it { must have_index_for(:email, :login) }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe Pet do
|
24
|
+
subject { Pet }
|
25
|
+
|
26
|
+
it { must have_index_for(:owner_id) }
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class Person
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Timestamps
|
4
|
+
unless Mongoid::VERSION == '4.0.0'
|
5
|
+
include Mongoid::Paranoia
|
6
|
+
include Mongoid::Versioning
|
7
|
+
end
|
8
|
+
|
9
|
+
field :login, type: String, default: 'me'
|
10
|
+
field :password, type: String
|
11
|
+
field :name, type: String, default: 'me'
|
12
|
+
field :age, type: Integer
|
13
|
+
field :email, type: String
|
14
|
+
field :role, type: String
|
15
|
+
field :site, type: String
|
16
|
+
|
17
|
+
index({ name: 1 }, { name: 'name' })
|
18
|
+
index({ email: 1, login: 1 })
|
19
|
+
|
20
|
+
has_one :account
|
21
|
+
has_many :pets, inverse_of: :owner
|
22
|
+
has_and_belongs_to_many :friends, class_name: 'Person'
|
23
|
+
|
24
|
+
embeds_one :profile
|
25
|
+
embeds_many :sites
|
26
|
+
end
|
27
|
+
|
28
|
+
class Pet
|
29
|
+
include Mongoid::Document
|
30
|
+
|
31
|
+
belongs_to :owner, class_name: 'Person', index: :true
|
32
|
+
end
|
33
|
+
|
34
|
+
class Account
|
35
|
+
include Mongoid::Document
|
36
|
+
|
37
|
+
belongs_to :person
|
38
|
+
end
|
39
|
+
|
40
|
+
class Profile
|
41
|
+
include Mongoid::Document
|
42
|
+
end
|
43
|
+
|
44
|
+
class Site
|
45
|
+
include Mongoid::Document
|
46
|
+
|
47
|
+
embedded_in :person
|
48
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
gem 'minitest'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'mongoid'
|
5
|
+
require 'mongoid-minitest'
|
6
|
+
|
7
|
+
Dir["#{File.dirname(__FILE__)}/models/*.rb"].each { |f| require f }
|
8
|
+
|
9
|
+
Mongoid.configure do |config|
|
10
|
+
config.connect_to 'mongoid-minitest-test'
|
11
|
+
end
|
12
|
+
|
13
|
+
class MiniTest::Spec
|
14
|
+
include Mongoid::Matchers
|
15
|
+
end
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-minitest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francesco Rodriguez
|
8
8
|
- Sascha Wessel
|
9
9
|
- Godfrey Chan
|
10
|
+
- Ryan McGeary
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2013-02-
|
14
|
+
date: 2013-02-27 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: minitest
|
@@ -42,18 +43,32 @@ dependencies:
|
|
42
43
|
version: '1.2'
|
43
44
|
- !ruby/object:Gem::Dependency
|
44
45
|
name: mongoid
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '3'
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '3'
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: minitest-activemodel
|
45
60
|
requirement: !ruby/object:Gem::Requirement
|
46
61
|
requirements:
|
47
62
|
- - ~>
|
48
63
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
64
|
+
version: '1.0'
|
50
65
|
type: :runtime
|
51
66
|
prerelease: false
|
52
67
|
version_requirements: !ruby/object:Gem::Requirement
|
53
68
|
requirements:
|
54
69
|
- - ~>
|
55
70
|
- !ruby/object:Gem::Version
|
56
|
-
version: '
|
71
|
+
version: '1.0'
|
57
72
|
- !ruby/object:Gem::Dependency
|
58
73
|
name: rake
|
59
74
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,47 +83,51 @@ dependencies:
|
|
68
83
|
- - '>='
|
69
84
|
- !ruby/object:Gem::Version
|
70
85
|
version: '0'
|
71
|
-
description:
|
86
|
+
description: MiniTest matchers for Mongoid
|
72
87
|
email:
|
73
88
|
- lrodriguezsanc@gmail.com
|
89
|
+
- ryan@mcgeary.org
|
74
90
|
executables: []
|
75
91
|
extensions: []
|
76
|
-
extra_rdoc_files:
|
92
|
+
extra_rdoc_files:
|
93
|
+
- CHANGELOG.md
|
94
|
+
- LICENSE.md
|
95
|
+
- README.md
|
77
96
|
files:
|
97
|
+
- .gitignore
|
98
|
+
- .travis.yml
|
99
|
+
- CHANGELOG.md
|
100
|
+
- Gemfile
|
101
|
+
- Gemfile.edge
|
102
|
+
- LICENSE.md
|
103
|
+
- README.md
|
104
|
+
- Rakefile
|
78
105
|
- lib/matchers/associations/associations.rb
|
79
106
|
- lib/matchers/document/be_stored_in.rb
|
80
107
|
- lib/matchers/document/document.rb
|
81
108
|
- lib/matchers/document/have_field.rb
|
82
109
|
- lib/matchers/document/have_index.rb
|
83
|
-
- lib/matchers/helpers.rb
|
84
110
|
- lib/matchers/matcher.rb
|
85
|
-
- lib/matchers/validations/acceptance.rb
|
86
|
-
- lib/matchers/validations/associated.rb
|
87
|
-
- lib/matchers/validations/confirmation.rb
|
88
|
-
- lib/matchers/validations/exclusion.rb
|
89
|
-
- lib/matchers/validations/format.rb
|
90
|
-
- lib/matchers/validations/inclusion.rb
|
91
|
-
- lib/matchers/validations/length.rb
|
92
|
-
- lib/matchers/validations/presence.rb
|
93
|
-
- lib/matchers/validations/uniqueness.rb
|
94
|
-
- lib/matchers/validations/validations.rb
|
95
|
-
- lib/mongoid-minitest/version.rb
|
96
111
|
- lib/mongoid-minitest.rb
|
97
|
-
-
|
98
|
-
-
|
99
|
-
-
|
112
|
+
- mongoid-minitest.gemspec
|
113
|
+
- test/matchers/associations_test.rb
|
114
|
+
- test/matchers/document_test.rb
|
115
|
+
- test/models/models.rb
|
116
|
+
- test/test_helper.rb
|
100
117
|
homepage: https://github.com/frodsan/mongoid-minitest
|
101
|
-
licenses:
|
118
|
+
licenses:
|
119
|
+
- MIT
|
102
120
|
metadata: {}
|
103
121
|
post_install_message:
|
104
|
-
rdoc_options:
|
122
|
+
rdoc_options:
|
123
|
+
- --charset=UTF-8
|
105
124
|
require_paths:
|
106
125
|
- lib
|
107
126
|
required_ruby_version: !ruby/object:Gem::Requirement
|
108
127
|
requirements:
|
109
128
|
- - '>='
|
110
129
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
130
|
+
version: 1.9.3
|
112
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
132
|
requirements:
|
114
133
|
- - '>='
|
@@ -119,5 +138,9 @@ rubyforge_project:
|
|
119
138
|
rubygems_version: 2.0.0
|
120
139
|
signing_key:
|
121
140
|
specification_version: 4
|
122
|
-
summary:
|
123
|
-
test_files:
|
141
|
+
summary: MiniTest matchers for Mongoid
|
142
|
+
test_files:
|
143
|
+
- test/matchers/associations_test.rb
|
144
|
+
- test/matchers/document_test.rb
|
145
|
+
- test/models/models.rb
|
146
|
+
- test/test_helper.rb
|