diff options
author | Edmund von der Burg <evdb@mysociety.org> | 2011-03-24 17:42:02 +0000 |
---|---|---|
committer | Edmund von der Burg <evdb@mysociety.org> | 2011-03-24 17:42:02 +0000 |
commit | e76bad9cb401c636542ac79788a0dd26eea35a6f (patch) | |
tree | c495c6c2ac57fe20874fe0c9022532e3b40442e6 | |
parent | 5c1343fb6d14dd8fb44b2cc626619845097b90a9 (diff) |
Store tokens correctly
-rwxr-xr-x | db/rerun_dbic_loader.pl | 4 | ||||
-rw-r--r-- | perl-external/minicpan/modules/02packages.details.txt.gz | bin | 13016 -> 13016 bytes | |||
-rw-r--r-- | perl-external/modules.txt | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Contact.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Session.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Token.pm | 18 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 46 | ||||
-rw-r--r-- | t/app/model/token.t | 23 |
9 files changed, 66 insertions, 41 deletions
diff --git a/db/rerun_dbic_loader.pl b/db/rerun_dbic_loader.pl index 9d94c2b8b..2b98560ee 100755 --- a/db/rerun_dbic_loader.pl +++ b/db/rerun_dbic_loader.pl @@ -37,6 +37,10 @@ make_schema_at( exclude => qr{$exclude}, # ignore some tables generate_pod => 0, # no need for pod overwrite_modifications => 1, # don't worry that the md5 is wrong + + # add in some extra components + components => ['FilterColumn'], + }, FixMyStreet->dbic_connect_info(), ); diff --git a/perl-external/minicpan/modules/02packages.details.txt.gz b/perl-external/minicpan/modules/02packages.details.txt.gz Binary files differindex 1d890a4a4..bda6c8a24 100644 --- a/perl-external/minicpan/modules/02packages.details.txt.gz +++ b/perl-external/minicpan/modules/02packages.details.txt.gz diff --git a/perl-external/modules.txt b/perl-external/modules.txt index 84934bdf6..0f9a7769a 100644 --- a/perl-external/modules.txt +++ b/perl-external/modules.txt @@ -15,6 +15,7 @@ Catalyst::View::TT Class::Unload Config::General DBIx::Class +DBIx::Class::FilterColumn DBIx::Class::Schema::Loader DBIx::Class::Storage::DBI Email::Send diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm index dd5d1f579..5a993a773 100644 --- a/perllib/FixMyStreet/DB/Result/Contact.pm +++ b/perllib/FixMyStreet/DB/Result/Contact.pm @@ -8,6 +8,7 @@ use warnings; use base 'DBIx::Class::Core'; +__PACKAGE__->load_components("FilterColumn"); __PACKAGE__->table("contacts"); __PACKAGE__->add_columns( "area_id", @@ -38,7 +39,7 @@ __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint( "contacts_area_id_category_idx", [ "area_id", "category" ] ); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-03-21 16:25:05 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:zuvUDlmZI74jTjrSCb1RTQ +# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-03-24 17:36:08 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:u6kRlRfgwAiCqmGhj6io5A 1; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index cc009ee81..bf05bd7bd 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -8,6 +8,7 @@ use warnings; use base 'DBIx::Class::Core'; +__PACKAGE__->load_components("FilterColumn"); __PACKAGE__->table("problem"); __PACKAGE__->add_columns( "id", @@ -80,8 +81,8 @@ __PACKAGE__->belongs_to( { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, ); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-03-23 12:42:18 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hXAYqPHjda6+DoSiQexpEg +# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-03-24 17:36:08 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+a9n7IKg3yFdgxNIbo3SGg =head2 check_for_errors diff --git a/perllib/FixMyStreet/DB/Result/Session.pm b/perllib/FixMyStreet/DB/Result/Session.pm index dd9496d8c..a50c3780b 100644 --- a/perllib/FixMyStreet/DB/Result/Session.pm +++ b/perllib/FixMyStreet/DB/Result/Session.pm @@ -8,6 +8,7 @@ use warnings; use base 'DBIx::Class::Core'; +__PACKAGE__->load_components("FilterColumn"); __PACKAGE__->table("sessions"); __PACKAGE__->add_columns( "id", { data_type => "char", is_nullable => 0, size => 72 }, @@ -16,8 +17,8 @@ __PACKAGE__->add_columns( ); __PACKAGE__->set_primary_key("id"); -# Created by DBIx::Class::Schema::Loader v0.07009 @ 2011-03-01 15:43:43 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:DrIweLdjIbsiss6MQRZM8A +# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-03-24 17:36:08 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:E6SUYbAPJMQSXTrvn0x3kg # You can replace this text with custom code or comments, and it will be preserved on regeneration 1; diff --git a/perllib/FixMyStreet/DB/Result/Token.pm b/perllib/FixMyStreet/DB/Result/Token.pm index 2bdd8f90b..e4ea7262a 100644 --- a/perllib/FixMyStreet/DB/Result/Token.pm +++ b/perllib/FixMyStreet/DB/Result/Token.pm @@ -8,6 +8,7 @@ use warnings; use base 'DBIx::Class::Core'; +__PACKAGE__->load_components("FilterColumn"); __PACKAGE__->table("token"); __PACKAGE__->add_columns( "scope", @@ -25,8 +26,8 @@ __PACKAGE__->add_columns( ); __PACKAGE__->set_primary_key( "scope", "token" ); -# Created by DBIx::Class::Schema::Loader v0.07009 @ 2011-03-02 16:14:01 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:UfM8itc52wy22+YsRKuxmw +# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-03-24 17:36:08 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tClh4Spd63IpCeiGVHfrEQ # Trying not to use this # use mySociety::DBHandle qw(dbh); @@ -52,16 +53,17 @@ ms_current_timestamp. =cut -__PACKAGE__->inflate_column( - 'data', - { - inflate => sub { - my $ser = shift; +__PACKAGE__->filter_column( + data => { + filter_from_storage => sub { + my $self = shift; + my $ser = shift; return undef unless defined $ser; my $h = new IO::String($ser); return RABX::wire_rd($h); }, - deflate => sub { + filter_to_storage => sub { + my $self = shift; my $data = shift; my $ser = ''; my $h = new IO::String($ser); diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 6f6514902..32361ca48 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -8,36 +8,36 @@ use warnings; use base 'DBIx::Class::Core'; +__PACKAGE__->load_components("FilterColumn"); __PACKAGE__->table("users"); __PACKAGE__->add_columns( - "id", - { - data_type => "integer", - is_auto_increment => 1, - is_nullable => 0, - sequence => "users_id_seq", - }, - "email", - { data_type => "text", is_nullable => 0 }, - "name", - { data_type => "text", is_nullable => 1 }, - "phone", - { data_type => "text", is_nullable => 1 }, - "password", - { data_type => "text", default_value => "", is_nullable => 0 }, + "id", + { + data_type => "integer", + is_auto_increment => 1, + is_nullable => 0, + sequence => "users_id_seq", + }, + "email", + { data_type => "text", is_nullable => 0 }, + "name", + { data_type => "text", is_nullable => 1 }, + "phone", + { data_type => "text", is_nullable => 1 }, + "password", + { data_type => "text", default_value => "", is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); -__PACKAGE__->add_unique_constraint("users_email_key", ["email"]); +__PACKAGE__->add_unique_constraint( "users_email_key", ["email"] ); __PACKAGE__->has_many( - "problems", - "FixMyStreet::DB::Result::Problem", - { "foreign.user_id" => "self.id" }, - { cascade_copy => 0, cascade_delete => 0 }, + "problems", + "FixMyStreet::DB::Result::Problem", + { "foreign.user_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, ); - -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-03-23 12:42:18 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:z+QRbRAIyy2omaKVfRFTMA +# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-03-24 17:36:08 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:36KVfhjrygEEmpmWm/vZBg use mySociety::EmailUtil; diff --git a/t/app/model/token.t b/t/app/model/token.t index f7124ffc0..12945975e 100644 --- a/t/app/model/token.t +++ b/t/app/model/token.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 13; +use Test::More tests => 45; use FixMyStreet; use FixMyStreet::App; @@ -19,15 +19,25 @@ FixMyStreet->configure_mysociety_dbhandle(); # create a token using DBIC and check we can read it using AuthToken, and vice # versa -my $test_data = { foo => 'bar', and => [ 'baz', 'bundy' ] }; +my %tests = ( + nested_hash => { foo => 'bar', and => [ 'baz', 'bundy' ] }, + array => [ 'foo', 'bar' ], + scalar => 123, +); my $token_rs = FixMyStreet::App->model('DB::Token'); -{ # create using DBIC +# create using DBIC +foreach my $test_data_name ( sort keys %tests ) { + my $test_data = $tests{$test_data_name}; + + pass "--- testing DBIC create using '$test_data_name'"; + my $dbic_token = $token_rs->create( { scope => 'testing', data => $test_data } ); my $token = $dbic_token->token; ok $token, "stored token '$token'"; + is_deeply $dbic_token->data, $test_data, "data stored correctly using DBIC"; # read back using DBIC @@ -52,7 +62,12 @@ my $token_rs = FixMyStreet::App->model('DB::Token'); } -{ # create using m::AT +# create using m::AT +foreach my $test_data_name ( sort keys %tests ) { + my $test_data = $tests{$test_data_name}; + + pass "--- testing m::AT create using '$test_data_name'"; + my $token = mySociety::AuthToken::store( 'testing', $test_data ); dbh->commit(); ok $token, "stored token '$token'"; |