Merge pull request #7621 from jibees/7534-upload-logo-and-promo-image-for-enterprise

Upload enterprise image (logo and promo): force content type to "text/plain"
This commit is contained in:
Pau Pérez Fabregat
2021-05-27 11:33:56 +02:00
committed by GitHub
5 changed files with 24 additions and 5 deletions

View File

@@ -44,9 +44,9 @@ module Api
authorize! :update, @enterprise
if params[:logo] && @enterprise.update( logo: params[:logo] )
render plain: @enterprise.logo.url(:medium), status: :ok
render html: @enterprise.logo.url(:medium), status: :ok
elsif params[:promo] && @enterprise.update( promo_image: params[:promo] )
render plain: @enterprise.promo_image.url(:medium), status: :ok
render html: @enterprise.promo_image.url(:medium), status: :ok
else
invalid_resource!(@enterprise)
end

View File

@@ -75,15 +75,24 @@ describe Api::V0::EnterprisesController, type: :controller do
end
describe "submitting a valid image" do
let!(:logo) { fixture_file_upload("files/logo.png", "image/png") }
before do
allow(Enterprise)
.to receive(:find_by).with({ permalink: enterprise.id.to_s }) { enterprise }
allow(enterprise).to receive(:update).and_return(true)
end
it "I can update enterprise image" do
api_post :update_image, logo: 'a logo', id: enterprise.id
it "I can update enterprise logo image" do
api_post :update_image, logo: logo, id: enterprise.id
expect(response.status).to eq 200
expect(response.content_type).to eq "text/html"
expect(response.body).to match %r{/images/enterprises/logos/\d*/medium/logo\.png\?\d*}
end
it "I can update enterprise promo image" do
api_post :update_image, promo: logo, id: enterprise.id
expect(response.status).to eq 200
expect(response.content_type).to eq "text/html"
expect(response.body).to match %r{/images/enterprises/promo_images/\d*/medium/logo\.jpg\?\d*}
end
end
end

View File

@@ -100,10 +100,20 @@ feature "Registration", js: true do
expect(e.charges_sales_tax).to be true
# Images
# Upload logo image
attach_file "image-select", Rails.root.join("spec/fixtures/files/logo.png"), visible: false
expect(page).to have_no_css('#image-placeholder .loading')
expect(page.find('#image-placeholder img')['src']).to_not be_empty
# Move from logo page
click_button "Continue"
expect(page).to have_content 'Step 3. Select Promo Image'
# Upload promo image
attach_file "image-select", Rails.root.join("spec/fixtures/files/promo.png"), visible: false
expect(page).to have_no_css('#image-placeholder .loading')
expect(page.find('#image-placeholder img')['src']).to_not be_empty
# Move from promo page
click_button "Continue"
expect(page).to have_content 'How can people find My Awesome Enterprise online?'

BIN
spec/fixtures/files/logo.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

BIN
spec/fixtures/files/promo.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB