yeastymobs-machinist_mongomapper 0.9.2 → 0.9.3

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.
data/README.md CHANGED
@@ -2,4 +2,4 @@ Machinist adapter for [MongoMapper](http://github.com/jnunemaker/mongomapper).
2
2
 
3
3
  ## TODO
4
4
 
5
- * Add associations support.
5
+ * Spec for EmbeddedDocument.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.2
1
+ 0.9.3
data/init.rb CHANGED
@@ -1 +1,4 @@
1
- require 'machinist/mongomapper' if Rails.env =~ /^test|cucumber$/
1
+ config.after_initialize do
2
+ require 'machinist/mongomapper' if Rails.env =~ /^test|cucumber$/
3
+ end
4
+
@@ -18,7 +18,7 @@ module Machinist
18
18
  lathe.assigned_attributes.each_pair do |attribute, value|
19
19
  association = lathe.object.class.associations[attribute]
20
20
  if association && association.belongs_to?
21
- attributes[association.belongs_to_key_name.to_sym] = value.id
21
+ attributes[association.foreign_key.to_sym] = value.id
22
22
  else
23
23
  attributes[attribute] = value
24
24
  end
@@ -28,21 +28,30 @@ module Machinist
28
28
  end
29
29
 
30
30
  module MongoMapperExtensions
31
- def make(*args, &block)
32
- lathe = Lathe.run(Machinist::MongoMapperAdapter, self.new, *args)
33
- lathe.object.save! unless Machinist.nerfed?
34
- lathe.object(&block)
35
- end
31
+ module Document
32
+ def make(*args, &block)
33
+ lathe = Lathe.run(Machinist::MongoMapperAdapter, self.new, *args)
34
+ lathe.object.save! unless Machinist.nerfed?
35
+ lathe.object(&block)
36
+ end
36
37
 
37
- def make_unsaved(*args)
38
- returning(Machinist.with_save_nerfed { make(*args) }) do |object|
39
- yield object if block_given?
38
+ def make_unsaved(*args)
39
+ returning(Machinist.with_save_nerfed { make(*args) }) do |object|
40
+ yield object if block_given?
41
+ end
40
42
  end
41
- end
42
43
 
43
- def plan(*args)
44
- lathe = Lathe.run(Machinist::MongoMapperAdapter, self.new, *args)
45
- Machinist::MongoMapperAdapter.assigned_attributes_without_associations(lathe)
44
+ def plan(*args)
45
+ lathe = Lathe.run(Machinist::MongoMapperAdapter, self.new, *args)
46
+ Machinist::MongoMapperAdapter.assigned_attributes_without_associations(lathe)
47
+ end
48
+ end
49
+
50
+ module EmbeddedDocument
51
+ def make(*args, &block)
52
+ lathe = Lathe.run(Machinist::MongoMapperAdapter, self.new, *args)
53
+ lathe.object(&block)
54
+ end
46
55
  end
47
56
  end
48
57
 
@@ -57,4 +66,6 @@ end
57
66
 
58
67
  MongoMapper::Associations::Proxy.send(:include, Machinist::MongoMapperAssociationsProxyExtensions)
59
68
  MongoMapper::Document::ClassMethods.send(:include, Machinist::Blueprints::ClassMethods)
60
- MongoMapper::Document::ClassMethods.send(:include, Machinist::MongoMapperExtensions)
69
+ MongoMapper::Document::ClassMethods.send(:include, Machinist::MongoMapperExtensions::Document)
70
+ MongoMapper::EmbeddedDocument::ClassMethods.send(:include, Machinist::Blueprints::ClassMethods)
71
+ MongoMapper::EmbeddedDocument::ClassMethods.send(:include, Machinist::MongoMapperExtensions::EmbeddedDocument)
@@ -1,12 +1,15 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
1
4
  # -*- encoding: utf-8 -*-
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{machinist_mongomapper}
5
- s.version = "0.9.2"
8
+ s.version = "0.9.3"
6
9
 
7
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
11
  s.authors = ["Nicolas M\303\251rouze", "Vincent Hellot", "Mathieu Fosse"]
9
- s.date = %q{2009-07-29}
12
+ s.date = %q{2009-09-24}
10
13
  s.email = %q{dev@yeastymobs.com}
11
14
  s.extra_rdoc_files = [
12
15
  "LICENSE",
@@ -1,6 +1,14 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
  require 'machinist/mongomapper'
3
3
 
4
+ class Address
5
+ include MongoMapper::EmbeddedDocument
6
+
7
+ key :street, String
8
+ key :zip, String
9
+ key :country, String
10
+ end
11
+
4
12
  class Person
5
13
  include MongoMapper::Document
6
14
 
@@ -8,6 +16,7 @@ class Person
8
16
  key :type, String
9
17
  key :password, String
10
18
  key :admin, Boolean, :default => false
19
+ key :address, Address
11
20
  end
12
21
 
13
22
  class Post
@@ -24,12 +33,14 @@ class Comment
24
33
  include MongoMapper::Document
25
34
 
26
35
  key :body, String
36
+ key :post_id, String
37
+ key :author_id, String
27
38
 
28
39
  belongs_to :post
29
40
  belongs_to :author, :class_name => "Person"
30
41
  end
31
42
 
32
- describe Machinist, "MongoMapper adapter" do
43
+ describe Machinist, "MongoMapper::Document adapter" do
33
44
 
34
45
  before(:each) do
35
46
  Person.clear_blueprints!
@@ -107,4 +118,29 @@ describe Machinist, "MongoMapper adapter" do
107
118
  end
108
119
  end
109
120
 
121
+ end
122
+
123
+ describe Machinist, "MongoMapper::EmbeddedDocument adapter" do
124
+
125
+ before(:each) do
126
+ Person.clear_blueprints!
127
+ Address.clear_blueprints!
128
+ end
129
+
130
+ describe "make method" do
131
+ it "should construct object" do
132
+ Address.blueprint { }
133
+ address = Address.make
134
+ address.should be_instance_of(Address)
135
+ end
136
+
137
+ it "should make an embed object" do
138
+ Address.blueprint { }
139
+ Person.blueprint do
140
+ address { Address.make }
141
+ end
142
+ Person.make.address.should be_instance_of(Address)
143
+ end
144
+ end
145
+
110
146
  end
@@ -3,16 +3,17 @@ require "rubygems"
3
3
  require "spec"
4
4
  require "sham"
5
5
 
6
- gem "mongomapper", "~> 0.3.1"
6
+ begin
7
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../../mongomapper/lib"
8
+ rescue
9
+ gem "mongomapper"
10
+ end
11
+
7
12
  require "mongomapper"
8
13
 
9
14
  MongoMapper.database = "machinist_mongomapper"
10
15
 
11
- def reset_test_db!
12
- MongoMapper.connection.drop_database("machinist_mongomapper")
13
- end
14
-
15
16
  Spec::Runner.configure do |config|
16
17
  config.before(:each) { Sham.reset }
17
- config.after(:all) { reset_test_db! }
18
+ config.after(:all) { MongoMapper.database.collections.each { |c| c.clear } }
18
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yeastymobs-machinist_mongomapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Nicolas M\xC3\xA9rouze"
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-07-29 00:00:00 -07:00
14
+ date: 2009-09-24 00:00:00 -07:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency