mongoa 0.1.11 → 0.1.12
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/LICENSE +16 -14
- data/README.rdoc +18 -2
- data/VERSION +1 -1
- data/lib/mongoa/mongo_mapper/association_matcher.rb +6 -1
- data/mongoa.gemspec +2 -2
- data/spec/association_matcher_spec.rb +32 -0
- metadata +3 -3
data/LICENSE
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2010, Scott J. Tamosunas
|
2
2
|
|
3
|
-
Permission is hereby granted, free of charge, to any person
|
4
|
-
a copy of this software and associated documentation
|
5
|
-
"Software"), to deal in the Software without
|
6
|
-
without limitation the rights to use,
|
7
|
-
distribute, sublicense, and/or sell
|
8
|
-
|
9
|
-
the following
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
10
11
|
|
11
12
|
The above copyright notice and this permission notice shall be
|
12
13
|
included in all copies or substantial portions of the Software.
|
13
14
|
|
14
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING
|
20
|
-
WITH THE SOFTWARE OR THE USE OR
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -1,6 +1,22 @@
|
|
1
|
-
=
|
1
|
+
= Mongoa - The missing matchers for Rspec and Mongo Mapper! Inspired by Shoulda (thanks Thoughtbot!)
|
2
2
|
|
3
|
-
|
3
|
+
= Usage
|
4
|
+
|
5
|
+
Test your MongoMapper associations and validations. Currently only works with RSpec.
|
6
|
+
|
7
|
+
describe Post do
|
8
|
+
it { should belong_to(:user) }
|
9
|
+
it { should have_many(:comments) }
|
10
|
+
|
11
|
+
it { should validate_presence_of(:body) }
|
12
|
+
it { should validate_inclusion_of(:state, %w("new" "active" "closed")) }
|
13
|
+
it { should validate_length_of(:image_path, :maximum => 256) }
|
14
|
+
it { should validate_numericality_of(:times_read) } #FORTHCOMING
|
15
|
+
end
|
16
|
+
|
17
|
+
= Credits
|
18
|
+
|
19
|
+
Mongoa was inspired by Shoulda, the excellent gem by {thoughtbot}[http://thoughtbot.com/community]
|
4
20
|
|
5
21
|
== Note on Patches/Pull Requests
|
6
22
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.12
|
@@ -8,6 +8,10 @@ module Mongoa
|
|
8
8
|
def have_many(name)
|
9
9
|
MongoAssociationMatcher.new(:has_many, name)
|
10
10
|
end
|
11
|
+
|
12
|
+
def has_one(name)
|
13
|
+
MongoAssociationMatcher.new(:has_one, name)
|
14
|
+
end
|
11
15
|
end
|
12
16
|
|
13
17
|
class MongoAssociationMatcher
|
@@ -83,7 +87,8 @@ module Mongoa
|
|
83
87
|
|
84
88
|
def macro_correct?
|
85
89
|
(association.type == :belongs_to && macro == :belongs_to) ||
|
86
|
-
(association.type == :many && macro == :has_many)
|
90
|
+
(association.type == :many && macro == :has_many) ||
|
91
|
+
(association.type == :one && macro == :has_one)
|
87
92
|
end
|
88
93
|
|
89
94
|
def foreign_key_exists?
|
data/mongoa.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongoa}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.12"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Scott J. Tamosunas"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-20}
|
13
13
|
s.description = %q{Adds the association and validation macros for Rspec in the same way Shoulda does for ActiveRecord.}
|
14
14
|
s.email = %q{tamosunas@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -40,6 +40,26 @@ class EmbeddedCommentNoSpecification
|
|
40
40
|
include MongoMapper::EmbeddedDocument
|
41
41
|
end
|
42
42
|
|
43
|
+
class Employee
|
44
|
+
include MongoMapper::Document
|
45
|
+
key :name, :required => true
|
46
|
+
|
47
|
+
has_one :office
|
48
|
+
end
|
49
|
+
|
50
|
+
class EmployeeWOutHO
|
51
|
+
include MongoMapper::Document
|
52
|
+
key :name, :required => true
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
class Office
|
57
|
+
include MongoMapper::Document
|
58
|
+
key :name, :required => true
|
59
|
+
|
60
|
+
belongs_to :employee
|
61
|
+
end
|
62
|
+
|
43
63
|
describe Mongoa::MongoMapper::Matchers do
|
44
64
|
describe "#belongs_to" do
|
45
65
|
describe "document" do
|
@@ -78,4 +98,16 @@ describe Mongoa::MongoMapper::Matchers do
|
|
78
98
|
matcher.should_not be_matches(PostWOutHM.new)
|
79
99
|
end
|
80
100
|
end
|
101
|
+
|
102
|
+
describe "#has_one" do
|
103
|
+
it "should return true if the has_one relationship is specified" do
|
104
|
+
matcher = Mongoa::MongoMapper::MongoAssociationMatcher.new(:has_one, :office)
|
105
|
+
matcher.should be_matches(Employee.new)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should return false if the has_one relationship is not specified" do
|
109
|
+
matcher = Mongoa::MongoMapper::MongoAssociationMatcher.new(:has_one, :office)
|
110
|
+
matcher.should_not be_matches(EmployeeWOutHO.new)
|
111
|
+
end
|
112
|
+
end
|
81
113
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 12
|
9
|
+
version: 0.1.12
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Scott J. Tamosunas
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-20 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|