Replace Paperclip on EnterpriseGroup

This commit is contained in:
Maikel Linke
2022-04-12 14:37:41 +10:00
parent 421ffae78c
commit 45995ac984
4 changed files with 15 additions and 36 deletions

View File

@@ -1,12 +1,9 @@
# frozen_string_literal: true
require 'open_food_network/locking'
require 'spree/core/s3_support'
class EnterpriseGroup < ApplicationRecord
include HasMigratingFile
include PermalinkGenerator
include Spree::Core::S3Support
acts_as_list
@@ -28,21 +25,11 @@ class EnterpriseGroup < ApplicationRecord
delegate :phone, :address1, :address2, :city, :zipcode, :state, :country, to: :address
has_one_migrating :logo,
styles: { medium: "100x100" },
url: '/images/enterprise_groups/logos/:id/:style/:basename.:extension',
path: 'public/images/enterprise_groups/logos/:id/:style/:basename.:extension'
has_one_attached :logo
has_one_attached :promo_image
has_one_migrating :promo_image,
styles: { large: ["1200x260#", :jpg] },
url: '/images/enterprise_groups/promo_images/:id/:style/:basename.:extension',
path: 'public/images/enterprise_groups/promo_images/:id/:style/:basename.:extension'
validates_attachment_content_type :logo, content_type: %r{\Aimage/.*\Z}
validates_attachment_content_type :promo_image, content_type: %r{\Aimage/.*\Z}
supports_s3 :logo
supports_s3 :promo_image
validates :logo, content_type: %r{\Aimage/.*\Z}
validates :promo_image, content_type: %r{\Aimage/.*\Z}
scope :by_position, -> { order('position ASC') }
scope :on_front_page, -> { where(on_front_page: true) }

View File

@@ -6,13 +6,13 @@
%div{'ofn-with-tip' => t('admin_enterprise_groups_data_powertip_logo')}
%a= t 'admin.whats_this'
.omega.eight.columns
= image_tag @object.logo.url if @object.logo.present?
= f.file_field :logo
= image_tag @object.logo if @object.logo.attached?
= f.file_field :logo, accept: "image/*"
.row
.alpha.three.columns
= f.label :promo_image, 'ofn-with-tip' => t(:admin_enterprise_groups_data_powertip_promo_image)
%div{'ofn-with-tip' => t('admin_enterprise_groups_data_powertip_promo_image')}
%a= t 'admin.whats_this'
.omega.eight.columns
= image_tag @object.promo_image.url if @object.promo_image.present?
= f.file_field :promo_image
= image_tag @object.promo_image if @object.promo_image.attached?
= f.file_field :promo_image, accept: "image/*"

View File

@@ -3,7 +3,7 @@
- content_for(:description) do
= @group.description
- content_for(:image) do
= @group.logo.url
= url_for(@group.logo) if @group.logo.attached?
- content_for :scripts do
= render partial: "shared/google_maps_js"
@@ -22,14 +22,13 @@
%header
.row
.small-12.columns
- if @group.promo_image.present?
%img{"src" => @group.promo_image}
= image_tag @group.promo_image.variant(resize_to_limit: [1200, 260]) if @group.promo_image.attached?
.row
.small-12.columns.group-header.pad-top
- if @group.logo.present?
%img.group-logo{"src" => @group.logo}
- if @group.logo.attached?
= image_tag @group.logo.variant(resize_to_limit: [100, 100]), class: "group-logo"
- else
%img.group-logo{"src" => '/noimage/group.png' }
= image_tag "/noimage/group.png", class: "group-logo"
%h2.group-name= @group.name
%p= @group.description

View File

@@ -39,8 +39,8 @@ describe EnterpriseGroup do
e = build(:enterprise_group, description: '')
end
it { is_expected.to have_attached_file :promo_image }
it { is_expected.to have_attached_file :logo }
it { is_expected.to have_one_attached :promo_image }
it { is_expected.to have_one_attached :logo }
end
describe "relations" do
@@ -50,13 +50,6 @@ describe EnterpriseGroup do
eg.enterprises << e
expect(eg.reload.enterprises).to eq([e])
end
# it "can have an image" do
# eg = create(:enterprise_group)
# image_file = File.open(File.expand_path('../../../app/assets/images/logo-white.png', __FILE__))
# image = Spree::Image.create(viewable_id: eg.id, viewable_type: 'EnterpriseGroup', attachment: image_file)
# eg.reload.image.should == image
# end
end
describe "scopes" do