mongomodel 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Appraisals +9 -0
- data/Gemfile +2 -2
- data/Rakefile +23 -13
- data/gemfiles/rails-3.0.gemfile +10 -0
- data/gemfiles/rails-3.0.gemfile.lock +73 -0
- data/gemfiles/rails-3.1.gemfile +10 -0
- data/gemfiles/rails-3.1.gemfile.lock +83 -0
- data/lib/mongomodel.rb +0 -1
- data/lib/mongomodel/concerns/abstract_class.rb +1 -0
- data/lib/mongomodel/concerns/associations.rb +12 -3
- data/lib/mongomodel/concerns/associations/base/definition.rb +5 -3
- data/lib/mongomodel/concerns/attribute_methods.rb +14 -7
- data/lib/mongomodel/concerns/properties.rb +15 -4
- data/lib/mongomodel/document/indexes.rb +14 -5
- data/lib/mongomodel/document/persistence.rb +7 -5
- data/lib/mongomodel/document/scopes.rb +22 -8
- data/lib/mongomodel/railtie.rb +2 -3
- data/lib/mongomodel/support/collection.rb +3 -1
- data/lib/mongomodel/support/map.rb +4 -2
- data/lib/mongomodel/support/mongo_options.rb +9 -34
- data/lib/mongomodel/support/scope.rb +2 -14
- data/lib/mongomodel/version.rb +1 -1
- data/mongomodel.gemspec +3 -3
- data/spec/mongomodel/concerns/associations/belongs_to_spec.rb +4 -6
- data/spec/mongomodel/concerns/associations/has_many_by_ids_spec.rb +123 -123
- data/spec/mongomodel/concerns/logging_spec.rb +1 -1
- data/spec/mongomodel/document/dynamic_finders_spec.rb +32 -32
- data/spec/mongomodel/support/scope_spec.rb +0 -18
- data/spec/spec.opts +0 -3
- data/spec/spec_helper.rb +4 -4
- data/spec/support/helpers/document_finder_stubs.rb +2 -2
- data/spec/support/matchers/be_a_subclass_of.rb +1 -1
- data/spec/support/matchers/be_truthy.rb +1 -1
- data/spec/support/matchers/find_with.rb +4 -4
- data/spec/support/matchers/respond_to_boolean.rb +1 -1
- data/spec/support/matchers/run_callbacks.rb +1 -1
- metadata +23 -74
@@ -6,7 +6,7 @@ module MongoModel
|
|
6
6
|
define_class(:TestDocument, described_class)
|
7
7
|
|
8
8
|
let(:logger) { mock('logger').as_null_object }
|
9
|
-
before(:
|
9
|
+
before(:each) { MongoModel.logger = logger }
|
10
10
|
|
11
11
|
it "should have a logger reader on the class" do
|
12
12
|
TestDocument.logger.should == logger
|
@@ -18,6 +18,38 @@ module MongoModel
|
|
18
18
|
@mary = Person.create!(:name => 'Mary', :age => 33, :id => '5')
|
19
19
|
end
|
20
20
|
|
21
|
+
def self.should_find(*args, &block)
|
22
|
+
it "should return correct results when called with #{args.inspect}" do
|
23
|
+
expected = instance_eval(&block)
|
24
|
+
subject.send(valid_finder, *args).should == expected
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.should_raise(*args, &block)
|
29
|
+
it "should raise DocumentNotFound exception if results not found" do
|
30
|
+
message = instance_eval(&block)
|
31
|
+
lambda { subject.send(valid_finder, *args) }.should raise_error(DocumentNotFound, message)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.should_initialize(*args, &block)
|
36
|
+
it "should initialize new instance" do
|
37
|
+
result = subject.send(valid_finder, *args)
|
38
|
+
result.should be_a_new_record
|
39
|
+
result.should be_an_instance_of(Person)
|
40
|
+
yield(result).should be_true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.should_create(*args, &block)
|
45
|
+
it "should create new instance" do
|
46
|
+
result = subject.send(valid_finder, *args)
|
47
|
+
result.should_not be_a_new_record
|
48
|
+
result.should be_an_instance_of(Person)
|
49
|
+
yield(result).should be_true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
21
53
|
shared_examples_for "a dynamic finder" do
|
22
54
|
it { should respond_to(valid_finder) }
|
23
55
|
it { should_not respond_to(invalid_finder) }
|
@@ -25,38 +57,6 @@ module MongoModel
|
|
25
57
|
it "should raise NoMethodError calling an invalid finder" do
|
26
58
|
lambda { subject.send(invalid_finder, "Foo") }.should raise_error(NoMethodError)
|
27
59
|
end
|
28
|
-
|
29
|
-
def self.should_find(*args, &block)
|
30
|
-
it "should return correct results when called with #{args.inspect}" do
|
31
|
-
expected = instance_eval(&block)
|
32
|
-
subject.send(valid_finder, *args).should == expected
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.should_raise(*args, &block)
|
37
|
-
it "should raise DocumentNotFound exception if results not found" do
|
38
|
-
message = instance_eval(&block)
|
39
|
-
lambda { subject.send(valid_finder, *args) }.should raise_error(DocumentNotFound, message)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.should_initialize(*args, &block)
|
44
|
-
it "should initialize new instance" do
|
45
|
-
result = subject.send(valid_finder, *args)
|
46
|
-
result.should be_a_new_record
|
47
|
-
result.should be_an_instance_of(Person)
|
48
|
-
yield(result).should be_true
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.should_create(*args, &block)
|
53
|
-
it "should create new instance" do
|
54
|
-
result = subject.send(valid_finder, *args)
|
55
|
-
result.should_not be_a_new_record
|
56
|
-
result.should be_an_instance_of(Person)
|
57
|
-
yield(result).should be_true
|
58
|
-
end
|
59
|
-
end
|
60
60
|
end
|
61
61
|
|
62
62
|
describe "find first by single property" do
|
@@ -398,15 +398,6 @@ module MongoModel
|
|
398
398
|
subject.first.should == posts[0]
|
399
399
|
end
|
400
400
|
end
|
401
|
-
|
402
|
-
subject_not_loaded do
|
403
|
-
it "should cache find result" do
|
404
|
-
model.should_find(finder_options.merge(:limit => 1), [posts[0]]) do
|
405
|
-
subject.first
|
406
|
-
subject.first
|
407
|
-
end
|
408
|
-
end
|
409
|
-
end
|
410
401
|
end
|
411
402
|
end
|
412
403
|
end
|
@@ -483,15 +474,6 @@ module MongoModel
|
|
483
474
|
subject.last.should == post
|
484
475
|
end
|
485
476
|
end
|
486
|
-
|
487
|
-
subject_not_loaded do
|
488
|
-
it "should cache find result" do
|
489
|
-
model.should_find(reversed_finder_options.merge(:limit => 1), [post]) do
|
490
|
-
subject.last
|
491
|
-
subject.last
|
492
|
-
end
|
493
|
-
end
|
494
|
-
end
|
495
477
|
end
|
496
478
|
end
|
497
479
|
end
|
data/spec/spec.opts
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
|
-
require 'spec'
|
4
3
|
|
5
|
-
|
6
|
-
|
4
|
+
require 'rspec'
|
5
|
+
|
6
|
+
require 'mongomodel'
|
7
7
|
|
8
8
|
# Require spec helpers
|
9
9
|
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f }
|
10
10
|
|
11
|
-
|
11
|
+
RSpec.configure do |config|
|
12
12
|
include SpecsFor
|
13
13
|
include DefineClass
|
14
14
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require '
|
1
|
+
require 'rspec/mocks'
|
2
2
|
|
3
3
|
module DocumentFinderStubs
|
4
|
-
include
|
4
|
+
include RSpec::Mocks::ExampleMethods
|
5
5
|
|
6
6
|
def stub_find(result)
|
7
7
|
find_result = mock('find result', :to_a => result.map { |doc| doc.to_mongo }, :count => result.size).as_null_object
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
extend
|
1
|
+
RSpec::Matchers.define(:find_with) do |find_options|
|
2
|
+
extend RSpec::Mocks::ExampleMethods
|
3
3
|
|
4
4
|
match do |klass|
|
5
5
|
selector, options = MongoModel::MongoOptions.new(klass, find_options).to_a
|
@@ -16,8 +16,8 @@ Spec::Matchers.define(:find_with) do |find_options|
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
extend
|
19
|
+
RSpec::Matchers.define(:count_with) do |find_options|
|
20
|
+
extend RSpec::Mocks::ExampleMethods
|
21
21
|
|
22
22
|
match do |klass|
|
23
23
|
selector, options = MongoModel::MongoOptions.new(klass, find_options).to_a
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongomodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 21
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
- 3
|
10
|
-
version: 0.3.3
|
5
|
+
version: 0.3.4
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Sam Pohlenz
|
@@ -15,121 +10,75 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
13
|
+
date: 2011-07-06 00:00:00 +09:30
|
19
14
|
default_executable:
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
22
17
|
name: activesupport
|
23
|
-
prerelease: false
|
24
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
19
|
none: false
|
26
20
|
requirements:
|
27
21
|
- - ~>
|
28
22
|
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 3
|
32
|
-
- 0
|
33
|
-
- 3
|
34
|
-
version: 3.0.3
|
23
|
+
version: "3.0"
|
35
24
|
type: :runtime
|
25
|
+
prerelease: false
|
36
26
|
version_requirements: *id001
|
37
27
|
- !ruby/object:Gem::Dependency
|
38
28
|
name: activemodel
|
39
|
-
prerelease: false
|
40
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
30
|
none: false
|
42
31
|
requirements:
|
43
32
|
- - ~>
|
44
33
|
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
segments:
|
47
|
-
- 3
|
48
|
-
- 0
|
49
|
-
- 3
|
50
|
-
version: 3.0.3
|
34
|
+
version: "3.0"
|
51
35
|
type: :runtime
|
36
|
+
prerelease: false
|
52
37
|
version_requirements: *id002
|
53
38
|
- !ruby/object:Gem::Dependency
|
54
39
|
name: mongo
|
55
|
-
prerelease: false
|
56
40
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
41
|
none: false
|
58
42
|
requirements:
|
59
43
|
- - ~>
|
60
44
|
- !ruby/object:Gem::Version
|
61
|
-
hash: 27
|
62
|
-
segments:
|
63
|
-
- 1
|
64
|
-
- 3
|
65
|
-
- 0
|
66
45
|
version: 1.3.0
|
67
46
|
type: :runtime
|
47
|
+
prerelease: false
|
68
48
|
version_requirements: *id003
|
69
49
|
- !ruby/object:Gem::Dependency
|
70
50
|
name: will_paginate
|
71
|
-
prerelease: false
|
72
51
|
requirement: &id004 !ruby/object:Gem::Requirement
|
73
52
|
none: false
|
74
53
|
requirements:
|
75
54
|
- - ~>
|
76
55
|
- !ruby/object:Gem::Version
|
77
|
-
hash: 29
|
78
|
-
segments:
|
79
|
-
- 2
|
80
|
-
- 3
|
81
|
-
- 15
|
82
56
|
version: 2.3.15
|
83
57
|
type: :runtime
|
84
|
-
version_requirements: *id004
|
85
|
-
- !ruby/object:Gem::Dependency
|
86
|
-
name: SystemTimer
|
87
58
|
prerelease: false
|
88
|
-
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ~>
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
hash: 25
|
94
|
-
segments:
|
95
|
-
- 1
|
96
|
-
- 2
|
97
|
-
- 3
|
98
|
-
version: 1.2.3
|
99
|
-
type: :runtime
|
100
|
-
version_requirements: *id005
|
59
|
+
version_requirements: *id004
|
101
60
|
- !ruby/object:Gem::Dependency
|
102
61
|
name: bundler
|
103
|
-
|
104
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
105
63
|
none: false
|
106
64
|
requirements:
|
107
65
|
- - ">="
|
108
66
|
- !ruby/object:Gem::Version
|
109
|
-
hash: 23
|
110
|
-
segments:
|
111
|
-
- 1
|
112
|
-
- 0
|
113
|
-
- 0
|
114
67
|
version: 1.0.0
|
115
68
|
type: :development
|
116
|
-
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *id005
|
117
71
|
- !ruby/object:Gem::Dependency
|
118
72
|
name: rspec
|
119
|
-
|
120
|
-
requirement: &id007 !ruby/object:Gem::Requirement
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
121
74
|
none: false
|
122
75
|
requirements:
|
123
|
-
- -
|
76
|
+
- - ~>
|
124
77
|
- !ruby/object:Gem::Version
|
125
|
-
|
126
|
-
segments:
|
127
|
-
- 1
|
128
|
-
- 3
|
129
|
-
- 0
|
130
|
-
version: 1.3.0
|
78
|
+
version: 2.6.0
|
131
79
|
type: :development
|
132
|
-
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: *id006
|
133
82
|
description: MongoModel is a MongoDB ORM for Ruby/Rails similar to ActiveRecord and DataMapper.
|
134
83
|
email:
|
135
84
|
- sam@sampohlenz.com
|
@@ -141,12 +90,17 @@ extra_rdoc_files: []
|
|
141
90
|
|
142
91
|
files:
|
143
92
|
- .gitignore
|
93
|
+
- Appraisals
|
144
94
|
- Gemfile
|
145
95
|
- LICENSE
|
146
96
|
- README.md
|
147
97
|
- Rakefile
|
148
98
|
- autotest/discover.rb
|
149
99
|
- bin/console
|
100
|
+
- gemfiles/rails-3.0.gemfile
|
101
|
+
- gemfiles/rails-3.0.gemfile.lock
|
102
|
+
- gemfiles/rails-3.1.gemfile
|
103
|
+
- gemfiles/rails-3.1.gemfile.lock
|
150
104
|
- lib/mongomodel.rb
|
151
105
|
- lib/mongomodel/attributes/mongo.rb
|
152
106
|
- lib/mongomodel/attributes/store.rb
|
@@ -303,7 +257,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
303
257
|
requirements:
|
304
258
|
- - ">="
|
305
259
|
- !ruby/object:Gem::Version
|
306
|
-
hash:
|
260
|
+
hash: -3936197743219655173
|
307
261
|
segments:
|
308
262
|
- 0
|
309
263
|
version: "0"
|
@@ -312,16 +266,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
312
266
|
requirements:
|
313
267
|
- - ">="
|
314
268
|
- !ruby/object:Gem::Version
|
315
|
-
hash: 23
|
316
|
-
segments:
|
317
|
-
- 1
|
318
|
-
- 3
|
319
|
-
- 6
|
320
269
|
version: 1.3.6
|
321
270
|
requirements: []
|
322
271
|
|
323
272
|
rubyforge_project: mongomodel
|
324
|
-
rubygems_version: 1.
|
273
|
+
rubygems_version: 1.5.2
|
325
274
|
signing_key:
|
326
275
|
specification_version: 3
|
327
276
|
summary: MongoDB ORM for Ruby/Rails
|