From 9d9fad77a0efb4dc712a04ff69a3191115ed8008 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 23 Apr 2012 14:33:14 +0200 Subject: [PATCH] Set index headers for user id in Riak --- lib/remote_storage/riak.rb | 1 + spec/riak_spec.rb | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/remote_storage/riak.rb b/lib/remote_storage/riak.rb index be149f3..ab03cda 100644 --- a/lib/remote_storage/riak.rb +++ b/lib/remote_storage/riak.rb @@ -27,6 +27,7 @@ module RemoteStorage object = client.bucket("user_data").new("#{user}:#{category}:#{key}") object.content_type = "text/plain; charset=utf-8" object.data = data + object.indexes.merge!({:user_id_bin => [user]}) object.store rescue ::Riak::HTTPFailedRequest halt 422 diff --git a/spec/riak_spec.rb b/spec/riak_spec.rb index 138963a..66dee69 100644 --- a/spec/riak_spec.rb +++ b/spec/riak_spec.rb @@ -9,7 +9,11 @@ describe "App with Riak backend" do end def storage_client - ::Riak::Client.new(settings.riak_config) + @storage_client ||= ::Riak::Client.new(settings.riak_config) + end + + def data_bucket + @data_bucket ||= storage_client.bucket("user_data") end describe "GET public data" do @@ -76,11 +80,16 @@ describe "App with Riak backend" do it "saves the value" do last_response.status.must_equal 200 - storage_client.bucket("user_data").get("jimmy:documents:bar").data.must_equal "another text" + data_bucket.get("jimmy:documents:bar").data.must_equal "another text" end it "stores the data as plain text with utf-8 encoding" do - storage_client.bucket("user_data").get("jimmy:documents:bar").content_type.must_equal "text/plain; charset=utf-8" + data_bucket.get("jimmy:documents:bar").content_type.must_equal "text/plain; charset=utf-8" + end + + it "indexes the data set" do + data_bucket.get("jimmy:documents:bar").indexes["user_id_bin"].must_be_kind_of Set + data_bucket.get("jimmy:documents:bar").indexes["user_id_bin"].must_include "jimmy" end end