Code Monkey home page Code Monkey logo

fabrication-site's People

Contributors

andrii avatar camerond avatar cczona avatar davetapley avatar elizabrock avatar jodosha avatar mattpolito avatar micdahl avatar nruth avatar paulelliott avatar richardvenneman avatar swrobel avatar zacharydanger avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fabrication-site's Issues

attributes_for doesn't work with complex objects (2.5.0)

When I use attributes_for for a complex object, the complex object is not converted to a hash. For example:

class Order
  attr_accessor productType
  attr_accessor quoteRef
  attr_accessor allocations
  attr_accessor marketPrice
end

class Allocation
  attr_accessor account
  attr_accessor notionalAmount
end

class MarketPrice
  attr_accessor id
  attr_accessor prices
end

Fabricator :order do
  productType "Product"
  quoteRef ""
  allocations(count: 1, fabricator: :allocation)
  marketPrice(fabricator: :market_price)
end

Fabricator :allocation do
  account "10009-1"
  notionalAmount 500000.0
end

Fabricator :market_price do |f|
  f.id ""
  prices [85.7]
end
Fabricator.attributes_for(:order_do, :quoteRef=> 'olalala') = Hash (4 element(s))
  productType -> Product
  quoteRef -> olalala
  allocations = Array(1 element(s))
    [0] = {Allocation} #<Allocation:0x1140ecf2>
  marketPrice_id' ->

It is a bit annoying. Separately, I cannot use the word 'id' as an attribute, code in definition.rb:127 if value && value.respond_to?(:id) hardcodes the :id symbol and the object doesn't get parsed any further.

P.S. I am using fabricator 2.5.0, as 2.5.1 doesn't work. manager.rb [](name) tries to do a name.try(:to_sym) on a symbol, but name is already a symbol and doesn't have the try method... at least in my jruby 1.7

reserved words

One of my models has an 'alias' attribute. How would I define that attribute in a fabricator? If I do so with the normal block syntax, ruby gets confused because 'alias' is actually a ruby keyword.

Update Rails configuration instructions on the website

Using Rails 3.1.3 and test/unit the following syntax from the Fabrication site no longer works:

config.generators do |g|
  g.fixture_replacement :fabrication, :dir => "test/fabricators"
end

To get things to work properly I'm having to use the following config:

config.generators do |g|
  g.test_framework :test_unit, :fixture_replacement => :fabrication
  g.fixture_replacement :fabrication, :dir => "test/fabricators"
end

I'm not 100% sure this is exactly the right way to specify the config but it seems to be the only way to get it working in Rails 3.1.3.

The documentation could use some expected output

Without knowing the exact thinking and idea behind every part of fabrications it's sometimes hard to guess what some of the example code will actually do.

For better/easier/faster understanding I'd suggest to add some sections like "this should return..."
To keep documentation clean they could be hidden by default.

I might write something down if you like the idea.

Sequences not working?

Hey again.

I guess the fault is on my side but I don't know where else to ask:
Here is the code:

Fabricator(:ad) do
    # If I use Fabricate.sequence(:ad) { |i| "test_ad_#{i}" }
    # on the rails console it works perfectly.
    # Using it in a fabricator like below does not unfortunately.
    name { sequence(:ads) { |i| "test_ad_#{i}" } }  
end

When using Fabricate(:ad) two times on the console it'll throw an error:

ActiveRecord::RecordInvalid: Database entry invalid: Name is already taken 

PS: Are there any other places to ask for help than via Github issues?

attrs[:param] not passed to block

This is my Fabricator:

Fabricator(:user_with_specific_time, from: :user) do
  transient :time_elapsed
  scores    { |attrs| {Fabricate.build(:score, user: nil, time_elapsed: attrs[:time_elapsed]) } }
end

Fabricator(:score) do
   time_elapsed { rand(400) }
   user { Fabricate :user, user_id: nil}
end

u = Fabricate(:user_with_specific_time, time_elapsed: 1)
u.scores

[#<Score id: 23, time_elapsed: nil, user_id: 16, created_at: "2013-09-30 22:12:53", updated_at: "2013-09-30 22:12:53">]

As you can see, time_elapsed keeps nil

How did I get this working?

Sorry for my - maybe stupid - approach

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.