Giter Site home page Giter Site logo

Comments (10)

danielspaniel avatar danielspaniel commented on May 19, 2024

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

danielspaniel avatar danielspaniel commented on May 19, 2024

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

digitalcora avatar digitalcora commented on May 19, 2024

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.

digitalcora avatar digitalcora commented on May 19, 2024

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

danielspaniel avatar danielspaniel commented on May 19, 2024

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.

digitalcora avatar digitalcora commented on May 19, 2024

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.

danielspaniel avatar danielspaniel commented on May 19, 2024

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.

digitalcora avatar digitalcora commented on May 19, 2024

Awesome! Thanks so much for adding this, I'll try it out and report any issues I find.

from ember-data-factory-guy.

danielspaniel avatar danielspaniel commented on May 19, 2024

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.

danielspaniel avatar danielspaniel commented on May 19, 2024

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)

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.