Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/transloadit/assembly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,22 @@ def _wrap_steps_in_hash(steps)
when nil then steps
when Hash then steps
when Transloadit::Step then steps.to_hash
else
if steps.uniq(&:name) != steps
when Array
names = steps.inject([]) do |array, step|
case step
when Transloadit::Step then array << step.name
when Hash then array + step.keys.map(&:to_s)
else
raise ArgumentError, "Unsupported array element"
end
end

if names.uniq != names
raise ArgumentError, "There are different Assembly steps using the same name"
end
steps.inject({}) { |h, s| h.update s }
else
raise ArgumentError, "Unsupported steps class"
end
end

Expand Down
73 changes: 73 additions & 0 deletions test/unit/transloadit/test_assembly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,79 @@
end
end

describe "with multiple hash steps" do
it "must wrap its steps into one hash" do
hash_1 = {encode: {robot: "/video/encode"}, resize: {robot: "/image/resize"}}
hash_2 = {thumbs: {robot: "/video/thumbs"}}

assembly = Transloadit::Assembly.new @transloadit,
steps: [hash_1, hash_2]
(hash_1.keys + hash_2.keys).each do |key|
_(assembly.to_hash[:steps].keys).must_include key
end
end

it "must not allow duplicate steps" do
thumbs = {thumbs: {robot: "/video/thumbs"}}
thumbs_duplicate = {thumbs: {robot: "/video/encode"}}
assembly = Transloadit::Assembly.new @transloadit,
steps: [thumbs, thumbs_duplicate]
assert_raises ArgumentError do
assembly.create! open("lib/transloadit/version.rb")
end
end
end

describe "with mixture of hashes and steps" do
it "must wrap its steps into one hash" do
hash = {encode: {robot: "/video/encode"}, resize: {robot: "/image/resize"}}
step = @transloadit.step "thumbs", "/video/thumbs"

assembly = Transloadit::Assembly.new @transloadit,
steps: [hash, step]

hash.keys.each do |key|
_(assembly.to_hash[:steps].keys).must_include key
end

_(assembly.to_hash[:steps].keys).must_include step.name
end

it "must not allow duplicate steps" do
hash = {thumbs: {robot: "/video/thumbs"}}
step = @transloadit.step "thumbs", "/video/thumbs"

assembly = Transloadit::Assembly.new @transloadit,
steps: [hash, step]

assert_raises ArgumentError do
assembly.create! open("lib/transloadit/version.rb")
end
end
end

describe "with unsupported step class" do
it "raises error" do
assembly = Transloadit::Assembly.new @transloadit,
steps: Class.new

assert_raises ArgumentError do
assembly.create! open("lib/transloadit/version.rb")
end
end
end

describe "with unsupported array element" do
it "raises error" do
assembly = Transloadit::Assembly.new @transloadit,
steps: [Class.new]

assert_raises ArgumentError do
assembly.create! open("lib/transloadit/version.rb")
end
end
end

describe "using assembly API methods" do
include WebMock::API

Expand Down