mongoid4-rspec 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +6 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +21 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +207 -0
- data/Rakefile +17 -0
- data/lib/matchers/accept_nested_attributes.rb +67 -0
- data/lib/matchers/allow_mass_assignment.rb +101 -0
- data/lib/matchers/associations.rb +316 -0
- data/lib/matchers/collections.rb +9 -0
- data/lib/matchers/document.rb +163 -0
- data/lib/matchers/indexes.rb +84 -0
- data/lib/matchers/validations.rb +81 -0
- data/lib/matchers/validations/acceptance_of.rb +9 -0
- data/lib/matchers/validations/associated.rb +19 -0
- data/lib/matchers/validations/confirmation_of.rb +9 -0
- data/lib/matchers/validations/custom_validation_of.rb +47 -0
- data/lib/matchers/validations/exclusion_of.rb +49 -0
- data/lib/matchers/validations/format_of.rb +71 -0
- data/lib/matchers/validations/inclusion_of.rb +49 -0
- data/lib/matchers/validations/length_of.rb +147 -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 +82 -0
- data/lib/matchers/validations/with_message.rb +27 -0
- data/lib/mongoid-rspec.rb +33 -0
- data/lib/mongoid-rspec/version.rb +5 -0
- data/mongoid-rspec.gemspec +25 -0
- data/mongoid4-rspec.gemspec +25 -0
- data/spec/models/article.rb +29 -0
- data/spec/models/comment.rb +6 -0
- data/spec/models/log.rb +4 -0
- data/spec/models/movie_article.rb +8 -0
- data/spec/models/permalink.rb +5 -0
- data/spec/models/person.rb +10 -0
- data/spec/models/profile.rb +16 -0
- data/spec/models/record.rb +5 -0
- data/spec/models/site.rb +9 -0
- data/spec/models/user.rb +36 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/unit/accept_nested_attributes_spec.rb +12 -0
- data/spec/unit/associations_spec.rb +42 -0
- data/spec/unit/collections_spec.rb +7 -0
- data/spec/unit/document_spec.rb +21 -0
- data/spec/unit/indexes_spec.rb +13 -0
- data/spec/unit/validations_spec.rb +52 -0
- data/spec/validators/ssn_validator.rb +16 -0
- metadata +137 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "AcceptsNestedAttributes" do
|
4
|
+
describe User do
|
5
|
+
it { should accept_nested_attributes_for(:articles) }
|
6
|
+
it { should accept_nested_attributes_for(:comments) }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Article do
|
10
|
+
it { should accept_nested_attributes_for(:permalink) }
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Associations" do
|
4
|
+
describe User do
|
5
|
+
it { should have_many(:articles).with_foreign_key(:author_id).ordered_by(:title) }
|
6
|
+
|
7
|
+
it { should have_one(:record).with_autobuild }
|
8
|
+
|
9
|
+
it { should have_many(:comments).with_dependent(:destroy).with_autosave }
|
10
|
+
|
11
|
+
it { should embed_one(:profile) }
|
12
|
+
|
13
|
+
it { should have_and_belong_to_many(:children).of_type(User) }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Profile do
|
17
|
+
it { should be_embedded_in(:user).as_inverse_of(:profile) }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe Article do
|
21
|
+
it { should belong_to(:author).of_type(User).as_inverse_of(:articles).with_index }
|
22
|
+
it { should embed_many(:comments).with_cascading_callbacks }
|
23
|
+
it { should embed_one(:permalink) }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe Comment do
|
27
|
+
it { should be_embedded_in(:article).as_inverse_of(:comments).with_polymorphism }
|
28
|
+
it { should belong_to(:user).as_inverse_of(:comments) }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe Record do
|
32
|
+
it { should belong_to(:user).as_inverse_of(:record) }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe Permalink do
|
36
|
+
it { should be_embedded_in(:linkable).as_inverse_of(:link) }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe Site do
|
40
|
+
it { should have_many(:users).as_inverse_of(:site).ordered_by(:email.desc) }
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Document" do
|
4
|
+
describe User do
|
5
|
+
it { should have_fields(:email, :login) }
|
6
|
+
it { should be_timestamped_document }
|
7
|
+
it { should be_timestamped_document.with(:created) }
|
8
|
+
it { should_not be_timestamped_document.with(:updated) }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Article do
|
12
|
+
it { should have_field(:published).of_type(Mongoid::Boolean).with_default_value_of(false) }
|
13
|
+
it { should have_field(:allow_comments).of_type(Mongoid::Boolean).with_default_value_of(true) }
|
14
|
+
it { should belong_to(:author) }
|
15
|
+
it { should have_field(:title).localized }
|
16
|
+
it { should_not have_field(:allow_comments).of_type(Mongoid::Boolean).with_default_value_of(false) }
|
17
|
+
it { should_not have_field(:number_of_comments).of_type(Integer).with_default_value_of(1) }
|
18
|
+
it { should be_mongoid_document }
|
19
|
+
it { should be_timestamped_document }
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Indexes" do
|
4
|
+
describe Article do
|
5
|
+
it { should have_index_for(published: 1) }
|
6
|
+
it { should have_index_for(title: 1).with_options(unique: true, background: true, dropDups: true) }
|
7
|
+
it { should have_index_for('permalink._id' => 1) }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe Profile do
|
11
|
+
it { should have_index_for(first_name: 1, last_name: 1) }
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,52 @@
|
|
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_exclusion_of(:login).to_not_allow("super", "index", "edit") }
|
16
|
+
it { should validate_exclusion_of(:password).to_not_allow("password") }
|
17
|
+
it { should validate_inclusion_of(:role).to_allow("admin", "member") }
|
18
|
+
it { should validate_inclusion_of(:role).to_allow(["admin", "member"]) }
|
19
|
+
it { should validate_confirmation_of(:email) }
|
20
|
+
it { should validate_presence_of(:age).on(:create, :update) }
|
21
|
+
it { should validate_numericality_of(:age).on(:create, :update) }
|
22
|
+
it { should validate_inclusion_of(:age).to_allow(23..42).on([:create, :update]) }
|
23
|
+
it { should validate_presence_of(:password).on(:create) }
|
24
|
+
it { should validate_presence_of(:provider_uid).on(:create) }
|
25
|
+
it { should validate_inclusion_of(:locale).to_allow([:en, :ru]) }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe Profile do
|
29
|
+
it { should validate_numericality_of(:age).greater_than(0) }
|
30
|
+
it { should validate_acceptance_of(:terms_of_service) }
|
31
|
+
it { should validate_length_of(:hobbies).with_minimum(1).with_message("requires at least one hobby") }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe Article do
|
35
|
+
it { should validate_length_of(:title).within(8..16) }
|
36
|
+
it { should_not validate_length_of(:content).greater_than(200).less_than(16) }
|
37
|
+
it { should validate_length_of(:content).greater_than(200) }
|
38
|
+
it { should validate_inclusion_of(:status).to_allow([:pending]).on( :create ) }
|
39
|
+
it { should validate_inclusion_of(:status).to_allow([:approved, :rejected]).on( :update ) }
|
40
|
+
end
|
41
|
+
|
42
|
+
describe MovieArticle do
|
43
|
+
it { should validate_numericality_of(:rating).greater_than(0) }
|
44
|
+
it { should validate_numericality_of(:rating).to_allow(:greater_than => 0).less_than_or_equal_to(5) }
|
45
|
+
it { should validate_numericality_of(:classification).to_allow(:even => true, :only_integer => true, :nil => false) }
|
46
|
+
end
|
47
|
+
|
48
|
+
describe Person do
|
49
|
+
it { should custom_validate(:ssn).with_validator(SsnValidator) }
|
50
|
+
it { should_not custom_validate(:name) }
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class SsnValidator < ActiveModel::EachValidator
|
2
|
+
|
3
|
+
def validate_each(record, attribute, value)
|
4
|
+
unless valid_ssn?(record, attribute, value)
|
5
|
+
record.errors[attribute] << "#{value} is not a valid Social Security Number"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.kind() :custom end
|
10
|
+
|
11
|
+
def valid_ssn?(record, attribute, value)
|
12
|
+
# irrelevant here how validation is done
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid4-rspec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.11.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Francesco Boffa
|
8
|
+
- Evan Sagge
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-05-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: mongoid
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 4.0.0.beta2
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 4.0.0.beta2
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '2.14'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '2.14'
|
56
|
+
description: RSpec matches for Mongoid 4 models, including association and validation
|
57
|
+
matchers
|
58
|
+
email: fra.boffa@gmail.com evansagge@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".bundle/config"
|
64
|
+
- ".document"
|
65
|
+
- ".gitignore"
|
66
|
+
- ".ruby-gemset"
|
67
|
+
- ".ruby-version"
|
68
|
+
- ".travis.yml"
|
69
|
+
- Gemfile
|
70
|
+
- LICENSE
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- lib/matchers/accept_nested_attributes.rb
|
74
|
+
- lib/matchers/allow_mass_assignment.rb
|
75
|
+
- lib/matchers/associations.rb
|
76
|
+
- lib/matchers/collections.rb
|
77
|
+
- lib/matchers/document.rb
|
78
|
+
- lib/matchers/indexes.rb
|
79
|
+
- lib/matchers/validations.rb
|
80
|
+
- lib/matchers/validations/acceptance_of.rb
|
81
|
+
- lib/matchers/validations/associated.rb
|
82
|
+
- lib/matchers/validations/confirmation_of.rb
|
83
|
+
- lib/matchers/validations/custom_validation_of.rb
|
84
|
+
- lib/matchers/validations/exclusion_of.rb
|
85
|
+
- lib/matchers/validations/format_of.rb
|
86
|
+
- lib/matchers/validations/inclusion_of.rb
|
87
|
+
- lib/matchers/validations/length_of.rb
|
88
|
+
- lib/matchers/validations/numericality_of.rb
|
89
|
+
- lib/matchers/validations/presence_of.rb
|
90
|
+
- lib/matchers/validations/uniqueness_of.rb
|
91
|
+
- lib/matchers/validations/with_message.rb
|
92
|
+
- lib/mongoid-rspec.rb
|
93
|
+
- lib/mongoid-rspec/version.rb
|
94
|
+
- mongoid-rspec.gemspec
|
95
|
+
- mongoid4-rspec.gemspec
|
96
|
+
- spec/models/article.rb
|
97
|
+
- spec/models/comment.rb
|
98
|
+
- spec/models/log.rb
|
99
|
+
- spec/models/movie_article.rb
|
100
|
+
- spec/models/permalink.rb
|
101
|
+
- spec/models/person.rb
|
102
|
+
- spec/models/profile.rb
|
103
|
+
- spec/models/record.rb
|
104
|
+
- spec/models/site.rb
|
105
|
+
- spec/models/user.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/unit/accept_nested_attributes_spec.rb
|
108
|
+
- spec/unit/associations_spec.rb
|
109
|
+
- spec/unit/collections_spec.rb
|
110
|
+
- spec/unit/document_spec.rb
|
111
|
+
- spec/unit/indexes_spec.rb
|
112
|
+
- spec/unit/validations_spec.rb
|
113
|
+
- spec/validators/ssn_validator.rb
|
114
|
+
homepage: http://github.com/aomega08/mongoid4-rspec
|
115
|
+
licenses: []
|
116
|
+
metadata: {}
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project: mongoid-rspec
|
133
|
+
rubygems_version: 2.2.1
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: RSpec matchers for Mongoid 4
|
137
|
+
test_files: []
|