Thread: [Codestriker-commits] CVS update: codestriker/lib/Codestriker/Http/Method DownloadTopicTextMethod.
Brought to you by:
sits
|
From: <si...@us...> - 2008-08-26 22:18:52
|
User: sits
Date: 08/08/26 15:18:51
Modified: lib/Codestriker/Http Dispatcher.pm UrlBuilder.pm
lib/Codestriker/Http/Method ListProjectsMethod.pm
Added: t/Http/Method add-project.t download-topic-text.t
lib/Codestriker/Http/Method DownloadTopicTextMethod.pm
AddProjectMethod.pm
Log:
Added support for downloading topic text and creating a new project under the new URL scheme.
Index: Dispatcher.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Dispatcher.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Dispatcher.pm 18 Aug 2008 22:11:05 -0000 1.5
+++ Dispatcher.pm 26 Aug 2008 22:18:50 -0000 1.6
@@ -20,6 +20,7 @@
use Codestriker::Http::Method::ViewTopicFileMethod;
use Codestriker::Http::Method::ViewTopicMetricsMethod;
use Codestriker::Http::Method::ViewTopicPropertiesMethod;
+use Codestriker::Http::Method::DownloadTopicTextMethod;
use Codestriker::Http::Method::UpdateTopicPropertiesMethod;
use Codestriker::Http::Method::AddCommentMethod;
use Codestriker::Http::Method::CreateCommentMethod;
@@ -33,6 +34,7 @@
use Codestriker::Http::Method::StaticResourcesMethod;
use Codestriker::Http::Method::ViewMetricsMethod;
use Codestriker::Http::Method::UpdateTopicStateMethod;
+use Codestriker::Http::Method::AddProjectMethod;
# Initialise all of the methods that are known to the system.
# TODO: add configuration to the parameter.
@@ -58,6 +60,7 @@
push @methods, Codestriker::Http::Method::AddTopicMethod->new($query);
push @methods, Codestriker::Http::Method::CreateProjectMethod->new($query);
push @methods, $self->{create_topic_method};
+ push @methods, Codestriker::Http::Method::DownloadTopicTextMethod->new($query);
push @methods, Codestriker::Http::Method::DownloadMetricsMethod->new($query);
push @methods, Codestriker::Http::Method::EditProjectMethod->new($query);
push @methods, Codestriker::Http::Method::ListProjectsMethod->new($query);
@@ -66,6 +69,7 @@
push @methods, Codestriker::Http::Method::StaticResourcesMethod->new($query);
push @methods, Codestriker::Http::Method::ViewMetricsMethod->new($query);
push @methods, Codestriker::Http::Method::UpdateTopicStateMethod->new($query);
+ push @methods, Codestriker::Http::Method::AddProjectMethod->new($query);
$self->{methods} = \@methods;
return bless $self, $type;
Index: UrlBuilder.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/UrlBuilder.pm,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- UrlBuilder.pm 18 Aug 2008 11:11:28 -0000 1.43
+++ UrlBuilder.pm 26 Aug 2008 22:18:50 -0000 1.44
@@ -43,6 +43,7 @@
use Codestriker::Http::Method::AddTopicMethod;
use Codestriker::Http::Method::CreateProjectMethod;
use Codestriker::Http::Method::DownloadMetricsMethod;
+use Codestriker::Http::Method::DownloadTopicTextMethod;
use Codestriker::Http::Method::EditProjectMethod;
use Codestriker::Http::Method::ListProjectsMethod;
use Codestriker::Http::Method::SearchTopicsMethod;
@@ -96,17 +97,7 @@
# Create the URL for downloading the topic text.
sub download_url {
my ($self, %args) = @_;
-
- # TODO: handle this as parameter to view topic text.
-
- die "Parameter topicid missing" unless defined $args{topicid};
- die "Parameter projectid missing" unless defined $args{projectid};
-
- if ($self->{cgi_style}) {
- return $self->{url_prefix} . "?action=download&topic=$args{topicid}";
- } else {
- return $self->{url_prefix} . "/project/$args{projectid}/topic/$args{topicid}/download/text";
- }
+ return Codestriker::Http::Method::DownloadTopicTextMethod->new($self->{query})->url(%args);
}
# Create the URL for creating a topic.
Index: add-project.t
===================================================================
RCS file: add-project.t
diff -N add-project.t
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ add-project.t 26 Aug 2008 22:18:51 -0000 1.1
@@ -0,0 +1,23 @@
+# Tests for the AddProject method.
+
+use strict;
+use Test::More tests => 2;
+
+use lib '../../../lib';
+use Test::MockObject;
+use Codestriker;
+use Codestriker::Http::Method::AddProjectMethod;
+
+# Create a CGI mock object for these tests.
+my $mock_query = Test::MockObject->new();
+$mock_query->mock('url',
+ sub { 'http://localhost.localdomain/codestriker/codestriker.pl' } );
+
+# Create two method objects to test each URL scheme.
+my $url_cgi = Codestriker::Http::Method::AddProjectMethod->new($mock_query, 1);
+my $url_nice = Codestriker::Http::Method::AddProjectMethod->new($mock_query, 0);
+
+is($url_cgi->url(), $mock_query->url() . '?action=submit_project',
+ "Add project URL CGI syntax");
+is($url_nice->url(), $mock_query->url() . '/admin/projects/add',
+ "Add project URL nice syntax");
Index: download-topic-text.t
===================================================================
RCS file: download-topic-text.t
diff -N download-topic-text.t
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ download-topic-text.t 26 Aug 2008 22:18:51 -0000 1.1
@@ -0,0 +1,38 @@
+# Tests for the DownloadTopicText method.
+
+use strict;
+use Test::More tests => 4;
+
+use lib '../../../lib';
+use Test::MockObject;
+use Codestriker;
+use Codestriker::Http::Method::DownloadTopicTextMethod;
+
+# Create a CGI mock object for these tests.
+my $mock_query = Test::MockObject->new();
+$mock_query->mock('url',
+ sub { 'http://localhost.localdomain/codestriker/codestriker.pl' } );
+
+# Create two method objects to test each URL scheme.
+my $url_cgi = Codestriker::Http::Method::DownloadTopicTextMethod->new($mock_query, 1);
+my $url_nice = Codestriker::Http::Method::DownloadTopicTextMethod->new($mock_query, 0);
+
+is($url_cgi->url(topicid => 1234, projectid => 10),
+ $mock_query->url() . '?action=download&topic=1234',
+ "Download topic text URL CGI syntax");
+
+is($url_nice->url(topicid => 1234, projectid => 10),
+ $mock_query->url() . '/project/10/topic/1234/download',
+ "Download topic text URL nice syntax");
+
+# Check that the parameters extracted correctly.
+my $mock_http_input = Test::MockObject->new();
+$mock_http_input->{query} = $mock_query;
+$mock_query->mock('path_info',
+ sub {
+ return $mock_query->url() . '/project/10/topic/1234/download';
+ });
+$mock_query->mock('param', sub { return undef; });
+$url_nice->extract_parameters($mock_http_input);
+is ($mock_http_input->{projectid}, "10", "project nice URL parameter extraction");
+is ($mock_http_input->{topicid}, "1234", "topicid nice URL parameter extraction");
Index: ListProjectsMethod.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method/ListProjectsMethod.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ListProjectsMethod.pm 10 Aug 2008 12:18:42 -0000 1.1
+++ ListProjectsMethod.pm 26 Aug 2008 22:18:51 -0000 1.2
@@ -30,7 +30,7 @@
my $action = $http_input->{query}->param('action');
my $path_info = $http_input->{query}->path_info();
- if ($self->{cgi_style} && defined $action && $action eq "list_project") {
+ if ($self->{cgi_style} && defined $action && $action eq "list_projects") {
$http_input->extract_cgi_parameters();
return 1;
} elsif ($path_info =~ m{^$self->{url_prefix}/admin/projects/list$}) {
Index: DownloadTopicTextMethod.pm
===================================================================
RCS file: DownloadTopicTextMethod.pm
diff -N DownloadTopicTextMethod.pm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DownloadTopicTextMethod.pm 26 Aug 2008 22:18:51 -0000 1.1
@@ -0,0 +1,56 @@
+###############################################################################
+# Codestriker: Copyright (c) 2001, 2002 David Sitsky. All rights reserved.
+# si...@us...
+#
+# This program is free software; you can redistribute it and modify it under
+# the terms of the GPL.
+
+# Method for downloading the topic text.
+
+package Codestriker::Http::Method::DownloadTopicTextMethod;
+
+use strict;
+use Carp;
+use Codestriker::Http::Method;
+
+@Codestriker::Http::Method::DownloadTopicTextMethod::ISA =
+ ("Codestriker::Http::Method");
+
+# Generate a URL for this method.
+sub url() {
+ my ($self, %args) = @_;
+
+ confess "Parameter topicid missing" unless defined $args{topicid};
+
+ if ($self->{cgi_style}) {
+ return $self->{url_prefix} . "?action=download&topic=$args{topicid}";
+ } else {
+ confess "Parameter projectid missing" unless defined $args{projectid};
+ return $self->{url_prefix} . "/project/$args{projectid}/topic/$args{topicid}/download";
+ }
+}
+
+sub extract_parameters {
+ my ($self, $http_input) = @_;
+
+ my $action = $http_input->{query}->param('action');
+ my $path_info = $http_input->{query}->path_info();
+ if ($self->{cgi_style} && defined $action && $action eq "download") {
+ $http_input->extract_cgi_parameters();
+ return 1;
+ } elsif ($path_info =~ m{^$self->{url_prefix}/project/\d+/topic/\d+/download}) {
+ $self->_extract_nice_parameters($http_input,
+ project => 'projectid', topic => 'topicid');
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+sub execute {
+ my ($self, $http_input, $http_output) = @_;
+
+ Codestriker::Action::DownloadTopic->process($http_input, $http_output);
+}
+
+1;
Index: AddProjectMethod.pm
===================================================================
RCS file: AddProjectMethod.pm
diff -N AddProjectMethod.pm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ AddProjectMethod.pm 26 Aug 2008 22:18:51 -0000 1.1
@@ -0,0 +1,49 @@
+###############################################################################
+# Codestriker: Copyright (c) 2001, 2002 David Sitsky. All rights reserved.
+# si...@us...
+#
+# This program is free software; you can redistribute it and modify it under
+# the terms of the GPL.
+
+# Method for adding a new project.
+
+package Codestriker::Http::Method::AddProjectMethod;
+
+use strict;
+use Codestriker::Http::Method;
+
+@Codestriker::Http::Method::AddProjectMethod::ISA = ("Codestriker::Http::Method");
+
+# Generate a URL for this method.
+sub url() {
+ my ($self, %args) = @_;
+
+ if ($self->{cgi_style}) {
+ return $self->{url_prefix} . "?action=submit_project";
+ } else {
+ return $self->{url_prefix} . "/admin/projects/add";
+ }
+}
+
+sub extract_parameters {
+ my ($self, $http_input) = @_;
+
+ my $action = $http_input->{query}->param('action');
+ my $path_info = $http_input->{query}->path_info();
+ if ($self->{cgi_style} && defined $action && $action eq "submit_project") {
+ $http_input->extract_cgi_parameters();
+ return 1;
+ } elsif ($path_info =~ m{^$self->{url_prefix}/admin/projects/add}) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+sub execute {
+ my ($self, $http_input, $http_output) = @_;
+
+ Codestriker::Action::SubmitNewProject->process($http_input, $http_output);
+}
+
+1;
|