From 873a976593e60916b6db47a6d95c056b6fe1a9cd Mon Sep 17 00:00:00 2001 From: Marc Altmann Date: Sun, 2 Jul 2017 12:53:11 +0200 Subject: [PATCH] Remove images for feedbacks, closes #1507 --- app/mailers/feedback_mailer.rb | 2 -- app/models/feedback.rb | 4 ---- app/models/images/feedback_image.rb | 24 ------------------- app/refineries/feedback_refinery.rb | 3 +-- .../feedbacks/varieties/_feedback.html.slim | 5 ---- app/views/feedbacks/varieties/_help.html.slim | 5 ---- test/models/image_test.rb | 8 +++---- 7 files changed, 4 insertions(+), 47 deletions(-) delete mode 100644 app/models/images/feedback_image.rb diff --git a/app/mailers/feedback_mailer.rb b/app/mailers/feedback_mailer.rb index a2d56a030b..7d6bcc8380 100644 --- a/app/mailers/feedback_mailer.rb +++ b/app/mailers/feedback_mailer.rb @@ -9,8 +9,6 @@ def feedback_and_help(feedback, topic) @last_article_id = @feedback.last_article_id from = feedback.from? ? feedback.from : EMAIL_ADDRESSES['default'] - attachments[feedback.image.image_file_name] = File.read(Rails.root.join(feedback.image.image.path(:original))) if feedback.image - if EMAIL_ADDRESSES mail(to: EMAIL_ADDRESSES['FeedbackMailer'][@feedback.variety][topic], from: from, subject: @feedback.subject) end diff --git a/app/models/feedback.rb b/app/models/feedback.rb index b8a5d18790..ea6ee4333e 100644 --- a/app/models/feedback.rb +++ b/app/models/feedback.rb @@ -6,10 +6,6 @@ class Feedback < ActiveRecord::Base extend Enumerize extend ActiveModel::Naming - # Optional image - has_one :image, class_name: 'FeedbackImage', foreign_key: 'imageable_id' - accepts_nested_attributes_for :image - enumerize :variety, in: [:report_article, :get_help, :send_feedback, :become_donation_partner] enumerize :feedback_subject, in: [:dealer, :technics, :other] diff --git a/app/models/images/feedback_image.rb b/app/models/images/feedback_image.rb deleted file mode 100644 index 4872f8a049..0000000000 --- a/app/models/images/feedback_image.rb +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (c) 2012-2017, Fairmondo eG. This file is -# licensed under the GNU Affero General Public License version 3 or later. -# See the COPYRIGHT file for details. - -class FeedbackImage < Image - extend STI - - has_attached_file( - :image, - styles: { - original: { geometry: '300>x300>', animated: false } - }, - default_url: '/assets/missing.png', - url: '/system/images/:id_partition/:style/:filename', - path: 'public/system/images/:id_partition/:style/:filename' - ) - - belongs_to :feedback, foreign_key: 'imageable_id' - - validates_attachment_presence :image, unless: :external_url - validates_attachment_content_type :image, - content_type: %w(image/jpeg image/png) - validates_attachment_size :image, in: 0..2.megabytes -end diff --git a/app/refineries/feedback_refinery.rb b/app/refineries/feedback_refinery.rb index b7c70f28f9..e45fdbdf77 100644 --- a/app/refineries/feedback_refinery.rb +++ b/app/refineries/feedback_refinery.rb @@ -6,8 +6,7 @@ class FeedbackRefinery < ApplicationRefinery def create [ :from, :subject, :text, :variety, :article_id, :feedback_subject, - :help_subject, :forename, :lastname, :organisation, :phone, :recaptcha, - { image_attributes: ImageRefinery.new(Image.new, user).default } + :help_subject, :forename, :lastname, :organisation, :phone, :recaptcha ] end end diff --git a/app/views/feedbacks/varieties/_feedback.html.slim b/app/views/feedbacks/varieties/_feedback.html.slim index 7775b25ef9..cd5eed784e 100644 --- a/app/views/feedbacks/varieties/_feedback.html.slim +++ b/app/views/feedbacks/varieties/_feedback.html.slim @@ -10,11 +10,6 @@ h1= t('feedback.title.send_feedback') = f.input :subject, required: true = f.input :text, label: false, required: true - - f.object.build_image - = f.semantic_fields_for :image do |image| - = f.inputs do - = image.input :image, as: :file, required: false - = f.input :feedback_subject, as: :select, required: true, include_blank: true .captacha = render '/shared/recaptcha' diff --git a/app/views/feedbacks/varieties/_help.html.slim b/app/views/feedbacks/varieties/_help.html.slim index 399a4ab431..ed68baad18 100644 --- a/app/views/feedbacks/varieties/_help.html.slim +++ b/app/views/feedbacks/varieties/_help.html.slim @@ -9,11 +9,6 @@ h1= t('feedback.title.get_help') = f.input :subject, required: true = f.input :text, label: false, required: true - - f.object.build_image - = f.semantic_fields_for :image do |image| - = f.inputs do - = image.input :image, as: :file, required: false - = f.input :help_subject, as: :select, required: true, include_blank: true .captacha = render '/shared/recaptcha' diff --git a/test/models/image_test.rb b/test/models/image_test.rb index b7645aca6b..8330b971da 100644 --- a/test/models/image_test.rb +++ b/test/models/image_test.rb @@ -6,7 +6,7 @@ describe Image do subject { Image.new } - let(:image) { create(:article_image) } + let(:image) { build_stubbed(:article_image) } it 'has a valid Factory' do subject.valid?.must_equal true @@ -28,11 +28,9 @@ end describe 'associations' do - let(:article_image) { ArticleImage.new } - let(:feedback_image) { FeedbackImage.new } - let(:user_image) { UserImage.new } + article_image = ArticleImage.new + user_image = UserImage.new it { article_image.must belong_to :article } - it { feedback_image.must belong_to :feedback } it { user_image.must belong_to :user } end