mongoid 0.7.10 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -15,8 +15,8 @@ begin
15
15
  gem.add_dependency("durran-validatable", "1.8.2")
16
16
  gem.add_dependency("will_paginate", "2.3.11")
17
17
  gem.add_dependency("activesupport", "2.3.4")
18
- gem.add_dependency("mongo", "0.16")
19
- gem.add_dependency("mongo_ext", "0.16")
18
+ gem.add_dependency("mongo", "0.17")
19
+ gem.add_dependency("mongo_ext", "0.17")
20
20
  end
21
21
  Jeweler::GemcutterTasks.new
22
22
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.10
1
+ 0.8.1
@@ -36,12 +36,12 @@ require "active_support/time_with_zone"
36
36
  require "will_paginate/collection"
37
37
  require "mongo"
38
38
  require "mongoid/associations"
39
+ require "mongoid/associations/options"
39
40
  require "mongoid/attributes"
40
41
  require "mongoid/commands"
41
42
  require "mongoid/criteria"
42
43
  require "mongoid/extensions"
43
44
  require "mongoid/field"
44
- require "mongoid/options"
45
45
  require "mongoid/timestamps"
46
46
  require "mongoid/versioning"
47
47
  require "mongoid/document"
@@ -43,7 +43,7 @@ module Mongoid # :nodoc:
43
43
  # end
44
44
  def belongs_to(name, options = {})
45
45
  @embedded = true
46
- add_association(Associations::BelongsTo, Options.new(options.merge(:association_name => name)))
46
+ add_association(Associations::BelongsTo, Associations::Options.new(options.merge(:name => name)))
47
47
  end
48
48
 
49
49
  # Adds the association from a parent document to its children. The name
@@ -64,7 +64,7 @@ module Mongoid # :nodoc:
64
64
  # belongs_to :person
65
65
  # end
66
66
  def has_many(name, options = {})
67
- add_association(Associations::HasMany, Options.new(options.merge(:association_name => name)))
67
+ add_association(Associations::HasMany, Associations::Options.new(options.merge(:name => name)))
68
68
  end
69
69
 
70
70
  # Adds the association from a parent document to its child. The name
@@ -85,15 +85,15 @@ module Mongoid # :nodoc:
85
85
  # belongs_to :person
86
86
  # end
87
87
  def has_one(name, options = {})
88
- add_association(Associations::HasOne, Options.new(options.merge(:association_name => name)))
88
+ add_association(Associations::HasOne, Associations::Options.new(options.merge(:name => name)))
89
89
  end
90
90
 
91
91
  private
92
92
  # Adds the association to the associations hash with the type as the key,
93
93
  # then adds the accessors for the association.
94
94
  def add_association(type, options)
95
- associations[options.association_name] = type
96
- name = options.association_name
95
+ name = options.name
96
+ associations[name] = type
97
97
  define_method(name) do
98
98
  return instance_variable_get("@#{name}") if instance_variable_defined?("@#{name}")
99
99
  proxy = Associations::Accessor.get(type, self, options)
@@ -61,7 +61,7 @@ module Mongoid #:nodoc:
61
61
  # essentially a proxy to an array itself.
62
62
  def initialize(document, options)
63
63
  @parent = document
64
- @association_name = options.association_name
64
+ @association_name = options.name
65
65
  @klass = options.klass
66
66
  attributes = document.attributes[@association_name]
67
67
  @documents = attributes ? attributes.collect do |attribute|
@@ -77,13 +77,13 @@ module Mongoid #:nodoc:
77
77
  # is initialized by setting the has_many to the supplied +Enumerable+
78
78
  # and setting up the parentization.
79
79
  def update(children, parent, options)
80
- parent.attributes.delete(options.association_name)
80
+ parent.attributes.delete(options.name)
81
81
  klass = options.klass
82
82
  children.each do |child|
83
83
  unless child.respond_to?(:parentize)
84
84
  child = klass.new(child)
85
85
  end
86
- child.parentize(parent, options.association_name)
86
+ child.parentize(parent, options.name)
87
87
  child.notify
88
88
  end
89
89
  new(parent, options)
@@ -15,9 +15,9 @@ module Mongoid #:nodoc:
15
15
  # to the internal document itself.
16
16
  def initialize(document, options)
17
17
  @klass = options.klass
18
- attributes = document.attributes[options.association_name]
18
+ attributes = document.attributes[options.name]
19
19
  @document = klass.instantiate(attributes || {})
20
- @document.parentize(document, options.association_name)
20
+ @document.parentize(document, options.name)
21
21
  decorate!
22
22
  end
23
23
 
@@ -29,7 +29,7 @@ module Mongoid #:nodoc:
29
29
  klass = options.klass
30
30
  child = klass.new(child)
31
31
  end
32
- child.parentize(parent, options.association_name)
32
+ child.parentize(parent, options.name)
33
33
  child.notify
34
34
  child
35
35
  end
@@ -0,0 +1,31 @@
1
+ module Mongoid #:nodoc:
2
+ module Associations #:nodoc:
3
+ class Options #:nodoc:
4
+
5
+ # Create the new +Options+ object, which provides convenience methods for
6
+ # accessing values out of an options +Hash+.
7
+ def initialize(attributes = {})
8
+ @attributes = attributes
9
+ end
10
+
11
+ # Returns the association name of the options.
12
+ def name
13
+ @attributes[:name]
14
+ end
15
+
16
+ # Return a +Class+ for the options. If a class_name was provided, then the
17
+ # constantized class_name will be returned. If not, a constant based on the
18
+ # association name will be returned.
19
+ def klass
20
+ class_name = @attributes[:class_name]
21
+ class_name ? class_name.constantize : name.to_s.classify.constantize
22
+ end
23
+
24
+ # Returns whether or not this association is polymorphic.
25
+ def polymorphic
26
+ @attributes[:polymorphic] == true
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -3,10 +3,10 @@ module Mongoid #:nodoc:
3
3
  module Date #:nodoc:
4
4
  module Conversions #:nodoc:
5
5
  def set(value)
6
- value.to_time.utc unless value.blank?
6
+ value.to_time unless value.blank?
7
7
  end
8
8
  def get(value)
9
- value ? value.to_date : value
9
+ value ? value.getlocal.to_date : value
10
10
  end
11
11
  end
12
12
  end
@@ -6,7 +6,7 @@ module Mongoid #:nodoc:
6
6
  ::Time.parse(value.to_s).utc
7
7
  end
8
8
  def get(value)
9
- ::Time.zone ? ::Time.zone.parse(value.to_s) : value
9
+ ::Time.zone ? ::Time.zone.parse(value.to_s).getlocal : value
10
10
  end
11
11
  end
12
12
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid}
8
- s.version = "0.7.10"
8
+ s.version = "0.8.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Durran Jordan"]
12
- s.date = %q{2009-11-16}
12
+ s.date = %q{2009-11-17}
13
13
  s.email = %q{durran@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.textile"
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  "lib/mongoid/associations/decorator.rb",
29
29
  "lib/mongoid/associations/has_many.rb",
30
30
  "lib/mongoid/associations/has_one.rb",
31
+ "lib/mongoid/associations/options.rb",
31
32
  "lib/mongoid/attributes.rb",
32
33
  "lib/mongoid/commands.rb",
33
34
  "lib/mongoid/commands/create.rb",
@@ -55,7 +56,6 @@ Gem::Specification.new do |s|
55
56
  "lib/mongoid/extensions/symbol/inflections.rb",
56
57
  "lib/mongoid/extensions/time/conversions.rb",
57
58
  "lib/mongoid/field.rb",
58
- "lib/mongoid/options.rb",
59
59
  "lib/mongoid/timestamps.rb",
60
60
  "lib/mongoid/versioning.rb",
61
61
  "mongoid.gemspec",
@@ -68,6 +68,7 @@ Gem::Specification.new do |s|
68
68
  "spec/unit/mongoid/associations/decorator_spec.rb",
69
69
  "spec/unit/mongoid/associations/has_many_spec.rb",
70
70
  "spec/unit/mongoid/associations/has_one_spec.rb",
71
+ "spec/unit/mongoid/associations/options_spec.rb",
71
72
  "spec/unit/mongoid/associations_spec.rb",
72
73
  "spec/unit/mongoid/attributes_spec.rb",
73
74
  "spec/unit/mongoid/commands/create_spec.rb",
@@ -94,7 +95,6 @@ Gem::Specification.new do |s|
94
95
  "spec/unit/mongoid/extensions/symbol/inflections_spec.rb",
95
96
  "spec/unit/mongoid/extensions/time/conversions_spec.rb",
96
97
  "spec/unit/mongoid/field_spec.rb",
97
- "spec/unit/mongoid/options_spec.rb",
98
98
  "spec/unit/mongoid/timestamps_spec.rb",
99
99
  "spec/unit/mongoid/versioning_spec.rb"
100
100
  ]
@@ -111,6 +111,7 @@ Gem::Specification.new do |s|
111
111
  "spec/unit/mongoid/associations/decorator_spec.rb",
112
112
  "spec/unit/mongoid/associations/has_many_spec.rb",
113
113
  "spec/unit/mongoid/associations/has_one_spec.rb",
114
+ "spec/unit/mongoid/associations/options_spec.rb",
114
115
  "spec/unit/mongoid/associations_spec.rb",
115
116
  "spec/unit/mongoid/attributes_spec.rb",
116
117
  "spec/unit/mongoid/commands/create_spec.rb",
@@ -137,7 +138,6 @@ Gem::Specification.new do |s|
137
138
  "spec/unit/mongoid/extensions/symbol/inflections_spec.rb",
138
139
  "spec/unit/mongoid/extensions/time/conversions_spec.rb",
139
140
  "spec/unit/mongoid/field_spec.rb",
140
- "spec/unit/mongoid/options_spec.rb",
141
141
  "spec/unit/mongoid/timestamps_spec.rb",
142
142
  "spec/unit/mongoid/versioning_spec.rb"
143
143
  ]
@@ -150,21 +150,21 @@ Gem::Specification.new do |s|
150
150
  s.add_runtime_dependency(%q<durran-validatable>, ["= 1.8.2"])
151
151
  s.add_runtime_dependency(%q<will_paginate>, ["= 2.3.11"])
152
152
  s.add_runtime_dependency(%q<activesupport>, ["= 2.3.4"])
153
- s.add_runtime_dependency(%q<mongo>, ["= 0.16"])
154
- s.add_runtime_dependency(%q<mongo_ext>, ["= 0.16"])
153
+ s.add_runtime_dependency(%q<mongo>, ["= 0.17"])
154
+ s.add_runtime_dependency(%q<mongo_ext>, ["= 0.17"])
155
155
  else
156
156
  s.add_dependency(%q<durran-validatable>, ["= 1.8.2"])
157
157
  s.add_dependency(%q<will_paginate>, ["= 2.3.11"])
158
158
  s.add_dependency(%q<activesupport>, ["= 2.3.4"])
159
- s.add_dependency(%q<mongo>, ["= 0.16"])
160
- s.add_dependency(%q<mongo_ext>, ["= 0.16"])
159
+ s.add_dependency(%q<mongo>, ["= 0.17"])
160
+ s.add_dependency(%q<mongo_ext>, ["= 0.17"])
161
161
  end
162
162
  else
163
163
  s.add_dependency(%q<durran-validatable>, ["= 1.8.2"])
164
164
  s.add_dependency(%q<will_paginate>, ["= 2.3.11"])
165
165
  s.add_dependency(%q<activesupport>, ["= 2.3.4"])
166
- s.add_dependency(%q<mongo>, ["= 0.16"])
167
- s.add_dependency(%q<mongo_ext>, ["= 0.16"])
166
+ s.add_dependency(%q<mongo>, ["= 0.17"])
167
+ s.add_dependency(%q<mongo_ext>, ["= 0.17"])
168
168
  end
169
169
  end
170
170
 
@@ -123,3 +123,17 @@ class Game < Mongoid::Document
123
123
  field :high_score, :default => 500
124
124
  field :score, :default => 0
125
125
  end
126
+
127
+ if RUBY_VERSION == '1.8.6'
128
+ class Array
129
+ alias :count :size
130
+ end
131
+ end
132
+
133
+ class Object
134
+ def tapp
135
+ tap do
136
+ puts "#{File.basename caller[2]}: #{self.inspect}"
137
+ end
138
+ end
139
+ end
@@ -12,8 +12,12 @@ describe Mongoid::Associations::Accessor do
12
12
  context "when type is has_many" do
13
13
 
14
14
  it "returns a HasMany" do
15
- @options = Mongoid::Options.new(:association_name => :addresses)
16
- association = Mongoid::Associations::Accessor.get(Mongoid::Associations::HasMany, @document, @options)
15
+ @options = Mongoid::Associations::Options.new(:name => :addresses)
16
+ association = Mongoid::Associations::Accessor.get(
17
+ Mongoid::Associations::HasMany,
18
+ @document,
19
+ @options
20
+ )
17
21
  association.should be_a_kind_of(Mongoid::Associations::HasMany)
18
22
  end
19
23
 
@@ -24,8 +28,12 @@ describe Mongoid::Associations::Accessor do
24
28
  context "when document is not nil" do
25
29
 
26
30
  it "returns a HasOne" do
27
- @options = Mongoid::Options.new(:association_name => :name)
28
- association = Mongoid::Associations::Accessor.get(Mongoid::Associations::HasOne, @document, @options)
31
+ @options = Mongoid::Associations::Options.new(:name => :name)
32
+ association = Mongoid::Associations::Accessor.get(
33
+ Mongoid::Associations::HasOne,
34
+ @document,
35
+ @options
36
+ )
29
37
  association.should be_a_kind_of(Name)
30
38
  end
31
39
 
@@ -34,8 +42,12 @@ describe Mongoid::Associations::Accessor do
34
42
  context "when document is nil" do
35
43
 
36
44
  it "returns nil" do
37
- @options = Mongoid::Options.new(:association_name => :name)
38
- association = Mongoid::Associations::Accessor.get(Mongoid::Associations::HasOne, nil, @options)
45
+ @options = Mongoid::Associations::Options.new(:name => :name)
46
+ association = Mongoid::Associations::Accessor.get(
47
+ Mongoid::Associations::HasOne,
48
+ nil,
49
+ @options
50
+ )
39
51
  association.should be_nil
40
52
  end
41
53
 
@@ -46,8 +58,12 @@ describe Mongoid::Associations::Accessor do
46
58
  context "when type is belongs_to" do
47
59
 
48
60
  it "returns a BelongsTo" do
49
- @options = Mongoid::Options.new(:association_name => :person)
50
- association = Mongoid::Associations::Accessor.get(Mongoid::Associations::BelongsTo, stub(:parent => @document), @options)
61
+ @options = Mongoid::Associations::Options.new(:name => :person)
62
+ association = Mongoid::Associations::Accessor.get(
63
+ Mongoid::Associations::BelongsTo,
64
+ stub(:parent => @document),
65
+ @options
66
+ )
51
67
  association.should be_a_kind_of(Person)
52
68
  end
53
69
 
@@ -60,9 +76,14 @@ describe Mongoid::Associations::Accessor do
60
76
  context "when type is has_many" do
61
77
 
62
78
  it "returns a HasMany" do
63
- @options = Mongoid::Options.new(:association_name => :addresses)
79
+ @options = Mongoid::Associations::Options.new(:name => :addresses)
64
80
  Mongoid::Associations::HasMany.expects(:update).with(@document, @object, @options)
65
- Mongoid::Associations::Accessor.set(Mongoid::Associations::HasMany, @document, @object, @options)
81
+ Mongoid::Associations::Accessor.set(
82
+ Mongoid::Associations::HasMany,
83
+ @document,
84
+ @object,
85
+ @options
86
+ )
66
87
  end
67
88
 
68
89
  end
@@ -70,9 +91,14 @@ describe Mongoid::Associations::Accessor do
70
91
  context "when type is has_one" do
71
92
 
72
93
  it "returns a HasOne" do
73
- @options = Mongoid::Options.new(:association_name => :name)
94
+ @options = Mongoid::Associations::Options.new(:name => :name)
74
95
  Mongoid::Associations::HasOne.expects(:update).with(@document, @object, @options)
75
- Mongoid::Associations::Accessor.set(Mongoid::Associations::HasOne, @document, @object, @options)
96
+ Mongoid::Associations::Accessor.set(
97
+ Mongoid::Associations::HasOne,
98
+ @document,
99
+ @object,
100
+ @options
101
+ )
76
102
  end
77
103
 
78
104
  end
@@ -80,9 +106,14 @@ describe Mongoid::Associations::Accessor do
80
106
  context "when type is belongs_to" do
81
107
 
82
108
  it "returns a BelongsTo" do
83
- @options = Mongoid::Options.new(:association_name => :person)
109
+ @options = Mongoid::Associations::Options.new(:name => :person)
84
110
  Mongoid::Associations::BelongsTo.expects(:update).with(@object, @document, @options)
85
- Mongoid::Associations::Accessor.set(Mongoid::Associations::BelongsTo, @document, @object, @options)
111
+ Mongoid::Associations::Accessor.set(
112
+ Mongoid::Associations::BelongsTo,
113
+ @document,
114
+ @object,
115
+ @options
116
+ )
86
117
  end
87
118
 
88
119
  end
@@ -7,7 +7,7 @@ describe Mongoid::Associations::BelongsTo do
7
7
  before do
8
8
  @parent = Name.new(:first_name => "Drexel")
9
9
  @document = stub(:parent => @parent)
10
- @options = Mongoid::Options.new(:association_name => :person)
10
+ @options = Mongoid::Associations::Options.new(:name => :person)
11
11
  @association = Mongoid::Associations::BelongsTo.new(@document, @options)
12
12
  end
13
13
 
@@ -27,7 +27,7 @@ describe Mongoid::Associations::BelongsTo do
27
27
  before do
28
28
  @parent = Name.new(:first_name => "Drexel")
29
29
  @document = stub(:parent => @parent)
30
- @options = Mongoid::Options.new(:association_name => :person)
30
+ @options = Mongoid::Associations::Options.new(:name => :person)
31
31
  @association = Mongoid::Associations::BelongsTo.new(@document, @options)
32
32
  end
33
33
 
@@ -57,7 +57,7 @@ describe Mongoid::Associations::BelongsTo do
57
57
  before do
58
58
  @name = Name.new(:first_name => "Test", :last_name => "User")
59
59
  @person = Person.new(:title => "Mrs")
60
- @options = Mongoid::Options.new(:association_name => :person)
60
+ @options = Mongoid::Associations::Options.new(:name => :person)
61
61
  Mongoid::Associations::BelongsTo.update(@person, @name, @options)
62
62
  end
63
63
 
@@ -14,7 +14,7 @@ describe Mongoid::Associations::HasMany do
14
14
  before do
15
15
  @address = Address.new(:street => "Madison Ave")
16
16
  @person = Person.new(:title => "Sir")
17
- Mongoid::Associations::HasMany.update([@address], @person, Mongoid::Options.new(:association_name => :addresses))
17
+ Mongoid::Associations::HasMany.update([@address], @person, Mongoid::Associations::Options.new(:name => :addresses))
18
18
  end
19
19
 
20
20
  it "parentizes the child document" do
@@ -31,7 +31,7 @@ describe Mongoid::Associations::HasMany do
31
31
  describe "#[]" do
32
32
 
33
33
  before do
34
- @association = Mongoid::Associations::HasMany.new(@document, Mongoid::Options.new(:association_name => :addresses))
34
+ @association = Mongoid::Associations::HasMany.new(@document, Mongoid::Associations::Options.new(:name => :addresses))
35
35
  end
36
36
 
37
37
  context "when the index is present in the association" do
@@ -56,7 +56,7 @@ describe Mongoid::Associations::HasMany do
56
56
  describe "#<<" do
57
57
 
58
58
  before do
59
- @association = Mongoid::Associations::HasMany.new(@document, Mongoid::Options.new(:association_name => :addresses))
59
+ @association = Mongoid::Associations::HasMany.new(@document, Mongoid::Associations::Options.new(:name => :addresses))
60
60
  @address = Address.new
61
61
  end
62
62
 
@@ -77,7 +77,7 @@ describe Mongoid::Associations::HasMany do
77
77
  describe "#concat" do
78
78
 
79
79
  before do
80
- @association = Mongoid::Associations::HasMany.new(@document, Mongoid::Options.new(:association_name => :addresses))
80
+ @association = Mongoid::Associations::HasMany.new(@document, Mongoid::Associations::Options.new(:name => :addresses))
81
81
  @address = Address.new
82
82
  end
83
83
 
@@ -92,7 +92,7 @@ describe Mongoid::Associations::HasMany do
92
92
  describe "#push" do
93
93
 
94
94
  before do
95
- @association = Mongoid::Associations::HasMany.new(@document, Mongoid::Options.new(:association_name => :addresses))
95
+ @association = Mongoid::Associations::HasMany.new(@document, Mongoid::Associations::Options.new(:name => :addresses))
96
96
  @address = Address.new
97
97
  end
98
98
 
@@ -107,7 +107,7 @@ describe Mongoid::Associations::HasMany do
107
107
  describe "#build" do
108
108
 
109
109
  before do
110
- @association = Mongoid::Associations::HasMany.new(@document, Mongoid::Options.new(:association_name => :addresses))
110
+ @association = Mongoid::Associations::HasMany.new(@document, Mongoid::Associations::Options.new(:name => :addresses))
111
111
  end
112
112
 
113
113
  it "adds a new document to the array with the suppied parameters" do
@@ -128,7 +128,7 @@ describe Mongoid::Associations::HasMany do
128
128
  describe "#find" do
129
129
 
130
130
  before do
131
- @association = Mongoid::Associations::HasMany.new(@document, Mongoid::Options.new(:association_name => :addresses))
131
+ @association = Mongoid::Associations::HasMany.new(@document, Mongoid::Associations::Options.new(:name => :addresses))
132
132
  end
133
133
 
134
134
  context "when finding all" do
@@ -155,7 +155,10 @@ describe Mongoid::Associations::HasMany do
155
155
  context "when there are elements in the array" do
156
156
 
157
157
  before do
158
- @association = Mongoid::Associations::HasMany.new(@document, Mongoid::Options.new(:association_name => :addresses))
158
+ @association = Mongoid::Associations::HasMany.new(
159
+ @document,
160
+ Mongoid::Associations::Options.new(:name => :addresses)
161
+ )
159
162
  end
160
163
 
161
164
  it "returns the first element" do
@@ -168,7 +171,10 @@ describe Mongoid::Associations::HasMany do
168
171
  context "when the array is empty" do
169
172
 
170
173
  before do
171
- @association = Mongoid::Associations::HasMany.new(Person.new, Mongoid::Options.new(:association_name => :addresses))
174
+ @association = Mongoid::Associations::HasMany.new(
175
+ Person.new,
176
+ Mongoid::Associations::Options.new(:name => :addresses)
177
+ )
172
178
  end
173
179
 
174
180
  it "returns nil" do
@@ -184,7 +190,10 @@ describe Mongoid::Associations::HasMany do
184
190
  context "#length" do
185
191
 
186
192
  it "returns the length of the delegated array" do
187
- @association = Mongoid::Associations::HasMany.new(@document, Mongoid::Options.new(:association_name => :addresses))
193
+ @association = Mongoid::Associations::HasMany.new(
194
+ @document,
195
+ Mongoid::Associations::Options.new(:name => :addresses)
196
+ )
188
197
  @association.length.should == 2
189
198
  end
190
199
 
@@ -195,7 +204,10 @@ describe Mongoid::Associations::HasMany do
195
204
  describe "#push" do
196
205
 
197
206
  before do
198
- @association = Mongoid::Associations::HasMany.new(@document, Mongoid::Options.new(:association_name => :addresses))
207
+ @association = Mongoid::Associations::HasMany.new(
208
+ @document,
209
+ Mongoid::Associations::Options.new(:name => :addresses)
210
+ )
199
211
  end
200
212
 
201
213
  it "appends the document to the end of the array" do
@@ -12,7 +12,11 @@ describe Mongoid::Associations::HasOne do
12
12
  before do
13
13
  @name = Name.new(:first_name => "Donald")
14
14
  @person = Person.new(:title => "Sir")
15
- Mongoid::Associations::HasOne.update(@name, @person, Mongoid::Options.new(:association_name => :name))
15
+ Mongoid::Associations::HasOne.update(
16
+ @name,
17
+ @person,
18
+ Mongoid::Associations::Options.new(:name => :name)
19
+ )
16
20
  end
17
21
 
18
22
  it "parentizes the child document" do
@@ -29,7 +33,10 @@ describe Mongoid::Associations::HasOne do
29
33
  describe "#decorate!" do
30
34
 
31
35
  before do
32
- @association = Mongoid::Associations::HasOne.new(@document, Mongoid::Options.new(:association_name => :mixed_drink))
36
+ @association = Mongoid::Associations::HasOne.new(
37
+ @document,
38
+ Mongoid::Associations::Options.new(:name => :mixed_drink)
39
+ )
33
40
  end
34
41
 
35
42
  context "when getting values" do
@@ -1,16 +1,16 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "/../../spec_helper.rb"))
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "/../../../spec_helper.rb"))
2
2
 
3
- describe Mongoid::Options do
3
+ describe Mongoid::Associations::Options do
4
4
 
5
- describe "#association_name" do
5
+ describe "#name" do
6
6
 
7
7
  before do
8
- @attributes = { :association_name => :addresses }
9
- @options = Mongoid::Options.new(@attributes)
8
+ @attributes = { :name => :addresses }
9
+ @options = Mongoid::Associations::Options.new(@attributes)
10
10
  end
11
11
 
12
12
  it "returns the association name" do
13
- @options.association_name.should == :addresses
13
+ @options.name.should == :addresses
14
14
  end
15
15
 
16
16
  end
@@ -21,7 +21,7 @@ describe Mongoid::Options do
21
21
 
22
22
  before do
23
23
  @attributes = { :class_name => "Person" }
24
- @options = Mongoid::Options.new(@attributes)
24
+ @options = Mongoid::Associations::Options.new(@attributes)
25
25
  end
26
26
 
27
27
  it "constantizes the class name" do
@@ -35,8 +35,8 @@ describe Mongoid::Options do
35
35
  context "when association name is singular" do
36
36
 
37
37
  before do
38
- @attributes = { :association_name => :person }
39
- @options = Mongoid::Options.new(@attributes)
38
+ @attributes = { :name => :person }
39
+ @options = Mongoid::Associations::Options.new(@attributes)
40
40
  end
41
41
 
42
42
  it "classifies and constantizes the association name" do
@@ -48,8 +48,8 @@ describe Mongoid::Options do
48
48
  context "when association name is plural" do
49
49
 
50
50
  before do
51
- @attributes = { :association_name => :people }
52
- @options = Mongoid::Options.new(@attributes)
51
+ @attributes = { :name => :people }
52
+ @options = Mongoid::Associations::Options.new(@attributes)
53
53
  end
54
54
 
55
55
  it "classifies and constantizes the association name" do
@@ -69,7 +69,7 @@ describe Mongoid::Options do
69
69
 
70
70
  before do
71
71
  @attributes = { :polymorphic => true }
72
- @options = Mongoid::Options.new(@attributes)
72
+ @options = Mongoid::Associations::Options.new(@attributes)
73
73
 
74
74
  end
75
75
 
@@ -82,7 +82,7 @@ describe Mongoid::Options do
82
82
  context "when attribute not provided" do
83
83
 
84
84
  before do
85
- @options = Mongoid::Options.new
85
+ @options = Mongoid::Associations::Options.new
86
86
  end
87
87
 
88
88
  it "returns false" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.10
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-16 00:00:00 -05:00
12
+ date: 2009-11-17 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - "="
52
52
  - !ruby/object:Gem::Version
53
- version: "0.16"
53
+ version: "0.17"
54
54
  version:
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: mongo_ext
@@ -60,7 +60,7 @@ dependencies:
60
60
  requirements:
61
61
  - - "="
62
62
  - !ruby/object:Gem::Version
63
- version: "0.16"
63
+ version: "0.17"
64
64
  version:
65
65
  description:
66
66
  email: durran@gmail.com
@@ -84,6 +84,7 @@ files:
84
84
  - lib/mongoid/associations/decorator.rb
85
85
  - lib/mongoid/associations/has_many.rb
86
86
  - lib/mongoid/associations/has_one.rb
87
+ - lib/mongoid/associations/options.rb
87
88
  - lib/mongoid/attributes.rb
88
89
  - lib/mongoid/commands.rb
89
90
  - lib/mongoid/commands/create.rb
@@ -111,7 +112,6 @@ files:
111
112
  - lib/mongoid/extensions/symbol/inflections.rb
112
113
  - lib/mongoid/extensions/time/conversions.rb
113
114
  - lib/mongoid/field.rb
114
- - lib/mongoid/options.rb
115
115
  - lib/mongoid/timestamps.rb
116
116
  - lib/mongoid/versioning.rb
117
117
  - mongoid.gemspec
@@ -124,6 +124,7 @@ files:
124
124
  - spec/unit/mongoid/associations/decorator_spec.rb
125
125
  - spec/unit/mongoid/associations/has_many_spec.rb
126
126
  - spec/unit/mongoid/associations/has_one_spec.rb
127
+ - spec/unit/mongoid/associations/options_spec.rb
127
128
  - spec/unit/mongoid/associations_spec.rb
128
129
  - spec/unit/mongoid/attributes_spec.rb
129
130
  - spec/unit/mongoid/commands/create_spec.rb
@@ -150,7 +151,6 @@ files:
150
151
  - spec/unit/mongoid/extensions/symbol/inflections_spec.rb
151
152
  - spec/unit/mongoid/extensions/time/conversions_spec.rb
152
153
  - spec/unit/mongoid/field_spec.rb
153
- - spec/unit/mongoid/options_spec.rb
154
154
  - spec/unit/mongoid/timestamps_spec.rb
155
155
  - spec/unit/mongoid/versioning_spec.rb
156
156
  has_rdoc: true
@@ -189,6 +189,7 @@ test_files:
189
189
  - spec/unit/mongoid/associations/decorator_spec.rb
190
190
  - spec/unit/mongoid/associations/has_many_spec.rb
191
191
  - spec/unit/mongoid/associations/has_one_spec.rb
192
+ - spec/unit/mongoid/associations/options_spec.rb
192
193
  - spec/unit/mongoid/associations_spec.rb
193
194
  - spec/unit/mongoid/attributes_spec.rb
194
195
  - spec/unit/mongoid/commands/create_spec.rb
@@ -215,6 +216,5 @@ test_files:
215
216
  - spec/unit/mongoid/extensions/symbol/inflections_spec.rb
216
217
  - spec/unit/mongoid/extensions/time/conversions_spec.rb
217
218
  - spec/unit/mongoid/field_spec.rb
218
- - spec/unit/mongoid/options_spec.rb
219
219
  - spec/unit/mongoid/timestamps_spec.rb
220
220
  - spec/unit/mongoid/versioning_spec.rb
@@ -1,30 +0,0 @@
1
- module Mongoid #:nodoc:
2
- class Options #:nodoc:
3
-
4
- # Create the new +Options+ object, which provides convenience methods for
5
- # accessing values out of an options +Hash+.
6
- def initialize(attributes = {})
7
- @attributes = attributes
8
- end
9
-
10
- # Returns the association name of the options.
11
- def association_name
12
- @attributes[:association_name]
13
- end
14
-
15
- # Return a +Class+ for the options. If a class_name was provided, then the
16
- # constantized class_name will be returned. If not, a constant based on the
17
- # association name will be returned.
18
- def klass
19
- class_name = @attributes[:class_name]
20
- association_name = @attributes[:association_name]
21
- class_name ? class_name.constantize : association_name.to_s.classify.constantize
22
- end
23
-
24
- # Returns whether or not this association is polymorphic.
25
- def polymorphic
26
- @attributes[:polymorphic] == true
27
- end
28
-
29
- end
30
- end