[Bps-public-commit] RT-Extension-NHD branch, master, updated. fce47f20858fff5b0ffa8c66f54333e84a90608d
Ruslan Zakirov
ruz at bestpractical.com
Thu Nov 3 17:44:14 EDT 2011
The branch, master has been updated
via fce47f20858fff5b0ffa8c66f54333e84a90608d (commit)
via a352302b3eda0e0171d8633498c81caebc60b994 (commit)
via ff6c8f172687670a8d2e594f1676676cd9236734 (commit)
via 2c0b03bbcab9363677fa4f48a3a0190ca50f30c9 (commit)
via 59e102596ccc2054a61e2784914e0bd66142702d (commit)
via b310e6ec2f5e61e1824a7920add0cc562ad0db58 (commit)
via 455213419b94285cf4c4786c995d5140b690650b (commit)
via 0a53b140f6d6806b40748dbbaae582319ca24437 (commit)
from 8ef50f7f870adaf7115d98a5dfdef238fe5b2fa5 (commit)
Summary of changes:
TODO | 4 --
etc/NHD_Config.pm | 6 ++++
html/Admin/Tools/NHD/Elements/SelectStatus | 6 ++--
lib/RT/Extension/NHD/Test.pm | 44 ++++++++++++++++++++++++----
lib/RT/NHD/Agreement.pm | 13 +++++++-
t/api/agreement.t | 24 ++++++++++++++-
t/web/agreement.t | 30 ++++++++++++++++++-
7 files changed, 109 insertions(+), 18 deletions(-)
- Log -----------------------------------------------------------------
commit 0a53b140f6d6806b40748dbbaae582319ca24437
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Nov 3 16:59:03 2011 +0400
don't intercept request if it's to us
diff --git a/lib/RT/Extension/NHD/Test.pm b/lib/RT/Extension/NHD/Test.pm
index a78b679..422ee1c 100644
--- a/lib/RT/Extension/NHD/Test.pm
+++ b/lib/RT/Extension/NHD/Test.pm
@@ -24,7 +24,10 @@ sub import {
$class->export_to_level(1);
no strict 'subs';
+ my $orig = \&RT::Extension::NHD::SendRequest;
*RT::Extension::NHD::SendRequest = sub {
+ return $orig->(@_) if $_[1] && $_[1]->uri =~ RT->Config->Get('WebDomain');
+
my $self = shift;
push @requests, shift;
return shift @responses;
commit 455213419b94285cf4c4786c995d5140b690650b
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Nov 3 17:27:05 2011 +0400
use files to store requests/responses
we fork server
diff --git a/lib/RT/Extension/NHD/Test.pm b/lib/RT/Extension/NHD/Test.pm
index 422ee1c..c820cfe 100644
--- a/lib/RT/Extension/NHD/Test.pm
+++ b/lib/RT/Extension/NHD/Test.pm
@@ -7,8 +7,6 @@ use lib qw(/opt/rt4/local/lib /opt/rt4/lib);
package RT::Extension::NHD::Test;
use base 'RT::Test';
-my (@requests, @responses);
-
sub import {
my $class = shift;
my %args = @_;
@@ -29,8 +27,8 @@ sub import {
return $orig->(@_) if $_[1] && $_[1]->uri =~ RT->Config->Get('WebDomain');
my $self = shift;
- push @requests, shift;
- return shift @responses;
+ return RT::Extension::NHD::Test->push_object_into_file( 'requests', shift );
+ return RT::Extension::NHD::Test->get_object_from_file( 'responses' );
};
}
@@ -40,7 +38,7 @@ sub new_agent {
return RT::Extension::NHD::Test::Web->new_agent( @_ );
}
-sub remote_requests { return splice @requests }
+sub remote_requests { return RT::Extension::NHD::Test->get_objects_from_file('requests') }
sub set_next_remote_response {
my $self = shift;
@@ -58,9 +56,40 @@ sub set_next_remote_response {
my $content = $args{'Data'};
$content = RT::Extension::NHD->ToJSON( $content )
if ref $content;
- push @responses, HTTP::Response->new(
+ RT::Extension::NHD::Test->push_object_into_file( responses => HTTP::Response->new(
$code, $msg, [%headers], $content,
+ ) );
+ return;
+}
+
+my $magic_string = "\nvery magic string that probably will work just fine\n";
+sub push_object_into_file {
+ my $self = shift;
+ my $type = shift;
+ open my $fh, '>>', $self->temp_directory ."/nhd-${type}-file"
+ or die $!;
+ print $fh $_."$magic_string" foreach map Storable::nfreeze($_), @_;
+ close $fh;
+}
+sub get_object_from_file {
+ my $self = shift;
+ my $type = shift;
+
+ my @list = $self->get_objects_from_file( $type );
+
+ my $res = shift @list;
+ $self->push_object_into_file( $type, @list );
+ return $res;
+}
+sub get_objects_from_file {
+ my $self = shift;
+ my $type = shift;
+
+ my $data = $self->file_content(
+ [$self->temp_directory, "nhd-${type}-file"],
+ unlink => 1
);
+ return map Storable::thaw($_), split /\Q$magic_string/, $data;
}
1;
commit b310e6ec2f5e61e1824a7920add0cc562ad0db58
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Nov 3 17:29:33 2011 +0400
don't rollback if txn is not there, but return error
diff --git a/lib/RT/NHD/Agreement.pm b/lib/RT/NHD/Agreement.pm
index 5a9c6ef..22cddc2 100644
--- a/lib/RT/NHD/Agreement.pm
+++ b/lib/RT/NHD/Agreement.pm
@@ -53,7 +53,7 @@ sub Create {
if ( $we_are eq $by ) {
my ($status, $msg) = $self->Send( 'create' );
return $self->RollbackTransaction( "Couldn't send update to remote host: $msg" )
- if !$status && $self->Handle->TransactionDepth;
+ unless $status;
}
return @rv;
@@ -315,7 +315,7 @@ sub RollbackTransaction {
my $self = shift;
my $msg = shift;
- $RT::Handle->Rollback;
+ $RT::Handle->Rollback if $self->_Handle->TransactionDepth;
$self->LoadByCols( id => $self->id );
commit 59e102596ccc2054a61e2784914e0bd66142702d
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Nov 3 17:30:57 2011 +0400
simple typos in SelectStatus
diff --git a/html/Admin/Tools/NHD/Elements/SelectStatus b/html/Admin/Tools/NHD/Elements/SelectStatus
index 11af030..4940c48 100644
--- a/html/Admin/Tools/NHD/Elements/SelectStatus
+++ b/html/Admin/Tools/NHD/Elements/SelectStatus
@@ -10,12 +10,12 @@ $Name => 'Status'
$Default => undef
</%ARGS>
<%INIT>
-my $current = $agreement->Status;
-my $Default ||= $current;
+my $current = $Agreement->Status;
+$Default ||= $current;
my @statuses;
-my $who_we_are = $agreement->WhoWeAre;
+my $who_we_are = $Agreement->WhoWeAre;
if ( $who_we_are eq 'Receiver' ) {
if ( $current eq 'pending' ) {
$m->out(loc('pending'));
commit 2c0b03bbcab9363677fa4f48a3a0190ca50f30c9
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Nov 3 17:31:21 2011 +0400
expand testing web UI
diff --git a/t/web/agreement.t b/t/web/agreement.t
index 2b32e74..e0cfcca 100644
--- a/t/web/agreement.t
+++ b/t/web/agreement.t
@@ -22,4 +22,27 @@ my $remote_url = 'http://hoster.example.com/sharing';
$m->field( Name => 'Test' );
$m->field( Receiver => $remote_url );
$m->click( 'Create' );
+
+ my $agreement = last_agreement();
+ ok( $agreement && $agreement->id, 'loaded agreement' );
+
+ my @requests = $test->remote_requests;
+ is scalar @requests, 1, 'one outgoing request';
+ is $requests[0]->uri, "$remote_url/agreements/". $agreement->UUID;
+ is $requests[0]->method, "POST";
+ is $requests[0]->header('X-Ticket-Sharing-Version'), 1;
+ is $requests[0]->header('X-Ticket-Sharing-Token'),
+ $agreement->UUID .':'. $agreement->AccessKey;
+ is lc $requests[0]->header('Content-Type'), 'text/x-json; charset="utf-8"';
+ is_deeply(
+ RT::Extension::NHD->FromJSON( $requests[0]->content ),
+ $agreement->ForJSON,
+ );
+}
+
+sub last_agreement {
+ my $agreements = RT::NHD::Agreements->new( RT->SystemUser );
+ $agreements->UnLimit;
+ $agreements->OrderBy(FIELD => 'id', ORDER => 'DESC');
+ return $agreements->First;
}
commit ff6c8f172687670a8d2e594f1676676cd9236734
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Nov 3 23:41:51 2011 +0400
use tranasction during creation
diff --git a/TODO b/TODO
index ee09db2..3a10757 100644
--- a/TODO
+++ b/TODO
@@ -1,8 +1,6 @@
* in Agreement::Create make sure that the following situation
is denined: WhoWeAre == Sender and CurrentUserIs Receiver
-* Transactional Create
-
* When AccessKey changes locally we send wrong auth token
to the other side
** covered with TODO test
diff --git a/lib/RT/NHD/Agreement.pm b/lib/RT/NHD/Agreement.pm
index 22cddc2..f201f8b 100644
--- a/lib/RT/NHD/Agreement.pm
+++ b/lib/RT/NHD/Agreement.pm
@@ -48,7 +48,11 @@ sub Create {
return (undef, "New agreement must have 'pending' status");
}
+ $RT::Handle->BeginTransaction;
+
my @rv = $self->SUPER::Create( %args );
+ return $self->RollbackTransaction( "Couldn't create agreement record: $rv[1]" )
+ unless $rv[0];
if ( $we_are eq $by ) {
my ($status, $msg) = $self->Send( 'create' );
@@ -56,6 +60,8 @@ sub Create {
unless $status;
}
+ $RT::Handle->Commit;
+
return @rv;
}
diff --git a/t/api/agreement.t b/t/api/agreement.t
index b934c5d..9135de7 100644
--- a/t/api/agreement.t
+++ b/t/api/agreement.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use RT::Extension::NHD::Test tests => 55;
+use RT::Extension::NHD::Test tests => 58;
my $test = 'RT::Extension::NHD::Test';
use Digest::SHA1 qw(sha1_hex);
@@ -55,7 +55,7 @@ my $i = 0;
is( $agreement->Receiver, RT->Config->Get('NHD_WebURL'), 'correct value' );
like( $agreement->AccessKey, qr{^[0-9a-f]{40}$}i, 'correct value' );
- is scalar $test->remote_requests, undef, 'no outgoing requests';
+ ok !scalar $test->remote_requests, 'no outgoing requests';
}
# bad status
@@ -139,6 +139,26 @@ my $i = 0;
ok !scalar $test->remote_requests, 'no outgoing requests';
}
+# create with error
+{
+ my $agreement = RT::NHD::Agreement->new( RT::CurrentUser->new( $remote_user ) );
+ my $uuid = sha1_hex( ''. ++$i );
+ my ($id, $msg) = $agreement->Create(
+ UUID => $uuid,
+ Name => 'Test Company',
+ Status => 'booo',
+ Sender => $remote_url,
+ Receiver => RT->Config->Get('NHD_WebURL'),
+ AccessKey => sha1_hex( ''. ++$i ),
+ );
+ ok(!$id, "failed to create agreement");
+
+ $agreement = RT::NHD::Agreement->new( RT->SystemUser );
+ $agreement->Load($uuid);
+ ok !$agreement->id, "no agreement in DB";
+ ok !scalar $test->remote_requests, 'no outgoing requests';
+}
+
# we are sending
{
$test->set_next_remote_response(201);
commit a352302b3eda0e0171d8633498c81caebc60b994
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Nov 3 23:42:36 2011 +0400
fix freezing/thawing req/resp in tests
diff --git a/lib/RT/Extension/NHD/Test.pm b/lib/RT/Extension/NHD/Test.pm
index c820cfe..de2d34a 100644
--- a/lib/RT/Extension/NHD/Test.pm
+++ b/lib/RT/Extension/NHD/Test.pm
@@ -27,8 +27,8 @@ sub import {
return $orig->(@_) if $_[1] && $_[1]->uri =~ RT->Config->Get('WebDomain');
my $self = shift;
- return RT::Extension::NHD::Test->push_object_into_file( 'requests', shift );
- return RT::Extension::NHD::Test->get_object_from_file( 'responses' );
+ __PACKAGE__->push_object_into_file( 'requests', shift );
+ return __PACKAGE__->get_object_from_file( 'responses' );
};
}
@@ -68,7 +68,7 @@ sub push_object_into_file {
my $type = shift;
open my $fh, '>>', $self->temp_directory ."/nhd-${type}-file"
or die $!;
- print $fh $_."$magic_string" foreach map Storable::nfreeze($_), @_;
+ print $fh map Storable::nfreeze($_)."$magic_string", @_;
close $fh;
}
sub get_object_from_file {
@@ -87,9 +87,9 @@ sub get_objects_from_file {
my $data = $self->file_content(
[$self->temp_directory, "nhd-${type}-file"],
- unlink => 1
+ noexist => 1, unlink => 1
);
- return map Storable::thaw($_), split /\Q$magic_string/, $data;
+ return map Storable::thaw($_), grep length, split /\Q$magic_string/, $data;
}
1;
commit fce47f20858fff5b0ffa8c66f54333e84a90608d
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Fri Nov 4 01:30:07 2011 +0400
when we are sharing, free Name for admins
use NHD_Name for remotes
diff --git a/TODO b/TODO
index 3a10757..8084931 100644
--- a/TODO
+++ b/TODO
@@ -5,8 +5,6 @@
to the other side
** covered with TODO test
-* add meaning to Agreement->Name when we're sharing
-
* script that updates remote agreements when Organization or
NHD_WebURL changes.
diff --git a/etc/NHD_Config.pm b/etc/NHD_Config.pm
index 2a53dce..0eb385b 100644
--- a/etc/NHD_Config.pm
+++ b/etc/NHD_Config.pm
@@ -14,6 +14,12 @@ package RT;
Set( $NHD_WebURL, RT->Config->Get('WebURL') . 'NoAuth/NHD/1.0' );
+=item C<$NHD_Name>
+
+=cut
+
+Set( $NHD_Name, RT->Config->Get('Organization') );
+
=back
=cut
diff --git a/lib/RT/NHD/Agreement.pm b/lib/RT/NHD/Agreement.pm
index f201f8b..ec4b7cd 100644
--- a/lib/RT/NHD/Agreement.pm
+++ b/lib/RT/NHD/Agreement.pm
@@ -307,6 +307,9 @@ sub ForJSON {
my %res;
$res{ $FIELDS_MAP{$_} } = $self->$_() foreach @fields;
+ if ( exists $res{'name'} && $self->WhoWeAre eq 'Sender' ) {
+ $res{'name'} = RT->Config->Get('NHD_Name');
+ }
return \%res;
}
diff --git a/t/web/agreement.t b/t/web/agreement.t
index e0cfcca..f6ca09a 100644
--- a/t/web/agreement.t
+++ b/t/web/agreement.t
@@ -7,6 +7,9 @@ use RT::Extension::NHD::Test tests => 18;
my $test = 'RT::Extension::NHD::Test';
use Digest::SHA1 qw(sha1_hex);
+my $org = 'Cool Company Sharing Tickets';
+RT->Config->Set(NHD_Name => $org);
+
$test->started_ok;
my $m = $test->new_agent;
$m->login;
@@ -19,12 +22,14 @@ my $remote_url = 'http://hoster.example.com/sharing';
$m->get_ok('/Admin/Tools/NHD/');
$m->follow_link_ok({text => 'Create Agreement', url_regex => qr{/NHD/}});
$m->form_name('CreateAgreement');
- $m->field( Name => 'Test' );
+ $m->field( Name => 'Evil Hosting We Use' );
$m->field( Receiver => $remote_url );
$m->click( 'Create' );
my $agreement = last_agreement();
ok( $agreement && $agreement->id, 'loaded agreement' );
+ is $agreement->Name, 'Evil Hosting We Use';
+ is $agreement->ForJSON->{name}, $org;
my @requests = $test->remote_requests;
is scalar @requests, 1, 'one outgoing request';
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list