Casecommons / with_model

Dynamically build an Active Record model (with table) within a test context
http://www.casebook.net
MIT License
167 stars 18 forks source link

Add `namespace` option to create nested constants #26

Closed palkan closed 6 years ago

palkan commented 8 years ago

Make possible creation of namespaced models:

with_model :TestUser, namespace: Users, superclass: User

with_model :Test, namespace: MyModule, superclass: MyModule::Base
amarshall commented 8 years ago

Does with_model :"A::B" not work?

amarshall commented 8 years ago

Actually…it won’t. But for the same reason this P.R. won’t if the namespace isn’t already defined. (I think…it’s early—I’ll look into this further later.)

amarshall commented 6 years ago

This has been implemented in aa788c02615e29cddd73d4286625cfdcda768a3d. Will make a release sometime soon. I’ve implemented this a bit differently than your P.R.; instead, just provide the namespace in the name (e.g. with_model :'Foo::Bar'). The namespace does still need to already exist (with_model will not create it, as that feels, to me, overreaching). I think this API is perhaps a bit more intuitive than a separate option.

Sorry it took so long to get this feature in!

amarshall commented 6 years ago

@palkan This is now in v2.1.0.