Skip to content

Commit

Permalink
add missing parameters and tests to generate-archive
Browse files Browse the repository at this point in the history
  • Loading branch information
nadavofir authored and tocker committed Apr 8, 2017
1 parent 86ac7eb commit f347dc2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
4 changes: 3 additions & 1 deletion lib/cloudinary/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,9 @@ def self.archive_params(options = {})
:public_ids=>options[:public_ids] && Cloudinary::Utils.build_array(options[:public_ids]),
:prefixes=>options[:prefixes] && Cloudinary::Utils.build_array(options[:prefixes]),
:expires_at=>options[:expires_at],
:transformations => build_eager(options[:transformations])
:transformations => build_eager(options[:transformations]),
:skip_transformation_name=>Cloudinary::Utils.as_safe_bool(options[:skip_transformation_name]),
:allow_missing=>Cloudinary::Utils.as_safe_bool(options[:allow_missing])
}
end

Expand Down
51 changes: 38 additions & 13 deletions spec/archive_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
:effect => :blackwhite
}
)
Cloudinary::Uploader.upload(
"http://res.cloudinary.com/demo/image/upload/sample.jpg",
:public_id => 'tag_sample_raw.jpg',
:resource_type => 'raw',
:tags => [TEST_TAG, TIMESTAMP_TAG],
)
end
include_context "cleanup", TIMESTAMP_TAG
end
Expand Down Expand Up @@ -64,18 +70,6 @@
let!(:target_public_id) {
"gem_test#{ rand(1000000)}"
}
let!(:archive_result) {
Cloudinary::Uploader.create_archive(
{
:target_public_id => target_public_id,
:public_ids => %w(tag_sample tag_samplebw),
:tags => [TEST_TAG, TIMESTAMP_TAG]
}.merge(options))
}
let(:options) { { :mode => :create } }
it 'should return a Hash' do
expect(archive_result).to be_a(Hash)
end
expected_keys = %w(
resource_type
type
Expand All @@ -91,10 +85,41 @@
resource_count
file_count
)
it "should include keys: #{expected_keys.join(', ')}" do
let!(:archive_result) {
Cloudinary::Uploader.create_archive(
{
:target_public_id => target_public_id,
:public_ids => %w(tag_sample tag_samplebw),
:tags => [TEST_TAG, TIMESTAMP_TAG],
:transformations => [{width: 100, height: 100, crop: "fill"},{effect: "grayscale"}],
:skip_transformation_name => true
}.merge(options))
}
let(:options) { { :mode => :create } }
it 'should return a Hash with suitable set of keys' do
expect(archive_result).to be_a(Hash)
expect(archive_result.keys).to include(*expected_keys)
end
end
describe 'create archive based on raw resources and missing public IDs' do
let!(:target_public_id) {
"gem_test#{ rand(1000000)}"
}
let!(:archive_result) {
Cloudinary::Uploader.create_archive(
{
:target_public_id => target_public_id,
:public_ids => %w(tag_sample_raw.jpg non-wxisting-resource),
:resource_type => 'raw',
:allow_missing => true
}.merge(options))
}
let(:options) { { :mode => :create } }
it 'should skip missing public IDs and successfully generate the archive containing raw resources' do
expect(archive_result).to be_a(Hash)
expect(archive_result["resource_count"]).to equal(1)
end
end
describe '.create_zip' do
it 'should call create_archive with "zip" format' do
expect(Cloudinary::Uploader).to receive(:create_archive).with({ :tags => TEST_TAG }, "zip")
Expand Down

0 comments on commit f347dc2

Please sign in to comment.