spec/utils_spec.rb in cloudinary-1.9.1 vs spec/utils_spec.rb in cloudinary-1.10.0

- old
+ new

@@ -1,11 +1,13 @@ require 'spec_helper' require 'cloudinary' describe Cloudinary::Utils do + before :each do + Cloudinary.reset_config Cloudinary.config do |config| # config.cloud_name = "demo" config.secure_distribution = nil config.private_cdn = false config.secure = false @@ -448,10 +450,16 @@ expect(["test", { :effect => ["sepia", 10] }]) .to produce_url("#{upload_path}/e_sepia:10/test") .and empty_options end + it "should support blur effect with ocr gravity" do + expect(["test", { :effect => ["blur_region", 5000], :gravity => "ocr_text" }]) + .to produce_url("#{upload_path}/e_blur_region:5000,g_ocr_text/test") + .and empty_options + end + it "should support keyframe_interval" do expect(["test", { :keyframe_interval => 10 }]) .to produce_url("#{upload_path}/ki_10/test") .and empty_options end @@ -563,11 +571,12 @@ ["explicit layer parameter", "text:test_text:#{text_encoded}", "text:test_text:#{text_encoded}"], ["text parameter", { :public_id => "test_text", :text => text_layer }, "text:test_text:#{text_encoded}"], ["text with font family and size parameters", { :text => text_layer, :font_family => "Arial", :font_size => "18" }, "text:Arial_18:#{text_encoded}"], ["text with text style parameter", { :text => text_layer, :font_family => "Arial", :font_size => "18", :font_weight => "bold", :font_style => "italic", :letter_spacing => 4, :line_spacing => 2 }, "text:Arial_18_bold_italic_letter_spacing_4_line_spacing_2:#{text_encoded}"], ["subtitles", { :resource_type => "subtitles", :public_id => "subtitles.srt" }, "subtitles:subtitles.srt"], - ["subtitles with font family and size", { :resource_type => "subtitles", :public_id => "subtitles.srt", :font_family => "Arial", :font_size => "40" }, "subtitles:Arial_40:subtitles.srt"] + ["subtitles with font family and size", { :resource_type => "subtitles", :public_id => "subtitles.srt", :font_family => "Arial", :font_size => "40" }, "subtitles:Arial_40:subtitles.srt"], + ["image of type fetch", { :public_id => "http://res.cloudinary.com/demo/image/upload/ci", :type => "fetch" }, "fetch:aHR0cDovL3Jlcy5jbG91ZGluYXJ5LmNvbS9kZW1vL2ltYWdlL3VwbG9hZC9jaQ=="] ] layers_options.each do |name, options, result| it "should support #{name}" do expect(["sample.jpg", { param => options }]).to produce_url("#{upload_path}/#{short}_#{result}/sample.jpg").and empty_options # expect("#{upload_path}/#{short}_#{result}/sample.jpg").to be_served_by_cloudinary @@ -615,12 +624,12 @@ .to produce_url("http://hello.com/#{cloud_name}/image/upload/test") .and empty_options end it "should support extenal cname with cdn_subdomain on" do - expect(["test", { :cname => "hello.com", :cdn_subdomain => true }]) - .to produce_url("http://a2.hello.com/#{cloud_name}/image/upload/test") + expect(["test", { :cname => "hello.com", :private_cdn => true, :cdn_subdomain => true}]) + .to produce_url("http://a2.hello.com/image/upload/test") .and empty_options end it "should support cdn_subdomain with secure on if using shared_domain" do expect(["test", { :secure => true, :cdn_subdomain => true }]) @@ -805,10 +814,16 @@ expect(["sample", transformation: [{ if: "w_lt_200", crop: "fill", height: 120, width: 80 }, { if: "w_gt_400", crop: "fit", width: 150, height: 150 }, { effect: "sepia" }]]) .to produce_url("#{upload_path}/if_w_lt_200,c_fill,h_120,w_80/if_w_gt_400,c_fit,h_150,w_150/e_sepia/sample") end + it "should allow multiple tags condition" do + expect(["sample", transformation: [{ if: "!tag1:tag2:tag3!_in_tags", crop: "fill", height: 120, width: 80 }, + { if: "else", crop: "fit", width: 150, height: 150 }, + { effect: "sepia" }]]) + .to produce_url("#{upload_path}/if_!tag1:tag2:tag3!_in_tags,c_fill,h_120,w_80/if_else,c_fit,h_150,w_150/e_sepia/sample") + end describe "including spaces and operators" do it "should translate operators" do expect(["sample", { if: "w < 200", crop: "fill", height: 120, width: 80 }]) .to produce_url("#{upload_path}/if_w_lt_200,c_fill,h_120,w_80/sample") @@ -899,8 +914,36 @@ it 'should support symbols' do context = {:symbol_key => "string_value", "string_key" => :symbol_value} result = Cloudinary::Utils.encode_context(context) expect(result).to eq("string_key=symbol_value|symbol_key=string_value") .or eq("symbol_key=string_value|string_key=symbol_value") + end + end + + describe "customFunction" do + custom_function_wasm = { + :function_type => 'wasm', + :source => 'blur.wasm' + } + custom_function_wasm_str = 'wasm:blur.wasm' + + custom_function_remote = { + :function_type => 'remote', + :source => 'https://df34ra4a.execute-api.us-west-2.amazonaws.com/default/cloudinaryFunction' + } + custom_function_remote_str = 'remote:aHR0cHM6Ly9kZjM0cmE0YS5leGVjdXRlLWFwaS51cy13ZXN0LTIuYW1hem9uYXdzLmNvbS9kZWZhdWx0L2Nsb3VkaW5hcnlGdW5jdGlvbg==' + + it 'should accept a string value' do + actual = Cloudinary::Utils.generate_transformation_string :custom_function => custom_function_wasm_str + expect( actual).to eq("fn_#{custom_function_wasm_str}") + end + it 'should accept a hash of options' do + actual = Cloudinary::Utils.generate_transformation_string :custom_function => custom_function_wasm + expect( actual).to eq("fn_#{custom_function_wasm_str}") + end + it 'should base64 encoded URL for a remote function' do + actual = Cloudinary::Utils.generate_transformation_string :custom_function => custom_function_remote + expect( actual).to eq("fn_#{custom_function_remote_str}") + end end end