Skip to content

Commit

Permalink
Support CarrierWave 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibuya committed Jan 12, 2025
1 parent 55e7da5 commit 42995b1
Show file tree
Hide file tree
Showing 7 changed files with 298 additions and 167 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
mongodb: [4.4]
ruby: [2.7, "3.0", 3.1, 3.2, 3.3]
gemfile:
- carrierwave-2.1
- carrierwave-2.2
- carrierwave-3.1
- mongoid-7
- mongoid-8
- mongoid-9
Expand All @@ -20,6 +20,8 @@ jobs:
- { mongodb: "4.4", ruby: "2.6", gemfile: "carrierwave-1.2" }
- { mongodb: "4.4", ruby: "2.6", gemfile: "carrierwave-1.3" }
- { mongodb: "4.4", ruby: "2.6", gemfile: "carrierwave-2.0" }
- { mongodb: "4.4", ruby: "2.6", gemfile: "carrierwave-2.1" }
- { mongodb: "4.4", ruby: "2.6", gemfile: "carrierwave-3.0" }
- { mongodb: "4.4", ruby: "2.6", gemfile: "mongoid-3" }
- { mongodb: "4.4", ruby: "2.6", gemfile: "mongoid-4" }
- { mongodb: "4.4", ruby: "2.6", gemfile: "mongoid-5" }
Expand Down
2 changes: 1 addition & 1 deletion carrierwave-mongoid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_dependency "carrierwave", [">= 0.8", "< 3"]
s.add_dependency "carrierwave", [">= 0.8", "< 4"]
s.add_dependency "mongoid", [">= 3.0", "< 10.0"]
s.add_dependency "mongoid-grid_fs", [">= 1.3", "< 3.0"]
s.add_dependency "mime-types", "< 3" if RUBY_VERSION < "2.0" # mime-types 3+ doesn't support ruby 1.9
Expand Down
5 changes: 5 additions & 0 deletions gemfiles/carrierwave-3.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

gem "carrierwave", "~> 3.0.0"

gemspec path: "../"
5 changes: 5 additions & 0 deletions gemfiles/carrierwave-3.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

gem "carrierwave", "~> 3.1.0"

gemspec path: "../"
415 changes: 261 additions & 154 deletions lib/carrierwave/mongoid.rb

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions spec/carrierwave/mongoid/mount_uploaders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,20 @@ def munge

before do
model_class.create!(images: files)
end

it 'replaced it by a file with the same name' do
record.update!(images: [stub_file('test.jpeg')])

record.reload
end

expect(record[:images]).to match_array(['test.jpeg'])
expect(record.images_identifiers).to match_array(['test.jpeg'])
if Gem::Version.new(CarrierWave::VERSION) >= Gem::Version.new("3.0.beta")
it "performs deduplication" do
expect(record[:images]).to match_array(['test(2).jpeg'])
expect(record.images_identifiers).to match_array(['test(2).jpeg'])
end
else
it 'replaced it by a file with the same name' do
expect(record[:images]).to match_array(['test.jpeg'])
expect(record.images_identifiers).to match_array(['test.jpeg'])
end
end
end

Expand Down
17 changes: 12 additions & 5 deletions spec/mongoid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,21 @@ def extension_white_list
@doc.image = stub_file('test.jpeg')
@doc.save
@doc.reload
end

it "replaced it by a file with the same name" do
@doc.image = stub_file('test.jpeg')
@doc.save
@doc.reload
expect(@doc[:image]).to eq 'test.jpeg'
expect(@doc.image_identifier).to eq 'test.jpeg'
end

if Gem::Version.new(CarrierWave::VERSION) >= Gem::Version.new("3.0.beta")
it "performs deduplication" do
expect(@doc[:image]).to eq 'test(2).jpeg'
expect(@doc.image_identifier).to eq 'test(2).jpeg'
end
else
it "replaced it by a file with the same name" do
expect(@doc[:image]).to eq 'test.jpeg'
expect(@doc.image_identifier).to eq 'test.jpeg'
end
end

end
Expand Down

0 comments on commit 42995b1

Please sign in to comment.