mongo_mapper 0.13.0 → 0.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +1 -1
- data/README.md +61 -0
- data/examples/keys.rb +1 -1
- data/examples/modifiers/set.rb +1 -1
- data/examples/querying.rb +1 -1
- data/examples/safe.rb +2 -2
- data/examples/scopes.rb +1 -1
- data/lib/mongo_mapper.rb +7 -0
- data/lib/mongo_mapper/connection.rb +16 -37
- data/lib/mongo_mapper/document.rb +4 -0
- data/lib/mongo_mapper/extensions/array.rb +14 -6
- data/lib/mongo_mapper/extensions/hash.rb +15 -3
- data/lib/mongo_mapper/extensions/object.rb +4 -0
- data/lib/mongo_mapper/extensions/object_id.rb +5 -1
- data/lib/mongo_mapper/extensions/string.rb +13 -5
- data/lib/mongo_mapper/extensions/symbol.rb +18 -0
- data/lib/mongo_mapper/plugins/accessible.rb +15 -5
- data/lib/mongo_mapper/plugins/associations.rb +7 -6
- data/lib/mongo_mapper/plugins/associations/base.rb +27 -14
- data/lib/mongo_mapper/plugins/associations/belongs_to_association.rb +10 -1
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +9 -8
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +12 -11
- data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +4 -4
- data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +60 -29
- data/lib/mongo_mapper/plugins/associations/in_foreign_array_proxy.rb +136 -0
- data/lib/mongo_mapper/plugins/associations/many_association.rb +4 -2
- data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +18 -16
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +55 -48
- data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +14 -13
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +7 -6
- data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +7 -5
- data/lib/mongo_mapper/plugins/associations/one_as_proxy.rb +14 -11
- data/lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb +14 -13
- data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +9 -9
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +27 -26
- data/lib/mongo_mapper/plugins/associations/proxy.rb +36 -29
- data/lib/mongo_mapper/plugins/associations/single_association.rb +5 -4
- data/lib/mongo_mapper/plugins/callbacks.rb +13 -0
- data/lib/mongo_mapper/plugins/counter_cache.rb +97 -0
- data/lib/mongo_mapper/plugins/dirty.rb +29 -37
- data/lib/mongo_mapper/plugins/document.rb +1 -1
- data/lib/mongo_mapper/plugins/dynamic_querying.rb +10 -9
- data/lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb +18 -17
- data/lib/mongo_mapper/plugins/embedded_callbacks.rb +2 -1
- data/lib/mongo_mapper/plugins/embedded_document.rb +1 -1
- data/lib/mongo_mapper/plugins/identity_map.rb +4 -2
- data/lib/mongo_mapper/plugins/indexes.rb +14 -7
- data/lib/mongo_mapper/plugins/keys.rb +170 -151
- data/lib/mongo_mapper/plugins/keys/key.rb +27 -16
- data/lib/mongo_mapper/plugins/keys/static.rb +45 -0
- data/lib/mongo_mapper/plugins/modifiers.rb +64 -38
- data/lib/mongo_mapper/plugins/partial_updates.rb +86 -0
- data/lib/mongo_mapper/plugins/persistence.rb +13 -8
- data/lib/mongo_mapper/plugins/protected.rb +6 -5
- data/lib/mongo_mapper/plugins/querying.rb +85 -42
- data/lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb +20 -15
- data/lib/mongo_mapper/plugins/rails.rb +1 -0
- data/lib/mongo_mapper/plugins/safe.rb +10 -4
- data/lib/mongo_mapper/plugins/sci.rb +0 -0
- data/lib/mongo_mapper/plugins/scopes.rb +78 -7
- data/lib/mongo_mapper/plugins/stats.rb +17 -0
- data/lib/mongo_mapper/plugins/strong_parameters.rb +26 -0
- data/lib/mongo_mapper/plugins/timestamps.rb +1 -0
- data/lib/mongo_mapper/plugins/validations.rb +1 -1
- data/lib/mongo_mapper/railtie.rb +4 -3
- data/lib/mongo_mapper/utils.rb +2 -2
- data/lib/mongo_mapper/version.rb +1 -1
- data/lib/rails/generators/mongo_mapper/config/config_generator.rb +12 -13
- data/lib/rails/generators/mongo_mapper/model/model_generator.rb +9 -9
- data/spec/examples.txt +1717 -0
- data/spec/functional/accessible_spec.rb +19 -13
- data/spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb +13 -13
- data/spec/functional/associations/belongs_to_proxy_spec.rb +36 -20
- data/spec/functional/associations/in_array_proxy_spec.rb +145 -10
- data/spec/functional/associations/in_foreign_array_proxy_spec.rb +321 -0
- data/spec/functional/associations/many_documents_as_proxy_spec.rb +6 -6
- data/spec/functional/associations/many_documents_proxy_spec.rb +85 -14
- data/spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb +13 -13
- data/spec/functional/associations/many_embedded_proxy_spec.rb +1 -1
- data/spec/functional/associations/many_polymorphic_proxy_spec.rb +4 -4
- data/spec/functional/associations/one_as_proxy_spec.rb +10 -10
- data/spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb +9 -9
- data/spec/functional/associations/one_embedded_proxy_spec.rb +3 -3
- data/spec/functional/associations/one_proxy_spec.rb +10 -10
- data/spec/functional/associations_spec.rb +3 -3
- data/spec/functional/binary_spec.rb +2 -2
- data/spec/functional/caching_spec.rb +8 -15
- data/spec/functional/callbacks_spec.rb +89 -2
- data/spec/functional/counter_cache_spec.rb +235 -0
- data/spec/functional/dirty_spec.rb +63 -46
- data/spec/functional/document_spec.rb +30 -5
- data/spec/functional/dumpable_spec.rb +1 -1
- data/spec/functional/embedded_document_spec.rb +17 -17
- data/spec/functional/identity_map_spec.rb +29 -16
- data/spec/functional/indexes_spec.rb +19 -18
- data/spec/functional/keys_spec.rb +86 -28
- data/spec/functional/logger_spec.rb +3 -3
- data/spec/functional/modifiers_spec.rb +81 -19
- data/spec/functional/partial_updates_spec.rb +577 -0
- data/spec/functional/protected_spec.rb +14 -14
- data/spec/functional/querying_spec.rb +77 -28
- data/spec/functional/safe_spec.rb +23 -27
- data/spec/functional/sci_spec.rb +9 -9
- data/spec/functional/scopes_spec.rb +235 -2
- data/spec/functional/static_keys_spec.rb +153 -0
- data/spec/functional/stats_spec.rb +86 -0
- data/spec/functional/strong_parameters_spec.rb +49 -0
- data/spec/functional/touch_spec.rb +1 -1
- data/spec/functional/validations_spec.rb +51 -57
- data/spec/quality_spec.rb +51 -0
- data/spec/spec_helper.rb +37 -9
- data/spec/support/matchers.rb +5 -14
- data/spec/unit/associations/base_spec.rb +12 -12
- data/spec/unit/associations/belongs_to_association_spec.rb +2 -2
- data/spec/unit/associations/many_association_spec.rb +2 -2
- data/spec/unit/associations/one_association_spec.rb +2 -2
- data/spec/unit/associations/proxy_spec.rb +19 -20
- data/spec/unit/clone_spec.rb +1 -1
- data/spec/unit/document_spec.rb +8 -8
- data/spec/unit/dynamic_finder_spec.rb +8 -8
- data/spec/unit/embedded_document_spec.rb +18 -19
- data/spec/unit/extensions_spec.rb +41 -17
- data/spec/unit/identity_map_middleware_spec.rb +65 -96
- data/spec/unit/key_spec.rb +28 -26
- data/spec/unit/keys_spec.rb +20 -11
- data/spec/unit/model_generator_spec.rb +0 -0
- data/spec/unit/mongo_mapper_spec.rb +38 -85
- data/spec/unit/rails_spec.rb +5 -0
- data/spec/unit/serialization_spec.rb +1 -1
- data/spec/unit/time_zones_spec.rb +2 -2
- data/spec/unit/validations_spec.rb +46 -33
- metadata +66 -37
- data/README.rdoc +0 -59
- data/lib/mongo_mapper/connections/10gen.rb +0 -0
- data/lib/mongo_mapper/connections/moped.rb +0 -0
- data/lib/mongo_mapper/extensions/ordered_hash.rb +0 -23
data/spec/spec_helper.rb
CHANGED
@@ -2,10 +2,15 @@ $:.unshift(File.expand_path('../../lib', __FILE__))
|
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'bundler/setup'
|
5
|
+
Bundler.require(:default)
|
5
6
|
require 'fileutils'
|
6
7
|
require 'timecop'
|
7
8
|
require "generator_spec/test_case"
|
8
9
|
|
10
|
+
if RUBY_ENGINE == "ruby" && RUBY_VERSION >= '2.3'
|
11
|
+
require 'byebug'
|
12
|
+
end
|
13
|
+
|
9
14
|
if RUBY_PLATFORM != "java"
|
10
15
|
if ENV['TRAVIS']
|
11
16
|
require 'coveralls'
|
@@ -39,7 +44,7 @@ def Doc(name='Class', &block)
|
|
39
44
|
end
|
40
45
|
|
41
46
|
klass.class_eval(&block) if block_given?
|
42
|
-
klass.collection.
|
47
|
+
klass.collection.drop
|
43
48
|
klass
|
44
49
|
end
|
45
50
|
|
@@ -58,24 +63,47 @@ def EDoc(name='Class', &block)
|
|
58
63
|
end
|
59
64
|
|
60
65
|
def drop_indexes(klass)
|
61
|
-
klass.collection.
|
66
|
+
klass.collection.indexes.drop_all if klass.database.collection_names.include?(klass.collection.name)
|
62
67
|
end
|
63
68
|
|
64
69
|
log_dir = File.expand_path('../../log', __FILE__)
|
65
70
|
FileUtils.mkdir_p(log_dir) unless File.exist?(log_dir)
|
66
71
|
logger = Logger.new(log_dir + '/test.log')
|
67
72
|
|
68
|
-
|
69
|
-
|
70
|
-
MongoMapper.
|
73
|
+
Mongo::Logger.logger = logger
|
74
|
+
|
75
|
+
MongoMapper.connection = Mongo::Client.new(['127.0.0.1:27017'], :database => 'test')
|
76
|
+
MongoMapper.database.collections.each { |c| c.indexes.drop_all }
|
71
77
|
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
72
78
|
|
73
|
-
RSpec.configure do |
|
74
|
-
|
75
|
-
|
79
|
+
RSpec.configure do |config|
|
80
|
+
config.example_status_persistence_file_path = "./spec/examples.txt"
|
81
|
+
|
82
|
+
config.expect_with :rspec do |c|
|
83
|
+
c.syntax = :should
|
84
|
+
end
|
85
|
+
|
86
|
+
config.mock_with :rspec do |mocks|
|
87
|
+
mocks.syntax = :should
|
88
|
+
end
|
89
|
+
|
90
|
+
config.around(:each, :without_connection) do |example|
|
76
91
|
old, MongoMapper.connection = MongoMapper.connection, nil
|
77
92
|
example.run
|
78
93
|
MongoMapper.connection = old
|
79
94
|
end
|
80
|
-
end
|
81
95
|
|
96
|
+
def suppress_stderr
|
97
|
+
begin
|
98
|
+
original_stderr = $stderr.clone
|
99
|
+
$stderr.reopen(File.new('/dev/null', 'w'))
|
100
|
+
retval = yield
|
101
|
+
rescue Exception => e
|
102
|
+
$stderr.reopen(original_stderr)
|
103
|
+
raise e
|
104
|
+
ensure
|
105
|
+
$stderr.reopen(original_stderr)
|
106
|
+
end
|
107
|
+
retval
|
108
|
+
end
|
109
|
+
end
|
data/spec/support/matchers.rb
CHANGED
@@ -1,24 +1,15 @@
|
|
1
1
|
RSpec::Matchers.define :have_error_on do |*args|
|
2
|
-
@message = nil
|
3
|
-
@attributes = [args]
|
4
|
-
|
5
|
-
chain :or do |*args|
|
6
|
-
@attributes << args
|
7
|
-
end
|
8
|
-
|
9
2
|
match do |model|
|
3
|
+
field = args.dup.shift
|
4
|
+
error_messages = args
|
5
|
+
|
10
6
|
model.valid?
|
11
|
-
|
12
|
-
if @message
|
13
|
-
!!@has_errors && model.errors[@has_errors[0]].include?(@has_errors[1])
|
14
|
-
else
|
15
|
-
!!@has_errors
|
16
|
-
end
|
7
|
+
model.errors[field].any?
|
17
8
|
end
|
18
9
|
end
|
19
10
|
|
20
11
|
RSpec::Matchers.define :have_index do |index_name|
|
21
12
|
match do |model|
|
22
|
-
model.collection.
|
13
|
+
model.collection.indexes.get(index_name).present?
|
23
14
|
end
|
24
15
|
end
|
@@ -12,7 +12,7 @@ module AssociationSpec
|
|
12
12
|
|
13
13
|
it "should also allow options when initializing" do
|
14
14
|
base = ManyAssociation.new(:foos, :polymorphic => true)
|
15
|
-
base.options[:polymorphic].should
|
15
|
+
base.options[:polymorphic].should be_truthy
|
16
16
|
end
|
17
17
|
|
18
18
|
context "klass" do
|
@@ -28,31 +28,31 @@ module AssociationSpec
|
|
28
28
|
|
29
29
|
context "polymorphic?" do
|
30
30
|
it "should be true if polymorphic" do
|
31
|
-
ManyAssociation.new(:foos, :polymorphic => true).polymorphic?.should
|
31
|
+
ManyAssociation.new(:foos, :polymorphic => true).polymorphic?.should be_truthy
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should be false if not polymorphic" do
|
35
|
-
ManyAssociation.new(:bars).polymorphic?.should
|
35
|
+
ManyAssociation.new(:bars).polymorphic?.should be_falsey
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
context "as?" do
|
40
40
|
it "should be true if one" do
|
41
|
-
OneAssociation.new(:foo, :as => :commentable).as?.should
|
41
|
+
OneAssociation.new(:foo, :as => :commentable).as?.should be_truthy
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should be false if not one" do
|
45
|
-
ManyAssociation.new(:foo).as?.should
|
45
|
+
ManyAssociation.new(:foo).as?.should be_falsey
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
context "in_array?" do
|
50
50
|
it "should be true if one" do
|
51
|
-
OneAssociation.new(:foo, :in => :list_ids).in_array?.should
|
51
|
+
OneAssociation.new(:foo, :in => :list_ids).in_array?.should be_truthy
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should be false if not one" do
|
55
|
-
ManyAssociation.new(:foo).in_array?.should
|
55
|
+
ManyAssociation.new(:foo).in_array?.should be_falsey
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -98,15 +98,15 @@ module AssociationSpec
|
|
98
98
|
context "embeddable?" do
|
99
99
|
it "should be true if class is embeddable" do
|
100
100
|
base = ManyAssociation.new(:medias)
|
101
|
-
base.embeddable?.should
|
101
|
+
base.embeddable?.should be_truthy
|
102
102
|
end
|
103
103
|
|
104
104
|
it "should be false if class is not embeddable" do
|
105
105
|
base = ManyAssociation.new(:statuses)
|
106
|
-
base.embeddable?.should
|
106
|
+
base.embeddable?.should be_falsey
|
107
107
|
|
108
108
|
base = BelongsToAssociation.new(:project)
|
109
|
-
base.embeddable?.should
|
109
|
+
base.embeddable?.should be_falsey
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
@@ -134,11 +134,11 @@ module AssociationSpec
|
|
134
134
|
|
135
135
|
context "touch?" do
|
136
136
|
it "should be true if touch" do
|
137
|
-
BelongsToAssociation.new(:car, :touch => true).touch?.should
|
137
|
+
BelongsToAssociation.new(:car, :touch => true).touch?.should be_truthy
|
138
138
|
end
|
139
139
|
|
140
140
|
it "should be false if not touch" do
|
141
|
-
BelongsToAssociation.new(:car).touch?.should
|
141
|
+
BelongsToAssociation.new(:car).touch?.should be_falsey
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
@@ -18,12 +18,12 @@ module BelongsToAssociation
|
|
18
18
|
context "embeddable?" do
|
19
19
|
it "should be false even if class is embeddable" do
|
20
20
|
base = BelongsToAssociation.new(:address)
|
21
|
-
base.embeddable?.should
|
21
|
+
base.embeddable?.should be_falsey
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should be false if class is not embeddable" do
|
25
25
|
base = BelongsToAssociation.new(:project)
|
26
|
-
base.embeddable?.should
|
26
|
+
base.embeddable?.should be_falsey
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -25,12 +25,12 @@ module ManyAssociationSpec
|
|
25
25
|
context "embeddable?" do
|
26
26
|
it "should be true if class is embeddable" do
|
27
27
|
base = ManyAssociation.new(:medias)
|
28
|
-
base.embeddable?.should
|
28
|
+
base.embeddable?.should be_truthy
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should be false if class is not embeddable" do
|
32
32
|
base = ManyAssociation.new(:statuses)
|
33
|
-
base.embeddable?.should
|
33
|
+
base.embeddable?.should be_falsey
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -14,12 +14,12 @@ module OneAssociationSpec
|
|
14
14
|
context "embeddable?" do
|
15
15
|
it "should be true if class is embeddable" do
|
16
16
|
base = OneAssociation.new(:media)
|
17
|
-
base.embeddable?.should
|
17
|
+
base.embeddable?.should be_truthy
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should be false if class is not embeddable" do
|
21
21
|
base = OneAssociation.new(:project)
|
22
|
-
base.embeddable?.should
|
22
|
+
base.embeddable?.should be_falsey
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -18,10 +18,8 @@ end
|
|
18
18
|
|
19
19
|
describe "Proxy" do
|
20
20
|
before do
|
21
|
-
@owner = double('owner')
|
22
|
-
@
|
23
|
-
@association = double('association')
|
24
|
-
@association.stub(:options).and_return({:extend => []})
|
21
|
+
@owner = double('owner', :new? => false)
|
22
|
+
@association = double('association', :options => {:extend => []})
|
25
23
|
|
26
24
|
@proxy = FakeProxy.new(@owner, @association)
|
27
25
|
@nil_proxy = FakeNilProxy.new(@owner, @association)
|
@@ -39,50 +37,46 @@ describe "Proxy" do
|
|
39
37
|
|
40
38
|
context "nil?" do
|
41
39
|
it "should be true if nil" do
|
42
|
-
@nil_proxy.nil?.should
|
40
|
+
@nil_proxy.nil?.should be_truthy
|
43
41
|
end
|
44
42
|
|
45
43
|
it "should be false if not nil" do
|
46
|
-
@proxy.nil?.should
|
44
|
+
@proxy.nil?.should be_falsey
|
47
45
|
end
|
48
46
|
end
|
49
47
|
|
50
48
|
context "blank?" do
|
51
49
|
it "should be true if blank" do
|
52
|
-
@blank_proxy.blank?.should
|
53
|
-
@nil_proxy.blank?.should
|
50
|
+
@blank_proxy.blank?.should be_truthy
|
51
|
+
@nil_proxy.blank?.should be_truthy
|
54
52
|
end
|
55
53
|
|
56
54
|
it "should be false if not blank" do
|
57
|
-
@proxy.blank?.should
|
55
|
+
@proxy.blank?.should be_falsey
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
61
59
|
context "present?" do
|
62
60
|
it "should be true if present" do
|
63
|
-
@proxy.present?.should
|
61
|
+
@proxy.present?.should be_truthy
|
64
62
|
end
|
65
63
|
|
66
64
|
it "should be false if not present" do
|
67
|
-
@blank_proxy.present?.should
|
68
|
-
@nil_proxy.present?.should
|
65
|
+
@blank_proxy.present?.should be_falsey
|
66
|
+
@nil_proxy.present?.should be_falsey
|
69
67
|
end
|
70
68
|
end
|
71
69
|
|
72
70
|
it "should delegate respond_to? to target" do
|
73
|
-
@proxy.respond_to?(:each).should
|
74
|
-
@proxy.respond_to?(:size).should
|
75
|
-
@proxy.respond_to?(:gsub).should
|
71
|
+
@proxy.respond_to?(:each).should be_truthy
|
72
|
+
@proxy.respond_to?(:size).should be_truthy
|
73
|
+
@proxy.respond_to?(:gsub).should be_falsey
|
76
74
|
end
|
77
75
|
|
78
76
|
it "should alias proxy owner to owner" do
|
79
77
|
@proxy.proxy_owner.should == @owner
|
80
78
|
end
|
81
79
|
|
82
|
-
it "should alias proxy target to target" do
|
83
|
-
@proxy.proxy_target.should == @target
|
84
|
-
end
|
85
|
-
|
86
80
|
context "send" do
|
87
81
|
it "should work if proxy responds to method" do
|
88
82
|
@proxy.send(:reset)
|
@@ -94,7 +88,12 @@ describe "Proxy" do
|
|
94
88
|
end
|
95
89
|
|
96
90
|
it "should not work if neither the proxy or target respond to method" do
|
97
|
-
lambda { @proxy.send(:gsub) }.should raise_error
|
91
|
+
lambda { @proxy.send(:gsub) }.should raise_error(NoMethodError)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should work if a proc is passed" do
|
95
|
+
p = Proc.new {|x| x+1}
|
96
|
+
@proxy.send(:collect, &p).should == [2,3]
|
98
97
|
end
|
99
98
|
end
|
100
99
|
end
|
data/spec/unit/clone_spec.rb
CHANGED
data/spec/unit/document_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe "Document" do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should return false for embeddable" do
|
11
|
-
Doc().embeddable?.should
|
11
|
+
Doc().embeddable?.should be_falsey
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should have logger method" do
|
@@ -21,11 +21,11 @@ describe "Document" do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should have a connection" do
|
24
|
-
@document.connection.should be_instance_of(Mongo::
|
24
|
+
@document.connection.should be_instance_of(Mongo::Client)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should allow setting different connection without affecting the default" do
|
28
|
-
conn = Mongo::
|
28
|
+
conn = Mongo::Client.new(['127.0.0.1:27001'])
|
29
29
|
@document.connection conn
|
30
30
|
@document.connection.should == conn
|
31
31
|
@document.connection.should_not == MongoMapper.connection
|
@@ -122,8 +122,8 @@ describe "Document" do
|
|
122
122
|
it "should use default values if defined for keys" do
|
123
123
|
@document.key :active, Boolean, :default => true
|
124
124
|
|
125
|
-
@document.new.active.should
|
126
|
-
@document.new(:active => false).active.should
|
125
|
+
@document.new.active.should be_truthy
|
126
|
+
@document.new(:active => false).active.should be_falsey
|
127
127
|
end
|
128
128
|
|
129
129
|
it "should use default values if defined even when custom data type" do
|
@@ -147,14 +147,14 @@ describe "Document" do
|
|
147
147
|
|
148
148
|
context "new?" do
|
149
149
|
it "should be true if no id" do
|
150
|
-
@document.new.new?.should
|
150
|
+
@document.new.new?.should be_truthy
|
151
151
|
end
|
152
152
|
|
153
153
|
it "should be true if id but using custom id and not saved yet" do
|
154
154
|
@document.key :_id, String
|
155
|
-
doc =
|
155
|
+
doc = suppress_stderr { @document.new }
|
156
156
|
doc.id = '1234'
|
157
|
-
doc.new?.should
|
157
|
+
doc.new?.should be_truthy
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
@@ -10,28 +10,28 @@ describe "DynamicFinder" do
|
|
10
10
|
|
11
11
|
context "found?" do
|
12
12
|
it "should be true for find_by" do
|
13
|
-
DynamicFinder.new(:find_by_foo).found?.should
|
13
|
+
DynamicFinder.new(:find_by_foo).found?.should be_truthy
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should be true for find_by with !" do
|
17
|
-
DynamicFinder.new(:find_by_foo!).found?.should
|
17
|
+
DynamicFinder.new(:find_by_foo!).found?.should be_truthy
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should be true for find_all_by" do
|
21
|
-
DynamicFinder.new(:find_all_by_foo).found?.should
|
21
|
+
DynamicFinder.new(:find_all_by_foo).found?.should be_truthy
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should be true for find_or_initialize_by" do
|
25
|
-
DynamicFinder.new(:find_or_initialize_by_foo).found?.should
|
25
|
+
DynamicFinder.new(:find_or_initialize_by_foo).found?.should be_truthy
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should be true for find_or_create_by" do
|
29
|
-
DynamicFinder.new(:find_or_create_by_foo).found?.should
|
29
|
+
DynamicFinder.new(:find_or_create_by_foo).found?.should be_truthy
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should be false for anything else" do
|
33
33
|
[:foobar, :bazwick].each do |method|
|
34
|
-
DynamicFinder.new(method).found?.should
|
34
|
+
DynamicFinder.new(method).found?.should be_falsey
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -65,7 +65,7 @@ describe "DynamicFinder" do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should set bang to false" do
|
68
|
-
DynamicFinder.new(:find_by_foo).bang.should
|
68
|
+
DynamicFinder.new(:find_by_foo).bang.should be_falsey
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -83,7 +83,7 @@ describe "DynamicFinder" do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should set bang to true" do
|
86
|
-
DynamicFinder.new(:find_by_foo!).bang.should
|
86
|
+
DynamicFinder.new(:find_by_foo!).bang.should be_truthy
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -66,12 +66,12 @@ describe "EmbeddedDocument" do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should know it is using object id" do
|
69
|
-
@klass.using_object_id?.should
|
69
|
+
@klass.using_object_id?.should be_truthy
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should know it is not using object id if _id type is changed" do
|
73
73
|
@klass.key :_id, String
|
74
|
-
@klass.using_object_id?.should
|
74
|
+
@klass.using_object_id?.should be_falsey
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -83,7 +83,7 @@ describe "EmbeddedDocument" do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should return false for embeddable" do
|
86
|
-
EDoc().embeddable?.should
|
86
|
+
EDoc().embeddable?.should be_truthy
|
87
87
|
end
|
88
88
|
|
89
89
|
context "#to_mongo" do
|
@@ -96,7 +96,7 @@ describe "EmbeddedDocument" do
|
|
96
96
|
it "should convert to_mongo for other values" do
|
97
97
|
doc = @klass.new(:foo => 'bar')
|
98
98
|
to_mongo = @klass.to_mongo(doc)
|
99
|
-
to_mongo.is_a?(Hash).should
|
99
|
+
to_mongo.is_a?(Hash).should be_truthy
|
100
100
|
to_mongo['foo'].should == 'bar'
|
101
101
|
end
|
102
102
|
end
|
@@ -115,7 +115,7 @@ describe "EmbeddedDocument" do
|
|
115
115
|
|
116
116
|
it "should be instance if hash of attributes" do
|
117
117
|
doc = @klass.from_mongo({:foo => 'bar'})
|
118
|
-
doc.instance_of?(@klass).should
|
118
|
+
doc.instance_of?(@klass).should be_truthy
|
119
119
|
doc.foo.should == 'bar'
|
120
120
|
end
|
121
121
|
end
|
@@ -140,13 +140,13 @@ describe "EmbeddedDocument" do
|
|
140
140
|
key = @document.key(:name, String, :required => true)
|
141
141
|
key.name.should == 'name'
|
142
142
|
key.type.should == String
|
143
|
-
key.options[:required].should
|
143
|
+
key.options[:required].should be_truthy
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should work with name and options" do
|
147
147
|
key = @document.key(:name, :required => true)
|
148
148
|
key.name.should == 'name'
|
149
|
-
key.options[:required].should
|
149
|
+
key.options[:required].should be_truthy
|
150
150
|
end
|
151
151
|
|
152
152
|
it "should be tracked per document" do
|
@@ -206,11 +206,11 @@ describe "EmbeddedDocument" do
|
|
206
206
|
end
|
207
207
|
|
208
208
|
it "should not add anonymous objects to the ancestor tree" do
|
209
|
-
OtherChild.ancestors.any? { |a| a.name.blank? }.should
|
209
|
+
OtherChild.ancestors.any? { |a| a.name.blank? }.should be_falsey
|
210
210
|
end
|
211
211
|
|
212
212
|
it "should not include descendant keys" do
|
213
|
-
lambda { Parent.new.other_child }.should raise_error
|
213
|
+
lambda { Parent.new.other_child }.should raise_error(NoMethodError)
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
@@ -308,7 +308,7 @@ describe "EmbeddedDocument" do
|
|
308
308
|
end
|
309
309
|
|
310
310
|
it "should not throw error if initialized with nil" do
|
311
|
-
|
311
|
+
lambda { @document.new(nil) }.should_not raise_error
|
312
312
|
end
|
313
313
|
end
|
314
314
|
|
@@ -422,7 +422,7 @@ describe "EmbeddedDocument" do
|
|
422
422
|
it "should create key and write value for missing key" do
|
423
423
|
doc = @document.new
|
424
424
|
doc[:foo] = 'string'
|
425
|
-
doc.class.keys.include?('foo').should
|
425
|
+
doc.class.keys.include?('foo').should be_truthy
|
426
426
|
doc[:foo].should == 'string'
|
427
427
|
end
|
428
428
|
|
@@ -550,9 +550,9 @@ describe "EmbeddedDocument" do
|
|
550
550
|
context "checking if a keys value is present" do
|
551
551
|
it "should work for defined keys" do
|
552
552
|
doc = @document.new
|
553
|
-
doc.name?.should
|
553
|
+
doc.name?.should be_falsey
|
554
554
|
doc.name = 'John'
|
555
|
-
doc.name?.should
|
555
|
+
doc.name?.should be_truthy
|
556
556
|
end
|
557
557
|
|
558
558
|
it "should raise no method error for undefined keys" do
|
@@ -590,16 +590,16 @@ describe "EmbeddedDocument" do
|
|
590
590
|
end
|
591
591
|
|
592
592
|
it "should be equal if id and class are the same" do
|
593
|
-
(@document.new('_id' => @oid) == @document.new('_id' => @oid)).should
|
593
|
+
(@document.new('_id' => @oid) == @document.new('_id' => @oid)).should be_truthy
|
594
594
|
end
|
595
595
|
|
596
596
|
it "should not be equal if class same but id different" do
|
597
|
-
(@document.new('_id' => @oid) == @document.new('_id' => BSON::ObjectId.new)).should
|
597
|
+
(@document.new('_id' => @oid) == @document.new('_id' => BSON::ObjectId.new)).should be_falsey
|
598
598
|
end
|
599
599
|
|
600
600
|
it "should not be equal if id same but class different" do
|
601
601
|
another_document = Doc()
|
602
|
-
(@document.new('_id' => @oid) == another_document.new('_id' => @oid)).should
|
602
|
+
(@document.new('_id' => @oid) == another_document.new('_id' => @oid)).should be_falsey
|
603
603
|
end
|
604
604
|
end
|
605
605
|
|
@@ -661,16 +661,15 @@ describe "EmbeddedDocument" do
|
|
661
661
|
|
662
662
|
it "should should raise errors when invalid" do
|
663
663
|
@doc.name = ''
|
664
|
-
|
664
|
+
lambda { @doc.save! }.should raise_error(MongoMapper::DocumentNotValid)
|
665
665
|
end
|
666
666
|
|
667
667
|
it "should should raise errors when root document is invalid" do
|
668
668
|
@root.name = ''
|
669
669
|
@root.save(:validate => false)
|
670
|
-
|
670
|
+
lambda { @doc.save! }.should raise_error(MongoMapper::DocumentNotValid)
|
671
671
|
end
|
672
672
|
end
|
673
673
|
end # instance of a embedded document
|
674
674
|
end
|
675
675
|
end
|
676
|
-
|