spec/rid/design_document_spec.rb in rid-0.3.0 vs spec/rid/design_document_spec.rb in rid-0.3.1

- old
+ new

@@ -4,10 +4,11 @@ describe "DesignDocument" do before do @doc = Rid::DesignDocument.new end + describe "read" do it "should assign key-value pair" do @doc.read("key") do |filename| "value" end @@ -40,33 +41,11 @@ "value" end @doc.hash.should == { "hash" => { "hash" => { "key" => "value" } } } end - describe "_attachments encoding and content_type" do - it "should proper encode and add plain text content type" do - @doc.read("_attachments/key") do |filename| - "value" - end - @doc.hash.should == { "_attachments" => { "key" => { "data" => "dmFsdWU=", "content_type" => "text/plain" } } } - end - it "should proper encode and add html content type" do - @doc.read("_attachments/key.html") do |filename| - "value" - end - @doc.hash.should == { "_attachments" => { "key.html" => { "data" => "dmFsdWU=", "content_type" => "text/html" } } } - end - - it "should proper encode nested keys" do - @doc.read("_attachments/hash/key") do |filename| - "value" - end - @doc.hash.should == { "_attachments" => { "hash/key" => { "data" => "dmFsdWU=", "content_type" => "text/plain" } } } - end - end - describe "exclude files should not be mapped" do it "should not map README" do @doc.read("README") do |filename| "value" end @@ -94,153 +73,63 @@ "value" end @doc.hash.should == { "views" => { "my_view" => { "map" => "value" } } } end end - - describe "code makro" do - it "should expand code" do - idx = 0 - @doc.read("key", "lib/code.js") do |filename| - case idx += 1 - when 1 - "// !code code.js" - when 2 - "value" - end - end - @doc.hash.should == { "key" => "value", "lib" => { "code.js" => "value" } } - end - end - - describe "json makro" do - it "should expand json" do - idx = 0 - @doc.read("key", "lib/json.json") do |filename| - case idx += 1 - when 1 - "// !json json.json" - when 2 - "value" - end - end - @doc.hash.should == { "key" => "var json = \"value\";", "lib" => { "json.json" => "value" } } - end - end end + describe "write" do it "should return key-value pair" do @doc.hash = { "key" => "value" } - filename, content = nil, nil @doc.write do |key, value| - filename, content = key, value + key.should == "key" + value.should == "value" end - filename.should == "key" - content.should == "value" end it "should return subdirectory for nested hash" do @doc.hash = { "hash" => { "key" => "value" } } - filename, content = nil, nil @doc.write do |key, value| - filename, content = key, value + key.should == "hash/key" + value.should == "value" end - filename.should == "hash/key" - content.should == "value" end it "should return subdirectory for nested hash" do @doc.hash = { "hash" => { "hash" => { "key" => "value" } } } - filename, content = nil, nil @doc.write do |key, value| - filename, content = key, value + key.should == "hash/hash/key" + value.should == "value" end - filename.should == "hash/hash/key" - content.should == "value" end - it "should return decoded _attachments data" do - @doc.hash = { "_attachments" => { "key" => { "data" => "dmFsdWU=" } } } - filename, content = nil, nil - @doc.write do |key, value| - filename, content = key, value - end - filename.should == "_attachments/key" - content.should == "value" - end - describe "javascript extensions" do it "should append validate_doc_update" do @doc.hash = { "validate_doc_update" => "value" } - filename = nil @doc.write do |key, value| - filename = key + key.should == "validate_doc_update.js" end - filename.should == "validate_doc_update.js" end it "should append lists/my_list" do @doc.hash = { "lists" => { "my_list" => "value" } } - filename = nil @doc.write do |key, value| - filename = key + key.should == "lists/my_list.js" end - filename.should == "lists/my_list.js" end it "should append views/my_view/map" do @doc.hash = { "views" => { "my_view" => { "map" => "value" } } } - filename = nil @doc.write do |key, value| - filename = key + key.should == "views/my_view/map.js" end - filename.should == "views/my_view/map.js" end end - - describe "code makro" do - it "should reject code" do - @doc.hash = { "key" => "value", "lib" => { "code.js" => "value" } } - content = nil - @doc.write do |key, value| - content = value - end - content.should == "// !code code.js" - end - - it "should reject nested code" do - @doc.hash = { "key" => "value", "lib" => { "hash" => { "code.js" => "value" } } } - content = nil - @doc.write do |key, value| - content = value - end - content.should == "// !code hash/code.js" - end - end - - describe "json makro" do - it "should reject json" do - @doc.hash = { "key" => "var json = \"value\";", "lib" => { "json.json" => "value" } } - content = nil - @doc.write do |key, value| - content = value - end - content.should == "// !json json.json" - end - - it "should reject nested json" do - @doc.hash = { "key" => "var json = \"value\";", "lib" => { "hash" => { "json.json" => "value" } } } - content = nil - @doc.write do |key, value| - content = value - end - content.should == "// !json hash/json.json" - end - end end + describe "json" do it "should convert key-value pair" do @doc.hash = { "key" => "value" } @doc.json.should == '{"key":"value"}' end @@ -261,10 +150,11 @@ @doc.json = '{"hash":{"key":"value"}}' @doc.hash.should == { "hash" => { "key" => "value" } } end end + describe "id accessor" do it "should return id from hash" do @doc.hash = { "_id" => "my_id" } @doc.id.should == "my_id" end @@ -299,9 +189,10 @@ it "should return database rid" do Rid.stub!(:database).and_return("my_db") @doc.database.should == "my_db" end end + describe "base url" do it "should combine database and id" do @doc.should_receive(:id).and_return("my_id") @doc.should_receive(:database).and_return("my_db")