yeastymobs-machinist_mongomapper 0.9.1 → 0.9.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/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
+ require 'spec/rake/spectask'
3
4
 
4
5
  begin
5
6
  require 'jeweler'
@@ -15,4 +16,13 @@ begin
15
16
  end
16
17
  rescue LoadError
17
18
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
21
+ desc 'Default: run specs.'
22
+ task :default => :spec
23
+
24
+ desc 'Run all the specs for the machinist plugin.'
25
+ Spec::Rake::SpecTask.new do |t|
26
+ t.spec_files = FileList['spec/**/*_spec.rb']
27
+ t.rcov = false
18
28
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.1
1
+ 0.9.2
@@ -4,6 +4,27 @@ require 'machinist/blueprints'
4
4
  module Machinist
5
5
 
6
6
  class MongoMapperAdapter
7
+ def self.has_association?(object, attribute)
8
+ object.class.associations[attribute]
9
+ end
10
+
11
+ def self.class_for_association(object, attribute)
12
+ association = object.class.associations[attribute]
13
+ association && association.klass
14
+ end
15
+
16
+ def self.assigned_attributes_without_associations(lathe)
17
+ attributes = {}
18
+ lathe.assigned_attributes.each_pair do |attribute, value|
19
+ association = lathe.object.class.associations[attribute]
20
+ if association && association.belongs_to?
21
+ attributes[association.belongs_to_key_name.to_sym] = value.id
22
+ else
23
+ attributes[attribute] = value
24
+ end
25
+ end
26
+ attributes
27
+ end
7
28
  end
8
29
 
9
30
  module MongoMapperExtensions
@@ -20,11 +41,20 @@ module Machinist
20
41
  end
21
42
 
22
43
  def plan(*args)
23
- Lathe.run(Machinist::MongoMapperAdapter, self.new, *args)
44
+ lathe = Lathe.run(Machinist::MongoMapperAdapter, self.new, *args)
45
+ Machinist::MongoMapperAdapter.assigned_attributes_without_associations(lathe)
46
+ end
47
+ end
48
+
49
+ module MongoMapperAssociationsProxyExtensions
50
+ def nil?
51
+ self.klass.nil?
24
52
  end
25
53
  end
26
54
 
27
55
  end
28
56
 
57
+
58
+ MongoMapper::Associations::Proxy.send(:include, Machinist::MongoMapperAssociationsProxyExtensions)
29
59
  MongoMapper::Document::ClassMethods.send(:include, Machinist::Blueprints::ClassMethods)
30
60
  MongoMapper::Document::ClassMethods.send(:include, Machinist::MongoMapperExtensions)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{machinist_mongomapper}
5
- s.version = "0.9.1"
5
+ s.version = "0.9.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Nicolas M\303\251rouze", "Vincent Hellot", "Mathieu Fosse"]
@@ -20,13 +20,19 @@ Gem::Specification.new do |s|
20
20
  "VERSION",
21
21
  "init.rb",
22
22
  "lib/machinist/mongomapper.rb",
23
- "machinist_mongomapper.gemspec"
23
+ "machinist_mongomapper.gemspec",
24
+ "spec/mongomapper_spec.rb",
25
+ "spec/spec_helper.rb"
24
26
  ]
25
27
  s.homepage = %q{http://github.com/yeastymobs/machinist_mongomapper}
26
28
  s.rdoc_options = ["--charset=UTF-8"]
27
29
  s.require_paths = ["lib"]
28
30
  s.rubygems_version = %q{1.3.5}
29
31
  s.summary = %q{Machinist adapter for MongoMapper}
32
+ s.test_files = [
33
+ "spec/mongomapper_spec.rb",
34
+ "spec/spec_helper.rb"
35
+ ]
30
36
 
31
37
  if s.respond_to? :specification_version then
32
38
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -0,0 +1,110 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require 'machinist/mongomapper'
3
+
4
+ class Person
5
+ include MongoMapper::Document
6
+
7
+ key :name, String
8
+ key :type, String
9
+ key :password, String
10
+ key :admin, Boolean, :default => false
11
+ end
12
+
13
+ class Post
14
+ include MongoMapper::Document
15
+
16
+ key :title, String
17
+ key :body, String
18
+ key :published, Boolean, :default => true
19
+
20
+ many :comments
21
+ end
22
+
23
+ class Comment
24
+ include MongoMapper::Document
25
+
26
+ key :body, String
27
+
28
+ belongs_to :post
29
+ belongs_to :author, :class_name => "Person"
30
+ end
31
+
32
+ describe Machinist, "MongoMapper adapter" do
33
+
34
+ before(:each) do
35
+ Person.clear_blueprints!
36
+ Post.clear_blueprints!
37
+ Comment.clear_blueprints!
38
+ end
39
+
40
+ describe "make method" do
41
+ it "should save the constructed object" do
42
+ Person.blueprint { }
43
+ person = Person.make
44
+ person.should_not be_new_record
45
+ end
46
+
47
+ it "should create an object through belongs_to association" do
48
+ Post.blueprint { }
49
+ Comment.blueprint { post }
50
+ Comment.make.post.class.should == Post
51
+ end
52
+
53
+ it "should create an object through belongs_to association with a class_name attribute" do
54
+ Person.blueprint { }
55
+ Comment.blueprint { author }
56
+ Comment.make.author.class.should == Person
57
+ end
58
+ end
59
+
60
+ describe "plan method" do
61
+ it "should not save the constructed object" do
62
+ person_count = Person.count
63
+ Person.blueprint { }
64
+ person = Person.plan
65
+ Person.count.should == person_count
66
+ end
67
+
68
+ it "should return a regular attribute in the hash" do
69
+ Post.blueprint { title "Test" }
70
+ post = Post.plan
71
+ post[:title].should == "Test"
72
+ end
73
+
74
+ it "should create an object through a belongs_to association, and return its id" do
75
+ Post.blueprint { }
76
+ Comment.blueprint { post }
77
+ post_count = Post.count
78
+ comment = Comment.plan
79
+ Post.count.should == post_count + 1
80
+ comment[:post].should be_nil
81
+ comment[:post_id].should_not be_nil
82
+ end
83
+ end
84
+
85
+ describe "make_unsaved method" do
86
+ it "should not save the constructed object" do
87
+ Person.blueprint { }
88
+ person = Person.make_unsaved
89
+ person.should be_new_record
90
+ end
91
+
92
+ it "should not save associated objects" do
93
+ pending
94
+ # Post.blueprint { }
95
+ # Comment.blueprint { post }
96
+ # comment = Comment.make_unsaved
97
+ # comment.post.should be_new_record
98
+ end
99
+
100
+ it "should save objects made within a passed-in block" do
101
+ Post.blueprint { }
102
+ Comment.blueprint { }
103
+ comment = nil
104
+ post = Post.make_unsaved { comment = Comment.make }
105
+ post.should be_new_record
106
+ comment.should_not be_new_record
107
+ end
108
+ end
109
+
110
+ end
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
2
+ require "rubygems"
3
+ require "spec"
4
+ require "sham"
5
+
6
+ gem "mongomapper", "~> 0.3.1"
7
+ require "mongomapper"
8
+
9
+ MongoMapper.database = "machinist_mongomapper"
10
+
11
+ def reset_test_db!
12
+ MongoMapper.connection.drop_database("machinist_mongomapper")
13
+ end
14
+
15
+ Spec::Runner.configure do |config|
16
+ config.before(:each) { Sham.reset }
17
+ config.after(:all) { reset_test_db! }
18
+ 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.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Nicolas M\xC3\xA9rouze"
@@ -52,6 +52,8 @@ files:
52
52
  - init.rb
53
53
  - lib/machinist/mongomapper.rb
54
54
  - machinist_mongomapper.gemspec
55
+ - spec/mongomapper_spec.rb
56
+ - spec/spec_helper.rb
55
57
  has_rdoc: false
56
58
  homepage: http://github.com/yeastymobs/machinist_mongomapper
57
59
  licenses:
@@ -79,5 +81,6 @@ rubygems_version: 1.3.5
79
81
  signing_key:
80
82
  specification_version: 3
81
83
  summary: Machinist adapter for MongoMapper
82
- test_files: []
83
-
84
+ test_files:
85
+ - spec/mongomapper_spec.rb
86
+ - spec/spec_helper.rb