machinist-mongoid 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Appraisals +7 -0
- data/Gemfile +7 -2
- data/README.md +11 -5
- data/Rakefile +6 -0
- data/lib/machinist/mongoid.rb +25 -14
- data/lib/machinist/mongoid/version.rb +1 -1
- data/machinist-mongoid.gemspec +3 -4
- data/spec/mongoid_spec.rb +30 -24
- data/spec/spec_helper.rb +2 -3
- data/spec/support/mongoid.yml +2 -4
- metadata +10 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7b118d41d219b8e5ac787858076b92fc30ba860
|
4
|
+
data.tar.gz: 54d2f7a098497791a68b7b93fcc6ab53159637d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df504caaf2ad49fdf0a261cdd2ff204271ef5131529787e84a441b5c6f21977237923164b166b1634aef98284c27204036bad73bcbb68a0946e14bbbe7042924
|
7
|
+
data.tar.gz: 9a852bf152ebaa432f2a39d73f1c9c7d9ce20d3a0bcaae8992438649566abacd8e5d0d0d2b0efeb07aa3781db52748a102f8672d5fdd288be8a2e70ba65a0e94
|
data/.gitignore
CHANGED
data/Appraisals
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# Machinist::Mongoid
|
2
2
|
|
3
|
-
This library is intended to support machinist 2.0 factories within Mongoid 3.x
|
4
|
-
|
5
|
-
support mongoid 3.x.
|
3
|
+
This library is intended to support machinist 2.0 factories within Mongoid 3.x
|
4
|
+
and 4.x versions. It's originally inspired by the existing [machinist_mongo][mm] gem.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
@@ -18,9 +17,16 @@ Or install it yourself as:
|
|
18
17
|
|
19
18
|
$ gem install machinist-mongoid
|
20
19
|
|
21
|
-
##
|
20
|
+
## Testing
|
21
|
+
|
22
|
+
# once
|
23
|
+
bundle install
|
24
|
+
appraisal install
|
25
|
+
|
26
|
+
# each test run.
|
27
|
+
appraisal mongoid-3x rake spec
|
28
|
+
appraisal mongoid-4x rake spec
|
22
29
|
|
23
|
-
TODO: Write usage instructions here
|
24
30
|
|
25
31
|
## Contributing
|
26
32
|
|
data/Rakefile
CHANGED
data/lib/machinist/mongoid.rb
CHANGED
@@ -10,12 +10,12 @@ rescue LoadError
|
|
10
10
|
end
|
11
11
|
|
12
12
|
module Machinist
|
13
|
-
|
13
|
+
|
14
14
|
module Mongoid
|
15
|
-
|
15
|
+
|
16
16
|
module Machinable
|
17
17
|
extend ActiveSupport::Concern
|
18
|
-
|
18
|
+
|
19
19
|
module ClassMethods
|
20
20
|
include Machinist::Machinable
|
21
21
|
def blueprint_class
|
@@ -23,23 +23,23 @@ module Machinist
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
class Blueprint < Machinist::Blueprint
|
28
|
-
|
28
|
+
|
29
29
|
def make!(attributes = {})
|
30
30
|
object = make(attributes)
|
31
31
|
object.save!
|
32
32
|
object.reload
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def lathe_class #:nodoc:
|
36
36
|
Machinist::Mongoid::Lathe
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def outside_transaction
|
40
40
|
yield
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def box(object)
|
44
44
|
object.id
|
45
45
|
end
|
@@ -49,7 +49,7 @@ module Machinist
|
|
49
49
|
@klass.find(id)
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
class Lathe < Machinist::Lathe
|
54
54
|
def make_one_value(attribute, args) #:nodoc:
|
55
55
|
if block_given?
|
@@ -59,16 +59,16 @@ module Machinist
|
|
59
59
|
make_association(attribute, args)
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
def make_association(attribute, args) #:nodoc:
|
64
|
-
|
65
|
-
if
|
66
|
-
|
64
|
+
relation = relations_for(@klass)[attribute.to_s]
|
65
|
+
if relation
|
66
|
+
relation.klass.make(*args)
|
67
67
|
else
|
68
68
|
raise_argument_error(attribute)
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
def assign_attribute(key, value)
|
73
73
|
@assigned_attributes[key.to_sym] = value
|
74
74
|
if @object.respond_to?("#{key}=")
|
@@ -77,6 +77,17 @@ module Machinist
|
|
77
77
|
@object[key] = value
|
78
78
|
end
|
79
79
|
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def relations_for(obj)
|
84
|
+
if ::Mongoid::VERSION =~ /^4\./
|
85
|
+
obj.relations
|
86
|
+
else
|
87
|
+
obj.associations
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
80
91
|
end
|
81
92
|
end
|
82
93
|
end
|
data/machinist-mongoid.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Machinist::Mongoid::VERSION
|
9
9
|
spec.authors = ["Blake Chambers"]
|
10
10
|
spec.email = ["chambb1@gmail.com"]
|
11
|
-
spec.description = %q{Machinist for Mongoid 3
|
12
|
-
spec.summary = %q{Machinist for Mongoid 3
|
11
|
+
spec.description = %q{Machinist for Mongoid 3 and 4}
|
12
|
+
spec.summary = %q{Machinist for Mongoid 3 and 4}
|
13
13
|
spec.homepage = "http://github.com/blakechambers/machinist-mongoid"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
@@ -18,6 +18,5 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.
|
22
|
-
spec.add_development_dependency "rake"
|
21
|
+
spec.add_dependency "machinist", "~> 2.0"
|
23
22
|
end
|
data/spec/mongoid_spec.rb
CHANGED
@@ -5,7 +5,7 @@ MachinistTestHelper.configure!
|
|
5
5
|
|
6
6
|
class Address
|
7
7
|
include Mongoid::Document
|
8
|
-
|
8
|
+
|
9
9
|
field :street
|
10
10
|
field :zip
|
11
11
|
field :country
|
@@ -14,7 +14,7 @@ end
|
|
14
14
|
|
15
15
|
class Person
|
16
16
|
include Mongoid::Document
|
17
|
-
|
17
|
+
|
18
18
|
field :name
|
19
19
|
field :password
|
20
20
|
field :admin, :type => Boolean, :default => false
|
@@ -24,26 +24,26 @@ end
|
|
24
24
|
|
25
25
|
class Post
|
26
26
|
include Mongoid::Document
|
27
|
-
|
27
|
+
|
28
28
|
field :title
|
29
29
|
field :body
|
30
30
|
field :published, :type => Boolean, :default => true
|
31
|
-
|
31
|
+
|
32
32
|
has_many :comments
|
33
33
|
end
|
34
34
|
|
35
35
|
class Comment
|
36
36
|
include Mongoid::Document
|
37
|
-
|
37
|
+
|
38
38
|
field :body
|
39
39
|
field :post_id
|
40
40
|
field :author_id
|
41
|
-
|
41
|
+
|
42
42
|
belongs_to :post
|
43
43
|
belongs_to :author, :class_name => "Person"
|
44
44
|
end
|
45
45
|
|
46
|
-
describe Machinist, "Mongoid::Document adapter" do
|
46
|
+
describe Machinist, "Mongoid::Document adapter" do
|
47
47
|
|
48
48
|
before(:each) do
|
49
49
|
Person.clear_blueprints!
|
@@ -57,19 +57,19 @@ describe Machinist, "Mongoid::Document adapter" do
|
|
57
57
|
person = Person.make!
|
58
58
|
person.should_not be_new_record
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
it "should create an object through embedded_in association" do
|
62
62
|
Post.blueprint { }
|
63
63
|
Comment.blueprint { post }
|
64
64
|
Comment.make.post.should be_instance_of(Post)
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
it "should create an object through embedded_in association with a class_name attribute" do
|
68
68
|
Person.blueprint { }
|
69
69
|
Comment.blueprint { author }
|
70
70
|
Comment.make.author.should be_instance_of(Person)
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
it "should create an object through embedded_in association using a named blueprint" do
|
74
74
|
Post.blueprint { }
|
75
75
|
Post.blueprint(:dummy) do
|
@@ -79,30 +79,33 @@ describe Machinist, "Mongoid::Document adapter" do
|
|
79
79
|
Comment.make.post.title.should == 'Dummy Post'
|
80
80
|
end
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
describe "plan method" do
|
84
|
-
context "attribute assignment" do
|
84
|
+
context "attribute assignment" do
|
85
85
|
it "should allow assigning a value to an attribute" do
|
86
86
|
Post.blueprint { title {"1234"} }
|
87
87
|
post = Post.make!
|
88
88
|
post.title.should == "1234"
|
89
89
|
end
|
90
90
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
91
|
+
# see: https://github.com/mongoid/mongoid/issues/3035#issuecomment-17858040
|
92
|
+
unless ::Mongoid::VERSION =~ /^4\./
|
93
|
+
it "should allow arbitrary attributes on the base model in its blueprint" do
|
94
|
+
Post.blueprint { foo {"bar"} }
|
95
|
+
post = Post.make!
|
96
|
+
post.foo.should == "bar"
|
97
|
+
end
|
95
98
|
end
|
96
99
|
end
|
97
100
|
end
|
98
|
-
|
101
|
+
|
99
102
|
describe "make_unsaved method" do
|
100
103
|
it "should not save the constructed object" do
|
101
104
|
Person.blueprint { }
|
102
105
|
person = Person.make
|
103
106
|
person.should be_new_record
|
104
107
|
end
|
105
|
-
|
108
|
+
|
106
109
|
it "should not save associated objects" do
|
107
110
|
Post.blueprint { }
|
108
111
|
Comment.blueprint { post }
|
@@ -110,7 +113,7 @@ describe Machinist, "Mongoid::Document adapter" do
|
|
110
113
|
comment.post.should be_new_record
|
111
114
|
end
|
112
115
|
end
|
113
|
-
|
116
|
+
|
114
117
|
describe "make method with embedded documents" do
|
115
118
|
it "should construct object" do
|
116
119
|
Address.blueprint { }
|
@@ -126,11 +129,14 @@ describe Machinist, "Mongoid::Document adapter" do
|
|
126
129
|
Person.make.address.should be_instance_of(Address)
|
127
130
|
end
|
128
131
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
132
|
+
# see: https://github.com/mongoid/mongoid/issues/3035#issuecomment-17858040
|
133
|
+
unless ::Mongoid::VERSION =~ /^4\./
|
134
|
+
it "should allow arbitrary attributes on the base model in its blueprint" do
|
135
|
+
Address.blueprint { foo {"bar"} }
|
136
|
+
addr = Address.make
|
137
|
+
addr.foo.should == "bar"
|
138
|
+
end
|
133
139
|
end
|
134
140
|
end
|
135
|
-
|
141
|
+
|
136
142
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
|
2
2
|
require "rubygems"
|
3
|
-
require "rspec"
|
4
|
-
#require "sham"
|
5
|
-
|
6
3
|
require 'bundler/setup'
|
7
4
|
|
5
|
+
require "rspec"
|
6
|
+
|
8
7
|
module MachinistTestHelper
|
9
8
|
def self.configure!
|
10
9
|
::Mongoid.load!(File.join([File.dirname(__FILE__), "support/mongoid.yml"]), :test)
|
data/spec/support/mongoid.yml
CHANGED
metadata
CHANGED
@@ -1,44 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: machinist-mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Chambers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: machinist
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
type: :
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
27
|
-
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
description: Machinist for Mongoid 3.x
|
26
|
+
version: '2.0'
|
27
|
+
description: Machinist for Mongoid 3 and 4
|
42
28
|
email:
|
43
29
|
- chambb1@gmail.com
|
44
30
|
executables: []
|
@@ -47,6 +33,7 @@ extra_rdoc_files: []
|
|
47
33
|
files:
|
48
34
|
- .gitignore
|
49
35
|
- .rspec
|
36
|
+
- Appraisals
|
50
37
|
- Gemfile
|
51
38
|
- LICENSE.txt
|
52
39
|
- README.md
|
@@ -77,10 +64,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
64
|
version: '0'
|
78
65
|
requirements: []
|
79
66
|
rubyforge_project:
|
80
|
-
rubygems_version: 2.
|
67
|
+
rubygems_version: 2.4.5
|
81
68
|
signing_key:
|
82
69
|
specification_version: 4
|
83
|
-
summary: Machinist for Mongoid 3
|
70
|
+
summary: Machinist for Mongoid 3 and 4
|
84
71
|
test_files:
|
85
72
|
- spec/mongoid_spec.rb
|
86
73
|
- spec/spec_helper.rb
|