mongo_doc 0.6.7 → 0.6.8
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/README.textile +1 -1
- data/VERSION +1 -1
- data/lib/mongo_doc/document.rb +11 -2
- data/lib/mongo_doc.rb +1 -1
- data/mongo_doc.gemspec +5 -3
- data/spec/active_model_behavior.rb +64 -0
- data/spec/document_spec.rb +27 -18
- data/spec/spec_helper.rb +2 -0
- metadata +6 -4
data/README.textile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.8
|
data/lib/mongo_doc/document.rb
CHANGED
@@ -48,7 +48,7 @@ module MongoDoc
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def initialize(attrs = {})
|
51
|
-
self.attributes = attrs
|
51
|
+
self.attributes = attrs if attrs
|
52
52
|
end
|
53
53
|
|
54
54
|
def ==(other)
|
@@ -64,6 +64,10 @@ module MongoDoc
|
|
64
64
|
_id.nil?
|
65
65
|
end
|
66
66
|
|
67
|
+
def persisted?
|
68
|
+
_id.present?
|
69
|
+
end
|
70
|
+
|
67
71
|
def remove
|
68
72
|
raise UnsupportedOperation.new('Document#remove is not supported for embedded documents') if _root
|
69
73
|
remove_document
|
@@ -95,9 +99,14 @@ module MongoDoc
|
|
95
99
|
end
|
96
100
|
end
|
97
101
|
|
102
|
+
def to_model
|
103
|
+
self
|
104
|
+
end
|
105
|
+
|
98
106
|
def to_param
|
99
|
-
_id.to_s
|
107
|
+
_id ? _id.to_s : nil
|
100
108
|
end
|
109
|
+
alias to_key to_param
|
101
110
|
|
102
111
|
def update_attributes(attrs)
|
103
112
|
self.attributes = attrs
|
data/lib/mongo_doc.rb
CHANGED
data/mongo_doc.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongo_doc}
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Les Hill"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-11}
|
13
13
|
s.description = %q{ODM for MongoDB}
|
14
14
|
s.email = %q{leshill@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -135,6 +135,7 @@ Gem::Specification.new do |s|
|
|
135
135
|
"perf/mongo_document.rb",
|
136
136
|
"perf/ruby_driver.rb",
|
137
137
|
"script/console",
|
138
|
+
"spec/active_model_behavior.rb",
|
138
139
|
"spec/array_including_argument_matcher.rb",
|
139
140
|
"spec/associations/collection_proxy_spec.rb",
|
140
141
|
"spec/associations/document_proxy_spec.rb",
|
@@ -178,7 +179,8 @@ Gem::Specification.new do |s|
|
|
178
179
|
s.rubygems_version = %q{1.3.7}
|
179
180
|
s.summary = %q{ODM for MongoDB}
|
180
181
|
s.test_files = [
|
181
|
-
"spec/
|
182
|
+
"spec/active_model_behavior.rb",
|
183
|
+
"spec/array_including_argument_matcher.rb",
|
182
184
|
"spec/associations/collection_proxy_spec.rb",
|
183
185
|
"spec/associations/document_proxy_spec.rb",
|
184
186
|
"spec/associations/hash_proxy_spec.rb",
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module ActiveModelBehavior
|
2
|
+
share_as :AnActiveModel do
|
3
|
+
def be_a_boolean
|
4
|
+
::Rspec::Matchers::Matcher.new :be_a_boolean do
|
5
|
+
match do |value|
|
6
|
+
[ true, false ].include?( value )
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it { should respond_to(:to_model) }
|
12
|
+
it { should respond_to(:to_key) }
|
13
|
+
it { should respond_to(:to_param) }
|
14
|
+
|
15
|
+
it { should respond_to(:valid?) }
|
16
|
+
its(:valid?) { should be_a_boolean }
|
17
|
+
|
18
|
+
it { should respond_to(:persisted?) }
|
19
|
+
its(:persisted?) { should be_a_boolean }
|
20
|
+
|
21
|
+
its(:class) { should respond_to(:model_name) }
|
22
|
+
|
23
|
+
context "the model name" do
|
24
|
+
subject do
|
25
|
+
described_class.model_name
|
26
|
+
end
|
27
|
+
|
28
|
+
it { should be_kind_of(String) }
|
29
|
+
its(:human) { should be_kind_of(String) }
|
30
|
+
its(:partial_path) { should be_kind_of(String) }
|
31
|
+
its(:singular) { should be_kind_of(String) }
|
32
|
+
its(:plural) { should be_kind_of(String) }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when its not persisted" do
|
36
|
+
subject do
|
37
|
+
obj = described_class.new
|
38
|
+
obj.stub!(:persisted?).and_return(false)
|
39
|
+
obj
|
40
|
+
end
|
41
|
+
|
42
|
+
its(:to_key) { should be_nil }
|
43
|
+
its(:to_param) { should be_nil }
|
44
|
+
end
|
45
|
+
|
46
|
+
it { should respond_to(:errors) }
|
47
|
+
|
48
|
+
context "errors" do
|
49
|
+
subject do
|
50
|
+
described_class.new.errors
|
51
|
+
end
|
52
|
+
|
53
|
+
it { should respond_to(:[]) }
|
54
|
+
it { should respond_to(:full_messages) }
|
55
|
+
|
56
|
+
context "[:hello]" do
|
57
|
+
it { subject[:hello].should be_an_instance_of(Array) }
|
58
|
+
|
59
|
+
its(:full_messages) { should be_an_instance_of(Array) }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
data/spec/document_spec.rb
CHANGED
@@ -23,44 +23,53 @@ describe "MongoDoc::Document" do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
context "
|
26
|
+
context "ActiveModel" do
|
27
27
|
class FormForTest
|
28
28
|
include MongoDoc::Document
|
29
29
|
|
30
30
|
attr_accessor :data
|
31
31
|
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
@doc._id = '1'
|
33
|
+
describe FormForTest do
|
34
|
+
it_should_behave_like AnActiveModel
|
36
35
|
end
|
37
36
|
|
38
|
-
|
39
|
-
@doc.id.should == @doc._id
|
40
|
-
end
|
37
|
+
let(:doc) { FormForTest.new }
|
41
38
|
|
42
|
-
|
43
|
-
|
39
|
+
context "persisted record" do
|
40
|
+
subject { doc._id = '1'; doc }
|
41
|
+
|
42
|
+
it { should_not be_new_record }
|
43
|
+
it { should be_persisted }
|
44
|
+
its(:id) { should == doc._id }
|
45
|
+
its(:to_param) { should == doc._id.to_s }
|
46
|
+
its(:to_key) { should == doc._id.to_s }
|
44
47
|
end
|
45
48
|
|
46
|
-
context "
|
47
|
-
|
48
|
-
@doc._id = nil
|
49
|
-
@doc.should be_new_record
|
50
|
-
end
|
49
|
+
context "record has not been persisted" do
|
50
|
+
subject { doc }
|
51
51
|
|
52
|
-
it
|
53
|
-
|
54
|
-
|
52
|
+
it { should be_new_record }
|
53
|
+
it { should_not be_persisted }
|
54
|
+
its(:id) { should be_nil }
|
55
|
+
its(:to_param) { should be_nil }
|
56
|
+
its(:to_key) { should be_nil }
|
55
57
|
end
|
56
58
|
|
57
59
|
it "#initialize takes a hash" do
|
58
60
|
data = 'data'
|
59
61
|
FormForTest.new(:data => data).data.should == data
|
60
62
|
end
|
63
|
+
|
64
|
+
it "#initialize accepts a nil" do
|
65
|
+
expect do
|
66
|
+
FormForTest.new(nil)
|
67
|
+
end.should_not raise_error
|
68
|
+
end
|
69
|
+
|
61
70
|
end
|
62
71
|
|
63
|
-
|
72
|
+
context "saving" do
|
64
73
|
class SaveRoot
|
65
74
|
include MongoDoc::Document
|
66
75
|
|
data/spec/spec_helper.rb
CHANGED
@@ -6,9 +6,11 @@ require 'rspec/autorun'
|
|
6
6
|
require 'bson_matchers'
|
7
7
|
require 'hash_matchers'
|
8
8
|
require 'array_including_argument_matcher'
|
9
|
+
require 'active_model_behavior'
|
9
10
|
require 'document_ext'
|
10
11
|
|
11
12
|
RSpec.configure do |config|
|
12
13
|
config.include(BsonMatchers)
|
13
14
|
config.include(HashMatchers)
|
15
|
+
config.include(ActiveModelBehavior)
|
14
16
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_doc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 8
|
10
|
+
version: 0.6.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Les Hill
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-11 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -264,6 +264,7 @@ files:
|
|
264
264
|
- perf/mongo_document.rb
|
265
265
|
- perf/ruby_driver.rb
|
266
266
|
- script/console
|
267
|
+
- spec/active_model_behavior.rb
|
267
268
|
- spec/array_including_argument_matcher.rb
|
268
269
|
- spec/associations/collection_proxy_spec.rb
|
269
270
|
- spec/associations/document_proxy_spec.rb
|
@@ -335,6 +336,7 @@ signing_key:
|
|
335
336
|
specification_version: 3
|
336
337
|
summary: ODM for MongoDB
|
337
338
|
test_files:
|
339
|
+
- spec/active_model_behavior.rb
|
338
340
|
- spec/array_including_argument_matcher.rb
|
339
341
|
- spec/associations/collection_proxy_spec.rb
|
340
342
|
- spec/associations/document_proxy_spec.rb
|