Git Product home page Git Product logo

Comments (12)

xofred avatar xofred commented on July 17, 2024 1

Was this ever implemented?

Sorry to say, but no. Luckily I found a neat script(creditπŸŽ‰) can somehow automate the feature. But it will break if the table does not have a model definition. We better rescue that situation.

from factory_bot_rails.

gerrywastaken avatar gerrywastaken commented on July 17, 2024

Shouldn't --from-schema be the default if no options are provided, after all what's the point of a generator that only generates an empty factory? If anything --without-schema would be a better option if needed at all.

Other than that I like you idea although I had assumed there was a good reason this wasn't implemented to start with.

from factory_bot_rails.

mike-burns avatar mike-burns commented on July 17, 2024

Our default factories are minimal: they contain only what is needed to build a valid object, and no more.

We then add additional factories that go above and beyond.

class User < ActiveRecord::Base
  validates_presence_of :name
end

FactoryGirl.define do
  factory :user do
    name "Franklin Bluth"

    factory :admin do
      role 'admin'
    end
  end
end

from factory_bot_rails.

asanghi avatar asanghi commented on July 17, 2024

@mike-burns understood and accepted that it should not be the default as per your philosophy on how this gem should behave.

Do you still think there is value in having an option (--from-schema) when the user knows that minimal generated is not enough for the model to be saved and they'de rather remove the ones they know are non-essential manually? Just that sometimes attributes essential are more than attributes non-essential.

If not, I'm happy for you to close the ticket.

from factory_bot_rails.

mike-burns avatar mike-burns commented on July 17, 2024

What would the values be? I guess it could do some simple mapping: int -> 1, varchar -> "hello", datetime -> { Time.now }.

Looking for feedback from @joshuaclayton and @jferris on what they are willing to support. Here's an idea: split the generators off into a separate gem, look for someone else to maintain it?

from factory_bot_rails.

joshuaclayton avatar joshuaclayton commented on July 17, 2024

If we were able to move the generators out to a separate gem, this gem would effectively go away I think; last I checked, the only other piece of functionality the factory_girl_rails gem added was using railties to wire everything up and set up the location of the factories

from factory_bot_rails.

asanghi avatar asanghi commented on July 17, 2024

@joshuaclayton thanks for that. So are you saying there is scope for this gem to do a bit more? :)

from factory_bot_rails.

joshuaclayton avatar joshuaclayton commented on July 17, 2024

@asanghi not sure exactly; I'll have to dig through a bit more to fully understand everything it's doing and what functionality we want it to provide.

from factory_bot_rails.

gregors avatar gregors commented on July 17, 2024

+1 on this

from factory_bot_rails.

joshuaclayton avatar joshuaclayton commented on July 17, 2024

I've thought about this and I don't typically set a lot of defaults on my factories. When I do, it's often times implicit attributes for email/username/title (which need to be unique) and wouldn't benefit from the auto-generation of attributes anyway. We'd also have to probably be intelligent about STI, polymorphism, associations, etc. which are oftentimes ORM-specific, meaning we'd need to have different code paths per ORM. I don't think that it's worth introducing that amount of complexity for a minimal benefit, so I'm going to close the issue. If someone can argue against this and provide some great examples of factories vs schema definitions and how they're using FG, I'd definitely sit down and think about it more but I think this is the right decision for now.

Thanks for the discussion everyone; it's definitely an interesting/difficult problem to solve but I don't think it's one FGR wants to handle right now.

from factory_bot_rails.

rastogiachyut avatar rastogiachyut commented on July 17, 2024

This would be very helpful in generating some demo data!

from factory_bot_rails.

randall-coding avatar randall-coding commented on July 17, 2024

Was this ever implemented?

from factory_bot_rails.

Related Issues (20)

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.