Skip to content

Commit

Permalink
🚧 Setting up controllers to take banner_images
Browse files Browse the repository at this point in the history
Here we are making sure the AppearancesController will set the site's
banner_images.  Currently, removing the banner is not supported.
However, uploading new banners will remove previous ones.
  • Loading branch information
kirkkwang committed Aug 4, 2024
1 parent 293f23e commit 6bb9460
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions app/controllers/hyrax/admin/appearances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def update
ReindexWorksJob.perform_later
end

if update_params['banner_images']
site = Site.instance
site.banner_images = update_params['banner_images']
site.save!
end

redirect_to({ action: :show }, notice: t('.flash.success'))
end

Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/hyrax/admin/appearances_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
end

it "sets a banner image" do
expect(Site.instance.banner_image?).to be false
expect(Site.instance.banner_images.any?).to be false
f = fixture_file_upload('/images/nypl-hydra-of-lerna.jpg', 'image/jpg')
post :update, params: { admin_appearance: { banner_image: f } }
post :update, params: { admin_appearance: { banner_images: [f] } }
expect(response).to redirect_to(hyrax.admin_appearance_path(locale: 'en'))
expect(flash[:notice]).to include("The appearance was successfully updated")
expect(Site.instance.banner_image?).to be true
expect(Site.instance.banner_images.any?).to be true
end

it "sets a directory image" do
Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/sites_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@
.and_return(CarrierWave::Storage::File)
.at_least(3).times
f = fixture_file_upload('/images/nypl-hydra-of-lerna.jpg', 'image/jpg')
Site.instance.update(banner_image: f)
Site.instance.update(banner_images: [f])
ContentBlock.find_or_create_by(name: 'banner_image_text').update!(value: 'Sample text')
end

it "#update with remove_banner_image deletes a banner image" do
expect(Site.instance.banner_image?).to be true
it "#update with remove_banner_images deletes a banner image" do
expect(Site.instance.banner_images.any?).to be true
expect(ContentBlock.find_by(name: 'banner_image_text')).not_to be nil
post :update, params: { id: Site.instance.id, remove_banner_image: 'Remove banner image' }
post :update, params: { id: Site.instance.id, remove_banner_images: 'Remove all banner images' }
expect(response).to redirect_to('/admin/appearance?locale=en')
expect(flash[:notice]).to include("The appearance was successfully updated")
expect(Site.instance.banner_image?).to be false
expect(Site.instance.banner_images.any?).to be false
expect(ContentBlock.find_by(name: 'banner_image_text')).to be nil
end
end
Expand Down

0 comments on commit 6bb9460

Please sign in to comment.