mongo_mapper 0.12.0 → 0.13.0.beta1
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.
- checksums.yaml +7 -0
- data/README.rdoc +35 -13
- data/bin/mmconsole +1 -1
- data/lib/mongo_mapper.rb +4 -0
- data/lib/mongo_mapper/connection.rb +17 -6
- data/lib/mongo_mapper/document.rb +1 -0
- data/lib/mongo_mapper/exceptions.rb +4 -1
- data/lib/mongo_mapper/extensions/binary.rb +1 -1
- data/lib/mongo_mapper/extensions/boolean.rb +20 -23
- data/lib/mongo_mapper/extensions/date.rb +3 -3
- data/lib/mongo_mapper/extensions/integer.rb +5 -1
- data/lib/mongo_mapper/extensions/kernel.rb +2 -0
- data/lib/mongo_mapper/extensions/ordered_hash.rb +23 -0
- data/lib/mongo_mapper/extensions/string.rb +2 -2
- data/lib/mongo_mapper/extensions/time.rb +7 -5
- data/lib/mongo_mapper/middleware/identity_map.rb +3 -4
- data/lib/mongo_mapper/plugins.rb +1 -1
- data/lib/mongo_mapper/plugins/associations.rb +11 -5
- data/lib/mongo_mapper/plugins/associations/base.rb +5 -3
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +0 -0
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +8 -8
- data/lib/mongo_mapper/plugins/associations/collection.rb +2 -0
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +32 -7
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +2 -2
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +12 -12
- data/lib/mongo_mapper/plugins/associations/proxy.rb +5 -1
- data/lib/mongo_mapper/plugins/associations/single_association.rb +6 -6
- data/lib/mongo_mapper/plugins/clone.rb +4 -2
- data/lib/mongo_mapper/plugins/dirty.rb +22 -21
- data/lib/mongo_mapper/plugins/document.rb +4 -4
- data/lib/mongo_mapper/plugins/dumpable.rb +22 -0
- data/lib/mongo_mapper/plugins/embedded_callbacks.rb +58 -9
- data/lib/mongo_mapper/plugins/identity_map.rb +42 -32
- data/lib/mongo_mapper/plugins/keys.rb +133 -54
- data/lib/mongo_mapper/plugins/keys/key.rb +68 -22
- data/lib/mongo_mapper/plugins/modifiers.rb +26 -19
- data/lib/mongo_mapper/plugins/persistence.rb +15 -5
- data/lib/mongo_mapper/plugins/querying.rb +15 -40
- data/lib/mongo_mapper/plugins/querying/{decorator.rb → decorated_plucky_query.rb} +24 -4
- data/lib/mongo_mapper/plugins/rails.rb +22 -2
- data/lib/mongo_mapper/plugins/safe.rb +8 -5
- data/lib/mongo_mapper/plugins/sci.rb +26 -4
- data/lib/mongo_mapper/plugins/scopes.rb +5 -4
- data/lib/mongo_mapper/plugins/timestamps.rb +11 -4
- data/lib/mongo_mapper/plugins/validations.rb +1 -1
- data/lib/mongo_mapper/utils.rb +12 -0
- data/lib/mongo_mapper/version.rb +1 -1
- data/lib/rails/generators/mongo_mapper/config/config_generator.rb +20 -7
- data/lib/rails/generators/mongo_mapper/config/templates/mongo.yml +6 -0
- data/lib/rails/generators/mongo_mapper/model/model_generator.rb +18 -1
- data/lib/rails/generators/mongo_mapper/model/templates/model.rb +9 -5
- data/{test/functional/test_accessible.rb → spec/functional/accessible_spec.rb} +29 -29
- data/{test/functional/associations/test_belongs_to_polymorphic_proxy.rb → spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb} +10 -10
- data/{test/functional/associations/test_belongs_to_proxy.rb → spec/functional/associations/belongs_to_proxy_spec.rb} +82 -64
- data/{test/functional/associations/test_in_array_proxy.rb → spec/functional/associations/in_array_proxy_spec.rb} +68 -68
- data/{test/functional/associations/test_many_documents_as_proxy.rb → spec/functional/associations/many_documents_as_proxy_spec.rb} +37 -38
- data/{test/functional/associations/test_many_documents_proxy.rb → spec/functional/associations/many_documents_proxy_spec.rb} +233 -146
- data/{test/functional/associations/test_many_embedded_polymorphic_proxy.rb → spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb} +19 -20
- data/{test/functional/associations/test_many_embedded_proxy.rb → spec/functional/associations/many_embedded_proxy_spec.rb} +23 -24
- data/{test/functional/associations/test_many_polymorphic_proxy.rb → spec/functional/associations/many_polymorphic_proxy_spec.rb} +45 -46
- data/{test/functional/associations/test_one_as_proxy.rb → spec/functional/associations/one_as_proxy_spec.rb} +75 -77
- data/{test/functional/associations/test_one_embedded_polymorphic_proxy.rb → spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb} +31 -32
- data/{test/functional/associations/test_one_embedded_proxy.rb → spec/functional/associations/one_embedded_proxy_spec.rb} +10 -10
- data/{test/functional/associations/test_one_proxy.rb → spec/functional/associations/one_proxy_spec.rb} +125 -102
- data/spec/functional/associations_spec.rb +48 -0
- data/{test/functional/test_binary.rb → spec/functional/binary_spec.rb} +6 -6
- data/spec/functional/caching_spec.rb +75 -0
- data/{test/functional/test_callbacks.rb → spec/functional/callbacks_spec.rb} +84 -26
- data/{test/functional/test_dirty.rb → spec/functional/dirty_spec.rb} +57 -42
- data/{test/functional/test_document.rb → spec/functional/document_spec.rb} +52 -52
- data/spec/functional/dumpable_spec.rb +24 -0
- data/{test/functional/test_dynamic_querying.rb → spec/functional/dynamic_querying_spec.rb} +14 -14
- data/{test/functional/test_embedded_document.rb → spec/functional/embedded_document_spec.rb} +51 -42
- data/{test/functional/test_equality.rb → spec/functional/equality_spec.rb} +4 -4
- data/spec/functional/extensions_spec.rb +16 -0
- data/{test/functional/test_identity_map.rb → spec/functional/identity_map_spec.rb} +73 -61
- data/spec/functional/indexes_spec.rb +48 -0
- data/spec/functional/keys_spec.rb +224 -0
- data/{test/functional/test_logger.rb → spec/functional/logger_spec.rb} +6 -6
- data/spec/functional/modifiers_spec.rb +550 -0
- data/spec/functional/pagination_spec.rb +89 -0
- data/spec/functional/protected_spec.rb +199 -0
- data/spec/functional/querying_spec.rb +1003 -0
- data/spec/functional/rails_spec.rb +55 -0
- data/spec/functional/safe_spec.rb +163 -0
- data/{test/functional/test_sci.rb → spec/functional/sci_spec.rb} +123 -34
- data/{test/functional/test_scopes.rb → spec/functional/scopes_spec.rb} +59 -26
- data/spec/functional/timestamps_spec.rb +97 -0
- data/{test/functional/test_touch.rb → spec/functional/touch_spec.rb} +13 -13
- data/spec/functional/userstamps_spec.rb +46 -0
- data/{test/functional/test_validations.rb → spec/functional/validations_spec.rb} +64 -64
- data/spec/spec_helper.rb +81 -0
- data/spec/support/matchers.rb +24 -0
- data/{test → spec/support}/models.rb +1 -6
- data/spec/unit/associations/base_spec.rb +146 -0
- data/spec/unit/associations/belongs_to_association_spec.rb +30 -0
- data/spec/unit/associations/many_association_spec.rb +64 -0
- data/spec/unit/associations/one_association_spec.rb +48 -0
- data/{test/unit/associations/test_proxy.rb → spec/unit/associations/proxy_spec.rb} +21 -21
- data/{test/unit/test_clone.rb → spec/unit/clone_spec.rb} +21 -11
- data/spec/unit/config_generator_spec.rb +24 -0
- data/{test/unit/test_document.rb → spec/unit/document_spec.rb} +42 -42
- data/{test/unit/test_dynamic_finder.rb → spec/unit/dynamic_finder_spec.rb} +28 -28
- data/{test/unit/test_embedded_document.rb → spec/unit/embedded_document_spec.rb} +102 -108
- data/{test/unit/test_equality.rb → spec/unit/equality_spec.rb} +7 -7
- data/{test/unit/test_exceptions.rb → spec/unit/exceptions_spec.rb} +3 -3
- data/{test/unit/test_extensions.rb → spec/unit/extensions_spec.rb} +85 -71
- data/spec/unit/identity_map_middleware_spec.rb +134 -0
- data/{test/unit/test_inspect.rb → spec/unit/inspect_spec.rb} +8 -8
- data/{test/unit/test_key.rb → spec/unit/key_spec.rb} +82 -52
- data/spec/unit/keys_spec.rb +155 -0
- data/spec/unit/model_generator_spec.rb +47 -0
- data/spec/unit/mongo_mapper_spec.rb +184 -0
- data/spec/unit/pagination_spec.rb +11 -0
- data/{test/unit/test_plugins.rb → spec/unit/plugins_spec.rb} +14 -14
- data/spec/unit/rails_compatibility_spec.rb +40 -0
- data/{test/unit/test_rails_reflect_on_association.rb → spec/unit/rails_reflect_on_association_spec.rb} +9 -9
- data/{test/unit/test_rails.rb → spec/unit/rails_spec.rb} +31 -31
- data/spec/unit/serialization_spec.rb +169 -0
- data/spec/unit/serializers/json_serializer_spec.rb +218 -0
- data/spec/unit/serializers/xml_serializer_spec.rb +198 -0
- data/{test/unit/test_time_zones.rb → spec/unit/time_zones_spec.rb} +8 -8
- data/{test/unit/test_translation.rb → spec/unit/translation_spec.rb} +6 -6
- data/{test/unit/test_validations.rb → spec/unit/validations_spec.rb} +72 -59
- metadata +199 -179
- data/test/_NOTE_ON_TESTING +0 -1
- data/test/functional/test_associations.rb +0 -46
- data/test/functional/test_caching.rb +0 -77
- data/test/functional/test_indexes.rb +0 -50
- data/test/functional/test_modifiers.rb +0 -537
- data/test/functional/test_pagination.rb +0 -91
- data/test/functional/test_protected.rb +0 -201
- data/test/functional/test_querying.rb +0 -935
- data/test/functional/test_safe.rb +0 -76
- data/test/functional/test_timestamps.rb +0 -62
- data/test/functional/test_userstamps.rb +0 -44
- data/test/support/railtie.rb +0 -4
- data/test/support/railtie/autoloaded.rb +0 -2
- data/test/support/railtie/not_autoloaded.rb +0 -3
- data/test/support/railtie/parent.rb +0 -3
- data/test/test_active_model_lint.rb +0 -18
- data/test/test_helper.rb +0 -93
- data/test/unit/associations/test_base.rb +0 -146
- data/test/unit/associations/test_belongs_to_association.rb +0 -29
- data/test/unit/associations/test_many_association.rb +0 -63
- data/test/unit/associations/test_one_association.rb +0 -47
- data/test/unit/serializers/test_json_serializer.rb +0 -216
- data/test/unit/serializers/test_xml_serializer.rb +0 -196
- data/test/unit/test_identity_map_middleware.rb +0 -132
- data/test/unit/test_keys.rb +0 -65
- data/test/unit/test_mongo_mapper.rb +0 -157
- data/test/unit/test_pagination.rb +0 -11
- data/test/unit/test_rails_compatibility.rb +0 -38
- data/test/unit/test_serialization.rb +0 -166
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class SafeTest < Test::Unit::TestCase
|
4
|
-
context "A Document" do
|
5
|
-
should "default safe to off" do
|
6
|
-
Doc().should_not be_safe
|
7
|
-
end
|
8
|
-
|
9
|
-
should "allow turning safe on" do
|
10
|
-
Doc() { safe }.should be_safe
|
11
|
-
end
|
12
|
-
|
13
|
-
context "inherited with safe setting on" do
|
14
|
-
should "set subclass safe setting on" do
|
15
|
-
inherited = Class.new(Doc() { safe })
|
16
|
-
inherited.should be_safe
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "inherited with safe setting off" do
|
21
|
-
should "leave subclass safe setting off" do
|
22
|
-
inherited = Class.new(Doc())
|
23
|
-
inherited.should_not be_safe
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "A safe document" do
|
29
|
-
setup do
|
30
|
-
@klass = Doc() do
|
31
|
-
safe
|
32
|
-
end
|
33
|
-
end
|
34
|
-
teardown { drop_indexes(@klass) }
|
35
|
-
|
36
|
-
context "#save" do
|
37
|
-
setup do
|
38
|
-
@klass.ensure_index :email, :unique => true
|
39
|
-
end
|
40
|
-
|
41
|
-
context "using safe setting from class" do
|
42
|
-
should "work fine when all is well" do
|
43
|
-
assert_nothing_raised do
|
44
|
-
@klass.new(:email => 'john@doe.com').save
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
should "raise error when operation fails" do
|
49
|
-
assert_raises(Mongo::OperationFailure) do
|
50
|
-
2.times do
|
51
|
-
@klass.new(:email => 'john@doe.com').save
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "overriding safe setting" do
|
58
|
-
should "raise error if safe is true" do
|
59
|
-
assert_raises(Mongo::OperationFailure) do
|
60
|
-
2.times do
|
61
|
-
@klass.new(:email => 'john@doe.com').save(:safe => true)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
should "not raise error if safe is false" do
|
67
|
-
assert_nothing_raised do
|
68
|
-
2.times do
|
69
|
-
@klass.new(:email => 'john@doe.com').save(:safe => false)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class TimestampsTest < Test::Unit::TestCase
|
4
|
-
context "timestamping" do
|
5
|
-
setup do
|
6
|
-
@klass = Doc do
|
7
|
-
key :first_name, String
|
8
|
-
key :last_name, String
|
9
|
-
key :age, Integer
|
10
|
-
key :date, Date
|
11
|
-
end
|
12
|
-
@klass.timestamps!
|
13
|
-
end
|
14
|
-
|
15
|
-
should "set created_at and updated_at on create" do
|
16
|
-
doc = @klass.new(:first_name => 'John', :age => 27)
|
17
|
-
doc.created_at.should be(nil)
|
18
|
-
doc.updated_at.should be(nil)
|
19
|
-
doc.save
|
20
|
-
doc.created_at.should_not be(nil)
|
21
|
-
doc.updated_at.should_not be(nil)
|
22
|
-
end
|
23
|
-
|
24
|
-
should "not overwrite created_at if it already exists" do
|
25
|
-
original_created_at = 1.month.ago
|
26
|
-
doc = @klass.new(:first_name => 'John', :age => 27, :created_at => original_created_at)
|
27
|
-
doc.created_at.to_i.should == original_created_at.to_i
|
28
|
-
doc.updated_at.should be_nil
|
29
|
-
doc.save
|
30
|
-
doc.created_at.to_i.should == original_created_at.to_i
|
31
|
-
doc.updated_at.should_not be_nil
|
32
|
-
end
|
33
|
-
|
34
|
-
should "set updated_at on field update but leave created_at alone" do
|
35
|
-
doc = @klass.create(:first_name => 'John', :age => 27)
|
36
|
-
old_created_at = doc.created_at
|
37
|
-
old_updated_at = doc.updated_at
|
38
|
-
doc.first_name = 'Johnny'
|
39
|
-
|
40
|
-
Timecop.freeze(Time.now + 5.seconds) do
|
41
|
-
doc.save
|
42
|
-
end
|
43
|
-
|
44
|
-
doc.created_at.should == old_created_at
|
45
|
-
doc.updated_at.should_not == old_updated_at
|
46
|
-
end
|
47
|
-
|
48
|
-
should "set updated_at on document update but leave created_at alone" do
|
49
|
-
doc = @klass.create(:first_name => 'John', :age => 27)
|
50
|
-
old_created_at = doc.created_at.to_f
|
51
|
-
|
52
|
-
new_updated_at = Time.now + 5.seconds
|
53
|
-
Timecop.freeze(new_updated_at) do
|
54
|
-
@klass.update(doc._id, { :first_name => 'Johnny' })
|
55
|
-
end
|
56
|
-
|
57
|
-
doc = doc.reload
|
58
|
-
doc.created_at.to_f.should be_close(old_created_at, 0.001)
|
59
|
-
doc.updated_at.to_f.should be_close(new_updated_at.to_f, 0.001)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class UserstampsTest < Test::Unit::TestCase
|
4
|
-
class AltUser
|
5
|
-
include MongoMapper::Document
|
6
|
-
end
|
7
|
-
|
8
|
-
context "userstamping" do
|
9
|
-
setup do
|
10
|
-
@document = Doc do
|
11
|
-
userstamps!
|
12
|
-
end
|
13
|
-
@document_alt_user = Doc do
|
14
|
-
userstamps! :class_name => 'AltUser'
|
15
|
-
end
|
16
|
-
@document_alt_user_class = Doc do
|
17
|
-
userstamps! :class => AltUser
|
18
|
-
end
|
19
|
-
@docs = [@document, @document_alt_user, @document_alt_user_class]
|
20
|
-
end
|
21
|
-
|
22
|
-
should "add creator_id key" do
|
23
|
-
@docs.each{ |d| d.keys.should include('creator_id') }
|
24
|
-
end
|
25
|
-
|
26
|
-
should "add updater_id key" do
|
27
|
-
@docs.each{ |d| d.keys.should include('updater_id') }
|
28
|
-
end
|
29
|
-
|
30
|
-
should "add belongs_to creator" do
|
31
|
-
@docs.each{ |d| d.associations.keys.should include(:creator) }
|
32
|
-
end
|
33
|
-
|
34
|
-
should "add belongs_to updater" do
|
35
|
-
@docs.each{ |d| d.associations.keys.should include(:updater) }
|
36
|
-
end
|
37
|
-
|
38
|
-
should "properly set class names" do
|
39
|
-
@document.associations[:creator].class_name.should == 'User'
|
40
|
-
@document_alt_user.associations[:creator].class_name.should == 'AltUser'
|
41
|
-
@document_alt_user_class.associations[:creator].class_name.should == 'UserstampsTest::AltUser'
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/test/support/railtie.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
# For testing against edge rails also.
|
3
|
-
# $:.unshift '/Users/jnunemaker/dev/ruby/rails/activemodel/lib'
|
4
|
-
require 'active_model'
|
5
|
-
require 'models'
|
6
|
-
|
7
|
-
class ActiveModelLintTest < ActiveModel::TestCase
|
8
|
-
include ::ActiveModel::Lint::Tests
|
9
|
-
|
10
|
-
def setup
|
11
|
-
@model = Post.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_naming
|
15
|
-
Post.model_name.plural.should == 'posts'
|
16
|
-
Post.new.respond_to?(:model_name).should be_false
|
17
|
-
end
|
18
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler/setup'
|
3
|
-
|
4
|
-
$:.unshift File.expand_path('../../lib', __FILE__)
|
5
|
-
require 'mongo_mapper'
|
6
|
-
require 'fileutils'
|
7
|
-
require 'ostruct'
|
8
|
-
|
9
|
-
Bundler.require(:default, :test)
|
10
|
-
|
11
|
-
class Test::Unit::TestCase
|
12
|
-
def Doc(name='Class', &block)
|
13
|
-
klass = Class.new
|
14
|
-
klass.class_eval do
|
15
|
-
include MongoMapper::Document
|
16
|
-
|
17
|
-
if name
|
18
|
-
class_eval "def self.name; '#{name}' end"
|
19
|
-
class_eval "def self.to_s; '#{name}' end"
|
20
|
-
else
|
21
|
-
set_collection_name :test
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
klass.class_eval(&block) if block_given?
|
26
|
-
klass.collection.remove
|
27
|
-
klass
|
28
|
-
end
|
29
|
-
|
30
|
-
def EDoc(name='Class', &block)
|
31
|
-
klass = Class.new do
|
32
|
-
include MongoMapper::EmbeddedDocument
|
33
|
-
|
34
|
-
if name
|
35
|
-
class_eval "def self.name; '#{name}' end"
|
36
|
-
class_eval "def self.to_s; '#{name}' end"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
klass.class_eval(&block) if block_given?
|
41
|
-
klass
|
42
|
-
end
|
43
|
-
|
44
|
-
def drop_indexes(klass)
|
45
|
-
if klass.database.collection_names.include?(klass.collection.name)
|
46
|
-
klass.collection.drop_indexes
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
custom_matcher :be_true do |receiver, matcher, args|
|
51
|
-
matcher.positive_failure_message = "Expected #{receiver} to be true but it wasn't"
|
52
|
-
matcher.negative_failure_message = "Expected #{receiver} not to be true but it was"
|
53
|
-
receiver.eql?(true)
|
54
|
-
end
|
55
|
-
|
56
|
-
custom_matcher :be_false do |receiver, matcher, args|
|
57
|
-
matcher.positive_failure_message = "Expected #{receiver} to be false but it wasn't"
|
58
|
-
matcher.negative_failure_message = "Expected #{receiver} not to be false but it was"
|
59
|
-
receiver.eql?(false)
|
60
|
-
end
|
61
|
-
|
62
|
-
custom_matcher :have_error_on do |receiver, matcher, args|
|
63
|
-
receiver.valid?
|
64
|
-
attribute = args[0]
|
65
|
-
expected_message = args[1]
|
66
|
-
|
67
|
-
if expected_message.nil?
|
68
|
-
matcher.positive_failure_message = "#{receiver} had no errors on #{attribute}"
|
69
|
-
matcher.negative_failure_message = "#{receiver} had errors on #{attribute} #{receiver.errors.inspect}"
|
70
|
-
!receiver.errors[attribute].blank?
|
71
|
-
else
|
72
|
-
actual = receiver.errors[attribute]
|
73
|
-
matcher.positive_failure_message = %Q(Expected error on #{attribute} to be "#{expected_message}" but was "#{actual}")
|
74
|
-
matcher.negative_failure_message = %Q(Expected error on #{attribute} not to be "#{expected_message}" but was "#{actual}")
|
75
|
-
actual.include? expected_message
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
custom_matcher :have_index do |receiver, matcher, args|
|
80
|
-
index_name = args[0]
|
81
|
-
matcher.positive_failure_message = "#{receiver} does not have index named #{index_name}, but should"
|
82
|
-
matcher.negative_failure_message = "#{receiver} does have index named #{index_name}, but should not"
|
83
|
-
!receiver.collection.index_information.detect { |index| index[0] == index_name }.nil?
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
log_dir = File.expand_path('../../log', __FILE__)
|
88
|
-
FileUtils.mkdir_p(log_dir) unless File.exist?(log_dir)
|
89
|
-
logger = Logger.new(log_dir + '/test.log')
|
90
|
-
|
91
|
-
MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017, :logger => logger)
|
92
|
-
MongoMapper.database = "test"
|
93
|
-
MongoMapper.database.collections.each { |c| c.drop_indexes }
|
@@ -1,146 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'models'
|
3
|
-
|
4
|
-
class FooMonster; end
|
5
|
-
|
6
|
-
class AssociationBaseTest < Test::Unit::TestCase
|
7
|
-
include MongoMapper::Plugins::Associations
|
8
|
-
|
9
|
-
should "initialize with type and name" do
|
10
|
-
base = ManyAssociation.new(:foos)
|
11
|
-
base.name.should == :foos
|
12
|
-
end
|
13
|
-
|
14
|
-
should "also allow options when initializing" do
|
15
|
-
base = ManyAssociation.new(:foos, :polymorphic => true)
|
16
|
-
base.options[:polymorphic].should be_true
|
17
|
-
end
|
18
|
-
|
19
|
-
context "klass" do
|
20
|
-
should "default to class_name constantized" do
|
21
|
-
BelongsToAssociation.new(:foo_monster).klass.should == FooMonster
|
22
|
-
end
|
23
|
-
|
24
|
-
should "be the specified class" do
|
25
|
-
anonnymous_class = Class.new
|
26
|
-
BelongsToAssociation.new(:foo_monster, :class => anonnymous_class).klass.should == anonnymous_class
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "polymorphic?" do
|
31
|
-
should "be true if polymorphic" do
|
32
|
-
ManyAssociation.new(:foos, :polymorphic => true).polymorphic?.should be_true
|
33
|
-
end
|
34
|
-
|
35
|
-
should "be false if not polymorphic" do
|
36
|
-
ManyAssociation.new(:bars).polymorphic?.should be_false
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "as?" do
|
41
|
-
should "be true if one" do
|
42
|
-
OneAssociation.new(:foo, :as => :commentable).as?.should be_true
|
43
|
-
end
|
44
|
-
|
45
|
-
should "be false if not one" do
|
46
|
-
ManyAssociation.new(:foo).as?.should be_false
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "in_array?" do
|
51
|
-
should "be true if one" do
|
52
|
-
OneAssociation.new(:foo, :in => :list_ids).in_array?.should be_true
|
53
|
-
end
|
54
|
-
|
55
|
-
should "be false if not one" do
|
56
|
-
ManyAssociation.new(:foo).in_array?.should be_false
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "query_options" do
|
61
|
-
should "default to empty hash" do
|
62
|
-
base = ManyAssociation.new(:foos)
|
63
|
-
base.query_options.should == {}
|
64
|
-
end
|
65
|
-
|
66
|
-
should "work with order" do
|
67
|
-
base = ManyAssociation.new(:foos, :order => 'position')
|
68
|
-
base.query_options.should == {:order => 'position'}
|
69
|
-
end
|
70
|
-
|
71
|
-
should "correctly parse from options" do
|
72
|
-
base = ManyAssociation.new(:foos, :order => 'position', :somekey => 'somevalue')
|
73
|
-
base.query_options.should == {:order => 'position', :somekey => 'somevalue'}
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "type_key_name" do
|
78
|
-
should "be association name _ type for belongs_to" do
|
79
|
-
BelongsToAssociation.new(:foo).type_key_name.should == 'foo_type'
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context "foreign_key" do
|
84
|
-
should "default to assocation name _id for belongs to" do
|
85
|
-
base = BelongsToAssociation.new(:foo)
|
86
|
-
base.foreign_key.should == 'foo_id'
|
87
|
-
end
|
88
|
-
|
89
|
-
should "be overridable with :foreign_key option" do
|
90
|
-
base = BelongsToAssociation.new(:foo, :foreign_key => 'foobar_id')
|
91
|
-
base.foreign_key.should == 'foobar_id'
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
should "have ivar that is association name" do
|
96
|
-
BelongsToAssociation.new(:foo).ivar.should == '@_foo'
|
97
|
-
end
|
98
|
-
|
99
|
-
context "embeddable?" do
|
100
|
-
should "be true if class is embeddable" do
|
101
|
-
base = ManyAssociation.new(:medias)
|
102
|
-
base.embeddable?.should be_true
|
103
|
-
end
|
104
|
-
|
105
|
-
should "be false if class is not embeddable" do
|
106
|
-
base = ManyAssociation.new(:statuses)
|
107
|
-
base.embeddable?.should be_false
|
108
|
-
|
109
|
-
base = BelongsToAssociation.new(:project)
|
110
|
-
base.embeddable?.should be_false
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
context "proxy_class" do
|
115
|
-
should "be BelongsToProxy for belongs_to" do
|
116
|
-
base = BelongsToAssociation.new(:project)
|
117
|
-
base.proxy_class.should == BelongsToProxy
|
118
|
-
end
|
119
|
-
|
120
|
-
should "be BelongsToPolymorphicProxy for polymorphic belongs_to" do
|
121
|
-
base = BelongsToAssociation.new(:target, :polymorphic => true)
|
122
|
-
base.proxy_class.should == BelongsToPolymorphicProxy
|
123
|
-
end
|
124
|
-
|
125
|
-
should "be OneProxy for one" do
|
126
|
-
base = OneAssociation.new(:status, :polymorphic => true)
|
127
|
-
base.proxy_class.should == OneProxy
|
128
|
-
end
|
129
|
-
|
130
|
-
should "be OneEmbeddedProxy for one embedded" do
|
131
|
-
base = OneAssociation.new(:media)
|
132
|
-
base.proxy_class.should == OneEmbeddedProxy
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context "touch?" do
|
137
|
-
should "be true if touch" do
|
138
|
-
BelongsToAssociation.new(:car, :touch => true).touch?.should be_true
|
139
|
-
end
|
140
|
-
|
141
|
-
should "be false if not touch" do
|
142
|
-
BelongsToAssociation.new(:car).touch?.should be_false
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
end
|