Re: [Catalyst] Modify config in a test
On Wed, Sep 26, 2012 at 1:15 AM, Manni Heumann heum...@strato-rz.de wrote: Bill Moseley mose...@hank.org schrieb am 25.09.2012: The app has a myapp.yml config which includes configuration for creating an instance of a Model component -- and part of that Model's config is a database dsn attribute. When running my test I do want to have the app load this config file -- but I want to modify it on-the-fly. Why? Why not simply create a myapp_test.yml file and set CATALYST_CONFIG_LOCAL_SUFFIX to test when you run your test-suite? I guess this is probably the cleanest/easiest. Create my database and write out the config in a BEGIN block -- or somehow otherwise delay loading Catalyst::Test. My other option could be to create my own instance of the Model object and then swap it out in the MyApp-components hash. The fact that my model is dynamically generated at startup based on config adds a bit of complexity to it -- but that can be handled. BTW -- for tests where I need to build a database on-the-fly what I currently do is set my make test config use dsn = 'dbi:Pg' and then set the PG* environment variables. But, in this case what I'm doing is swapping my Postgresql config in my configuration with one to use a SQLite database in a temporary file just for a few tests. Thanks for the ideas. -- Bill Moseley mose...@hank.org ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] Modify config in a test
I'm using Catalyst::Test on an app. The app has a myapp.yml config which includes configuration for creating an instance of a Model component -- and part of that Model's config is a database dsn attribute. When running my test I do want to have the app load this config file -- but I want to modify it on-the-fly. My test builds a SQLite database when it runs, and I'd like to be able to modify the config as (before) Catalyst creates the instance of the model component -- that is just filter the config to inject my temporary database. The model dsn attribute is readonly -- otherwise I could just do MyApp-model( 'MyModel' )-dns( $new_dsn ); What's a good, clean way of doing this? Or perhaps a better approach all together? -- Bill Moseley mose...@hank.org ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Modify config in a test
2012/9/26 Bill Moseley mose...@hank.org: I'm using Catalyst::Test on an app. The app has a myapp.yml config which includes configuration for creating an instance of a Model component -- and part of that Model's config is a database dsn attribute. When running my test I do want to have the app load this config file -- but I want to modify it on-the-fly. My test builds a SQLite database when it runs, and I'd like to be able to modify the config as (before) Catalyst creates the instance of the model component -- that is just filter the config to inject my temporary database. The model dsn attribute is readonly -- otherwise I could just do MyApp-model( 'MyModel' )-dns( $new_dsn ); What's a good, clean way of doing this? Or perhaps a better approach all together? Ohh.. I'am also interested in clean way to do this. But now in the similar situation, I'm doing this: (it is from my base test class whitch extends Test::Class itself) use Class::Load qw(load_class is_class_loaded); use Class::Method::Modifiers (); ... sub default_config { return { ... # somewere dsn = 'dbi:SQLite::memory:' }; } sub init : Test(startup) { my $self = shift; my $app_class = 'MyApp'; ... unless (is_class_loaded($app_class)) { load_class($app_class); $app_class-config($self-default_config); # set default config # filter out some plugins Class::Method::Modifiers::install_modifier('Catalyst', 'around', 'setup_plugins', sub { my $orig = shift; my ($class, $plugins) = @_; $orig-($class, [grep { ! ( $_ ~~ ['ConfigLoader',some other plugins] ) } @$plugins]); }); $app_class-import; # now allow Catalyst properly setup application # create schema $app_class-model('General')-schema-deploy({quote_field_names=1,quote_table_names=1}); } ... } Hackish, but works... -- Bill Moseley mose...@hank.org ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ -- Vladimir Timofeev vovk...@gmail.com ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/