spec/api_spec.rb in cloudinary-1.11.1 vs spec/api_spec.rb in cloudinary-1.12.0

- old
+ new

@@ -33,10 +33,18 @@ end end end end + it "should allow using derived_next_cursor when listing details of a single resource" do + expected = { + [:payload, :derived_next_cursor] => "b16b8bd80426df43a107f26b0348" + } + expect(RestClient::Request).to receive(:execute).with(deep_hash_value(expected)) + @api.resource("test", {"derived_next_cursor" => "b16b8bd80426df43a107f26b0348"}) + end + it "should allow listing resource_types" do expect(@api.resource_types()["resource_types"]).to include("image") end it "should allow listing resources" do @@ -135,10 +143,19 @@ expect(resource).not_to be_blank expect(resource).to have_key("quality_analysis") expect(resource["quality_analysis"]).to have_key("focus") end + it "should support the cinemagraph_analysis parameter" do + expected = { + [:payload, :cinemagraph_analysis] => true, + [:method] => :get + } + expect(RestClient::Request).to receive(:execute).with(deep_hash_value(expected)) + @api.resource(test_id_1, :cinemagraph_analysis => true) + end + it "should allow deleting derived resource" do derived_resource_id = "derived_id" expect(RestClient::Request).to receive(:execute).with(deep_hash_value( {[:payload, :derived_resource_ids] => derived_resource_id})) @api.delete_derived_resources(derived_resource_id) end @@ -357,11 +374,11 @@ expect(api_result["moderation"][0]["status"]).to eq("approved") expect(api_result["moderation"][0]["kind"]).to eq("manual") end it "should support requesting raw conversion" do - result = Cloudinary::Uploader.upload("spec/docx.docx", :resource_type => :raw, :tags => [TEST_TAG, TIMESTAMP_TAG]) + result = Cloudinary::Uploader.upload(TEST_RAW, :resource_type => :raw, :tags => [TEST_TAG, TIMESTAMP_TAG]) expect{Cloudinary::Api.update(result["public_id"], {:resource_type => :raw, :raw_convert => :illegal})}.to raise_error(Cloudinary::Api::BadRequest, /^Illegal value|not a valid/) end it "should support requesting categorization" do result = Cloudinary::Uploader.upload(TEST_IMG, :tags => [TEST_TAG, TIMESTAMP_TAG]) @@ -393,21 +410,61 @@ it "should support listing by moderation kind and value" do expect(RestClient::Request).to receive(:execute).with(deep_hash_value([:url] => /.*manual\/approved$/, [:payload, :max_results] => 1000)) Cloudinary::Api.resources_by_moderation(:manual, :approved, :max_results => 1000) end - it "should support listing folders" do - expect(RestClient::Request).to receive(:execute).with(deep_hash_value( [:url] => /.*\/folders$/, [:method] => :get)) - Cloudinary::Api.root_folders - expect(RestClient::Request).to receive(:execute).with(deep_hash_value( [:url] => /.*\/folders\/test_folder1$/, [:method] => :get)) - Cloudinary::Api.subfolders("test_folder1") + describe 'folders' do + it 'should create folder' do + expected = { + [:url] => /.*\/folders\/#{UNIQUE_TEST_FOLDER}$/, + [:method] => :post + } + expect(RestClient::Request).to receive(:execute).with(deep_hash_value(expected)) + @api.create_folder(UNIQUE_TEST_FOLDER) + end + it "should support listing folders" do + expect(RestClient::Request).to receive(:execute).with(deep_hash_value( [:url] => /.*\/folders$/, [:method] => :get)) + Cloudinary::Api.root_folders + expect(RestClient::Request).to receive(:execute).with(deep_hash_value( [:url] => /.*\/folders\/test_folder1$/, [:method] => :get)) + Cloudinary::Api.subfolders("test_folder1") + end + it "should URL escape the folder name" do + expected = { + [:url] => %r".*\/folders\/sub%5Efolder%20test$" + } + expect(RestClient::Request).to receive(:execute).with(deep_hash_value(expected)) + Cloudinary::Api.subfolders("sub^folder test") + end + it "should throw if folder is missing" do + expect{Cloudinary::Api.subfolders("I_do_not_exist")}.to raise_error(Cloudinary::Api::NotFound) + end + it 'should include max_results and next_cursor for root_folders call' do + expected = { + [:payload, :max_results] => 3, + [:payload, :next_cursor] => NEXT_CURSOR, + } + expect(RestClient::Request).to receive(:execute).with(deep_hash_value(expected)) + @api.root_folders :max_results => 3, :next_cursor => NEXT_CURSOR + end + it 'should include max_results and next_cursor for subfolders call' do + expected = { + [:payload, :max_results] => 3, + [:payload, :next_cursor] => NEXT_CURSOR, + } + expect(RestClient::Request).to receive(:execute).with(deep_hash_value(expected)) + @api.subfolders GENERIC_FOLDER_NAME, :max_results => 3, :next_cursor => NEXT_CURSOR + end + it "should support deleting a folder" do + expected = { + :url => %r"/folders/#{GENERIC_FOLDER_NAME}$", + :method => :delete + } + expect(RestClient::Request).to receive(:execute).with(deep_hash_value(expected)) + @api.delete_folder(GENERIC_FOLDER_NAME) + end end - it "should throw if folder is missing" do - expect{Cloudinary::Api.subfolders("I_do_not_exist")}.to raise_error(Cloudinary::Api::NotFound) - end - describe '.restore' do it 'should restore a deleted resource' do expect(RestClient::Request).to receive(:execute).with(deep_hash_value( [:payload, :public_ids] => "api_test_restore", [:url] => /.*\/restore$/)) Cloudinary::Api.restore("api_test_restore") end @@ -419,12 +476,11 @@ expect(RestClient::Request).to receive(:execute).with(deep_hash_value( [:payload, :template] => "http://cloudinary.com")) Cloudinary::Api.create_upload_mapping(mapping, :template =>"http://cloudinary.com") expect(RestClient::Request).to receive(:execute).with(deep_hash_value( [:payload, :template] => "http://res.cloudinary.com")) Cloudinary::Api.update_upload_mapping(mapping, "template" =>"http://res.cloudinary.com") end - - end + describe "access_mode" do i = 0 publicId = "" access_mode_tag = ''