From 8bc06e633ac71dfe4833279bd799cb23933da794 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Tue, 22 Mar 2011 12:48:30 -0500 Subject: [PATCH] Fix: API problems with new parliament methods. --- lib/Lacuna.pm | 2 +- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 2 +- lib/Lacuna/DB/Result/Propositions.pm | 10 ++--- lib/Lacuna/RPC/Building/Parliament.pm | 5 ++- t/Parliament.t | 57 +++++++++++++++++++++++++ var/www/public/changes.txt | 2 + 6 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 t/Parliament.t diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index 362dbc5e..9219bd86 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0100; +our $VERSION = 3.0201; my $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf'); my $db = Lacuna::DB->connect($config->get('db/dsn'),$config->get('db/username'),$config->get('db/password'), { mysql_enable_utf8 => 1}); diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index cc18e8c6..c8838a5e 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -684,7 +684,7 @@ sub convert_to_station { $self->empire($empire); $self->usable_as_starter_enabled(0); $self->last_tick(DateTime->now); - $self->alliance_id($self->empire->alliance_id); + $self->alliance_id($empire->alliance_id); $self->class('Lacuna::DB::Result::Map::Body::Planet::Station'); $self->update; diff --git a/lib/Lacuna/DB/Result/Propositions.pm b/lib/Lacuna/DB/Result/Propositions.pm index 1886612e..56059086 100644 --- a/lib/Lacuna/DB/Result/Propositions.pm +++ b/lib/Lacuna/DB/Result/Propositions.pm @@ -81,7 +81,7 @@ sub check_status { sub pass { my $self = shift; $self->status('Passed'); - $self->station->alliance->send_message( + $self->station->alliance->send_predefined_message( filename => 'parliament_vote_passed.txt', tag => 'Correspondence', params => [ @@ -103,7 +103,7 @@ has pass_extra_message => ( sub fail { my $self = shift; $self->status('Failed'); - $self->station->alliance->send_message( + $self->station->alliance->send_predefined_message( filename => 'parliament_vote_failed.txt', tag => 'Correspondence', params => [ @@ -124,7 +124,7 @@ has fail_extra_message => ( before insert => sub { my $self = shift; - $self->votes_needed( int($self->station->alliance->members->count / 2) ); + $self->votes_needed( int($self->station->alliance->members->count + 1 / 2) ); $self->date_ends( DateTime->now->add(hours => 72) ); }; @@ -150,9 +150,9 @@ sub get_status { }, }; if (defined $empire) { - my $vote = $self->votes->search({ empire_id => $empire->id})->get_column('vote'); + my $vote = $self->votes->search({ empire_id => $empire->id},{rows=>1})->single; if (defined $vote) { - $out->{my_vote} = $vote; + $out->{my_vote} = $vote->vote; } } return $out; diff --git a/lib/Lacuna/RPC/Building/Parliament.pm b/lib/Lacuna/RPC/Building/Parliament.pm index fd37811e..4c02307f 100644 --- a/lib/Lacuna/RPC/Building/Parliament.pm +++ b/lib/Lacuna/RPC/Building/Parliament.pm @@ -4,6 +4,7 @@ use Moose; use utf8; no warnings qw(uninitialized); extends 'Lacuna::RPC::Building'; +use Guard qw(guard); sub app_url { return '/parliament'; @@ -47,7 +48,7 @@ sub cast_vote { unless (defined $proposition) { confess [1002, 'Proposition not found.']; } - $proposition->cast_vote($self->empire, $vote); + $proposition->cast_vote($empire, $vote); return { status => $self->format_status($empire, $building->body), proposition => $proposition->get_status($empire), @@ -55,7 +56,7 @@ sub cast_vote { } -__PACKAGE__->register_rpc_method_names(qw(view_propositions)); +__PACKAGE__->register_rpc_method_names(qw(view_propositions cast_vote)); no Moose; __PACKAGE__->meta->make_immutable; diff --git a/t/Parliament.t b/t/Parliament.t new file mode 100644 index 00000000..e66dc0f1 --- /dev/null +++ b/t/Parliament.t @@ -0,0 +1,57 @@ +use lib '../lib'; +use Test::More tests => 8; +use Test::Deep; +use Data::Dumper; +use 5.010; +use DateTime; +use Lacuna::Constants qw(ORE_TYPES); + +use TestHelper; +my $tester = TestHelper->new->generate_test_empire->build_infrastructure; +my $session_id = $tester->session->id; +my $empire = $tester->empire; +my $home = $empire->home_planet; + +my $emb = Lacuna->db->resultset('Lacuna::DB::Result::Building')->new({ + x => 4, + y => 4, + class => 'Lacuna::DB::Result::Building::Embassy', + }); +$home->build_building($emb); +$emb->finish_upgrade; + +my $result; +$result = $tester->post('embassy', 'create_alliance', [$session_id, $emb->id, 'test alliance']); +ok(exists $result->{result}, 'can create alliance'); +$result = $tester->post('embassy', 'get_alliance_status', [$session_id, $emb->id]); +ok(scalar@{$result->{result}{alliance}{members}}, 'alliance has members'); +$empire = $empire->get_from_storage; +ok $empire->alliance_id, 'empire has alliance'; + +my $station = Lacuna->db->resultset('Map::Body')->search({class => {like => 'Lacuna::DB::Result::Map::Body::Planet::P%'}, empire_id => undef},{rows=>1})->single; +$station->convert_to_station($empire); +$station = $station->get_from_storage; # just in case + +ok $station->alliance_id, 'alliance assigned to station'; + +my $par = $station->parliament; +$par->level(3); +$par->update; + +$result = $tester->post('parliament', 'view', [$session_id, $par->id]); +is($result->{result}{building}{name}, 'Parliament', 'built successfully'); + +$result = $tester->post('body', 'rename', [$session_id, $station->id, 'station'.rand(1000000)]); +is($result->{error}{code}, 1017, 'renaming the station causes a proposition response'); + +$result = $tester->post('parliament', 'view_propositions', [$session_id, $par->id]); +is($result->{result}{propositions}[0]{name}, 'Rename Station', 'got a list of propositions'); + +$result = $tester->post('parliament', 'cast_vote', [$session_id, $par->id, $result->{result}{propositions}[0]{id}, 1]); +is($result->{result}{proposition}{my_vote}, 1, 'got my vote'); + + +END { + $station->sanitize; + $tester->cleanup; +} diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 0df6d86b..72ab377b 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,5 @@ +3.0201 + 3.0200 - Add: Added Amalgus Meadow and Denton Brambles glyph buildings. - Add: Small improvements to starting player experience. -- 2.54.0