Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Net-Twitter CPAN distribution.

Report information
The Basics
Id: 41667
Status: resolved
Priority: 0/
Queue: Net-Twitter

People
Owner: Nobody in particular
Requestors: shawn [...] eye.fi
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: relationship_exists
Date: Fri, 12 Dec 2008 16:25:54 -0800
To: bug-Net-Twitter [...] rt.cpan.org
From: Shawn Shah <shawn [...] eye.fi>
Hi, I noticed there is a slight bug in how the relationship_exists method constructs the API call. The user_b parameter should be preceded by '&' instead of another '?'. Thanks! Shawn Shah
Subject: [PATCH] relationship_exists
Hi, Chris. Just ran into this myself. Patch attached. Has me wondering how to write tests for Net::Twitter.
diff --git a/lib/Net/Twitter.pm b/lib/Net/Twitter.pm index 1ea0297..fba2b38 100755 --- a/lib/Net/Twitter.pm +++ b/lib/Net/Twitter.pm @@ -412,7 +412,7 @@ sub relationship_exists { my $url = $self->{apiurl} . "/friendships/exists.json"; $url .= "?user_a=$user_a"; - $url .= "?user_b=$user_b"; + $url .= "&user_b=$user_b"; my $req = $self->{ua}->get( $self->{apiurl} . "/friendships/exists.json" ); $self->{response_code} = $req->code;
On Mon Dec 15 13:44:50 2008, MMIMS wrote: Show quoted text
> Hi, Chris. Just ran into this myself. Patch attached. > > Has me wondering how to write tests for Net::Twitter.
That last patch fixed only the frist of 2 errors. Found the 2nd while experimenting with Test::MockObject. Here's a new patch that includes a test.
diff --git a/Makefile.PL b/Makefile.PL index cae8ea4..13a892c 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -9,10 +9,12 @@ WriteMakefile( ABSTRACT_FROM => 'lib/Net/Twitter.pm', PL_FILES => {}, PREREQ_PM => { - 'LWP::UserAgent' => 0, - 'URI::Escape' => 0, + 'LWP::UserAgent' => 0, + 'URI::Escape' => 0, 'Test::More' => 0, - 'JSON::Any' => 0, + 'JSON::Any' => 0, + URI => 0, + 'Test::MockObject' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Net-Twitter-*' }, diff --git a/lib/Net/Twitter.pm b/lib/Net/Twitter.pm index 1ea0297..c079b58 100755 --- a/lib/Net/Twitter.pm +++ b/lib/Net/Twitter.pm @@ -412,9 +412,9 @@ sub relationship_exists { my $url = $self->{apiurl} . "/friendships/exists.json"; $url .= "?user_a=$user_a"; - $url .= "?user_b=$user_b"; + $url .= "&user_b=$user_b"; - my $req = $self->{ua}->get( $self->{apiurl} . "/friendships/exists.json" ); + my $req = $self->{ua}->get( $url ); $self->{response_code} = $req->code; $self->{response_message} = $req->message; return ( $req->is_success ) ? JSON::Any->jsonToObj( $req->content ) : undef;
RT-Send-CC: [patch], test, for, relationship_exists
On Mon Dec 15 15:56:50 2008, MMIMS wrote: Show quoted text
> That last patch fixed only the frist of 2 errors. Found the 2nd while > experimenting with Test::MockObject. Here's a new patch that includes a > test.
...and then I didn't include the test in the patch. <sigh/> Here it is. -Marc
diff --git a/t/relationship_exists.t b/t/relationship_exists.t new file mode 100644 index 0000000..8143463 --- /dev/null +++ b/t/relationship_exists.t @@ -0,0 +1,28 @@ +use warnings; +use strict; +use Net::Twitter; +use URI; +use Test::MockObject; +use Test::More tests => 4; + +my $twitter = Net::Twitter->new(username => 'NetTwitter', password => 'secret'); +my $mock = Test::MockObject->new($twitter->{ua}); + +$mock->mock(get => sub { + my $self = shift; + my $uri = URI->new(shift); + $uri = $uri->rel($twitter->{apiurl}); + + is $uri->path, 'friendships/exists.json', 'relationship_exists path'; + + my %args = $uri->query_form; + is $args{user_a}, 'me', 'user_a'; + is $args{user_b}, 'you', 'user_b'; + + my $res = HTTP::Response->new(200); + $res->content('true'); + + return $res; +}); + +ok $twitter->relationship_exists('me', 'you'), 'friendship exists';
This is fixed in 1.20. I did not include the Mock stuff in the test because I did not want to add another dependancy.