Thread: [Codestriker-commits] CVS update: codestriker/t/Http/Method update-topic-properties.t view-topic-pr
Brought to you by:
sits
|
From: <si...@us...> - 2008-08-18 11:20:02
|
User: sits
Date: 08/08/18 04:19:59
Modified: lib/Codestriker/Http Dispatcher.pm
lib/Codestriker/Http/Method ViewTopicPropertiesMethod.pm
t/Http/Method view-topic-properties.t
Added: lib/Codestriker/Http/Method UpdateTopicPropertiesMethod.pm
t/Http/Method update-topic-properties.t
Log:
Support updating topic properties.
Index: Dispatcher.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Dispatcher.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Dispatcher.pm 18 Aug 2008 11:11:28 -0000 1.3
+++ Dispatcher.pm 18 Aug 2008 11:19:58 -0000 1.4
@@ -20,6 +20,7 @@
use Codestriker::Http::Method::ViewTopicFileMethod;
use Codestriker::Http::Method::ViewTopicMetricsMethod;
use Codestriker::Http::Method::ViewTopicPropertiesMethod;
+use Codestriker::Http::Method::UpdateTopicPropertiesMethod;
use Codestriker::Http::Method::AddCommentMethod;
use Codestriker::Http::Method::CreateCommentMethod;
use Codestriker::Http::Method::AddTopicMethod;
@@ -49,6 +50,7 @@
push @methods, Codestriker::Http::Method::ViewTopicFileMethod->new($query);
push @methods, Codestriker::Http::Method::ViewTopicMetricsMethod->new($query);
push @methods, Codestriker::Http::Method::ViewTopicPropertiesMethod->new($query);
+ push @methods, Codestriker::Http::Method::UpdateTopicPropertiesMethod->new($query);
push @methods, $self->{list_topics_method};
push @methods, Codestriker::Http::Method::CreateCommentMethod->new($query);
push @methods, Codestriker::Http::Method::AddCommentMethod->new($query);
Index: ViewTopicPropertiesMethod.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method/ViewTopicPropertiesMethod.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ViewTopicPropertiesMethod.pm 10 Aug 2008 12:18:42 -0000 1.1
+++ ViewTopicPropertiesMethod.pm 18 Aug 2008 11:19:59 -0000 1.2
@@ -24,7 +24,7 @@
if ($self->{cgi_style}) {
return $self->{url_prefix} . "?action=view_topic_properties&topic=$args{topicid}";
} else {
- return $self->{url_prefix} . "/project/$args{projectid}/topic/$args{topicid}/properties";
+ return $self->{url_prefix} . "/project/$args{projectid}/topic/$args{topicid}/properties/view";
}
}
@@ -36,7 +36,7 @@
if ($self->{cgi_style} && defined $action && $action eq "view_topic_properties") {
$http_input->extract_cgi_parameters();
return 1;
- } elsif ($path_info =~ m{^$self->{url_prefix}/project/\d+/topic/\d+/properties}) {
+ } elsif ($path_info =~ m{^$self->{url_prefix}/project/\d+/topic/\d+/properties/view}) {
$self->_extract_nice_parameters($http_input,
project => 'projectid', topic => 'topicid');
return 1;
Index: UpdateTopicPropertiesMethod.pm
===================================================================
RCS file: UpdateTopicPropertiesMethod.pm
diff -N UpdateTopicPropertiesMethod.pm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ UpdateTopicPropertiesMethod.pm 18 Aug 2008 11:19:59 -0000 1.1
@@ -0,0 +1,54 @@
+###############################################################################
+# 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 viewing the topic properties.
+
+package Codestriker::Http::Method::UpdateTopicPropertiesMethod;
+
+use strict;
+use Carp;
+use Codestriker::Http::Method;
+
+@Codestriker::Http::Method::UpdateTopicPropertiesMethod::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_edit_topic_properties&topic=$args{topicid}";
+ } else {
+ confess "Parameter topicid missing" unless defined $args{topicid};
+ confess "Parameter projectid missing" unless defined $args{projectid};
+ return $self->{url_prefix} . "/project/$args{projectid}/topic/$args{topicid}/properties/update";
+ }
+}
+
+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 "edit_topic_properties") {
+ $http_input->extract_cgi_parameters();
+ return 1;
+ } elsif ($path_info =~ m{^$self->{url_prefix}/project/\d+/topic/\d+/properties}) {
+ $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::SubmitEditTopicProperties->process($http_input, $http_output);
+}
+
+1;
Index: view-topic-properties.t
===================================================================
RCS file: /cvsroot/codestriker/codestriker/t/Http/Method/view-topic-properties.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- view-topic-properties.t 10 Aug 2008 12:18:42 -0000 1.1
+++ view-topic-properties.t 18 Aug 2008 11:19:59 -0000 1.2
@@ -22,7 +22,7 @@
"View topic properties URL CGI syntax");
is($url_nice->url(topicid => 1234, projectid => 10),
- $mock_query->url() . '/project/10/topic/1234/properties',
+ $mock_query->url() . '/project/10/topic/1234/properties/view',
"View topic properties URL nice syntax");
# Check that the parameters extracted correctly.
@@ -30,7 +30,7 @@
$mock_http_input->{query} = $mock_query;
$mock_query->mock('path_info',
sub {
- return $mock_query->url() . '/project/10/topic/1234/properties';
+ return $mock_query->url() . '/project/10/topic/1234/properties/view';
});
$mock_query->mock('param', sub { return undef; });
$url_nice->extract_parameters($mock_http_input);
Index: update-topic-properties.t
===================================================================
RCS file: update-topic-properties.t
diff -N update-topic-properties.t
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ update-topic-properties.t 18 Aug 2008 11:19:59 -0000 1.1
@@ -0,0 +1,40 @@
+# Tests for the UpdateTopicProperties method.
+
+use strict;
+use Test::More tests => 4;
+
+use lib '../../../lib';
+use Test::MockObject;
+use Codestriker;
+use Codestriker::Http::Method::UpdateTopicPropertiesMethod;
+
+# 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::UpdateTopicPropertiesMethod->new($mock_query, 1);
+my $url_nice = Codestriker::Http::Method::UpdateTopicPropertiesMethod->new($mock_query, 0);
+
+is($url_cgi->url(topicid => 1234, projectid => 10),
+ $mock_query->url() . '?action=submit_edit_topic_properties&topic=1234',
+ "Update topic properties URL CGI syntax");
+
+is($url_nice->url(topicid => 1234, projectid => 10),
+ $mock_query->url() . '/project/10/topic/1234/properties/update',
+ "Update topic properties 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/properties/update';
+ });
+$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");
+
+
\ No newline at end of file
|