require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'rid/design_document' describe "Attachments" do before do @doc = Rid::DesignDocument.new end describe "map" do describe "_attachments encoding and content_type" do it "should proper encode and add plain text content type" do @doc.hash = { "_attachments" => { "key" => "value" } } @doc.map_attachments! @doc.hash.should == { "_attachments" => { "key" => { "data" => "dmFsdWU=", "content_type" => "text/plain" } } } end it "should proper encode and add html content type" do @doc.hash = { "_attachments" => { "key.html" => "value" } } @doc.map_attachments! @doc.hash.should == { "_attachments" => { "key.html" => { "data" => "dmFsdWU=", "content_type" => "text/html" } } } end it "should proper map nested attachments" do @doc.hash = { "_attachments" => { "hash" => { "key" => "value" } } } @doc.map_attachments! @doc.hash.should == { "_attachments" => { "hash/key" => { "data" => "dmFsdWU=", "content_type" => "text/plain" } } } end end end describe "reduce" do it "should decode _attachments data" do @doc.hash = { "_attachments" => { "key" => { "data" => "dmFsdWU=" } } } @doc.reduce_attachments! @doc.hash.should == { "_attachments" => { "key" => "value" } } end end end