mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
We configured Paperclip to convert images to JPG in some cases but I omitted that here because we don't need it. If an image is better represented as PNG or another format then the user should be able to choose that. Some specs were also testing the generated URL but the Active Storage URL doesn't contain a style name anymore and it's not helpful to test the URL.
95 lines
2.9 KiB
Ruby
95 lines
2.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "spec_helper"
|
|
|
|
module Api
|
|
describe V0::LogosController, type: :controller do
|
|
include AuthenticationHelper
|
|
include FileHelper
|
|
|
|
let(:admin_user) { create(:admin_user) }
|
|
let(:enterprise_owner) { create(:user) }
|
|
let(:enterprise) { create(:enterprise, owner: enterprise_owner ) }
|
|
let(:enterprise_manager) { create(:user, enterprise_limit: 10, enterprises: [enterprise]) }
|
|
let(:other_enterprise_owner) { create(:user) }
|
|
let(:other_enterprise) { create(:enterprise, owner: other_enterprise_owner ) }
|
|
let(:other_enterprise_manager) {
|
|
create(:user, enterprise_limit: 10, enterprises: [other_enterprise])
|
|
}
|
|
|
|
describe "removing logo" do
|
|
let(:image) { Rack::Test::UploadedFile.new(black_logo_file, "image/png") }
|
|
|
|
let(:enterprise) { create(:enterprise, owner: enterprise_owner, logo: image) }
|
|
|
|
before do
|
|
allow(controller).to receive(:spree_current_user) { current_user }
|
|
end
|
|
|
|
context "as manager" do
|
|
let(:current_user) { enterprise_manager }
|
|
|
|
it "removes logo" do
|
|
spree_delete :destroy, enterprise_id: enterprise
|
|
|
|
expect(response.status).to eq 200
|
|
expect(json_response["id"]).to eq enterprise.id
|
|
enterprise.reload
|
|
expect(enterprise.logo).to_not be_attached
|
|
end
|
|
|
|
context "when logo does not exist" do
|
|
let(:enterprise) { create(:enterprise, owner: enterprise_owner, logo: nil) }
|
|
|
|
it "responds with error" do
|
|
spree_delete :destroy, enterprise_id: enterprise
|
|
|
|
expect(response.status).to eq(409)
|
|
expect(json_response["error"]).to eq I18n.t("api.enterprise_logo.destroy_attachment_does_not_exist")
|
|
end
|
|
end
|
|
end
|
|
|
|
context "as owner" do
|
|
let(:current_user) { enterprise_owner }
|
|
|
|
it "allows removal of logo" do
|
|
spree_delete :destroy, enterprise_id: enterprise
|
|
expect(response.status).to eq 200
|
|
end
|
|
end
|
|
|
|
context "as super admin" do
|
|
let(:current_user) { admin_user }
|
|
|
|
it "allows removal of logo" do
|
|
spree_delete :destroy, enterprise_id: enterprise
|
|
expect(response.status).to eq 200
|
|
end
|
|
end
|
|
|
|
context "as manager of other enterprise" do
|
|
let(:current_user) { other_enterprise_manager }
|
|
|
|
it "does not allow removal of logo" do
|
|
spree_delete :destroy, enterprise_id: enterprise
|
|
expect(response.status).to eq(401)
|
|
enterprise.reload
|
|
expect(enterprise.logo).to be_attached
|
|
end
|
|
end
|
|
|
|
context "as owner of other enterprise" do
|
|
let(:current_user) { other_enterprise_owner }
|
|
|
|
it "does not allow removal of logo" do
|
|
spree_delete :destroy, enterprise_id: enterprise
|
|
expect(response.status).to eq(401)
|
|
enterprise.reload
|
|
expect(enterprise.logo).to be_attached
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|