mongo_mapper 0.8.6 → 0.9.0

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.
Files changed (107) hide show
  1. data/UPGRADES +10 -0
  2. data/bin/mmconsole +0 -1
  3. data/examples/identity_map/automatic.rb +1 -7
  4. data/examples/plugins.rb +9 -9
  5. data/examples/safe.rb +43 -0
  6. data/lib/mongo_mapper.rb +46 -33
  7. data/lib/mongo_mapper/document.rb +33 -32
  8. data/lib/mongo_mapper/embedded_document.rb +22 -22
  9. data/lib/mongo_mapper/locale/en.yml +5 -0
  10. data/lib/mongo_mapper/middleware/identity_map.rb +16 -0
  11. data/lib/mongo_mapper/plugins.rb +16 -3
  12. data/lib/mongo_mapper/plugins/accessible.rb +2 -0
  13. data/lib/mongo_mapper/plugins/active_model.rb +18 -0
  14. data/lib/mongo_mapper/plugins/associations.rb +37 -42
  15. data/lib/mongo_mapper/plugins/associations/base.rb +14 -50
  16. data/lib/mongo_mapper/plugins/associations/belongs_to_association.rb +58 -0
  17. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +6 -1
  18. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +30 -2
  19. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +4 -0
  20. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +12 -6
  21. data/lib/mongo_mapper/plugins/associations/many_association.rb +67 -0
  22. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +5 -5
  23. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +1 -1
  24. data/lib/mongo_mapper/plugins/associations/one_association.rb +20 -0
  25. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +5 -0
  26. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +7 -7
  27. data/lib/mongo_mapper/plugins/associations/proxy.rb +2 -2
  28. data/lib/mongo_mapper/plugins/caching.rb +3 -1
  29. data/lib/mongo_mapper/plugins/callbacks.rb +12 -221
  30. data/lib/mongo_mapper/plugins/clone.rb +3 -1
  31. data/lib/mongo_mapper/plugins/dirty.rb +38 -91
  32. data/lib/mongo_mapper/plugins/document.rb +4 -2
  33. data/lib/mongo_mapper/plugins/dynamic_querying.rb +2 -0
  34. data/lib/mongo_mapper/plugins/embedded_callbacks.rb +43 -0
  35. data/lib/mongo_mapper/plugins/embedded_document.rb +16 -9
  36. data/lib/mongo_mapper/plugins/equality.rb +2 -0
  37. data/lib/mongo_mapper/plugins/identity_map.rb +4 -2
  38. data/lib/mongo_mapper/plugins/indexes.rb +2 -0
  39. data/lib/mongo_mapper/plugins/inspect.rb +3 -1
  40. data/lib/mongo_mapper/plugins/keys.rb +28 -22
  41. data/lib/mongo_mapper/plugins/keys/key.rb +12 -6
  42. data/lib/mongo_mapper/plugins/logger.rb +2 -0
  43. data/lib/mongo_mapper/plugins/modifiers.rb +3 -1
  44. data/lib/mongo_mapper/plugins/pagination.rb +2 -0
  45. data/lib/mongo_mapper/plugins/persistence.rb +2 -0
  46. data/lib/mongo_mapper/plugins/protected.rb +2 -0
  47. data/lib/mongo_mapper/plugins/querying.rb +5 -4
  48. data/lib/mongo_mapper/plugins/rails.rb +3 -5
  49. data/lib/mongo_mapper/plugins/safe.rb +2 -0
  50. data/lib/mongo_mapper/plugins/sci.rb +2 -0
  51. data/lib/mongo_mapper/plugins/scopes.rb +2 -0
  52. data/lib/mongo_mapper/plugins/serialization.rb +67 -46
  53. data/lib/mongo_mapper/plugins/timestamps.rb +3 -1
  54. data/lib/mongo_mapper/plugins/userstamps.rb +2 -0
  55. data/lib/mongo_mapper/plugins/validations.rb +40 -24
  56. data/lib/mongo_mapper/railtie.rb +49 -0
  57. data/lib/mongo_mapper/railtie/database.rake +60 -0
  58. data/lib/mongo_mapper/support/descendant_appends.rb +11 -11
  59. data/lib/mongo_mapper/translation.rb +10 -0
  60. data/lib/mongo_mapper/version.rb +1 -1
  61. data/lib/rails/generators/mongo_mapper/config/config_generator.rb +24 -0
  62. data/lib/rails/generators/mongo_mapper/config/templates/mongo.yml +18 -0
  63. data/lib/rails/generators/mongo_mapper/model/model_generator.rb +23 -0
  64. data/lib/rails/generators/mongo_mapper/model/templates/model.rb +11 -0
  65. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +1 -0
  66. data/test/functional/associations/test_belongs_to_proxy.rb +131 -1
  67. data/test/functional/associations/test_in_array_proxy.rb +30 -0
  68. data/test/functional/associations/test_many_documents_proxy.rb +30 -2
  69. data/test/functional/associations/test_many_embedded_proxy.rb +33 -0
  70. data/test/functional/associations/test_many_polymorphic_proxy.rb +1 -0
  71. data/test/functional/associations/test_one_embedded_proxy.rb +21 -2
  72. data/test/functional/associations/test_one_proxy.rb +49 -9
  73. data/test/functional/test_associations.rb +2 -0
  74. data/test/functional/test_caching.rb +3 -2
  75. data/test/functional/test_callbacks.rb +25 -18
  76. data/test/functional/test_dirty.rb +123 -1
  77. data/test/functional/test_document.rb +26 -2
  78. data/test/functional/test_embedded_document.rb +68 -2
  79. data/test/functional/test_identity_map.rb +3 -4
  80. data/test/functional/test_querying.rb +11 -0
  81. data/test/functional/test_userstamps.rb +2 -2
  82. data/test/functional/test_validations.rb +31 -29
  83. data/test/models.rb +10 -0
  84. data/test/test_active_model_lint.rb +1 -1
  85. data/test/test_helper.rb +9 -10
  86. data/test/unit/associations/test_base.rb +24 -100
  87. data/test/unit/associations/test_belongs_to_association.rb +29 -0
  88. data/test/unit/associations/test_many_association.rb +63 -0
  89. data/test/unit/associations/test_one_association.rb +18 -0
  90. data/test/unit/serializers/test_json_serializer.rb +0 -1
  91. data/test/unit/test_descendant_appends.rb +8 -16
  92. data/test/unit/test_document.rb +4 -9
  93. data/test/unit/test_dynamic_finder.rb +1 -1
  94. data/test/unit/test_embedded_document.rb +51 -18
  95. data/test/unit/test_identity_map_middleware.rb +34 -0
  96. data/test/unit/test_inspect.rb +22 -0
  97. data/test/unit/test_key.rb +21 -1
  98. data/test/unit/test_keys.rb +0 -2
  99. data/test/unit/test_plugins.rb +106 -20
  100. data/test/unit/test_rails.rb +8 -8
  101. data/test/unit/test_serialization.rb +116 -1
  102. data/test/unit/test_translation.rb +27 -0
  103. data/test/unit/test_validations.rb +66 -81
  104. metadata +103 -43
  105. data/examples/identity_map/middleware.rb +0 -14
  106. data/lib/mongo_mapper/plugins/descendants.rb +0 -17
  107. data/rails/init.rb +0 -19
@@ -66,7 +66,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
66
66
  @klass.key :foo, @address_class
67
67
  end
68
68
 
69
- should "be true until document is saved" do
69
+ should "be true until document is created" do
70
70
  address = @address_class.new(:city => 'South Bend', :state => 'IN')
71
71
  doc = @klass.new(:foo => address)
72
72
  address.new?.should be_true
@@ -89,7 +89,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
89
89
  end
90
90
  end
91
91
 
92
- context "new? (embedded association)" do
92
+ context "new? (embedded many association)" do
93
93
  setup do
94
94
  @doc = @klass.new(:pets => [{:name => 'poo bear'}])
95
95
  end
@@ -110,6 +110,61 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
110
110
  @doc.reload
111
111
  @doc.pets.first.should_not be_new
112
112
  end
113
+
114
+ should "be true until existing document is saved" do
115
+ @doc.save
116
+ pet = @doc.pets.build(:name => 'Rasmus')
117
+ pet.new?.should be_true
118
+ @doc.save
119
+ pet.new?.should be_false
120
+ end
121
+ end
122
+
123
+ context "new? (nested embedded many association)" do
124
+ setup do
125
+ @pet_klass.many :addresses, :class=> @address_class
126
+ @doc = @klass.new
127
+ @doc.pets.build(:name => 'Rasmus')
128
+ @doc.save
129
+ end
130
+
131
+ should "be true until existing document is saved" do
132
+ address = @doc.pets.first.addresses.build(:city => 'Holland', :state => 'MI')
133
+ address.new?.should be_true
134
+ @doc.save
135
+ address.new?.should be_false
136
+ end
137
+ end
138
+
139
+ context "new? (embedded one association)" do
140
+ setup do
141
+ @klass.one :address, :class => @address_class
142
+ @doc = @klass.new
143
+ end
144
+
145
+ should "be true until existing document is saved" do
146
+ @doc.save
147
+ @doc.build_address(:city => 'Holland', :state => 'MI')
148
+ @doc.address.new?.should be_true
149
+ @doc.save
150
+ @doc.address.new?.should be_false
151
+ end
152
+ end
153
+
154
+ context "new? (nested embedded one association)" do
155
+ setup do
156
+ @pet_klass.one :address, :class => @address_class
157
+ @doc = @klass.new
158
+ @doc.pets.build(:name => 'Rasmus')
159
+ @doc.save
160
+ end
161
+
162
+ should "be true until existing document is saved" do
163
+ address = @doc.pets.first.build_address(:city => 'Holland', :stats => 'MI')
164
+ address.new?.should be_true
165
+ @doc.save
166
+ address.new?.should be_false
167
+ end
113
168
  end
114
169
 
115
170
  context "#destroyed?" do
@@ -164,6 +219,17 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
164
219
  person.pets.first.should == pet
165
220
  end
166
221
 
222
+ should "be able to save!" do
223
+ person = @klass.create
224
+
225
+ pet = @pet_klass.new(:name => 'sparky')
226
+ person.pets << pet
227
+ pet.should be_new
228
+
229
+ person.expects(:save!)
230
+ pet.save!
231
+ end
232
+
167
233
  should "be able to dynamically add new keys and save" do
168
234
  person = @klass.create
169
235
 
@@ -410,7 +410,6 @@ class IdentityMapTest < Test::Unit::TestCase
410
410
  assert_in_map(root)
411
411
 
412
412
  blog = Blog.create(:title => 'Jill', :parent => root)
413
- blog.parent.inspect
414
413
  assert_in_map(blog)
415
414
  root.should equal(blog.parent.target)
416
415
  end
@@ -426,7 +425,7 @@ class IdentityMapTest < Test::Unit::TestCase
426
425
 
427
426
  should "work correctly with one proxy create" do
428
427
  root = Item.create(:title => 'Root')
429
- blog = root.blog.create(:title => 'Blog')
428
+ blog = root.create_blog(:title => 'Blog')
430
429
  blog.parent.should equal(root)
431
430
  end
432
431
  end
@@ -465,11 +464,11 @@ class IdentityMapTest < Test::Unit::TestCase
465
464
  loaded.should_not equal(post)
466
465
  end
467
466
  end
468
-
467
+
469
468
  should "not load attributes from map when finding" do
470
469
  post = @post_class.create(:title => 'Awesome!')
471
470
  post.title = 'Temporary'
472
- @post_class.without_identity_map do
471
+ @post_class.without_identity_map do
473
472
  @post_class.find(post.id).title.should == 'Awesome!'
474
473
  end
475
474
  end
@@ -677,6 +677,17 @@ class QueryingTesting < Test::Unit::TestCase
677
677
  end
678
678
  end
679
679
 
680
+ context "#update_attribute" do
681
+ setup do
682
+ @doc = @document.create(:first_name => 'John', :age => '27')
683
+ end
684
+
685
+ should "update the attribute" do
686
+ @doc.update_attribute(:first_name, 'Chris').should be_true
687
+ @doc.reload.first_name.should == 'Chris'
688
+ end
689
+ end
690
+
680
691
  context "#save (new document)" do
681
692
  setup do
682
693
  @doc = @document.new(:first_name => 'John', :age => '27')
@@ -17,11 +17,11 @@ class UserstampsTest < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  should "add belongs_to creator" do
20
- @document.associations.keys.should include('creator')
20
+ @document.associations.keys.should include(:creator)
21
21
  end
22
22
 
23
23
  should "add belongs_to updater" do
24
- @document.associations.keys.should include('updater')
24
+ @document.associations.keys.should include(:updater)
25
25
  end
26
26
  end
27
27
  end
@@ -18,7 +18,7 @@ class ValidationsTest < Test::Unit::TestCase
18
18
  doc = @document.new
19
19
  doc.errors.size.should == 0
20
20
  doc.save
21
- doc.errors.full_messages.should == ["Name can't be empty"]
21
+ doc.errors.full_messages.should == ["Name can't be blank"]
22
22
  end
23
23
  end
24
24
 
@@ -70,7 +70,7 @@ class ValidationsTest < Test::Unit::TestCase
70
70
  should "populate document's errors" do
71
71
  @doc.name = nil
72
72
  @doc.save
73
- @doc.errors.full_messages.should == ["Name can't be empty"]
73
+ @doc.errors.full_messages.should == ["Name can't be blank"]
74
74
  end
75
75
  end
76
76
 
@@ -84,23 +84,19 @@ class ValidationsTest < Test::Unit::TestCase
84
84
  end
85
85
  end
86
86
 
87
- should "work with validate_on_create callback" do
88
- @document.validate_on_create :action_present
87
+ should "work with validate :on => :create callback" do
88
+ @document.validate :action_present, :on => :create
89
89
 
90
- doc = @document.new
91
- doc.action = nil
90
+ doc = @document.create(:action => nil)
92
91
  doc.should have_error_on(:action)
93
92
 
94
93
  doc.action = 'kick'
95
- doc.should_not have_error_on(:action)
96
94
  doc.save
97
-
98
- doc.action = nil
99
95
  doc.should_not have_error_on(:action)
100
96
  end
101
97
 
102
- should "work with validate_on_update callback" do
103
- @document.validate_on_update :action_present
98
+ should "work with validate :on => :update callback" do
99
+ @document.validate :action_present, :on => :update
104
100
 
105
101
  doc = @document.new
106
102
  doc.action = nil
@@ -141,6 +137,12 @@ class ValidationsTest < Test::Unit::TestCase
141
137
  doc2.should be_valid
142
138
  end
143
139
 
140
+ should "work with i18n taken message" do
141
+ @document.create(:name => 'joe')
142
+ doc = @document.create(:name => 'joe')
143
+ doc.should have_error_on(:name, 'has already been taken')
144
+ end
145
+
144
146
  should "allow to update an object" do
145
147
  doc = @document.new("name" => "joe")
146
148
  doc.save.should be_true
@@ -321,22 +323,22 @@ class ValidationsTest < Test::Unit::TestCase
321
323
  end
322
324
  end
323
325
 
324
- context "validates uniqueness of with :unique shortcut" do
325
- should "work" do
326
- @document = Doc do
327
- key :name, String, :unique => true
328
- end
329
-
330
- doc = @document.create(:name => 'John')
331
- doc.should_not have_error_on(:name)
332
-
333
- @document \
334
- .stubs(:first) \
335
- .with(:name => 'John') \
336
- .returns(doc)
337
-
338
- second_john = @document.create(:name => 'John')
339
- second_john.should have_error_on(:name, 'has already been taken')
340
- end
341
- end
326
+ # context "validates uniqueness of with :unique shortcut" do
327
+ # should "work" do
328
+ # @document = Doc do
329
+ # key :name, String, :unique => true
330
+ # end
331
+ #
332
+ # doc = @document.create(:name => 'John')
333
+ # doc.should_not have_error_on(:name)
334
+ #
335
+ # @document \
336
+ # .stubs(:first) \
337
+ # .with(:name => 'John') \
338
+ # .returns(doc)
339
+ #
340
+ # second_john = @document.create(:name => 'John')
341
+ # second_john.should have_error_on(:name, 'has already been taken')
342
+ # end
343
+ # end
342
344
  end
data/test/models.rb CHANGED
@@ -231,3 +231,13 @@ module TrModels
231
231
  key :name, String
232
232
  end
233
233
  end
234
+
235
+ module News
236
+ class Paper
237
+ include MongoMapper::Document
238
+ end
239
+
240
+ class Article
241
+ include MongoMapper::Document
242
+ end
243
+ end
@@ -5,7 +5,7 @@ require 'active_model'
5
5
  require 'models'
6
6
 
7
7
  class ActiveModelLintTest < ActiveModel::TestCase
8
- include ActiveModel::Lint::Tests
8
+ include ::ActiveModel::Lint::Tests
9
9
 
10
10
  def setup
11
11
  @model = Post.new
data/test/test_helper.rb CHANGED
@@ -6,17 +6,18 @@ require 'mongo_mapper'
6
6
  require 'fileutils'
7
7
  require 'ostruct'
8
8
 
9
- require 'active_support/version'
10
9
  require 'json'
11
10
  require 'log_buddy'
12
11
  require 'matchy'
13
12
  require 'shoulda'
14
13
  require 'timecop'
15
14
  require 'mocha'
15
+ require 'ruby-debug'
16
16
 
17
17
  class Test::Unit::TestCase
18
- def Doc(name=nil, &block)
19
- klass = Class.new do
18
+ def Doc(name='Class', &block)
19
+ klass = Class.new
20
+ klass.class_eval do
20
21
  include MongoMapper::Document
21
22
  set_collection_name :test
22
23
 
@@ -31,7 +32,7 @@ class Test::Unit::TestCase
31
32
  klass
32
33
  end
33
34
 
34
- def EDoc(name=nil, &block)
35
+ def EDoc(name='Class', &block)
35
36
  klass = Class.new do
36
37
  include MongoMapper::EmbeddedDocument
37
38
 
@@ -71,12 +72,12 @@ class Test::Unit::TestCase
71
72
  if expected_message.nil?
72
73
  matcher.positive_failure_message = "#{receiver} had no errors on #{attribute}"
73
74
  matcher.negative_failure_message = "#{receiver} had errors on #{attribute} #{receiver.errors.inspect}"
74
- !receiver.errors.on(attribute).blank?
75
+ !receiver.errors[attribute].blank?
75
76
  else
76
- actual = receiver.errors.on(attribute)
77
+ actual = receiver.errors[attribute]
77
78
  matcher.positive_failure_message = %Q(Expected error on #{attribute} to be "#{expected_message}" but was "#{actual}")
78
79
  matcher.negative_failure_message = %Q(Expected error on #{attribute} not to be "#{expected_message}" but was "#{actual}")
79
- actual == expected_message
80
+ actual.include? expected_message
80
81
  end
81
82
  end
82
83
 
@@ -94,7 +95,5 @@ logger = Logger.new(log_dir + '/test.log')
94
95
 
95
96
  LogBuddy.init(:logger => logger)
96
97
  MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017, :logger => logger)
97
- MongoMapper.database = "mm-test-#{RUBY_VERSION.gsub('.', '-')}"
98
+ MongoMapper.database = "test"
98
99
  MongoMapper.database.collections.each { |c| c.drop_indexes }
99
-
100
- puts "\n--- Active Support Version: #{ActiveSupport::VERSION::STRING} ---\n"
@@ -7,206 +7,130 @@ class AssociationBaseTest < Test::Unit::TestCase
7
7
  include MongoMapper::Plugins::Associations
8
8
 
9
9
  should "initialize with type and name" do
10
- base = Base.new(:many, :foos)
11
- base.type.should == :many
10
+ base = ManyAssociation.new(:foos)
12
11
  base.name.should == :foos
13
12
  end
14
13
 
15
14
  should "also allow options when initializing" do
16
- base = Base.new(:many, :foos, :polymorphic => true)
15
+ base = ManyAssociation.new(:foos, :polymorphic => true)
17
16
  base.options[:polymorphic].should be_true
18
17
  end
19
18
 
20
- context "class_name" do
21
- should "work for belongs_to" do
22
- Base.new(:belongs_to, :user).class_name.should == 'User'
23
- end
24
-
25
- should "work for many" do
26
- Base.new(:many, :smart_people).class_name.should == 'SmartPerson'
27
- end
28
-
29
- should "be changeable using class_name option" do
30
- base = Base.new(:many, :smart_people, :class_name => 'IntelligentPerson')
31
- base.class_name.should == 'IntelligentPerson'
32
- end
33
- end
34
-
35
19
  context "klass" do
36
20
  should "default to class_name constantized" do
37
- Base.new(:belongs_to, :foo_monster).klass.should == FooMonster
21
+ BelongsToAssociation.new(:foo_monster).klass.should == FooMonster
38
22
  end
39
23
 
40
24
  should "be the specified class" do
41
25
  anonnymous_class = Class.new
42
- Base.new(:belongs_to, :foo_monster, :class => anonnymous_class).klass.should == anonnymous_class
43
- end
44
- end
45
-
46
- context "many?" do
47
- should "be true if many" do
48
- Base.new(:many, :foos).many?.should be_true
49
- end
50
-
51
- should "be false if not many" do
52
- Base.new(:belongs_to, :foo).many?.should be_false
53
- Base.new(:one, :foo).many?.should be_false
54
- end
55
- end
56
-
57
- context "one?" do
58
- should "be true if one" do
59
- Base.new(:one, :foo).one?.should be_true
60
- end
61
-
62
- should "be false if not one" do
63
- Base.new(:many, :foo).one?.should be_false
64
- end
65
- end
66
-
67
- context "belongs_to?" do
68
- should "be true if belongs_to" do
69
- Base.new(:belongs_to, :foo).belongs_to?.should be_true
70
- end
71
-
72
- should "be false if not belongs_to" do
73
- Base.new(:many, :foos).belongs_to?.should be_false
26
+ BelongsToAssociation.new(:foo_monster, :class => anonnymous_class).klass.should == anonnymous_class
74
27
  end
75
28
  end
76
29
 
77
30
  context "polymorphic?" do
78
31
  should "be true if polymorphic" do
79
- Base.new(:many, :foos, :polymorphic => true).polymorphic?.should be_true
32
+ ManyAssociation.new(:foos, :polymorphic => true).polymorphic?.should be_true
80
33
  end
81
34
 
82
35
  should "be false if not polymorphic" do
83
- Base.new(:many, :bars).polymorphic?.should be_false
36
+ ManyAssociation.new(:bars).polymorphic?.should be_false
84
37
  end
85
38
  end
86
39
 
87
40
  context "as?" do
88
41
  should "be true if one" do
89
- Base.new(:one, :foo, :as => :commentable).as?.should be_true
42
+ OneAssociation.new(:foo, :as => :commentable).as?.should be_true
90
43
  end
91
44
 
92
45
  should "be false if not one" do
93
- Base.new(:many, :foo).as?.should be_false
46
+ ManyAssociation.new(:foo).as?.should be_false
94
47
  end
95
48
  end
96
49
 
97
50
  context "in_array?" do
98
51
  should "be true if one" do
99
- Base.new(:one, :foo, :in => :list_ids).in_array?.should be_true
52
+ OneAssociation.new(:foo, :in => :list_ids).in_array?.should be_true
100
53
  end
101
54
 
102
55
  should "be false if not one" do
103
- Base.new(:many, :foo).in_array?.should be_false
56
+ ManyAssociation.new(:foo).in_array?.should be_false
104
57
  end
105
58
  end
106
59
 
107
60
  context "query_options" do
108
61
  should "default to empty hash" do
109
- base = Base.new(:many, :foos)
62
+ base = ManyAssociation.new(:foos)
110
63
  base.query_options.should == {}
111
64
  end
112
65
 
113
66
  should "work with order" do
114
- base = Base.new(:many, :foos, :order => 'position')
67
+ base = ManyAssociation.new(:foos, :order => 'position')
115
68
  base.query_options.should == {:order => 'position'}
116
69
  end
117
70
 
118
71
  should "correctly parse from options" do
119
- base = Base.new(:many, :foos, :order => 'position', :somekey => 'somevalue')
72
+ base = ManyAssociation.new(:foos, :order => 'position', :somekey => 'somevalue')
120
73
  base.query_options.should == {:order => 'position', :somekey => 'somevalue'}
121
74
  end
122
75
  end
123
76
 
124
77
  context "type_key_name" do
125
- should "be _type for many" do
126
- Base.new(:many, :foos).type_key_name.should == '_type'
127
- end
128
-
129
78
  should "be association name _ type for belongs_to" do
130
- Base.new(:belongs_to, :foo).type_key_name.should == 'foo_type'
79
+ BelongsToAssociation.new(:foo).type_key_name.should == 'foo_type'
131
80
  end
132
81
  end
133
82
 
134
83
  context "foreign_key" do
135
84
  should "default to assocation name _id for belongs to" do
136
- base = Base.new(:belongs_to, :foo)
85
+ base = BelongsToAssociation.new(:foo)
137
86
  base.foreign_key.should == 'foo_id'
138
87
  end
139
88
 
140
89
  should "be overridable with :foreign_key option" do
141
- base = Base.new(:belongs_to, :foo, :foreign_key => 'foobar_id')
90
+ base = BelongsToAssociation.new(:foo, :foreign_key => 'foobar_id')
142
91
  base.foreign_key.should == 'foobar_id'
143
92
  end
144
93
  end
145
94
 
146
95
  should "have ivar that is association name" do
147
- Base.new(:belongs_to, :foo).ivar.should == '@_foo'
96
+ BelongsToAssociation.new(:foo).ivar.should == '@_foo'
148
97
  end
149
98
 
150
99
  context "embeddable?" do
151
100
  should "be true if class is embeddable" do
152
- base = Base.new(:many, :medias)
101
+ base = ManyAssociation.new(:medias)
153
102
  base.embeddable?.should be_true
154
103
  end
155
104
 
156
105
  should "be false if class is not embeddable" do
157
- base = Base.new(:many, :statuses)
106
+ base = ManyAssociation.new(:statuses)
158
107
  base.embeddable?.should be_false
159
108
 
160
- base = Base.new(:belongs_to, :project)
109
+ base = BelongsToAssociation.new(:project)
161
110
  base.embeddable?.should be_false
162
111
  end
163
112
  end
164
113
 
165
114
  context "proxy_class" do
166
- should "be ManyDocumentsProxy for many" do
167
- base = Base.new(:many, :statuses)
168
- base.proxy_class.should == ManyDocumentsProxy
169
- end
170
-
171
- should "be ManyPolymorphicProxy for polymorphic many" do
172
- base = Base.new(:many, :messages, :polymorphic => true)
173
- base.proxy_class.should == ManyPolymorphicProxy
174
- end
175
-
176
- should "be ManyEmbeddedProxy for many embedded" do
177
- base = Base.new(:many, :medias)
178
- base.proxy_class.should == ManyEmbeddedProxy
179
- end
180
-
181
- should "be ManyEmbeddedPolymorphicProxy for polymorphic many embedded" do
182
- base = Base.new(:many, :medias, :polymorphic => true)
183
- base.proxy_class.should == ManyEmbeddedPolymorphicProxy
184
- end
185
-
186
115
  should "be BelongsToProxy for belongs_to" do
187
- base = Base.new(:belongs_to, :project)
116
+ base = BelongsToAssociation.new(:project)
188
117
  base.proxy_class.should == BelongsToProxy
189
118
  end
190
119
 
191
120
  should "be BelongsToPolymorphicProxy for polymorphic belongs_to" do
192
- base = Base.new(:belongs_to, :target, :polymorphic => true)
121
+ base = BelongsToAssociation.new(:target, :polymorphic => true)
193
122
  base.proxy_class.should == BelongsToPolymorphicProxy
194
123
  end
195
124
 
196
125
  should "be OneProxy for one" do
197
- base = Base.new(:one, :status, :polymorphic => true)
126
+ base = OneAssociation.new(:status, :polymorphic => true)
198
127
  base.proxy_class.should == OneProxy
199
128
  end
200
129
 
201
130
  should "be OneEmbeddedProxy for one embedded" do
202
- base = Base.new(:one, :media)
131
+ base = OneAssociation.new(:media)
203
132
  base.proxy_class.should == OneEmbeddedProxy
204
133
  end
205
-
206
- should "be InArrayProxy for many with :in option" do
207
- base = Base.new(:many, :messages, :in => :message_ids)
208
- base.proxy_class.should == InArrayProxy
209
- end
210
134
  end
211
135
 
212
136
  end