Skip to content

Commit

Permalink
Merge pull request #318 from openstax/remove_carrierwave
Browse files Browse the repository at this point in the history
Removed Carrierwave and related gems
  • Loading branch information
Dantemss authored Mar 10, 2021
2 parents 80feea8 + d041268 commit 09fb2df
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 211 deletions.
5 changes: 0 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ gem 'fine_print'
# Keyword search
gem 'keyword_search'

# File uploads (old)
gem 'remotipart'
gem 'carrierwave'
gem 'mimemagic'

# Read Excel xlsx spreadsheet files
gem 'roo'

Expand Down
13 changes: 0 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,6 @@ GEM
brakeman (5.0.0)
builder (3.2.4)
byebug (11.1.3)
carrierwave (2.1.1)
activemodel (>= 5.0.0)
activesupport (>= 5.0.0)
addressable (~> 2.6)
image_processing (~> 1.1)
mimemagic (>= 0.3.0)
mini_mime (>= 0.1.3)
ssrf_filter (~> 1.0)
cheat (1.3.3)
pager (~> 1.0)
choice (0.2.0)
Expand Down Expand Up @@ -374,7 +366,6 @@ GEM
ffi (~> 1.0)
redis (4.2.5)
regexp_parser (2.0.3)
remotipart (1.4.4)
representable (3.0.0)
declarative (~> 0.0.5)
uber (~> 0.0.15)
Expand Down Expand Up @@ -476,7 +467,6 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
ssrf_filter (1.0.7)
test_xml (0.1.8)
diffy (~> 3.0)
nokogiri (>= 1.3.2)
Expand Down Expand Up @@ -528,7 +518,6 @@ DEPENDENCIES
bootstrap-sass
brakeman
byebug
carrierwave
cheat
codeclimate-test-reporter
codecov
Expand All @@ -550,7 +539,6 @@ DEPENDENCIES
listen
lograge
maruku
mimemagic
mini_racer
nifty-generators
oj
Expand All @@ -570,7 +558,6 @@ DEPENDENCIES
rails-erd
rails-html-sanitizer
redis
remotipart
representable (~> 3.0.0)
rinku
roar (= 1.0.3)
Expand Down
1 change: 0 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
//
//= require jquery
//= require jquery_ujs
//= require jquery.remotipart
//= require jquery-ui
//= require bootstrap-sprockets
//= require markitup
Expand Down
13 changes: 3 additions & 10 deletions app/models/attachment.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Record of old attachments (old tutor-deployment, Carrierwave)
class Attachment < ApplicationRecord

mount_uploader :asset, AssetUploader

belongs_to :parent, polymorphic: true, inverse_of: :attachments, touch: true

before_update { raise ActiveRecord::ReadOnlyRecord } # Prevent updates
Expand All @@ -10,20 +8,15 @@ class Attachment < ApplicationRecord
validate :unique_asset

def filename
new_record? ? asset.filename : read_attribute(:asset)
asset
end

protected

def remove_asset!
super unless Attachment.where(asset: filename).exists?
end

def unique_asset
return if asset.nil? || parent.nil?
return unless Attachment.where.not(id: id).where({parent_id: parent.id, asset: asset.identifier}).exists?
return unless Attachment.where.not(id: id).where(parent_id: parent.id, asset: asset).exists?
errors.add(:asset, 'has already been associated with this resource')
throw(:abort)
end

end
85 changes: 0 additions & 85 deletions app/uploaders/asset_uploader.rb

This file was deleted.

35 changes: 0 additions & 35 deletions config/initializers/carrierwave.rb

This file was deleted.

2 changes: 1 addition & 1 deletion spec/factories/attachments.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FactoryBot.define do
factory :attachment do
asset { File.open('spec/fixtures/os_exercises_logo.png') }
asset { 'spec/fixtures/os_exercises_logo.png' }
parent { build :exercise }
end
end
23 changes: 3 additions & 20 deletions spec/models/attachment_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
require "rails_helper"

RSpec.describe Attachment, type: :model do

subject(:attachment) { FactoryBot.create :attachment }
let(:asset_path) { attachment.asset.path }
let(:asset_path) { attachment.asset }

after(:each) { attachment.destroy }

Expand All @@ -24,12 +23,12 @@
attachment_2.parent = attachment.parent
expect(attachment_2).not_to be_valid

attachment_2.asset = File.open('spec/fixtures/rails.png')
attachment_2.asset = 'spec/fixtures/rails.png'
expect(attachment_2).to be_valid
end

it 'raises ActiveRecord::ReadOnlyRecord on update' do
attachment.asset = File.open('spec/fixtures/rails.png')
attachment.asset = 'spec/fixtures/rails.png'
expect{ attachment.save! }.to raise_error(ActiveRecord::ReadOnlyRecord)
end

Expand All @@ -40,20 +39,4 @@

expect { FactoryBot.create :attachment, parent: parent }.to change { parent.reload.updated_at }
end

context 'on destroy' do
it 'does not remove the asset when there are other references left' do
attachment_2 = FactoryBot.create :attachment, asset: attachment.asset
attachment_2.destroy

expect(File.exist?(asset_path)).to eq true
end

it 'removes the asset when there are no references left' do
attachment.destroy

expect(File.exist?(asset_path)).to eq false
end
end

end
41 changes: 0 additions & 41 deletions spec/uploaders/asset_uploader_spec.rb

This file was deleted.

0 comments on commit 09fb2df

Please sign in to comment.