machinist_mongo 1.0.1 → 1.0.2
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/.gitignore +1 -0
- data/Rakefile +0 -1
- data/VERSION +1 -1
- data/lib/machinist/mongo_mapper.rb +15 -5
- data/machinist_mongo.gemspec +1 -4
- data/spec/mongo_mapper_spec.rb +18 -7
- data/spec/spec_helper.rb +11 -13
- metadata +1 -11
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -12,7 +12,6 @@ begin
|
|
12
12
|
gem.authors = ["Nicolas Mérouze", "Cyril Mougel"]
|
13
13
|
|
14
14
|
gem.add_dependency('machinist', '~> 1.0.4')
|
15
|
-
gem.add_dependency('mongo_mapper', '~> 0.6.1')
|
16
15
|
end
|
17
16
|
rescue LoadError
|
18
17
|
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.2
|
@@ -1,5 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "machinist"
|
2
|
+
require "machinist/blueprints"
|
3
|
+
|
4
|
+
begin
|
5
|
+
require "mongo_mapper"
|
6
|
+
rescue LoadError
|
7
|
+
puts "MongoMapper is not installed (gem install mongo_mapper)"
|
8
|
+
exit
|
9
|
+
end
|
3
10
|
|
4
11
|
module Machinist
|
5
12
|
|
@@ -17,7 +24,7 @@ module Machinist
|
|
17
24
|
attributes = {}
|
18
25
|
lathe.assigned_attributes.each_pair do |attribute, value|
|
19
26
|
association = lathe.object.class.associations[attribute]
|
20
|
-
if association && association.belongs_to?
|
27
|
+
if association && association.belongs_to? && !value.nil?
|
21
28
|
attributes[association.foreign_key.to_sym] = value.id
|
22
29
|
else
|
23
30
|
attributes[attribute] = value
|
@@ -31,7 +38,10 @@ module Machinist
|
|
31
38
|
module Document
|
32
39
|
def make(*args, &block)
|
33
40
|
lathe = Lathe.run(Machinist::MongoMapperAdapter, self.new, *args)
|
34
|
-
|
41
|
+
unless Machinist.nerfed?
|
42
|
+
lathe.object.save!
|
43
|
+
lathe.object.reload
|
44
|
+
end
|
35
45
|
lathe.object(&block)
|
36
46
|
end
|
37
47
|
|
@@ -59,4 +69,4 @@ end
|
|
59
69
|
MongoMapper::Document.append_extensions(Machinist::Blueprints::ClassMethods)
|
60
70
|
MongoMapper::Document.append_extensions(Machinist::MongoMapperExtensions::Document)
|
61
71
|
MongoMapper::EmbeddedDocument::ClassMethods.send(:include, Machinist::Blueprints::ClassMethods)
|
62
|
-
MongoMapper::EmbeddedDocument::ClassMethods.send(:include, Machinist::MongoMapperExtensions::EmbeddedDocument)
|
72
|
+
MongoMapper::EmbeddedDocument::ClassMethods.send(:include, Machinist::MongoMapperExtensions::EmbeddedDocument)
|
data/machinist_mongo.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{machinist_mongo}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nicolas M\303\251rouze", "Cyril Mougel"]
|
@@ -42,14 +42,11 @@ Gem::Specification.new do |s|
|
|
42
42
|
|
43
43
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
44
44
|
s.add_runtime_dependency(%q<machinist>, ["~> 1.0.4"])
|
45
|
-
s.add_runtime_dependency(%q<mongo_mapper>, ["~> 0.6.1"])
|
46
45
|
else
|
47
46
|
s.add_dependency(%q<machinist>, ["~> 1.0.4"])
|
48
|
-
s.add_dependency(%q<mongo_mapper>, ["~> 0.6.1"])
|
49
47
|
end
|
50
48
|
else
|
51
49
|
s.add_dependency(%q<machinist>, ["~> 1.0.4"])
|
52
|
-
s.add_dependency(%q<mongo_mapper>, ["~> 0.6.1"])
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
data/spec/mongo_mapper_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
require File.dirname(__FILE__) +
|
2
|
-
require
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
require "machinist/mongo_mapper"
|
3
|
+
|
4
|
+
Spec::MongoMapper.configure!
|
3
5
|
|
4
6
|
class Address
|
5
7
|
include MongoMapper::EmbeddedDocument
|
@@ -52,7 +54,7 @@ describe Machinist, "MongoMapper::Document adapter" do
|
|
52
54
|
it "should save the constructed object" do
|
53
55
|
Person.blueprint { }
|
54
56
|
person = Person.make
|
55
|
-
person.should_not
|
57
|
+
person.should_not be_new
|
56
58
|
end
|
57
59
|
|
58
60
|
it "should create an object through belongs_to association" do
|
@@ -66,6 +68,15 @@ describe Machinist, "MongoMapper::Document adapter" do
|
|
66
68
|
Comment.blueprint { author }
|
67
69
|
Comment.make.author.class.should == Person
|
68
70
|
end
|
71
|
+
|
72
|
+
it "should create an object through belongs_to association using a named blueprint" do
|
73
|
+
Post.blueprint { }
|
74
|
+
Post.blueprint(:dummy) do
|
75
|
+
title { 'Dummy Post' }
|
76
|
+
end
|
77
|
+
Comment.blueprint { post(:dummy) }
|
78
|
+
Comment.make.post.title.should == 'Dummy Post'
|
79
|
+
end
|
69
80
|
end
|
70
81
|
|
71
82
|
describe "plan method" do
|
@@ -97,7 +108,7 @@ describe Machinist, "MongoMapper::Document adapter" do
|
|
97
108
|
it "should not save the constructed object" do
|
98
109
|
Person.blueprint { }
|
99
110
|
person = Person.make_unsaved
|
100
|
-
person.should
|
111
|
+
person.should be_new
|
101
112
|
end
|
102
113
|
|
103
114
|
it "should not save associated objects" do
|
@@ -105,7 +116,7 @@ describe Machinist, "MongoMapper::Document adapter" do
|
|
105
116
|
# Post.blueprint { }
|
106
117
|
# Comment.blueprint { post }
|
107
118
|
# comment = Comment.make_unsaved
|
108
|
-
# comment.post.should
|
119
|
+
# comment.post.should be_new
|
109
120
|
end
|
110
121
|
|
111
122
|
it "should save objects made within a passed-in block" do
|
@@ -113,8 +124,8 @@ describe Machinist, "MongoMapper::Document adapter" do
|
|
113
124
|
Comment.blueprint { }
|
114
125
|
comment = nil
|
115
126
|
post = Post.make_unsaved { comment = Comment.make }
|
116
|
-
post.should
|
117
|
-
comment.should_not
|
127
|
+
post.should be_new
|
128
|
+
comment.should_not be_new
|
118
129
|
end
|
119
130
|
end
|
120
131
|
|
data/spec/spec_helper.rb
CHANGED
@@ -3,17 +3,15 @@ require "rubygems"
|
|
3
3
|
require "spec"
|
4
4
|
require "sham"
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
6
|
+
module Spec
|
7
|
+
module MongoMapper
|
8
|
+
def self.configure!
|
9
|
+
::MongoMapper.database = "machinist_mongomapper"
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
MongoMapper.database
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
11
|
+
Spec::Runner.configure do |config|
|
12
|
+
config.before(:each) { Sham.reset }
|
13
|
+
config.after(:all) { ::MongoMapper.database.collections.each { |c| c.remove } }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: machinist_mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Nicolas M\xC3\xA9rouze"
|
@@ -23,16 +23,6 @@ dependencies:
|
|
23
23
|
- !ruby/object:Gem::Version
|
24
24
|
version: 1.0.4
|
25
25
|
version:
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: mongo_mapper
|
28
|
-
type: :runtime
|
29
|
-
version_requirement:
|
30
|
-
version_requirements: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - ~>
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: 0.6.1
|
35
|
-
version:
|
36
26
|
description:
|
37
27
|
email: nicolas.merouze@gmail.com
|
38
28
|
executables: []
|