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
2 changes: 1 addition & 1 deletion lib/transloadit/assembly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _wrap_steps_in_hash(steps)
when Hash then steps
when Transloadit::Step then steps.to_hash
else
if steps.uniq(&:name) != steps
if steps.uniq != steps
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore duplicate-name validation for array steps

steps.uniq != steps only detects fully equal elements, so it misses the duplicate-name case this guard is meant to catch (e.g., two hashes keyed by :thumbs with different robot options, or two Step objects with the same name). In those cases no ArgumentError is raised and steps.inject({}) { |h, s| h.update s } silently overwrites the earlier step, changing assembly instructions compared to previous behavior.

Useful? React with 👍 / 👎.

raise ArgumentError, "There are different Assembly steps using the same name"
end
steps.inject({}) { |h, s| h.update s }
Expand Down
4 changes: 4 additions & 0 deletions lib/transloadit/step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def to_json
MultiJson.dump(to_hash)
end

def eql?(other)
name == other.name
end

protected

attr_writer :robot
Expand Down
24 changes: 24 additions & 0 deletions test/unit/transloadit/test_assembly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,30 @@
end
end

describe "with multiple hash steps" do
before do
@encode = { "encode": { "robot": "/video/encode" } }
@thumbs = { "thumbs": { "robot": "/video/thumbs" } }

@assembly = Transloadit::Assembly.new @transloadit,
steps: [@encode, @thumbs]
end

it "must wrap its steps into one hash" do
_(@assembly.to_hash[:steps].keys).must_include @encode.keys
_(@assembly.to_hash[:steps].keys).must_include @thumbs.keys
end

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

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

Expand Down