Skip to content
This repository
Browse code

Added (simple) test for user creation.

  • Loading branch information...
commit 6e7ea9fcba134b2b636364571d60bd0989f2a9a1 1 parent 9c37b98
Dave Cross authored January 29, 2014
47  t/Test/Lystyng/Schema/Result/User.pm
... ...
@@ -0,0 +1,47 @@
  1
+package Test::Lystyng::Schema::Result::User;
  2
+
  3
+use base qw(Test::Class);
  4
+use Test::More;
  5
+use Moose;
  6
+
  7
+use Lystyng::Schema;
  8
+
  9
+has schema => (
  10
+  is      => 'rw',
  11
+  isa     => 'Lystyng::Schema',
  12
+  lazy    => 1,
  13
+  builder => '_build_schema',
  14
+);
  15
+
  16
+sub _build_schema {
  17
+  my @errors;
  18
+  foreach (qw[LYSTYNG_DB_SERVER LYSTYNG_DB_NAME
  19
+              LYSTYNG_DB_USER LYSTYNG_DB_PASS]) {
  20
+    push @errors, $_ unless defined $ENV{$_};
  21
+  }
  22
+
  23
+  if (@errors) {
  24
+    BAIL_OUT("Missing connection info: @errors");
  25
+  }
  26
+
  27
+  return Lystyng::Schema->connect(
  28
+    "dbi:mysql:hostname=$ENV{LYSTYNG_DB_SERVER};database=$ENV{LYSTYNG_DB_NAME}",
  29
+    $ENV{LYSTYNG_DB_USER}, $ENV{LYSTYNG_DB_PASS}
  30
+  );
  31
+}
  32
+
  33
+sub create : Tests {
  34
+  my $self = shift;
  35
+
  36
+  my $user_rs = $self->schema->resultset('User');
  37
+  my $user = $user_rs->create({
  38
+    username => 'user',
  39
+    password => 'pass',
  40
+    email    => 'user@example.com',
  41
+  });
  42
+
  43
+  ok($user, 'Got a user');
  44
+  isa_ok($user, 'Lystyng::Schema::Result::User');
  45
+}
  46
+
  47
+1;
1  t/tests.t
@@ -3,5 +3,6 @@
3 3
 use lib 't';
4 4
 use Test::Class;
5 5
 use Test::Lystyng::Schema;
  6
+use Test::Lystyng::Schema::Result::User;
6 7
 
7 8
 Test::Class->runtests;

0 notes on commit 6e7ea9f

Please sign in to comment.
Something went wrong with that request. Please try again.