Giter Club home page Giter Club logo

machinist_mongo's Introduction

Machinist Mongo

It aims to replace machinist_mongomapper to provide Machinist adapters not just for MongoMapper but for all the others MongoDB ORMs too. Right now it supports Mongoid and MongoMapper, but we aim to support all mongoDB ORMs, so If you’re using something other than MongoMapper or Mongoid, please be sure to write a adapter for it.

For Rails 2

Current Machinist Mongo versions (1.2.x) are only compatible with Rails 3. Use 1.1.x versions to use Machinist Mongo with Rails 2.

NB: For old users, don’t use 2.0.0.pre, use 1.2.x instead.

For Machinist 2

There’s a machinist2 branch if you want to use Machinist Mongo with Machinist 2.

Usage

Using Machinist MongoMapper is simple. Put this in your Gemfile:

gem 'machinist_mongo', :require => 'machinist/mongoid' # or mongo_mapper

And run:

bundle install

And you’re all set. Be sure read Machinist’s README to find out how to create your objects and get this thing running.

Contributors

machinist_mongo's People

Contributors

durran avatar jonathantron avatar jszmajda avatar nmerouze avatar papipo avatar shingara avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

machinist_mongo's Issues

associations do not work on machinis2 branch with mongoid

in below example the user assotiation does not work

have to specify user { User.make } which is hacky

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

Mongoid references_many and make

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

I can not set created_at attribute in blueprint

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

Encoding issue in Ruby 1.9.2

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.

.make! should work with embedded mongoid associations

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.

machinist_mongo don't create same objects in two different scenario

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

uninitialized constant MongoMapper::EmbeddedDocument::ClassMethods

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:inconst_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:inrequire'
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:inrequire'
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:inrequire'
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:inrequire'
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:inload'
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:ineach'
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:inrun_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

undefined method `blueprint'

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!

MongoMapper support on the Machinist2 branch

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

I can't use associations with mongo_mapper

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

Working with mixed ActiveRecord and Mongid blueprints

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 ....

Rails 3 + Mongoid: undefined method `blueprint'

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

No sham defined for sn

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?

Rails 3 load issue

I currently have the following setup:

  • rails 3.0.0.beta4
  • rspec 2.0.0.beta.12
  • mongoid 2.0.0.beta7
  • machinist 1.0.6
  • machinist_mongo 1.1.0

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.