File: | t/record-save.t |
Coverage: | 91.2% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | #!/usr/bin/env perl | ||||||
2 | |||||||
3 | 1 1 1 | 101 10 11 | use strict; | ||||
4 | 1 1 1 | 10 3 10 | use warnings; | ||||
5 | 1 1 1 | 109 5 16 | use Railsish::Database; | ||||
6 | 1 1 1 | 120 8 15 | use Railsish::Record; | ||||
7 | |||||||
8 | { | ||||||
9 | 1 1 1 1 | 6 10 3 7 | no strict; | ||||
10 | 1 1 1 | 9 3 9 | no warnings; | ||||
11 | *Railsish::Database::_build_config = sub { | ||||||
12 | return { | ||||||
13 | 1 | 15 | dsn => "hash", | ||||
14 | user => "", | ||||||
15 | password => "" | ||||||
16 | }; | ||||||
17 | } | ||||||
18 | 1 | 14 | } | ||||
19 | |||||||
20 | package Advertisement; | ||||||
21 | 1 1 1 | 11 3 9 | use Moose; | ||||
22 | # use Any::Moose; | ||||||
23 | 1 1 1 | 15 3 12 | use Any::Moose qw(X::Types::DateTimeX) => ['DateTime']; | ||||
24 | |||||||
25 | 1 | 10 | extends 'Railsish::Record'; | ||||
26 | |||||||
27 | 1 | 19 | has type => ( isa => "Str", is => "ro", required => 1); | ||||
28 | 1 | 48 | has url => ( isa => "Str", is => "rw", required => 1); | ||||
29 | 1 | 44 | has title => ( isa => "Str", is => "rw", required => 1); | ||||
30 | |||||||
31 | 1 | 43 | has start_date => ( isa => DateTime, is => "rw", required => 1, coerce => 1 ); | ||||
32 | 1 | 42 | has end_date => ( isa => DateTime, is => "rw", required => 1, coerce => 1 ); | ||||
33 | |||||||
34 | 1 | 40 | __PACKAGE__->meta->make_immutable; | ||||
35 | |||||||
36 | package main; | ||||||
37 | 1 1 1 | 89 4 20 | use Test::More tests => 1; | ||||
38 | |||||||
39 | 1 | 26 | my $obj = Advertisement->new( | ||||
40 | type => "normal", | ||||||
41 | url => "http://example.com", | ||||||
42 | title => "Example", | ||||||
43 | start_date => "2009/05/08", | ||||||
44 | end_date => "2009/10/08" | ||||||
45 | ); | ||||||
46 | |||||||
47 | |||||||
48 | 1 | 5 | my @titles = (); | ||||
49 | 1 | 15 | $obj->save; | ||||
50 | |||||||
51 | 1 1 | 23 4 | pass; exit; | ||||
52 | |||||||
53 | 0 | 0 | my $stream = Advertisement->find_all; | ||||
54 | 0 | 0 | while (my $block = $stream->next) { | ||||
55 | 0 | 0 | for my $obj (@$block) { | ||||
56 | 0 | 0 | push @titles, $obj->title; | ||||
57 | } | ||||||
58 | } | ||||||
59 | |||||||
60 | 0 | 0 | is_deeply(\@titles, ["Example"]); | ||||
61 |