From: Ash Berlin Date: Wed, 5 Aug 2009 17:19:10 +0000 (+0100) Subject: Notes + extra test for EPO workshop and YAPC::EU 2009 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;p=catagits%2Fcatbook-code.git Notes + extra test for EPO workshop and YAPC::EU 2009 --- diff --git a/Makefile.PL b/Makefile.PL index 124f215..619c0cc 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -18,8 +18,14 @@ requires 'Catalyst::View::TT'; requires 'Catalyst::View::JSON'; requires 'Moose'; requires 'namespace::clean'; +requires 'aliased'; +requires 'Catalyst::Model::Adaptor'; catalyst; +test_requires 'Test::Exception'; +test_requires 'Test::More'; + + tests_recursive; install_script glob('script/*.pl'); diff --git a/NOTES b/NOTES new file mode 100644 index 0000000..fc37963 --- /dev/null +++ b/NOTES @@ -0,0 +1,36 @@ +Notes: + +Snippet Store: +* In memory RS-like thing (i.e. a cache with an RS like interface) +* Snippets are just hashes: { text => 'foo' } + +* create(text => $text): make a new snippet. +* find(id): get a snippet + +Snippet: + +* has id and text accessors +* knows if it has been translated +* and how to translate itself. + +Translator: +* A text -> text transformer +* Work done by translation drivers +* Queryable translations (can I go to X?) + +Translation Driver: +* Has one method, 'translate' that takes a string and returns the translated one + + +Practical sessions: + +* Snippets and Translators +* + +Other Notes: +* Not sure the point of Test::Moose, I often just call the accessor and + check that it behaves right, I don't really care at the test level if + this is an accessor or some vodoo sacrifice so long as it works how i + want. + + diff --git a/t/snippet/simple.t b/t/snippet/simple.t new file mode 100644 index 0000000..f5a7440 --- /dev/null +++ b/t/snippet/simple.t @@ -0,0 +1,55 @@ +use strict; +use warnings; +use Test::More qw(no_plan); +use Test::Moose; +use Test::Exception; +use aliased 'LolCatalyst::Lite::Snippet'; + +{ package MockTranslator; + use Moose; + sub can_translate_to { $_[1] eq 'uc' }; + + sub translate { return uc $_[1] }; +} + +my ($id, $snippet); + +has_attribute_ok(Snippet, "id", "Snippets know about thier own id"); +has_attribute_ok(Snippet, "text", "Snippets have text attr"); + + +dies_ok { + $snippet = Snippet->new( + id => rand 9_999, + translator => MockTranslator->new + ) +} qr/\(text\) is required/; + +dies_ok { + $snippet = Snippet->new( + text => "hi there", + translator => MockTranslator->new + ) +} qr/\(id\) is required/; + +dies_ok { + $snippet = Snippet->new( + id => rand 9_999, + text => "hi there", + ) +} qr/\(translator\) is required/; + +lives_ok { + $snippet = Snippet->new( + id => ($id = rand 9_999), + text => "hi there", + translator => MockTranslator->new + ) +} "Can create a snippet"; + +is($snippet->id, $id, "this snippet has the right id"); +is($snippet->text, "hi there"); + +is($snippet->translated(), "HI THERE", "and the snippet can be translated"); + +