require File.dirname(__FILE__) + '/spec_helper.rb' describe CouchObject::Utils do it "should join urls" do CouchObject::Utils.join_url("http://x.tld", "foo").should == "http://x.tld/foo" CouchObject::Utils.join_url("http://x.tld", "/foo").should == "http://x.tld/foo" CouchObject::Utils.join_url("http://x.tld/", "/foo").should == "http://x.tld/foo" CouchObject::Utils.join_url("http://x.tld/", "/foo/").should == "http://x.tld/foo/" end it "should join two or more relative urls too" do CouchObject::Utils.join_url("foo", "bar").should == "foo/bar" CouchObject::Utils.join_url("foo/", "/bar").should == "foo/bar" CouchObject::Utils.join_url("/foo/", "/bar").should == "foo/bar" CouchObject::Utils.join_url("/foo/", "/bar/").should == "foo/bar" end it "should be able to add %22 to the beginning and end of a string" do CouchObject::Utils.encode_querystring_parameter("hei"). should == "%22hei%22" end it "should be able to encode values correctly" do CouchObject::Utils.encode_querystring_parameter(123). should == "123" CouchObject::Utils.encode_querystring_parameter("hallo"). should == "%22hallo%22" CouchObject::Utils.encode_querystring_parameter(true). should == "true" CouchObject::Utils.encode_querystring_parameter(false). should == "false" CouchObject::Utils.encode_querystring_parameter(123123123123123123123). should == "123123123123123123123" CouchObject::Utils.encode_querystring_parameter([12123,"ASD", \ true,false,123123123123123123123123]). should == "[12123,%22ASD%22,true,false,123123123123123123123123]" CouchObject::Utils.encode_querystring_parameter("http://hei.com"). should == JSON.unparse("%22http://hei.com%22")[1..-2] end # it "should convert strings in arrays and hashes to UTF-8" do # # a_encoded = "Math: ∮ E⋅da = Q, n → ∞, ∑ f(i) = ∏ g(i)," # a_decoded = "Math: ∮ E⋅da = Q, n → ∞, ∑ f(i) = ∏ g(i)," # b_encoded = "Geek: STARGΛ̊TE SG-1" # b_decoded = "Geek: STARG캛첊TE SG-1" # This is what we want though... "Geek: STARGΛ̊TE SG-1" # c_encoded = "Braille: ⡌⠁⠧⠑ ⠼⠁⠒ ⡍⠜⠇⠑⠹⠰⠎ ⡣⠕⠌" # c_decoded = "Braille: ⡌⠁⠧⠑ ⠼⠁⠒ ⡍⠜⠇⠑⠹⠰⠎ ⡣⠕⠌" # d_encoded = "На берегу пустынных волн" # d_decoded = "На берегу пустынных волн" # e_encoded = "Russian: На берегу пустынных волн" # e_decoded = "Russian: На берегу пустынных волн" # # array_before = [a_encoded,[b_encoded,[c_encoded,[d_encoded,[e_encoded]]]]] # array_after = [a_decoded,[b_decoded,[c_decoded,[d_decoded,[e_decoded]]]]] # # CouchObject::Utils::decode_strings(array_before).should == array_after # # hash_before = {:key => a_encoded, :sub => {:other_key => b_encoded, :more_keys => c_encoded}, :ha => d_encoded, :other_sub => {:ja => e_encoded}} # hash_after = {:key => a_decoded, :sub => {:other_key => b_decoded, :more_keys => c_decoded}, :ha => d_decoded, :other_sub => {:ja => e_decoded}} # # CouchObject::Utils::decode_strings(hash_before).should == hash_after # # mix_before = [a_encoded, {:key => b_encoded, :array => [c_encoded, 123, true]}] # mix_after = [a_decoded, {:key => b_decoded, :array => [c_decoded, 123, true]}] # # CouchObject::Utils::decode_strings(mix_before).should == mix_after # # end end