Skip to content
Merged
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
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ jobs:
strategy:
matrix:
ruby:
- 3.0
- 3.1
- 3.2
- 3.3
Comment thread
tim-kos marked this conversation as resolved.
- jruby
- truffleruby
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
lfs: true
- uses: actions/setup-node@v4
with:
node-version: 20
Expand Down Expand Up @@ -53,7 +52,9 @@ jobs:
TRANSLOADIT_KEY: ${{ secrets.TRANSLOADIT_KEY }}
TRANSLOADIT_SECRET: ${{ secrets.TRANSLOADIT_SECRET }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
lfs: true
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
Expand Down
26 changes: 26 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,29 @@ def run_transloadit_sig(payload, key:, secret:, algorithm: nil)
end

Minitest::Test.include(TransloaditCliHelpers)

module SingletonMethodOverrideHelpers
def with_singleton_method(target, name, implementation)
eigenclass = target.singleton_class

backup = "__orig_#{name}_for_test__"
had_method = eigenclass.method_defined?(name) || eigenclass.private_method_defined?(name)
eigenclass.send(:alias_method, backup, name) if had_method

target.define_singleton_method(name, &implementation)
yield
ensure
eigenclass = target.singleton_class
if eigenclass.method_defined?(name) || eigenclass.private_method_defined?(name)
eigenclass.send(:remove_method, name)
end
if had_method
eigenclass.send(:alias_method, name, backup)
if eigenclass.method_defined?(backup) || eigenclass.private_method_defined?(backup)
eigenclass.send(:remove_method, backup)
end
end
end
end

Minitest::Test.include(SingletonMethodOverrideHelpers)
2 changes: 1 addition & 1 deletion test/unit/test_transloadit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

it "must produce Transloadit-compatible JSON output" do
fixed_time = Time.utc(2025, 10, 28, 0, 0, 0)
Time.stub :now, fixed_time do
with_singleton_method(Time, :now, proc { fixed_time }) do
_(@transloadit.to_json).must_equal MultiJson.dump(@transloadit.to_hash)
end
end
Expand Down
10 changes: 6 additions & 4 deletions test/unit/transloadit/test_assembly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,14 @@
it "must call the create! method with the same parameters" do
VCR.use_cassette "submit_assembly" do
file = open("lib/transloadit/version.rb")
mocker = Minitest::Mock.new
mocker.expect :call, nil, [file]
@assembly.stub :create!, mocker do
create_arg = nil
with_singleton_method(@assembly, :create!, proc { |arg|
create_arg = arg
nil
}) do
@assembly.submit!(file)
end
mocker.verify
_(create_arg).must_equal file
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion transloadit.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
gem.description = "The transloadit gem allows you to automate uploading files through the Transloadit REST API"

gem.required_rubygems_version = ">= 2.2.0"
gem.required_ruby_version = ">= 3.0.0"
gem.required_ruby_version = ">= 3.1.0"

gem.files = `git ls-files`.split("\n")
gem.require_paths = %w[lib]
Expand Down
Loading