Comments (10)
@Grantovich , how could you see this working in FactoryGuy? Could you give me an idea of what you would like to see ( even if its just a copy of what FactoryGirl does ) .. will help to get my ideas going.
from ember-data-factory-guy.
@Grantovich .. I just looked over the callbacks in FactoryGirl, and I understand what you want .. I just want to make double extra sure that I have it 100% exactly correct ( the way you want it ) before I build this.
from ember-data-factory-guy.
If you're looking to implement the whole transients/callbacks thing, this is roughly how I'd envision it working in the factory definitions:
FactoryGuy.define 'location',
default:
name: 'Test Location'
FactoryGuy.define 'floorplan',
default:
location: {}
name: 'Test Floorplan'
transient:
locationInverse: null
afterMake: (model, attributes) ->
switch attributes.locationInverse
when 'currentFloorplan' then model.location.set('currentFloorplan', model)
when 'upcomingFloorplans' then model.location.get('upcomingFloorplans').addObject(model)
And the usage:
location = factories.make 'location'
floorplan = factories.make 'floorplan', location: location, locationInverse: 'upcomingFloorplans'
The transient
key would contain attributes that are ignored when constructing the model itself. The afterMake
callback would receive the constructed model instance and the hash of attributes provided to the make
call, including any transient attributes.
If implemented as-is, this would not be backwards compatible since transient
and afterMake
could previously be used as trait names. Since this problem would keep showing up if you added more "special" keys, it might be worthwhile to put traits under their own sub-key to ensure there are no collisions.
FactoryGuy.define 'user',
default:
username: 'bob'
isModerator: false
isAdmin: false
traits:
admin:
isAdmin: true
moderator:
isModerator: true
This would be super-not-backwards-compatible, but you could leave in the ability to define traits at the top level and just give a deprecation warning.
from ember-data-factory-guy.
(By the way, I and my team really appreciate your work on this project – I was only asking for advice on how to handle our particular situation, but you've gone far above and beyond. 👏 We are on a rather time-crunched project right now, but I hope to make some contributions to Factory Guy myself once I have more Ember experience.)
from ember-data-factory-guy.
Thanks for the proposed usage Alex, that was helpful, and thanks for the kind words :)
This library has made testing ember app's so much easier and fun for me, and I am happy to hear that others like yourselves are enjoying it too.
And good point about the collisions .. luckily traits already have their own sub_key already,
so that should not be too bad.
from ember-data-factory-guy.
luckily traits already have their own sub_key already, so that should not be too bad.
Ah, okay. I was looking at a section of the README that just used top-level keys for the traits.
from ember-data-factory-guy.
Hey @Grantovich , I finally got around to finishing this feature. Check it out in version 1.0.5, and let me know if you see any bugs?
from ember-data-factory-guy.
Awesome! Thanks so much for adding this, I'll try it out and report any issues I find.
from ember-data-factory-guy.
Actually I was not quite finished when I pushed out version 1.0.4 .. I am finishing it up today, and will release new version 1.0.5 when I am done.
from ember-data-factory-guy.
ok .. I fixed that issue, and its on version 1.0.6 where afterMake will work as you expected.
from ember-data-factory-guy.
Related Issues (20)
- `mockFindAll` should be able to also `mockFindRecord`
- Nothing returned by handler for mockQueryRecord when mocking ember-simple-auth currentUser HOT 20
- Compatibility with Ember Data Model Fragments new refactor HOT 9
- Putting this addon up for adoption? HOT 13
- Error: Pretender intercepted GET but no handler was defined for this type of request HOT 5
- Bump pretender to 3.4.3 HOT 1
- documention error for returns method for mockCreate and mockUpdate
- Mock status is not working. HOT 1
- Factory Guy incompatible with Embroider HOT 4
- Header verification
- Dependency on older broccoli plugin versions prevents test runs with more recent ember-data versions HOT 1
- Version v4 items HOT 2
- (enhancement) Make the documentation more accessible HOT 2
- modelName being used as payloadKey
- Could not find module `@ember/debug` HOT 1
- Fix ember-assign deprecation warning
- Pretender does not catch call when mock is not define - ERROR : "The adapter operation was aborted"
- can we publish a release HOT 8
- String vs number ids and ember-data 5.3+ issues HOT 2
- Switch from pretender to msw?
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 ember-data-factory-guy.