Comments (12)
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.
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.
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.
@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.
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.
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.
@joshuaclayton thanks for that. So are you saying there is scope for this gem to do a bit more? :)
from factory_bot_rails.
@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.
+1 on this
from factory_bot_rails.
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.
This would be very helpful in generating some demo data!
from factory_bot_rails.
Was this ever implemented?
from factory_bot_rails.
Related Issues (20)
- Invalid DateTime.now field on factory creation
- Multiple Tests Fail on Vanilla `bundle exec rake` HOT 2
- Model generation ignores --force-plural HOT 3
- Rails ignoring factory HOT 2
- Install fewer gems on Travis HOT 1
- Incompatibility with Rails 6.0.3? HOT 2
- Perform DB migration will make factory_bot looking for methods in the wrong place HOT 2
- Successive associations issue when migrating to rails 6.1 HOT 3
- Switch from Travis CI to GitHub Actions
- Duplicate factories problem HOT 5
- Automatically populate attributes and types when generating factories for existing models HOT 2
- Cannot create Factory with multiple traits got (ArgumentError Exception: wrong number of arguments (given 1, expected 0)) Ruby 3.0, Rails 6.1.72, factory_bot_rails 6.1.0 HOT 2
- Dead link in CONTRIBUTING.md HOT 2
- Release new version to allow upgrade to factory_bot 6.3.0 HOT 4
- The railtie included in #419 breaks compatibility with some gems "undefined method `config' for nil:NilClass" Factory Bot > 6.2.0 HOT 5
- 6.3.0: `NoMethodError: undefined method '<' for nil:NilClass` when using a factory with traits HOT 20
- undefined method `config' for nil:NilClass after upgrading to 6.4.0 HOT 16
- Ability to disable reject_primary_key_attributes per factory HOT 11
- RubyGems is not linking the CHANGELOG file
- gemspec is missing required_ruby_version HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from factory_bot_rails.