mark_mapper 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.rdoc +39 -0
- data/examples/attr_accessible.rb +24 -0
- data/examples/attr_protected.rb +24 -0
- data/examples/cache_key.rb +26 -0
- data/examples/custom_types.rb +26 -0
- data/examples/identity_map.rb +30 -0
- data/examples/identity_map/automatic.rb +2 -0
- data/examples/keys.rb +42 -0
- data/examples/modifiers/set.rb +27 -0
- data/examples/plugins.rb +40 -0
- data/examples/querying.rb +39 -0
- data/examples/sample_app.rb +43 -0
- data/examples/scopes.rb +56 -0
- data/examples/validating/embedded_docs.rb +31 -0
- data/lib/mark_mapper.rb +125 -0
- data/lib/mark_mapper/config.rb +90 -0
- data/lib/mark_mapper/connection.rb +60 -0
- data/lib/mark_mapper/criteria_hash.rb +194 -0
- data/lib/mark_mapper/document.rb +46 -0
- data/lib/mark_mapper/embedded_document.rb +32 -0
- data/lib/mark_mapper/exceptions.rb +33 -0
- data/lib/mark_mapper/extensions/array.rb +27 -0
- data/lib/mark_mapper/extensions/boolean.rb +45 -0
- data/lib/mark_mapper/extensions/date.rb +29 -0
- data/lib/mark_mapper/extensions/duplicable.rb +86 -0
- data/lib/mark_mapper/extensions/float.rb +18 -0
- data/lib/mark_mapper/extensions/hash.rb +26 -0
- data/lib/mark_mapper/extensions/integer.rb +27 -0
- data/lib/mark_mapper/extensions/kernel.rb +11 -0
- data/lib/mark_mapper/extensions/nil_class.rb +18 -0
- data/lib/mark_mapper/extensions/object.rb +30 -0
- data/lib/mark_mapper/extensions/object_id.rb +18 -0
- data/lib/mark_mapper/extensions/set.rb +20 -0
- data/lib/mark_mapper/extensions/string.rb +31 -0
- data/lib/mark_mapper/extensions/symbol.rb +87 -0
- data/lib/mark_mapper/extensions/time.rb +29 -0
- data/lib/mark_mapper/locale/en.yml +5 -0
- data/lib/mark_mapper/middleware/identity_map.rb +41 -0
- data/lib/mark_mapper/normalizers/criteria_hash_key.rb +17 -0
- data/lib/mark_mapper/normalizers/criteria_hash_value.rb +66 -0
- data/lib/mark_mapper/normalizers/fields_value.rb +26 -0
- data/lib/mark_mapper/normalizers/hash_key.rb +19 -0
- data/lib/mark_mapper/normalizers/integer.rb +19 -0
- data/lib/mark_mapper/normalizers/options_hash_value.rb +83 -0
- data/lib/mark_mapper/normalizers/sort_value.rb +55 -0
- data/lib/mark_mapper/options_hash.rb +103 -0
- data/lib/mark_mapper/pagination.rb +6 -0
- data/lib/mark_mapper/pagination/collection.rb +32 -0
- data/lib/mark_mapper/pagination/paginator.rb +46 -0
- data/lib/mark_mapper/plugins.rb +22 -0
- data/lib/mark_mapper/plugins/accessible.rb +61 -0
- data/lib/mark_mapper/plugins/active_model.rb +18 -0
- data/lib/mark_mapper/plugins/associations.rb +96 -0
- data/lib/mark_mapper/plugins/associations/base.rb +98 -0
- data/lib/mark_mapper/plugins/associations/belongs_to_association.rb +63 -0
- data/lib/mark_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +35 -0
- data/lib/mark_mapper/plugins/associations/belongs_to_proxy.rb +52 -0
- data/lib/mark_mapper/plugins/associations/collection.rb +29 -0
- data/lib/mark_mapper/plugins/associations/embedded_collection.rb +44 -0
- data/lib/mark_mapper/plugins/associations/in_array_proxy.rb +133 -0
- data/lib/mark_mapper/plugins/associations/many_association.rb +63 -0
- data/lib/mark_mapper/plugins/associations/many_documents_as_proxy.rb +28 -0
- data/lib/mark_mapper/plugins/associations/many_documents_proxy.rb +142 -0
- data/lib/mark_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +32 -0
- data/lib/mark_mapper/plugins/associations/many_embedded_proxy.rb +24 -0
- data/lib/mark_mapper/plugins/associations/many_polymorphic_proxy.rb +14 -0
- data/lib/mark_mapper/plugins/associations/one_as_proxy.rb +22 -0
- data/lib/mark_mapper/plugins/associations/one_association.rb +48 -0
- data/lib/mark_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb +30 -0
- data/lib/mark_mapper/plugins/associations/one_embedded_proxy.rb +44 -0
- data/lib/mark_mapper/plugins/associations/one_proxy.rb +95 -0
- data/lib/mark_mapper/plugins/associations/proxy.rb +138 -0
- data/lib/mark_mapper/plugins/associations/single_association.rb +46 -0
- data/lib/mark_mapper/plugins/caching.rb +21 -0
- data/lib/mark_mapper/plugins/callbacks.rb +42 -0
- data/lib/mark_mapper/plugins/clone.rb +24 -0
- data/lib/mark_mapper/plugins/counter_cache.rb +97 -0
- data/lib/mark_mapper/plugins/dirty.rb +61 -0
- data/lib/mark_mapper/plugins/document.rb +41 -0
- data/lib/mark_mapper/plugins/dumpable.rb +22 -0
- data/lib/mark_mapper/plugins/dynamic_querying.rb +45 -0
- data/lib/mark_mapper/plugins/dynamic_querying/dynamic_finder.rb +44 -0
- data/lib/mark_mapper/plugins/embedded_callbacks.rb +81 -0
- data/lib/mark_mapper/plugins/embedded_document.rb +53 -0
- data/lib/mark_mapper/plugins/equality.rb +23 -0
- data/lib/mark_mapper/plugins/identity_map.rb +144 -0
- data/lib/mark_mapper/plugins/indexable.rb +86 -0
- data/lib/mark_mapper/plugins/inspect.rb +16 -0
- data/lib/mark_mapper/plugins/keys.rb +470 -0
- data/lib/mark_mapper/plugins/keys/key.rb +134 -0
- data/lib/mark_mapper/plugins/keys/static.rb +45 -0
- data/lib/mark_mapper/plugins/logger.rb +18 -0
- data/lib/mark_mapper/plugins/modifiers.rb +140 -0
- data/lib/mark_mapper/plugins/pagination.rb +16 -0
- data/lib/mark_mapper/plugins/partial_updates.rb +77 -0
- data/lib/mark_mapper/plugins/persistence.rb +79 -0
- data/lib/mark_mapper/plugins/protected.rb +45 -0
- data/lib/mark_mapper/plugins/querying.rb +173 -0
- data/lib/mark_mapper/plugins/querying/decorated_markmapper_query.rb +75 -0
- data/lib/mark_mapper/plugins/rails.rb +79 -0
- data/lib/mark_mapper/plugins/rails/active_record_association_adapter.rb +33 -0
- data/lib/mark_mapper/plugins/sci.rb +82 -0
- data/lib/mark_mapper/plugins/scopes.rb +28 -0
- data/lib/mark_mapper/plugins/serialization.rb +109 -0
- data/lib/mark_mapper/plugins/timestamps.rb +29 -0
- data/lib/mark_mapper/plugins/touch.rb +18 -0
- data/lib/mark_mapper/plugins/userstamps.rb +18 -0
- data/lib/mark_mapper/plugins/validations.rb +96 -0
- data/lib/mark_mapper/query.rb +278 -0
- data/lib/mark_mapper/railtie.rb +52 -0
- data/lib/mark_mapper/railtie/database.rake +65 -0
- data/lib/mark_mapper/translation.rb +10 -0
- data/lib/mark_mapper/version.rb +4 -0
- data/lib/rails/generators/mark_mapper/config/config_generator.rb +37 -0
- data/lib/rails/generators/mark_mapper/config/templates/marklogic.yml +19 -0
- data/lib/rails/generators/mark_mapper/model/model_generator.rb +40 -0
- data/lib/rails/generators/mark_mapper/model/templates/model.rb +17 -0
- data/spec/config/mark_mapper.yml +6 -0
- data/spec/examples_spec.rb +25 -0
- data/spec/functional/accessible_spec.rb +198 -0
- data/spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb +64 -0
- data/spec/functional/associations/belongs_to_proxy_spec.rb +255 -0
- data/spec/functional/associations/in_array_proxy_spec.rb +349 -0
- data/spec/functional/associations/many_documents_as_proxy_spec.rb +230 -0
- data/spec/functional/associations/many_documents_proxy_spec.rb +968 -0
- data/spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb +238 -0
- data/spec/functional/associations/many_embedded_proxy_spec.rb +288 -0
- data/spec/functional/associations/many_polymorphic_proxy_spec.rb +302 -0
- data/spec/functional/associations/one_as_proxy_spec.rb +489 -0
- data/spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb +207 -0
- data/spec/functional/associations/one_embedded_proxy_spec.rb +100 -0
- data/spec/functional/associations/one_proxy_spec.rb +406 -0
- data/spec/functional/associations_spec.rb +48 -0
- data/spec/functional/caching_spec.rb +75 -0
- data/spec/functional/callbacks_spec.rb +330 -0
- data/spec/functional/counter_cache_spec.rb +235 -0
- data/spec/functional/dirty_spec.rb +316 -0
- data/spec/functional/document_spec.rb +310 -0
- data/spec/functional/dumpable_spec.rb +24 -0
- data/spec/functional/dynamic_querying_spec.rb +75 -0
- data/spec/functional/embedded_document_spec.rb +316 -0
- data/spec/functional/equality_spec.rb +20 -0
- data/spec/functional/extensions_spec.rb +16 -0
- data/spec/functional/identity_map_spec.rb +483 -0
- data/spec/functional/keys_spec.rb +339 -0
- data/spec/functional/logger_spec.rb +20 -0
- data/spec/functional/modifiers_spec.rb +446 -0
- data/spec/functional/options_hash_spec.rb +41 -0
- data/spec/functional/pagination_spec.rb +89 -0
- data/spec/functional/partial_updates_spec.rb +530 -0
- data/spec/functional/protected_spec.rb +199 -0
- data/spec/functional/querying_spec.rb +984 -0
- data/spec/functional/rails_spec.rb +55 -0
- data/spec/functional/sci_spec.rb +374 -0
- data/spec/functional/scopes_spec.rb +204 -0
- data/spec/functional/static_keys_spec.rb +153 -0
- data/spec/functional/timestamps_spec.rb +97 -0
- data/spec/functional/touch_spec.rb +125 -0
- data/spec/functional/userstamps_spec.rb +46 -0
- data/spec/functional/validations_spec.rb +416 -0
- data/spec/quality_spec.rb +51 -0
- data/spec/spec_helper.rb +150 -0
- data/spec/support/matchers.rb +15 -0
- data/spec/support/models.rb +256 -0
- data/spec/symbol_operator_spec.rb +70 -0
- data/spec/symbol_spec.rb +9 -0
- 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/spec/unit/associations/proxy_spec.rb +103 -0
- data/spec/unit/clone_spec.rb +79 -0
- data/spec/unit/config_generator_spec.rb +24 -0
- data/spec/unit/criteria_hash_spec.rb +218 -0
- data/spec/unit/document_spec.rb +251 -0
- data/spec/unit/dynamic_finder_spec.rb +125 -0
- data/spec/unit/embedded_document_spec.rb +676 -0
- data/spec/unit/equality_spec.rb +38 -0
- data/spec/unit/exceptions_spec.rb +12 -0
- data/spec/unit/extensions_spec.rb +368 -0
- data/spec/unit/identity_map_middleware_spec.rb +134 -0
- data/spec/unit/inspect_spec.rb +47 -0
- data/spec/unit/key_spec.rb +276 -0
- data/spec/unit/keys_spec.rb +155 -0
- data/spec/unit/mark_mapper_spec.rb +37 -0
- data/spec/unit/model_generator_spec.rb +45 -0
- data/spec/unit/normalizers/criteria_hash_key_spec.rb +37 -0
- data/spec/unit/normalizers/criteria_hash_value_spec.rb +200 -0
- data/spec/unit/normalizers/fields_value_spec.rb +45 -0
- data/spec/unit/normalizers/hash_key_spec.rb +15 -0
- data/spec/unit/normalizers/integer_spec.rb +24 -0
- data/spec/unit/normalizers/options_hash_value_spec.rb +99 -0
- data/spec/unit/normalizers/sort_value_spec.rb +98 -0
- data/spec/unit/options_hash_spec.rb +64 -0
- data/spec/unit/pagination/collection_spec.rb +30 -0
- data/spec/unit/pagination/paginator_spec.rb +118 -0
- data/spec/unit/pagination_spec.rb +11 -0
- data/spec/unit/plugins_spec.rb +89 -0
- data/spec/unit/query_spec.rb +837 -0
- data/spec/unit/rails_compatibility_spec.rb +40 -0
- data/spec/unit/rails_reflect_on_association_spec.rb +118 -0
- data/spec/unit/rails_spec.rb +188 -0
- 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/spec/unit/time_zones_spec.rb +44 -0
- data/spec/unit/translation_spec.rb +27 -0
- data/spec/unit/validations_spec.rb +588 -0
- metadata +307 -0
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SymbolOperator do
|
4
|
+
context "SymbolOperator" do
|
5
|
+
before { @operator = SymbolOperator.new(:foo, 'eq') }
|
6
|
+
subject { @operator }
|
7
|
+
|
8
|
+
it "has field" do
|
9
|
+
subject.field.should == :foo
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has operator" do
|
13
|
+
subject.operator.should == 'eq'
|
14
|
+
end
|
15
|
+
|
16
|
+
context "==" do
|
17
|
+
it "returns true if field and operator are equal" do
|
18
|
+
SymbolOperator.new(:foo, 'eq').should == SymbolOperator.new(:foo, 'eq')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns false if fields are equal but operators are not" do
|
22
|
+
SymbolOperator.new(:foo, 'eq').should_not == SymbolOperator.new(:foo, 'all')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns false if operators are equal but fields are not" do
|
26
|
+
SymbolOperator.new(:foo, 'eq').should_not == SymbolOperator.new(:bar, 'eq')
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns false if neither are equal" do
|
30
|
+
SymbolOperator.new(:foo, 'eq').should_not == SymbolOperator.new(:bar, 'all')
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns false if other isn't an symbol operator" do
|
34
|
+
SymbolOperator.new(:foo, 'eq').should_not == 'foo.in'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "hash" do
|
39
|
+
|
40
|
+
it 'returns sum of operator and hash field' do
|
41
|
+
SymbolOperator.new(:foo, 'eq').hash.should == :foo.hash + 'eq'.hash
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'eql?' do
|
47
|
+
|
48
|
+
it 'uses #== for equality comparison' do
|
49
|
+
expect(subject).to receive(:"==").with("dummy_value")
|
50
|
+
subject.eql?("dummy_value")
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
context "<=>" do
|
56
|
+
it "returns string comparison of operator for same field, different operator" do
|
57
|
+
(SymbolOperator.new(:foo, 'eq') <=> SymbolOperator.new(:foo, 'all')).should == 1
|
58
|
+
(SymbolOperator.new(:foo, 'all') <=> SymbolOperator.new(:foo, 'eq')).should == -1
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns 0 for same field same operator" do
|
62
|
+
(SymbolOperator.new(:foo, 'eq') <=> SymbolOperator.new(:foo, 'eq')).should == 0
|
63
|
+
end
|
64
|
+
|
65
|
+
it "returns 1 for different field" do
|
66
|
+
(SymbolOperator.new(:foo, 'eq') <=> SymbolOperator.new(:bar, 'eq')).should == 1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/symbol_spec.rb
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class FooMonster; end
|
4
|
+
module AssociationSpec
|
5
|
+
include MarkMapper::Plugins::Associations
|
6
|
+
|
7
|
+
describe MarkMapper::Plugins::Associations::Base do
|
8
|
+
it "should initialize with type and name" do
|
9
|
+
base = ManyAssociation.new(:foos)
|
10
|
+
base.name.should == :foos
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should also allow options when initializing" do
|
14
|
+
base = ManyAssociation.new(:foos, :polymorphic => true)
|
15
|
+
base.options[:polymorphic].should be_truthy
|
16
|
+
end
|
17
|
+
|
18
|
+
context "klass" do
|
19
|
+
it "should default to class_name constantized" do
|
20
|
+
BelongsToAssociation.new(:foo_monster).klass.should == FooMonster
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should be the specified class" do
|
24
|
+
anonnymous_class = Class.new
|
25
|
+
BelongsToAssociation.new(:foo_monster, :class => anonnymous_class).klass.should == anonnymous_class
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "polymorphic?" do
|
30
|
+
it "should be true if polymorphic" do
|
31
|
+
ManyAssociation.new(:foos, :polymorphic => true).polymorphic?.should be_truthy
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be false if not polymorphic" do
|
35
|
+
ManyAssociation.new(:bars).polymorphic?.should be_falsey
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "as?" do
|
40
|
+
it "should be true if one" do
|
41
|
+
OneAssociation.new(:foo, :as => :commentable).as?.should be_truthy
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be false if not one" do
|
45
|
+
ManyAssociation.new(:foo).as?.should be_falsey
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "in_array?" do
|
50
|
+
it "should be true if one" do
|
51
|
+
OneAssociation.new(:foo, :in => :list_ids).in_array?.should be_truthy
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should be false if not one" do
|
55
|
+
ManyAssociation.new(:foo).in_array?.should be_falsey
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "query_options" do
|
60
|
+
it "should default to empty hash" do
|
61
|
+
base = ManyAssociation.new(:foos)
|
62
|
+
base.query_options.should == {}
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should work with order" do
|
66
|
+
base = ManyAssociation.new(:foos, :order => 'position')
|
67
|
+
base.query_options.should == {:order => 'position'}
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should correctly parse from options" do
|
71
|
+
base = ManyAssociation.new(:foos, :order => 'position', :somekey => 'somevalue')
|
72
|
+
base.query_options.should == {:order => 'position', :somekey => 'somevalue'}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "type_key_name" do
|
77
|
+
it "should be association name _ type for belongs_to" do
|
78
|
+
BelongsToAssociation.new(:foo).type_key_name.should == 'foo_type'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "foreign_key" do
|
83
|
+
it "should default to assocation name _id for belongs to" do
|
84
|
+
base = BelongsToAssociation.new(:foo)
|
85
|
+
base.foreign_key.should == 'foo_id'
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should be overridable with :foreign_key option" do
|
89
|
+
base = BelongsToAssociation.new(:foo, :foreign_key => 'foobar_id')
|
90
|
+
base.foreign_key.should == 'foobar_id'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should have ivar that is association name" do
|
95
|
+
BelongsToAssociation.new(:foo).ivar.should == '@_foo'
|
96
|
+
end
|
97
|
+
|
98
|
+
context "embeddable?" do
|
99
|
+
it "should be true if class is embeddable" do
|
100
|
+
base = ManyAssociation.new(:medias)
|
101
|
+
base.embeddable?.should be_truthy
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should be false if class is not embeddable" do
|
105
|
+
base = ManyAssociation.new(:statuses)
|
106
|
+
base.embeddable?.should be_falsey
|
107
|
+
|
108
|
+
base = BelongsToAssociation.new(:project)
|
109
|
+
base.embeddable?.should be_falsey
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "proxy_class" do
|
114
|
+
it "should be BelongsToProxy for belongs_to" do
|
115
|
+
base = BelongsToAssociation.new(:project)
|
116
|
+
base.proxy_class.should == BelongsToProxy
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should be BelongsToPolymorphicProxy for polymorphic belongs_to" do
|
120
|
+
base = BelongsToAssociation.new(:target, :polymorphic => true)
|
121
|
+
base.proxy_class.should == BelongsToPolymorphicProxy
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should be OneProxy for one" do
|
125
|
+
base = OneAssociation.new(:status, :polymorphic => true)
|
126
|
+
base.proxy_class.should == OneProxy
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should be OneEmbeddedProxy for one embedded" do
|
130
|
+
base = OneAssociation.new(:media)
|
131
|
+
base.proxy_class.should == OneEmbeddedProxy
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context "touch?" do
|
136
|
+
it "should be true if touch" do
|
137
|
+
BelongsToAssociation.new(:car, :touch => true).touch?.should be_truthy
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should be false if not touch" do
|
141
|
+
BelongsToAssociation.new(:car).touch?.should be_falsey
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module BelongsToAssociation
|
4
|
+
include MarkMapper::Plugins::Associations
|
5
|
+
describe "BelongsToAssociation" do
|
6
|
+
|
7
|
+
context "class_name" do
|
8
|
+
it "should camelize the name" do
|
9
|
+
BelongsToAssociation.new(:user).class_name.should == 'User'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be changeable using class_name option" do
|
13
|
+
association = BelongsToAssociation.new(:user, :class_name => 'Person')
|
14
|
+
association.class_name.should == 'Person'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "embeddable?" do
|
19
|
+
it "should be false even if class is embeddable" do
|
20
|
+
base = BelongsToAssociation.new(:address)
|
21
|
+
base.embeddable?.should be_falsey
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should be false if class is not embeddable" do
|
25
|
+
base = BelongsToAssociation.new(:project)
|
26
|
+
base.embeddable?.should be_falsey
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
module ManyAssociationSpec
|
5
|
+
include MarkMapper::Plugins::Associations
|
6
|
+
describe "ManyAssociation" do
|
7
|
+
|
8
|
+
context "class_name" do
|
9
|
+
it "should camelize the name" do
|
10
|
+
ManyAssociation.new(:smart_people).class_name.should == 'SmartPerson'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be changeable using class_name option" do
|
14
|
+
base = ManyAssociation.new(:smart_people, :class_name => 'IntelligentPerson')
|
15
|
+
base.class_name.should == 'IntelligentPerson'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "type_key_name" do
|
20
|
+
it "should be _type" do
|
21
|
+
ManyAssociation.new(:foos).type_key_name.should == '_type'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "embeddable?" do
|
26
|
+
it "should be true if class is embeddable" do
|
27
|
+
base = ManyAssociation.new(:medias)
|
28
|
+
base.embeddable?.should be_truthy
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should be false if class is not embeddable" do
|
32
|
+
base = ManyAssociation.new(:statuses)
|
33
|
+
base.embeddable?.should be_falsey
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "proxy_class" do
|
38
|
+
it "should be ManyDocumentsProxy for many" do
|
39
|
+
base = ManyAssociation.new(:statuses)
|
40
|
+
base.proxy_class.should == ManyDocumentsProxy
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should be ManyPolymorphicProxy for polymorphic many" do
|
44
|
+
base = ManyAssociation.new(:messages, :polymorphic => true)
|
45
|
+
base.proxy_class.should == ManyPolymorphicProxy
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should be ManyEmbeddedProxy for many embedded" do
|
49
|
+
base = ManyAssociation.new(:medias)
|
50
|
+
base.proxy_class.should == ManyEmbeddedProxy
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should be ManyEmbeddedPolymorphicProxy for polymorphic many embedded" do
|
54
|
+
base = ManyAssociation.new(:medias, :polymorphic => true)
|
55
|
+
base.proxy_class.should == ManyEmbeddedPolymorphicProxy
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should be InArrayProxy for many with :in option" do
|
59
|
+
base = ManyAssociation.new(:messages, :in => :message_ids)
|
60
|
+
base.proxy_class.should == InArrayProxy
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
module OneAssociationSpec
|
5
|
+
include MarkMapper::Plugins::Associations
|
6
|
+
describe "OneAssociation" do
|
7
|
+
|
8
|
+
context "type_key_name" do
|
9
|
+
it "should be _type" do
|
10
|
+
OneAssociation.new(:foo).type_key_name.should == '_type'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "embeddable?" do
|
15
|
+
it "should be true if class is embeddable" do
|
16
|
+
base = OneAssociation.new(:media)
|
17
|
+
base.embeddable?.should be_truthy
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be false if class is not embeddable" do
|
21
|
+
base = OneAssociation.new(:project)
|
22
|
+
base.embeddable?.should be_falsey
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "proxy_class" do
|
27
|
+
it "should be OneProxy for one" do
|
28
|
+
base = OneAssociation.new(:status)
|
29
|
+
base.proxy_class.should == OneProxy
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should be OneAsProxy for one with :as option" do
|
33
|
+
base = OneAssociation.new(:message, :as => :messagable)
|
34
|
+
base.proxy_class.should == OneAsProxy
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should be OneEmbeddedProxy for one embedded" do
|
38
|
+
base = OneAssociation.new(:media)
|
39
|
+
base.proxy_class.should == OneEmbeddedProxy
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should be OneEmbeddedPolymorphicProxy for polymorphic one embedded" do
|
43
|
+
base = OneAssociation.new(:media, :polymorphic => true)
|
44
|
+
base.proxy_class.should == OneEmbeddedPolymorphicProxy
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class FakeNilProxy < MarkMapper::Plugins::Associations::Proxy
|
4
|
+
def find_target; nil end
|
5
|
+
end
|
6
|
+
|
7
|
+
class FakeBlankProxy < MarkMapper::Plugins::Associations::Proxy
|
8
|
+
def find_target; '' end
|
9
|
+
end
|
10
|
+
|
11
|
+
class FakeNumberProxy < MarkMapper::Plugins::Associations::Proxy
|
12
|
+
def find_target; 17 end
|
13
|
+
end
|
14
|
+
|
15
|
+
class FakeProxy < MarkMapper::Plugins::Associations::Proxy
|
16
|
+
def find_target; [1, 2] end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "Proxy" do
|
20
|
+
before do
|
21
|
+
@owner = double('owner', :new? => false)
|
22
|
+
@association = double('association', :options => {:extend => []})
|
23
|
+
|
24
|
+
@proxy = FakeProxy.new(@owner, @association)
|
25
|
+
@nil_proxy = FakeNilProxy.new(@owner, @association)
|
26
|
+
@blank_proxy = FakeBlankProxy.new(@owner, @association)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should set target to nil when reset is called" do
|
30
|
+
@proxy.reset
|
31
|
+
@proxy.target.should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be able to inspect the proxy" do
|
35
|
+
@proxy.inspect.should == '[1, 2]'
|
36
|
+
end
|
37
|
+
|
38
|
+
context "nil?" do
|
39
|
+
it "should be true if nil" do
|
40
|
+
@nil_proxy.nil?.should be_truthy
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should be false if not nil" do
|
44
|
+
@proxy.nil?.should be_falsey
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "blank?" do
|
49
|
+
it "should be true if blank" do
|
50
|
+
@blank_proxy.blank?.should be_truthy
|
51
|
+
@nil_proxy.blank?.should be_truthy
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should be false if not blank" do
|
55
|
+
@proxy.blank?.should be_falsey
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "present?" do
|
60
|
+
it "should be true if present" do
|
61
|
+
@proxy.present?.should be_truthy
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should be false if not present" do
|
65
|
+
@blank_proxy.present?.should be_falsey
|
66
|
+
@nil_proxy.present?.should be_falsey
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should delegate respond_to? to target" do
|
71
|
+
@proxy.respond_to?(:each).should be_truthy
|
72
|
+
@proxy.respond_to?(:size).should be_truthy
|
73
|
+
@proxy.respond_to?(:gsub).should be_falsey
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should alias proxy owner to owner" do
|
77
|
+
@proxy.proxy_owner.should == @owner
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should alias proxy target to target" do
|
81
|
+
@proxy.proxy_target.should == @target
|
82
|
+
end
|
83
|
+
|
84
|
+
context "send" do
|
85
|
+
it "should work if proxy responds to method" do
|
86
|
+
@proxy.send(:reset)
|
87
|
+
@proxy.target.should be_nil
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should work if the target responds to the method" do
|
91
|
+
@proxy.send(:size).should == 2
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should not work if neither the proxy or target respond to method" do
|
95
|
+
lambda { @proxy.send(:gsub) }.should raise_error
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should work if a proc is passed" do
|
99
|
+
p = Proc.new {|x| x+1}
|
100
|
+
@proxy.send(:collect, &p).should == [2,3]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|