fcoury-mongomapper 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
@@ -24,7 +24,8 @@ require dir + 'finder_options'
24
24
  require dir + 'key'
25
25
  require dir + 'observing'
26
26
  require dir + 'pagination'
27
- require dir + 'rails_compatibility'
27
+ require dir + 'document_rails_compatibility'
28
+ require dir + 'embedded_document_rails_compatibility'
28
29
  require dir + 'save_with_validation'
29
30
  require dir + 'serialization'
30
31
  require dir + 'validations'
@@ -9,7 +9,7 @@ module MongoMapper
9
9
  include Observing
10
10
  include Callbacks
11
11
  include SaveWithValidation
12
- include RailsCompatibility
12
+ include DocumentRailsCompatibility
13
13
  extend ClassMethods
14
14
 
15
15
  key :_id, String
@@ -0,0 +1,13 @@
1
+ module MongoMapper
2
+ module DocumentRailsCompatibility
3
+ def self.included(model)
4
+ model.class_eval do
5
+ alias_method :new_record?, :new?
6
+ end
7
+ end
8
+
9
+ def to_param
10
+ id
11
+ end
12
+ end
13
+ end
@@ -8,10 +8,11 @@ module MongoMapper
8
8
  model.class_eval do
9
9
  extend ClassMethods
10
10
  include InstanceMethods
11
-
11
+
12
12
  extend Associations::ClassMethods
13
13
  include Associations::InstanceMethods
14
14
 
15
+ include EmbeddedDocumentRailsCompatibility
15
16
  include Validatable
16
17
  include Serialization
17
18
  end
@@ -1,8 +1,7 @@
1
1
  module MongoMapper
2
- module RailsCompatibility
2
+ module EmbeddedDocumentRailsCompatibility
3
3
  def self.included(model)
4
4
  model.class_eval do
5
- alias_method :new_record?, :new?
6
5
  extend ClassMethods
7
6
  end
8
7
  class << model
@@ -17,7 +16,7 @@ module MongoMapper
17
16
  end
18
17
 
19
18
  def to_param
20
- id
19
+ raise "Missing to_param method in #{self.class.name}. You should implement it to return the unique identifier of this document within a collection."
21
20
  end
22
21
  end
23
22
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{mongomapper}
5
- s.version = "0.3.3"
5
+ s.version = "0.3.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["John Nunemaker"]
@@ -34,12 +34,13 @@ Gem::Specification.new do |s|
34
34
  "lib/mongomapper/associations/proxy.rb",
35
35
  "lib/mongomapper/callbacks.rb",
36
36
  "lib/mongomapper/document.rb",
37
+ "lib/mongomapper/document_rails_compatibility.rb",
37
38
  "lib/mongomapper/embedded_document.rb",
39
+ "lib/mongomapper/embedded_document_rails_compatibility.rb",
38
40
  "lib/mongomapper/finder_options.rb",
39
41
  "lib/mongomapper/key.rb",
40
42
  "lib/mongomapper/observing.rb",
41
43
  "lib/mongomapper/pagination.rb",
42
- "lib/mongomapper/rails_compatibility.rb",
43
44
  "lib/mongomapper/save_with_validation.rb",
44
45
  "lib/mongomapper/serialization.rb",
45
46
  "lib/mongomapper/serializers/json_serializer.rb",
@@ -1,29 +1,73 @@
1
1
  require 'test_helper'
2
2
 
3
+ class Item
4
+ include MongoMapper::EmbeddedDocument
5
+ key :for_all, String
6
+ end
7
+
8
+ class FirstItem < Item
9
+ key :first_only, String
10
+ end
11
+
12
+ class SecondItem < Item
13
+ key :second_only, String
14
+ end
15
+
16
+ class Order
17
+ include MongoMapper::Document
18
+ many :items, :polymorphic => true, :class_name => "Item"
19
+ key :order_only, String
20
+ end
21
+
3
22
  class TestRailsCompatibility < Test::Unit::TestCase
4
23
  def setup
5
24
  @document = Class.new do
6
25
  include MongoMapper::Document
7
26
  end
8
27
  end
28
+
29
+ context "EmbeddedDocument" do
30
+ should "have to_param that returns id" do
31
+ first_item = FirstItem.new
32
+ second_item = SecondItem.new
9
33
 
10
- should "have to_param that returns id" do
11
- instance = @document.create('_id' => '1234')
12
- instance.to_param.should == '1234'
13
- end
34
+ order = Order.create('_id' => '1234')
35
+ order.items = [
36
+ first_item,
37
+ second_item
38
+ ]
39
+ order.to_param.should == '1234'
14
40
 
15
- should "alias new to new_record?" do
16
- instance = @document.new
17
- instance.new_record?.should == instance.new?
18
- end
41
+ lambda { first_item.to_param }.should raise_error
42
+ lambda { second_item.to_param }.should raise_error
43
+ end
19
44
 
20
- should "alias many to has_many" do
21
- @document.should respond_to(:has_many)
22
- @document.method(:has_many).should == @document.method(:many)
45
+ should "have column names" do
46
+ Order.column_names.sort.should == ['_id', 'created_at', 'order_only', 'updated_at']
47
+ FirstItem.column_names.sort.should == ['first_only', 'for_all']
48
+ SecondItem.column_names.sort.should == ['for_all', 'second_only']
49
+ end
23
50
  end
24
51
 
25
- should "have column names" do
26
- @document.key :fname, String
27
- @document.column_names.sort.should == ['_id', 'created_at', 'fname', 'updated_at']
52
+ context "Document" do
53
+ should "have to_param that returns id" do
54
+ instance = @document.create('_id' => '1234')
55
+ instance.to_param.should == '1234'
56
+ end
57
+
58
+ should "alias new to new_record?" do
59
+ instance = @document.new
60
+ instance.new_record?.should == instance.new?
61
+ end
62
+
63
+ should "alias many to has_many" do
64
+ @document.should respond_to(:has_many)
65
+ @document.method(:has_many).should == @document.method(:many)
66
+ end
67
+
68
+ should "have column names" do
69
+ @document.key :fname, String
70
+ @document.column_names.sort.should == ['_id', 'created_at', 'fname', 'updated_at']
71
+ end
28
72
  end
29
73
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fcoury-mongomapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -91,12 +91,13 @@ files:
91
91
  - lib/mongomapper/associations/proxy.rb
92
92
  - lib/mongomapper/callbacks.rb
93
93
  - lib/mongomapper/document.rb
94
+ - lib/mongomapper/document_rails_compatibility.rb
94
95
  - lib/mongomapper/embedded_document.rb
96
+ - lib/mongomapper/embedded_document_rails_compatibility.rb
95
97
  - lib/mongomapper/finder_options.rb
96
98
  - lib/mongomapper/key.rb
97
99
  - lib/mongomapper/observing.rb
98
100
  - lib/mongomapper/pagination.rb
99
- - lib/mongomapper/rails_compatibility.rb
100
101
  - lib/mongomapper/save_with_validation.rb
101
102
  - lib/mongomapper/serialization.rb
102
103
  - lib/mongomapper/serializers/json_serializer.rb