Skip to content
Browse files

Merge branch 'feature-mongoid-fix'

  • Loading branch information...
2 parents d1ec7e1 + 1b645fc commit 376a60135e431de58914658672a641abbbb2426a @pointcom committed
Showing with 16 additions and 20 deletions.
  1. +2 −1 Gemfile
  2. +5 −10 Gemfile.lock
  3. +6 −6 lib/machinist/mongoid.rb
  4. +3 −3 spec/mongoid_spec.rb
View
3 Gemfile
@@ -3,7 +3,8 @@ source :gemcutter
gem 'mongo', '~> 1.1'
gem 'mongo_mapper', :git => 'git://github.com/jnunemaker/mongomapper.git'
-gem 'mongoid', :git => 'git://github.com/mongoid/mongoid.git'
+#gem 'mongoid', :git => 'git://github.com/mongoid/mongoid.git'
+gem 'mongoid', "~> 2.2"
gem 'machinist'
gem 'rspec', "2.4"
gem 'rake'
View
15 Gemfile.lock
@@ -7,15 +7,6 @@ GIT
activesupport (~> 3.0)
plucky (~> 0.3.8)
-GIT
- remote: git://github.com/mongoid/mongoid.git
- revision: 205068644be36a34ebff47f437ae2c00c2d48c5b
- specs:
- mongoid (2.1.0)
- activemodel (~> 3.0)
- mongo (~> 1.3)
- tzinfo (~> 0.3.22)
-
GEM
remote: http://rubygems.org/
specs:
@@ -31,6 +22,10 @@ GEM
machinist (1.0.6)
mongo (1.3.1)
bson (>= 1.3.1)
+ mongoid (2.2.0)
+ activemodel (~> 3.0)
+ mongo (~> 1.3)
+ tzinfo (~> 0.3.22)
plucky (0.3.8)
mongo (~> 1.3)
rack (1.3.2)
@@ -54,7 +49,7 @@ DEPENDENCIES
machinist
mongo (~> 1.1)
mongo_mapper!
- mongoid!
+ mongoid (~> 2.2)
rake
rspec (= 2.4)
sham_rack
View
12 lib/machinist/mongoid.rb
@@ -12,10 +12,10 @@ module Machinist
class Lathe
def assign_attribute(key, value)
assigned_attributes[key.to_sym] = value
- if @object.respond_to?("#{key}=")
+ begin
@object.send("#{key}=", value)
- else
- @object.process(key => value)
+ rescue
+ @object.write_attribute(key, value)
end
end
end
@@ -23,18 +23,18 @@ def assign_attribute(key, value)
class MongoidAdapter
class << self
def has_association?(object, attribute)
- object.class.associations[attribute.to_s]
+ object.associations[attribute.to_s]
end
def class_for_association(object, attribute)
- association = object.class.associations[attribute.to_s]
+ association = object.associations[attribute.to_s]
association && association.klass
end
def assigned_attributes_without_associations(lathe)
attributes = {}
lathe.assigned_attributes.each_pair do |attribute, value|
- association = lathe.object.class.associations[attribute.to_s]
+ association = lathe.object.associations[attribute.to_s]
if association && (association.macro == :referenced_in) && !value.nil?
attributes[association.foreign_key.to_sym] = value.id
else
View
6 spec/mongoid_spec.rb
@@ -29,7 +29,7 @@ class Post
field :body
field :published, :type => Boolean, :default => true
- has_many_related :comments
+ has_many :comments
end
class Comment
@@ -39,8 +39,8 @@ class Comment
field :post_id
field :author_id
- belongs_to_related :post
- belongs_to_related :author, :class_name => "Person"
+ belongs_to :post
+ belongs_to :author, :class_name => "Person"
end
describe Machinist, "Mongoid::Document adapter" do

0 comments on commit 376a601

Please sign in to comment.
Something went wrong with that request. Please try again.