Bugzilla – Attachment 10478 Details for
Bug 8309
Koha namespace organisation, first implementation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
DBIx::Class Branch.pm, first try
DBIxClass-Branchpm-first-try.patch (text/plain), 2.61 KB, created by
Paul Poulain
on 2012-06-25 13:06:17 UTC
(
hide
)
Description:
DBIx::Class Branch.pm, first try
Filename:
MIME Type:
Creator:
Paul Poulain
Created:
2012-06-25 13:06:17 UTC
Size:
2.61 KB
patch
obsolete
>From b9a44b7fc7cbc27de21b01ff0fc735995d4ec76e Mon Sep 17 00:00:00 2001 >From: Paul Poulain <paul.poulain@biblibre.com> >Date: Mon, 11 Jun 2012 15:45:31 +0200 >Subject: [PATCH] DBIx::Class Branch.pm, first try > >This package, and the test implement CRUD for Branches table. >Very basic, but proves we can do many things in a few lines ! > >http://bugs.koha-community.org/show_bug.cgi?id=8309 >--- > Koha/DB/Branch.pm | 36 ++++++++++++++++++++++++++ > t/db_dependent/lib/KohaTest/Koha/DB/Branch.t | 27 +++++++++++++++++++ > 2 files changed, 63 insertions(+) > create mode 100644 Koha/DB/Branch.pm > create mode 100755 t/db_dependent/lib/KohaTest/Koha/DB/Branch.t > >diff --git a/Koha/DB/Branch.pm b/Koha/DB/Branch.pm >new file mode 100644 >index 0000000..bf3b9d7 >--- /dev/null >+++ b/Koha/DB/Branch.pm >@@ -0,0 +1,36 @@ >+package Koha::DB::Branch; >+ >+use Modern::Perl; >+use C4::Context; #FIXME = create a Koha package for KOHA_CONF reading >+ >+use Koha::Schema; >+ >+use Moose; >+ >+my $schema = Koha::Schema->connect( >+ 'dbi:mysql:dbname='.C4::Context->config("database"), >+ C4::Context->config("user"), >+ C4::Context->config("pass"), >+ { AutoCommit => 1 }, >+ ); >+ >+sub create { >+ my ($self, $branch) = @_; >+ $schema->resultset('Branch')->create($branch); >+} >+ >+sub read { >+ my ($self, $branch) = @_; >+ return $schema->resultset('Branch')->search($branch); >+} >+ >+sub update { >+ my ($self, $branch) = @_; >+ return $schema->resultset('Branch')->search({branchcode => $branch->{branchcode}})->update($branch); >+} >+ >+sub delete { >+ my ($self,$branch) = @_; >+ $schema->resultset('Branch')->search($branch)->delete; >+} >+ >diff --git a/t/db_dependent/lib/KohaTest/Koha/DB/Branch.t b/t/db_dependent/lib/KohaTest/Koha/DB/Branch.t >new file mode 100755 >index 0000000..50dd221 >--- /dev/null >+++ b/t/db_dependent/lib/KohaTest/Koha/DB/Branch.t >@@ -0,0 +1,27 @@ >+#!/usr/bin/perl >+ >+use v5.10.0; >+use Modern::Perl; >+ >+use Test::More tests => 5; >+ >+BEGIN { >+ use_ok('Koha::DB::Branch', 'Loading Koha::DB::Branch OK'); >+} >+ >+# open a handler to the branch >+my $branch = Koha::DB::Branch->new(); >+ >+# CREATE >+ok($branch->create({'branchcode' => 'TEST','branchname' => 'TEST NAME'})->id eq 'TEST','Creating a branch OK'); >+ >+# READ >+ok(my $branch_f = $branch->read({'branchcode' => 'TEST'})->first->branchname eq 'TEST NAME','Reading a branch OK'); >+ >+# UPDATE >+$branch->update({'branchcode' => 'TEST','branchname' => 'TEST UPDATED'}); >+ok($branch_f = $branch->read({'branchcode' => 'TEST'})->first->branchname eq 'TEST UPDATED','Updating a branch OK'); >+ >+# DELETE >+ok($branch->delete({'branchcode' => 'TEST'}),'Deleting a branch OK'); >+ >-- >1.7.9.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 8309
:
10473
|
10474
|
10475
|
10476
|
10477
| 10478