nmerouze / machinist_mongo Goto Github PK
View Code? Open in Web Editor NEWThis project forked from yeastymobs/machinist_mongomapper
Machinist adapters for MongoDB ORMs.
License: MIT License
This project forked from yeastymobs/machinist_mongomapper
Machinist adapters for MongoDB ORMs.
License: MIT License
I'm getting that error when I run a spec.
I'm on Rails 3 beta 4, with machinist_mongo 2.0.0.pre. Any idea what's going on?
I currently have the following setup:
When running any spec task, the mongo documents will be loaded with the Machinist::ObjectAdapter instead of the Mongoid one. However, running the rails console and requiring 'spec/spec_helper' creates the expected behavior.
I currently patched this (horribly) by changing my blueprints.rb file:
#require 'machinist/object'
require 'machinist/mongoid'
#more requires
class Object
include Machinist::Blueprints
include Machinist::MongoidExtensions::Document
end
#Blueprint definitions
This is clearly far from ideal. What could be causing this behavior?
Thanks!
Convo.blueprint do
title {"title#{sn}"}
privacy {'public'}
user
end
Potentially because the assotiation on Convo is described as embedded like this:
embeds_one :user
I've created blueprint with Product and Item following these models
class Item
include MongoMapper::EmbeddedDocument
belongs_to :product
end
class Product
include MongoMapper::Document
many :items
end
And blueprints.rb
Item.blueprint do
product { Product.make }
quantity (1..10).to_a.shuffle.first.to_i
total 5 * quantity
end
I receive this error when tests running:
undefined method `each' for #Product:0x007f90324dde28
I'm using mongoid and rails 3. I'm getting the error: undefined method `blueprint' when I try to run the test. Here's the trace:
/Users/ScottMessinger/code/congoid/test/blueprints.rb:9: undefined method `blueprint' for Course:Class (NoMethodError)
from /Users/ScottMessinger/code/src/rails/activesupport/lib/active_support/dependencies.rb:209:in `require'
from /Users/ScottMessinger/code/src/rails/activesupport/lib/active_support/dependencies.rb:209:in `require'
from /Users/ScottMessinger/code/src/rails/activesupport/lib/active_support/dependencies.rb:197:in `load_dependency'
from /Users/ScottMessinger/code/src/rails/activesupport/lib/active_support/dependencies.rb:209:in `require'
from ./test/test_helper.rb:3
from ./test/integration/create_course_test.rb:1:in `require'
from ./test/integration/create_course_test.rb:1
from /Users/ScottMessinger/.rvm/gems/ruby-1.8.7-p249%global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `load'
from /Users/ScottMessinger/.rvm/gems/ruby-1.8.7-p249%global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
from /Users/ScottMessinger/.rvm/gems/ruby-1.8.7-p249%global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each'
from /Users/ScottMessinger/.rvm/gems/ruby-1.8.7-p249%global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
I have the gems installed:
machinist (1.0.6)
machinist_mongo (1.1.0)
and declared in my gemfile:
gem 'machinist_mongo'
My blueprints file looks like this:
require 'machinist/mongoid'
require 'sham'
require 'faker'
Sham.title { Faker::Lorem.sentence }
Sham.body { Faker::Lorem.paragraph }
Sham.time_string {Faker::Lorem.words}
Course.blueprint do
title
end
Sequence.blueprint do
course { Course.make }
time_string
end
My test_helper.rb looks like this:
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require File.expand_path(File.dirname(__FILE__) + '/blueprints')
require 'rails/test_help'
require 'shoulda'
require "webrat"
Webrat.configure do |config|
config.mode = :rails
end
class ActiveSupport::TestCase
setup { Sham.reset }
fixtures :all
end
I have step in cucumber:
email = '[email protected]'
password = 'secretpass'
User.make!(:confirmed, :email => email, :password => password)
This step called 2 times in cucumber feature. First time it is ok. User created an etc. But second time this step generate an error:
translation missing: ru, mongoid, errors, messages, document_not_found (Mongoid::Errors::DocumentNotFound)
/home/petrushka/.bundler/ruby/1.9.1/machinist_mongo-fa4819c4e123/lib/machinist/mongoid.rb:48:in `unbox'
logs:
pkl_test['users'].find({:_id=>BSON::ObjectId('4ced9c565e6f993856000001')}, {}).limit(-1)
pkl_test['system.namespaces'].find({}, {})
MONGODB pkl_test['system.indexes'].remove({})
MONGODB pkl_test['users'].remove({})
MONGODB pkl_test['accounts'].remove({})
MONGODB pkl_test['cards'].remove({})
MONGODB pkl_test['transactions'].remove({})
MONGODB pkl_test['card_orders'].remove({})
I use machinist2 and corresponding branch of machinist_mongo:
gem 'machinist', '2.0.0.beta2'
gem 'machinist_mongo', :git => 'git://github.com/nmerouze/machinist_mongo.git', :branch => 'machinist2', :require => 'machinist/mongoid'
Rails 3.0.3, cucumber 0.9.4, database cleaner and ruby 1.9
Error while running specs with machinist_mongo being required:
/Users/akhkharu/.rvm/rubies/ruby-1.8.7-p160/bin/ruby /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/rspec-1.3.0/bin/spec --autospec /Users/akhkharu/ror/shortener/spec/shortener_spec.rb -O spec/spec.opts
/Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:440:in load_missing_constant': uninitialized constant MongoMapper::EmbeddedDocument::ClassMethods (NameError) from /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in
const_missing'
from /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/machinist_mongo-1.1.0/lib/machinist/mongo_mapper.rb:82
from /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in require' from /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in
require'
from /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:521:in new_constants_in' from /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in
require'
from /Users/akhkharu/ror/shortener/spec/blueprints.rb:1
from /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in require' from /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in
require'
from /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:521:in new_constants_in' from /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in
require'
from /Users/akhkharu/ror/shortener/spec/spec_helper.rb:16
from /Users/akhkharu/ror/shortener/spec/shortener_spec.rb:1:in require' from /Users/akhkharu/ror/shortener/spec/shortener_spec.rb:1 from /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:15:in
load'
from /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:15:in load_files' from /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in
each'
from /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in load_files' from /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/rspec-1.3.0/lib/spec/runner/options.rb:133:in
run_examples'
from /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/rspec-1.3.0/lib/spec/runner/command_line.rb:9:in `run'
from /Users/akhkharu/.rvm/gems/ruby-1.8.7-p160/gems/rspec-1.3.0/bin/spec:5
I'm running my application in Rails 3.0 / Ruby 1.9.2 stack under Passenger. When I started it with machinist_mongo (from machinist2 branch) installed, it didn't like non-ascii characters in gemspec file for some reason. Removing non-ascii characters from .gemspec fixed the problem.
machinist_mongo (1.1.1)
mongoid (2.0.0.beta.20 4ef5fd0)
mongo (1.1.5)
rails 3.0.1
Code:
https://gist.github.com/776097
If I create @radar_traffic it always has created_at = Time.now not Time.new(2008).
When I add attr_accessible :created_at to my model it works.
I try to resolve this problem buy writing in my spec
@radar_traffic = Radar.make(:near_poznan3)
@radar_traffic.created_at = Time.new(2008)
but it also doesn't work
To make macjomost_mongo work with both ActiveRecord, Mongoid at the same time i have to put the following code in my blueprints.rb and then the spec runs only with spork, if test launched via spec .../some_spec.rb I got some error.
require 'machinist/active_record' require 'machinist/mongoid' require 'sham' require 'faker' require 'md5' module Machinist class Lathe def assign_attribute(key, value) if @object.kind_of? ActiveRecord::Base assign_attribute_active_record(key, value) elsif @object.class.include? Mongoid::Document assign_attribute_mongoid(key, value) elsif @object.class.include? MongoMapper::Document or @object.class.include? MongoMapper::EmbeddedDocument assign_attribute_mongo_mapper(key, value) else raise Exception("Unknown mapper") end end # mongoid def assign_attribute_mongoid(key, value) assigned_attributes[key.to_sym] = value @object.process(key => value) end # mongo_mapper def assign_attribute_mongo_mapper(key, value) assigned_attributes[key.to_sym] = value if @object.respond_to? "#{key}=" @object.send("#{key}=", value) else @object[key] = value end end def assign_attribute_active_record(key, value) assigned_attributes[key.to_sym] = value @object.send("#{key}=", value) end end end Blueprints bellow ....
Received following error when testing with MongoMapper 0.11
/gems/machinist_mongo-1.2.0/lib/machinist/mongo_mapper.rb:81:in `<top (required)>': undefined method `append_extensions' for MongoMapper::Document:Module (NoMethodError)
According to mongomapper/mongomapper#237 append_extensions is deprecated.
Hey all,
I'm trying to get machinist_mongo (HEAD from machinist2 branch) to work with mongoid 2.0.0.beta.19. This is not a Rails app by the way.
I've required machinist_mongo like so in my Gemfile (using Bundler 1.0.2):
gem 'machinist_mongo',
:require => 'machinist/mongoid',
:git => 'http://github.com/nmerouze/machinist_mongo.git',
:branch => 'machinist2'
And my spec_helper looks like this
require File.dirname(__FILE__) + '/../config/boot'
require 'rspec'
require 'machinist'
require 'machinist/mongoid'
RSpec.configure do |config|
config.before(:each) { Machinist.reset_before_test }
end
Store.blueprint do
name { Faker::Company.name }
email { Faker::Internet.email }
description { Faker::Lorem.paragraph(1 + rand(3)) }
location { Faker::Address.street_address }
end
Any ideas? Is the machinist2 branch working at all?
Thanks!
If you have a model that is embedded in a parent model, mongoid will let you call save
and create
on it, as long as you have specified the parent. The problem in machinist currently is the reload line -- mongoid doesn't allow calling reload on an embedded document.
When defining references associations, using "association.make" does not seem to provide the proxy as the reference object
Example (Account has the references_many)
Account.blueprint do
...
end
Page.blueprint do
account {Account.make}
end
account = Account.make :domain => 'test.com'
page = account.pages.make
puts account.id # 4c9d2e9a2249c72332000001
puts page.account.id # 4c9d2e9a2249c72332000003
Hi,
On the machinist branch, the lib/machinist/mongo_mapper.rb is a copy of lib/machinist/mongoid.rb.
Is this intentional? Is MongoMapper support simply not implemented yet?
Best,
Milan
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.