[dw-free] Per-user poll votes not being fetched when the voter is on a different cluster than journa
[commit: http://hg.dwscoalition.org/dw-free/rev/8551fcb0ad91]
http://bugs.dwscoalition.org/show_bug.cgi?id=3925
Check the cluster the poll was posted in, not the one the user voted.
Patch by
fu.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=3925
Check the cluster the poll was posted in, not the one the user voted.
Patch by
Files modified:
- cgi-bin/LJ/Poll.pm
- t/poll.t
--------------------------------------------------------------------------------
diff -r 8cb3878e2c4f -r 8551fcb0ad91 cgi-bin/LJ/Poll.pm
--- a/cgi-bin/LJ/Poll.pm Tue Aug 30 22:12:52 2011 -0500
+++ b/cgi-bin/LJ/Poll.pm Sat Sep 03 01:03:55 2011 +0800
@@ -619,16 +619,18 @@
# get the answer a user gave in a poll
sub get_pollanswers {
- my ( $pollid, $u ) = @_;
+ my ( $self, $u ) = @_;
- # try getting the has from memcache
- my $memkey = [$u->userid, "pollresult2:$u->userid:$pollid"];
+ my $pollid = $self->pollid;
+
+ # try getting first from memcache
+ my $memkey = [$u->userid, "pollresults:$u->userid:$pollid"];
my $result = LJ::MemCache::get( $memkey );
return %$result if $result;
my $sth;
my %answers;
- $sth = $u->prepare( "SELECT pollqid, value FROM pollresult2 WHERE pollid=? AND userid=?" );
+ $sth = $self->journal->prepare( "SELECT pollqid, value FROM pollresult2 WHERE pollid=? AND userid=?" );
$sth->execute( $pollid, $u->userid );
while ( my ( $qid, $value ) = $sth->fetchrow_array ) {
@@ -912,7 +914,7 @@
$ret .= qq{<div id='poll-$pollid-container' class='poll-container'>};
if ( $remote ) {
- %preval = get_pollanswers( $pollid, $remote );
+ %preval = $self->get_pollanswers( $remote );
}
if ( $do_form ) {
@@ -1404,7 +1406,7 @@
}
# delete user answer MemCache entry
- my $memkey = [$remote->userid, "pollresult2:$remote->userid:$pollid"];
+ my $memkey = [$remote->userid, "pollresults:$remote->userid:$pollid"];
LJ::MemCache::delete( $memkey );
# if unique prop is on, make sure that a particular email address can only vote once
diff -r 8cb3878e2c4f -r 8551fcb0ad91 t/poll.t
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/t/poll.t Sat Sep 03 01:03:55 2011 +0800
@@ -0,0 +1,43 @@
+# -*-perl-*-
+
+use strict;
+use Test::More;
+use lib "$ENV{LJHOME}/cgi-bin";
+require 'ljlib.pl';
+
+use LJ::Test qw( temp_user );
+use LJ::Poll;
+
+note( "Set up a poll where the voter is on a different cluster" );
+{
+ $LJ::DEFAULT_CLUSTER = 1;
+ my $poll_journal = temp_user();
+
+ my $entry = $poll_journal->t_post_fake_entry();
+ my $poll = LJ::Poll->create(
+ entry => $entry,
+ questions => [ { type => "text", qtext => "a text question" } ],
+ name => "poll answer across clusters",
+
+ isanon => 'no',
+ whovote => 'all',
+ whoview => 'all',
+ );
+
+
+ $LJ::DEFAULT_CLUSTER = 2;
+ my $voter = temp_user();
+ LJ::set_remote( $voter );
+
+ LJ::Poll->process_submission( { pollid => $poll->id, "pollq-1" => "voter's answers" } );
+
+ is_deeply( { $poll->get_pollanswers( $voter ) },
+ {
+ 1 => "voter's answers"
+ }, "Checking that we got the voter's answers correctly when journal / poll are on different clusters" );
+}
+
+done_testing();
+
+1;
+
--------------------------------------------------------------------------------

no subject
no subject
no subject
no subject
no subject