summaryrefslogtreecommitdiff
path: root/scripts/post_to_hook.pl
diff options
context:
space:
mode:
authorJonathan "Duke" Leto <jonathan@leto.net>2011-05-22 21:02:23 -0700
committerJonathan "Duke" Leto <jonathan@leto.net>2011-05-22 21:02:23 -0700
commit84147ee6d4a5d53d93f4a73300a192f854eb1ccd (patch)
tree883782c9efc36d21f1efbc19bb4f593ca9e5a9d8 /scripts/post_to_hook.pl
parentRemove dep on Git::Repository (diff)
parentMake hook test data refer to the new git repo for testing (diff)
downloadjitterbug-84147ee6d4a5d53d93f4a73300a192f854eb1ccd.tar.gz
Merge branch 'master' into git_refactor
Diffstat (limited to 'scripts/post_to_hook.pl')
-rw-r--r--scripts/post_to_hook.pl57
1 files changed, 57 insertions, 0 deletions
diff --git a/scripts/post_to_hook.pl b/scripts/post_to_hook.pl
new file mode 100644
index 0000000..55d3d73
--- /dev/null
+++ b/scripts/post_to_hook.pl
@@ -0,0 +1,57 @@
+use strict;
+use warnings;
+
+use jitterbug;
+use jitterbug::Schema;
+
+use JSON;
+use YAML qw/LoadFile Dump/;
+
+use File::Temp qw/tempdir/;
+
+use Dancer::Test;
+use Dancer::Config qw/setting/;
+use File::Spec::Functions;
+
+my $content = LoadFile(shift || catfile(qw/t data hook_data.yml/));
+
+my $db_file = catfile( qw/t data jitterbug.db/ );
+my $dsn = 'dbi:SQLite:dbname=' . $db_file;
+my $schema = jitterbug::Schema->connect($dsn);
+# assume we have a deployed schema
+# $schema->deploy;
+
+setting plugins => {
+ DBIC => {
+ schema => {
+ skip_automake => 1,
+ pckg => "jitterbug::Schema",
+ connect_info => [$dsn]
+ }
+ }
+};
+
+{
+ my $response = dancer_response(
+ POST => '/hook/',
+ {
+ headers =>
+ [ 'Content-Type' => 'application/x-www-form-urlencoded' ],
+ body => _generate_post_request($content),
+ }
+ );
+
+ printf "Response was: %s\n", $response->{status};
+}
+
+sub _generate_post_request {
+ my $content = shift;
+ my $payload = "payload=" . JSON::encode_json($content);
+ open my $in, '<', \$payload;
+
+ $ENV{'CONTENT_LENGTH'} = length($payload);
+ $ENV{'CONTENT_TYPE'} = 'application/x-www-form-urlencoded';
+ $ENV{'psgi.input'} = $in;
+ return $payload;
+}
+