Skip to content

Commit 68558fe

Browse files
author
Amir Tocker
committed
Fix transformation related tests.
Make the tests independent by randomizing the width parameter.
1 parent 84c42e3 commit 68558fe

1 file changed

Lines changed: 21 additions & 20 deletions

File tree

spec/api_spec.rb

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44
describe Cloudinary::Api do
55
break puts("Please setup environment for api test to run") if Cloudinary.config.api_secret.blank?
66
include_context "cleanup", TIMESTAMP_TAG
7-
7+
TEST_WIDTH = rand(1000)
8+
TEST_TRANSFOMATION = "c_scale,w_#{TEST_WIDTH}"
89
prefix = "api_test_#{Time.now.to_i}"
910
test_id_1 = "#{prefix}_1"
1011
test_id_2 = "#{prefix}_2"
1112
test_id_3 = "#{prefix}_3"
1213
before(:all) do
1314

1415
@api = Cloudinary::Api
15-
Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_1, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "key=value", :eager =>[:width =>100, :crop =>:scale])
16-
Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_2, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "key=value", :eager =>[:width =>100, :crop =>:scale])
17-
Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_3, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "key=value", :eager =>[:width =>100, :crop =>:scale])
18-
Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_1, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "test-key=test", :eager =>[:width =>100, :crop =>:scale])
19-
Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_3, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "test-key=tasty", :eager =>[:width =>100, :crop =>:scale])
16+
Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_1, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "key=value", :eager =>[:width =>TEST_WIDTH, :crop =>:scale])
17+
Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_2, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "key=value", :eager =>[:width =>TEST_WIDTH, :crop =>:scale])
18+
Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_3, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "key=value", :eager =>[:width =>TEST_WIDTH, :crop =>:scale])
19+
Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_1, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "test-key=test", :eager =>[:width =>TEST_WIDTH, :crop =>:scale])
20+
Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_3, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "test-key=tasty", :eager =>[:width =>TEST_WIDTH, :crop =>:scale])
2021
end
2122

2223
after(:all) do
@@ -198,37 +199,37 @@
198199

199200
describe 'transformations' do
200201
it "should allow listing transformations" do
201-
transformation = @api.transformations()["transformations"].find { |transformation| transformation["name"] == "c_scale,w_100" }
202+
transformation = @api.transformations(max_results: 500)["transformations"].find { |transformation| transformation["name"] == TEST_TRANSFOMATION }
202203
expect(transformation).not_to be_blank
203204
expect(transformation["used"]).to eq(true)
204205
end
205206

206207
it "should allow getting transformation metadata" do
207-
transformation = @api.transformation("c_scale,w_100")
208+
transformation = @api.transformation(TEST_TRANSFOMATION)
208209
expect(transformation).not_to be_blank
209-
expect(transformation["info"]).to eq(["crop" => "scale", "width" => 100])
210-
transformation = @api.transformation("crop" => "scale", "width" => 100)
210+
expect(transformation["info"]).to eq(["crop" => "scale", "width" => TEST_WIDTH])
211+
transformation = @api.transformation("crop" => "scale", "width" => TEST_WIDTH)
211212
expect(transformation).not_to be_blank
212-
expect(transformation["info"]).to eq(["crop" => "scale", "width" => 100])
213+
expect(transformation["info"]).to eq(["crop" => "scale", "width" => TEST_WIDTH])
213214
end
214215

215216
it "should allow updating transformation allowed_for_strict" do
216-
@api.update_transformation("c_scale,w_100", :allowed_for_strict => true)
217-
transformation = @api.transformation("c_scale,w_100")
217+
@api.update_transformation(TEST_TRANSFOMATION, :allowed_for_strict => true)
218+
transformation = @api.transformation(TEST_TRANSFOMATION)
218219
expect(transformation).not_to be_blank
219220
expect(transformation["allowed_for_strict"]).to eq(true)
220-
@api.update_transformation("c_scale,w_100", :allowed_for_strict => false)
221-
transformation = @api.transformation("c_scale,w_100")
221+
@api.update_transformation(TEST_TRANSFOMATION, :allowed_for_strict => false)
222+
transformation = @api.transformation(TEST_TRANSFOMATION)
222223
expect(transformation).not_to be_blank
223224
expect(transformation["allowed_for_strict"]).to eq(false)
224225
end
225226

226227
it "should fetch two different derived images using next_cursor" do
227-
result = @api.transformation("c_scale,w_100", :max_results=>1)
228+
result = @api.transformation(TEST_TRANSFOMATION, :max_results=>1)
228229
expect(result["derived"]).not_to be_blank
229230
expect(result["derived"].length).to eq(1)
230231
expect(result["next_cursor"]).not_to be_blank
231-
result2 = @api.transformation("c_scale,w_100", :max_results=>1, :next_cursor=>result["next_cursor"])
232+
result2 = @api.transformation(TEST_TRANSFOMATION, :max_results=>1, :next_cursor=>result["next_cursor"])
232233
expect(result2["derived"]).not_to be_blank
233234
expect(result2["derived"].length).to eq(1)
234235
expect(result2["derived"][0]["id"]).not_to eq(result["derived"][0]["id"] )
@@ -263,9 +264,9 @@
263264

264265
end
265266
it "should allow deleting implicit transformation" do
266-
@api.transformation("c_scale,w_100")
267-
@api.delete_transformation("c_scale,w_100")
268-
expect { @api.transformation("c_scale,w_100") }.to raise_error(Cloudinary::Api::NotFound)
267+
@api.transformation(TEST_TRANSFOMATION)
268+
@api.delete_transformation(TEST_TRANSFOMATION)
269+
expect { @api.transformation(TEST_TRANSFOMATION) }.to raise_error(Cloudinary::Api::NotFound)
269270
end
270271
end
271272

0 commit comments

Comments
 (0)