summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-06-16 14:28:55 +0200
committerfranck cuny <franck@lumberjaph.net>2010-06-16 14:28:55 +0200
commit97db9ec02dd488556156ec9c70b6b38228dd85ab (patch)
tree168f79fdb4f71f660bb1923f2ba772cf337ee43c
parentmore tests - properties (diff)
downloadnet-riak-97db9ec02dd488556156ec9c70b6b38228dd85ab.tar.gz
croak on error while updating properties; use json::{false,true} for allow_mult
-rw-r--r--lib/Net/Riak/Bucket.pm16
-rw-r--r--t/01_basic.t6
2 files changed, 11 insertions, 11 deletions
diff --git a/lib/Net/Riak/Bucket.pm b/lib/Net/Riak/Bucket.pm
index 66e998e..e213cb9 100644
--- a/lib/Net/Riak/Bucket.pm
+++ b/lib/Net/Riak/Bucket.pm
@@ -4,6 +4,7 @@ package Net::Riak::Bucket;
 
 use JSON;
 use Moose;
+use Carp;
 use Net::Riak::Object;
 
 with 'Net::Riak::Role::Replica' => {keys => [qw/r w dw/]};
@@ -33,9 +34,10 @@ sub n_val {
 
 sub allow_multiples {
     my $self = shift;
-    # XXX use JSON::false / true ?
+
     if (my $val = shift) {
-        $self->set_property('allow_mult', $val);
+        my $bool = ($val == 1 ? JSON::true : JSON::false);
+        $self->set_property('allow_mult', $bool);
     }
     else {
         return $self->get_property('allow_mult');
@@ -98,12 +100,8 @@ sub set_properties {
     $request->content(JSON::encode_json({props => $props}));
     my $response = $self->client->useragent->request($request);
 
-    if (!$response->is_success) {
-        # XXX
-    }
-
-    if ($response->code != 204) {
-        # XXX
+    if (!$response->is_success || $response->code != 204) {
+        croak "Error setting bucket properties.";
     }
 }
 
@@ -184,7 +182,7 @@ Get/set the N-value for this bucket, which is the number of replicas that will b
 
 =method allow_multiples
 
-    my $allow_mul = $bucket->allow_multiples;
+    $bucket->allow_multiples(1|0);
 
 If set to True, then writes with conflicting data will be stored and returned to the client. This situation can be detected by calling has_siblings() and get_siblings(). This should only be used if you know what you are doing.
 
diff --git a/t/01_basic.t b/t/01_basic.t
index a17f425..799f000 100644
--- a/t/01_basic.t
+++ b/t/01_basic.t
@@ -60,11 +60,13 @@ my $bucket_multi = 'multiBucket2';
 {
     my $client = Net::Riak->new();
     my $bucket = $client->bucket($bucket_name);
-    $bucket->allow_multiples('True');
+    $bucket->allow_multiples(1);
+    my $props = $bucket->get_properties;
     my $res = $bucket->allow_multiples;
     $bucket->n_val(3);
     is $bucket->n_val, 3, 'n_val is set to 3';
-    $bucket->set_properties({allow_mult => "False", "n_val" => 2});
+    $bucket->set_properties({allow_mult => 0, "n_val" => 2});
+    $res = $bucket->allow_multiples;
     ok !$bucket->allow_multiples, "don't allow multiple anymore";
     is $bucket->n_val, 2, 'n_val is set to 2';
 }