mongoid-rspec-multi-db 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +4 -0
- data/.rvmrc +1 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +117 -0
- data/Rakefile +17 -0
- data/lib/matchers/associations.rb +215 -0
- data/lib/matchers/collections.rb +9 -0
- data/lib/matchers/document.rb +111 -0
- data/lib/matchers/indexes.rb +51 -0
- data/lib/matchers/validations.rb +42 -0
- data/lib/matchers/validations/associated.rb +19 -0
- data/lib/matchers/validations/confirmation_of.rb +9 -0
- data/lib/matchers/validations/format_of.rb +71 -0
- data/lib/matchers/validations/inclusion_of.rb +42 -0
- data/lib/matchers/validations/length_of.rb +100 -0
- data/lib/matchers/validations/numericality_of.rb +74 -0
- data/lib/matchers/validations/presence_of.rb +9 -0
- data/lib/matchers/validations/uniqueness_of.rb +99 -0
- data/lib/mongoid-rspec.rb +24 -0
- data/lib/mongoid-rspec/version.rb +5 -0
- data/mongoid-rspec.gemspec +28 -0
- data/spec/models/article.rb +23 -0
- data/spec/models/comment.rb +6 -0
- data/spec/models/log.rb +4 -0
- data/spec/models/movie_article.rb +7 -0
- data/spec/models/permalink.rb +5 -0
- data/spec/models/profile.rb +18 -0
- data/spec/models/record.rb +5 -0
- data/spec/models/site.rb +10 -0
- data/spec/models/user.rb +24 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/unit/associations_spec.rb +47 -0
- data/spec/unit/collections_spec.rb +7 -0
- data/spec/unit/document_spec.rb +20 -0
- data/spec/unit/indexes_spec.rb +12 -0
- data/spec/unit/validations_spec.rb +32 -0
- metadata +134 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'mongoid'
|
4
|
+
require 'rspec'
|
5
|
+
require 'matchers/document'
|
6
|
+
require 'matchers/associations'
|
7
|
+
require 'matchers/collections'
|
8
|
+
require 'matchers/indexes'
|
9
|
+
require 'matchers/validations'
|
10
|
+
require 'matchers/validations/associated'
|
11
|
+
require 'matchers/validations/confirmation_of'
|
12
|
+
require 'matchers/validations/format_of'
|
13
|
+
require 'matchers/validations/inclusion_of'
|
14
|
+
require 'matchers/validations/length_of'
|
15
|
+
require 'matchers/validations/numericality_of'
|
16
|
+
require 'matchers/validations/presence_of'
|
17
|
+
require 'matchers/validations/uniqueness_of'
|
18
|
+
|
19
|
+
module Mongoid
|
20
|
+
module Matchers
|
21
|
+
include Mongoid::Matchers::Associations
|
22
|
+
include Mongoid::Matchers::Validations
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "mongoid-rspec/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "mongoid-rspec-multi-db"
|
7
|
+
s.version = Mongoid::Rspec::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Evan Sagge"]
|
10
|
+
s.email = %q{evansagge@gmail.com}
|
11
|
+
s.homepage = %q{http://github.com/evansagge/mongoid-rspec}
|
12
|
+
s.summary = %q{RSpec matchers for Mongoid}
|
13
|
+
s.description = %q{RSpec matches for Mongoid models, including association and validation matchers}
|
14
|
+
|
15
|
+
s.rubyforge_project = "mongoid-rspec"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
# s.add_runtime_dependency(%q<mongoid>, ["~> 2.0"])
|
23
|
+
# s.add_runtime_dependency(%q<rspec>, ["~> 2"])
|
24
|
+
|
25
|
+
s.add_dependency 'rake'#, '~> 0.9.2'
|
26
|
+
s.add_dependency 'mongoid-multi-db', '= 3.0.0'
|
27
|
+
s.add_dependency 'rspec', '~> 2'
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Article
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Timestamps
|
4
|
+
include Mongoid::Paranoia
|
5
|
+
include Mongoid::Versioning
|
6
|
+
|
7
|
+
field :title
|
8
|
+
field :content
|
9
|
+
field :published, :type => Boolean, :default => false
|
10
|
+
field :allow_comments, :type => Boolean, :default => true
|
11
|
+
|
12
|
+
embeds_many :comments
|
13
|
+
embeds_one :permalink
|
14
|
+
referenced_in :author, :class_name => 'User', :inverse_of => :articles, :index => true
|
15
|
+
|
16
|
+
validates :title, :presence => true
|
17
|
+
|
18
|
+
validates_length_of :title, :minimum => 8, :maximum => 16
|
19
|
+
|
20
|
+
index :title, :unique => true, :background => true
|
21
|
+
index :published
|
22
|
+
end
|
23
|
+
|
data/spec/models/log.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
class MovieArticle < Article
|
2
|
+
field :rating, :type => Float
|
3
|
+
field :classification, :type => Integer
|
4
|
+
|
5
|
+
validates_numericality_of :rating, :greater_than => 0, :less_than_or_equal_to => 5
|
6
|
+
validates_numericality_of :classification, :even => true, :only_integer => true, :allow_nil => false
|
7
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Profile
|
2
|
+
include Mongoid::Document
|
3
|
+
|
4
|
+
field :first_name
|
5
|
+
field :last_name
|
6
|
+
field :age
|
7
|
+
|
8
|
+
embedded_in :user, :inverse_of => :profile
|
9
|
+
|
10
|
+
validates_numericality_of :age, :greater_than => 0
|
11
|
+
|
12
|
+
index(
|
13
|
+
[
|
14
|
+
[ :first_name, Mongo::ASCENDING ],
|
15
|
+
[ :last_name, Mongo::ASCENDING ]
|
16
|
+
]
|
17
|
+
)
|
18
|
+
end
|
data/spec/models/site.rb
ADDED
data/spec/models/user.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
class User
|
2
|
+
include Mongoid::Document
|
3
|
+
|
4
|
+
field :login
|
5
|
+
field :email
|
6
|
+
field :role
|
7
|
+
|
8
|
+
referenced_in :site, :inverse_of => :users
|
9
|
+
references_many :articles, :foreign_key => :author_id
|
10
|
+
references_many :comments, :dependent => :destroy, :autosave => true, :index => true
|
11
|
+
references_and_referenced_in_many :children, :class_name => "User"
|
12
|
+
references_one :record
|
13
|
+
|
14
|
+
embeds_one :profile
|
15
|
+
|
16
|
+
validates :login, :presence => true, :uniqueness => { :scope => :site }, :format => { :with => /^[\w\-]+$/ }
|
17
|
+
validates :email, :uniqueness => { :case_sensitive => false, :scope => :site, :message => "is already taken" }, :confirmation => true
|
18
|
+
validates :role, :presence => true, :inclusion => { :in => ["admin", "moderator", "member"]}
|
19
|
+
validates :profile, :presence => true, :associated => true
|
20
|
+
|
21
|
+
def admin?
|
22
|
+
false
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "lib"))
|
3
|
+
MODELS = File.join(File.dirname(__FILE__), "models")
|
4
|
+
$LOAD_PATH.unshift(MODELS)
|
5
|
+
|
6
|
+
require "rubygems"
|
7
|
+
require "bundler"
|
8
|
+
Bundler.setup
|
9
|
+
|
10
|
+
require 'rspec'
|
11
|
+
require 'rspec/core'
|
12
|
+
require 'rspec/expectations'
|
13
|
+
require 'mongoid'
|
14
|
+
|
15
|
+
Mongoid.configure do |config|
|
16
|
+
name = "mongoid-rspec-test"
|
17
|
+
host = "localhost"
|
18
|
+
config.master = Mongo::Connection.new.db(name)
|
19
|
+
end
|
20
|
+
|
21
|
+
Dir[ File.join(MODELS, "*.rb") ].sort.each { |file| require File.basename(file) }
|
22
|
+
|
23
|
+
require 'mongoid-rspec'
|
24
|
+
|
25
|
+
RSpec.configure do |config|
|
26
|
+
config.include RSpec::Matchers
|
27
|
+
config.include Mongoid::Matchers
|
28
|
+
config.mock_with :rspec
|
29
|
+
config.after :all do
|
30
|
+
Mongoid.master.collections.each(&:drop)
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Associations" do
|
4
|
+
describe User do
|
5
|
+
it { should reference_many(:articles).with_foreign_key(:author_id) }
|
6
|
+
it { should have_many(:articles).with_foreign_key(:author_id) }
|
7
|
+
|
8
|
+
it { should reference_one(:record) }
|
9
|
+
it { should have_one(:record) }
|
10
|
+
|
11
|
+
it { should reference_many(:comments).with_dependent(:destroy).with_autosave }
|
12
|
+
it { should have_many(:comments).with_dependent(:destroy).with_autosave }
|
13
|
+
|
14
|
+
it { should embed_one :profile }
|
15
|
+
|
16
|
+
it { should reference_and_be_referenced_in_many(:children).of_type(User) }
|
17
|
+
it { should have_and_belong_to_many(:children) }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe Profile do
|
21
|
+
it { should be_embedded_in(:user).as_inverse_of(:profile) }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe Article do
|
25
|
+
it { should be_referenced_in(:author).of_type(User).as_inverse_of(:articles) }
|
26
|
+
it { should belong_to(:author).of_type(User).as_inverse_of(:articles).with_index }
|
27
|
+
it { should embed_many(:comments) }
|
28
|
+
it { should embed_one(:permalink) }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe Comment do
|
32
|
+
it { should be_embedded_in(:article).as_inverse_of(:comments) }
|
33
|
+
it { should be_referenced_in(:user).as_inverse_of(:comments) }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe Record do
|
37
|
+
it { should be_referenced_in(:user).as_inverse_of(:record) }
|
38
|
+
end
|
39
|
+
|
40
|
+
describe Permalink do
|
41
|
+
it { should be_embedded_in(:linkable).as_inverse_of(:link) }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe Site do
|
45
|
+
it { should reference_many(:users).as_inverse_of(:site) }
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Document" do
|
4
|
+
describe User do
|
5
|
+
it { should have_fields(:email, :login) }
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Article do
|
9
|
+
it { should have_field(:published).of_type(Boolean).with_default_value_of(false) }
|
10
|
+
it { should have_field(:allow_comments).of_type(Boolean).with_default_value_of(true) }
|
11
|
+
it { should_not have_field(:allow_comments).of_type(Boolean).with_default_value_of(false) }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe Article do
|
15
|
+
it { should be_mongoid_document }
|
16
|
+
it { should be_versioned_document }
|
17
|
+
it { should be_timestamped_document }
|
18
|
+
it { should be_paranoid_document }
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Indexes" do
|
4
|
+
describe Article do
|
5
|
+
it { should have_index_for(:published) }
|
6
|
+
it { should have_index_for(:title).with_options(:unique => true, :background => true) }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Profile do
|
10
|
+
it { should have_index_for([ [ :first_name, Mongo::ASCENDING ], [ :last_name, Mongo::ASCENDING ] ]) }
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Validations" do
|
4
|
+
describe Site do
|
5
|
+
it { should validate_presence_of(:name) }
|
6
|
+
it { should validate_uniqueness_of(:name) }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe User do
|
10
|
+
it { should validate_presence_of(:login) }
|
11
|
+
it { should validate_uniqueness_of(:login).scoped_to(:site) }
|
12
|
+
it { should validate_uniqueness_of(:email).case_insensitive.with_message("is already taken") }
|
13
|
+
it { should validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
|
14
|
+
it { should validate_associated(:profile) }
|
15
|
+
it { should validate_inclusion_of(:role).to_allow("admin", "member") }
|
16
|
+
it { should validate_confirmation_of(:email) }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe Profile do
|
20
|
+
it { should validate_numericality_of(:age).greater_than(0) }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe Article do
|
24
|
+
it { should validate_length_of(:title).within(8..16) }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe MovieArticle do
|
28
|
+
it { should validate_numericality_of(:rating).greater_than(0) }
|
29
|
+
it { should validate_numericality_of(:rating).to_allow(:greater_than => 0).less_than_or_equal_to(5) }
|
30
|
+
it { should validate_numericality_of(:classification).to_allow(:even => true, :only_integer => true, :nil => false) }
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid-rspec-multi-db
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.4.4
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Evan Sagge
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '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: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mongoid-multi-db
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - '='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 3.0.0
|
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: 3.0.0
|
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'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2'
|
62
|
+
description: RSpec matches for Mongoid models, including association and validation
|
63
|
+
matchers
|
64
|
+
email: evansagge@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .bundle/config
|
70
|
+
- .document
|
71
|
+
- .gitignore
|
72
|
+
- .rvmrc
|
73
|
+
- .travis.yml
|
74
|
+
- Gemfile
|
75
|
+
- Gemfile.lock
|
76
|
+
- LICENSE
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- lib/matchers/associations.rb
|
80
|
+
- lib/matchers/collections.rb
|
81
|
+
- lib/matchers/document.rb
|
82
|
+
- lib/matchers/indexes.rb
|
83
|
+
- lib/matchers/validations.rb
|
84
|
+
- lib/matchers/validations/associated.rb
|
85
|
+
- lib/matchers/validations/confirmation_of.rb
|
86
|
+
- lib/matchers/validations/format_of.rb
|
87
|
+
- lib/matchers/validations/inclusion_of.rb
|
88
|
+
- lib/matchers/validations/length_of.rb
|
89
|
+
- lib/matchers/validations/numericality_of.rb
|
90
|
+
- lib/matchers/validations/presence_of.rb
|
91
|
+
- lib/matchers/validations/uniqueness_of.rb
|
92
|
+
- lib/mongoid-rspec.rb
|
93
|
+
- lib/mongoid-rspec/version.rb
|
94
|
+
- mongoid-rspec.gemspec
|
95
|
+
- spec/models/article.rb
|
96
|
+
- spec/models/comment.rb
|
97
|
+
- spec/models/log.rb
|
98
|
+
- spec/models/movie_article.rb
|
99
|
+
- spec/models/permalink.rb
|
100
|
+
- spec/models/profile.rb
|
101
|
+
- spec/models/record.rb
|
102
|
+
- spec/models/site.rb
|
103
|
+
- spec/models/user.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
- spec/unit/associations_spec.rb
|
106
|
+
- spec/unit/collections_spec.rb
|
107
|
+
- spec/unit/document_spec.rb
|
108
|
+
- spec/unit/indexes_spec.rb
|
109
|
+
- spec/unit/validations_spec.rb
|
110
|
+
homepage: http://github.com/evansagge/mongoid-rspec
|
111
|
+
licenses: []
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project: mongoid-rspec
|
130
|
+
rubygems_version: 1.8.19
|
131
|
+
signing_key:
|
132
|
+
specification_version: 3
|
133
|
+
summary: RSpec matchers for Mongoid
|
134
|
+
test_files: []
|