Skip to content

Commit

Permalink
Merge pull request #2748 from r7kamura/version-const-name
Browse files Browse the repository at this point in the history
Change version constant naming pattern
  • Loading branch information
mshibuya authored Aug 25, 2024
2 parents 8761240 + 665e5e3 commit d1509b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/carrierwave/uploader/versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def configure(options, &block)
def build(superclass)
return @klass if @klass
@klass = Class.new(superclass)
superclass.const_set("#{@name.to_s.camelize}VersionUploader", @klass)
superclass.const_set("VersionUploader#{@name.to_s.camelize}", @klass)

@klass.version_names += [@name]
@klass.versions = {}
Expand Down
9 changes: 8 additions & 1 deletion spec/uploader/versions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

it "should set the class name" do
@uploader_class.version :thumb
expect(@uploader.thumb.class).to eq @uploader_class.const_get :ThumbVersionUploader
expect(@uploader.thumb.class).to eq @uploader_class.const_get :VersionUploaderThumb
end

it "should remember mount options" do
Expand Down Expand Up @@ -153,6 +153,13 @@ def store_dir
expect(@uploader.small_thumb.class.version_options[:from_version]).to eq(:thumb)
end

context 'when version name starts with non-alphabetic character' do
it "should set the class name" do
@uploader_class.version :_800x600
expect(@uploader._800x600.class).to eq @uploader_class.const_get :VersionUploader800x600
end
end

describe 'with nested versions' do
before do
@uploader_class.version :thumb do
Expand Down

0 comments on commit d1509b3

Please # to comment.