Testing Adapter Registry Implementation in Paperclip
This test suite validates the functionality of Paperclip’s AttachmentRegistry and AdapterRegistry classes, focusing on adapter registration and lookup capabilities. The tests ensure proper handling of adapter registration and verification mechanisms within the Paperclip gem.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
thoughtbot/paperclip
spec/paperclip/io_adapters/registry_spec.rb
require 'spec_helper'
describe Paperclip::AttachmentRegistry do
context "for" do
before do
class AdapterTest
def initialize(_target, _ = {}); end
end
@subject = Paperclip::AdapterRegistry.new
@subject.register(AdapterTest){|t| Symbol === t }
end
it "returns the class registered for the adapted type" do
assert_equal AdapterTest, @subject.for(:target).class
end
end
context "registered?" do
before do
class AdapterTest
def initialize(_target, _ = {}); end
end
@subject = Paperclip::AdapterRegistry.new
@subject.register(AdapterTest){|t| Symbol === t }
end
it "returns true when the class of this adapter has been registered" do
assert @subject.registered?(AdapterTest.new(:target))
end
it "returns false when the adapter has not been registered" do
assert ! @subject.registered?(Object)
end
end
end