durran-mongoid 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ begin
|
|
12
12
|
gem.email = "durran@gmail.com"
|
13
13
|
gem.homepage = "http://github.com/durran/mongoid"
|
14
14
|
gem.authors = ["Durran Jordan"]
|
15
|
-
gem.add_dependency "
|
15
|
+
gem.add_dependency "activesupport"
|
16
16
|
gem.add_dependency "mongodb-mongo"
|
17
17
|
end
|
18
18
|
|
@@ -46,4 +46,4 @@ Rake::RDocTask.new do |rdoc|
|
|
46
46
|
rdoc.rdoc_files.include("lib/**/*.rb")
|
47
47
|
end
|
48
48
|
|
49
|
-
task :default => ["rcov", "metrics:all"]
|
49
|
+
task :default => ["rcov", "metrics:all"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
@@ -10,16 +10,23 @@ module Mongoid #:nodoc:
|
|
10
10
|
# This then delegated all methods to the array class since this is
|
11
11
|
# essentially a proxy to an array itself.
|
12
12
|
def initialize(association_name, document)
|
13
|
-
klass = association_name.to_s.classify.constantize
|
13
|
+
@klass = association_name.to_s.classify.constantize
|
14
14
|
attributes = document.attributes[association_name]
|
15
15
|
@documents = attributes ? attributes.collect do |attribute|
|
16
|
-
child = klass.new(attribute)
|
16
|
+
child = @klass.new(attribute)
|
17
17
|
child.parent = document
|
18
18
|
child
|
19
19
|
end : []
|
20
20
|
super(@documents)
|
21
21
|
end
|
22
22
|
|
23
|
+
# Builds a new Document and adds it to the association collection. The
|
24
|
+
# document created will be of the same class as the others in the
|
25
|
+
# association, and the attributes will be passed into the constructor.
|
26
|
+
def build(attributes)
|
27
|
+
push(@klass.new(attributes))
|
28
|
+
end
|
29
|
+
|
23
30
|
end
|
24
31
|
end
|
25
32
|
end
|
data/mongoid.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongoid}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
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"]
|
@@ -66,14 +66,14 @@ Gem::Specification.new do |s|
|
|
66
66
|
s.specification_version = 3
|
67
67
|
|
68
68
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
69
|
-
s.add_runtime_dependency(%q<
|
69
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
70
70
|
s.add_runtime_dependency(%q<mongodb-mongo>, [">= 0"])
|
71
71
|
else
|
72
|
-
s.add_dependency(%q<
|
72
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
73
73
|
s.add_dependency(%q<mongodb-mongo>, [">= 0"])
|
74
74
|
end
|
75
75
|
else
|
76
|
-
s.add_dependency(%q<
|
76
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
77
77
|
s.add_dependency(%q<mongodb-mongo>, [">= 0"])
|
78
78
|
end
|
79
79
|
end
|
@@ -3,8 +3,8 @@ require File.join(File.dirname(__FILE__), "/../../../spec_helper.rb")
|
|
3
3
|
describe Mongoid::Associations::HasManyAssociation do
|
4
4
|
|
5
5
|
before do
|
6
|
-
@attributes = { :addresses => [
|
7
|
-
{ :street => "Street 1", :document_class => "Address" },
|
6
|
+
@attributes = { :addresses => [
|
7
|
+
{ :street => "Street 1", :document_class => "Address" },
|
8
8
|
{ :street => "Street 2", :document_class => "Address" } ] }
|
9
9
|
@document = stub(:attributes => @attributes)
|
10
10
|
end
|
@@ -47,6 +47,21 @@ describe Mongoid::Associations::HasManyAssociation do
|
|
47
47
|
|
48
48
|
end
|
49
49
|
|
50
|
+
describe "#build" do
|
51
|
+
|
52
|
+
before do
|
53
|
+
@association = Mongoid::Associations::HasManyAssociation.new(:addresses, @document)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "adds a new document to the array with the suppied parameters" do
|
57
|
+
@association.build({ :street => "Street 1", :document_class => "Address" })
|
58
|
+
@association.length.should == 3
|
59
|
+
@association[2].should be_a_kind_of(Address)
|
60
|
+
@association[2].street.should == "Street 1"
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
50
65
|
describe "#first" do
|
51
66
|
|
52
67
|
context "when there are elements in the array" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: durran-mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Durran Jordan
|
@@ -13,7 +13,7 @@ date: 2009-09-23 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: activesupport
|
17
17
|
type: :runtime
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|