Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
microstudi committed Jan 16, 2024
1 parent 856c95d commit 04c2b0a
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ class DocumentForm < Decidim::Form
attribute :box_opacity, Integer, default: 12
attribute :organization

attribute :file
attribute :file, Decidim::Attributes::Blob
attribute :remove_file, Boolean, default: false

# validates :file, presence: true, unless: :persisted?
validates :file, passthru: { to: Document }, if: ->(form) { form.file.present? }
validates :file, file_content_type: { allow: ["application/pdf"] }, if: ->(form) { form.file.present? }
validates :file, file_content_type: { allow: ["application/pdf"] }

# ensure color and opacity are present
def map_model(doc)
Expand Down
4 changes: 2 additions & 2 deletions app/models/decidim/participatory_documents/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Document < ApplicationRecord
has_one_attached :file
validates_upload :file, uploader: Decidim::ParticipatoryDocuments::PdfDocumentUploader
# compatibility with ratonvirus (see https://github.com/mainio/decidim-module-antivirus)
validates :file, antivirus: true if ParticipatoryDocuments.antivirus_enabled?
validates :file, antivirus: true if ParticipatoryDocuments.antivirus_enabled

has_many :sections, class_name: "Decidim::ParticipatoryDocuments::Section", dependent: :restrict_with_error
has_many :suggestions, class_name: "Decidim::ParticipatoryDocuments::Suggestion", dependent: :restrict_with_error, as: :suggestable
Expand All @@ -32,7 +32,7 @@ class Document < ApplicationRecord

# override the delegate from HasComponent for the dynamic upload validator
def organization
@organization ||= component&.organization
component&.organization || @organization
end

def self.log_presenter_class_for(_log)
Expand Down
2 changes: 1 addition & 1 deletion lib/decidim/participatory_documents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module ParticipatoryDocuments
ENV.fetch("MAX_SUGGESTION_LENGTH", 1000).to_i
end

def self.antivirus_enabled?
config_accessor :antivirus_enabled do
defined?(AntivirusValidator)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module Decidim::ParticipatoryDocuments::Admin
let(:file) { upload_test_file(Decidim::Dev.test_file("dummy-dummies-example.json", "application/pdf")) }

it "is valid" do
expect(subject).to be_invalid
expect(subject).to be_valid
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/decidim/participatory_documents/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ module ParticipatoryDocuments

context "when not ratonvirus defined" do
before do
allow(ParticipatoryDocuments).to receive(:antivirus_enabled?).and_return(false)
allow(ParticipatoryDocuments).to receive(:antivirus_enabled).and_return(false)
Decidim::ParticipatoryDocuments.send(:remove_const, :Document)
load "decidim/participatory_documents/document.rb"
end
Expand All @@ -261,7 +261,7 @@ module ParticipatoryDocuments

context "when defined ratonvirus" do
before do
allow(ParticipatoryDocuments).to receive(:antivirus_enabled?).and_return(true)
allow(ParticipatoryDocuments).to receive(:antivirus_enabled).and_return(true)
Decidim::ParticipatoryDocuments.send(:remove_const, :Document)
load "decidim/participatory_documents/document.rb"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
let(:default_color) { "rgb(30, 152, 215)" }
let(:default_color_with_opacity) { "rgba(30, 152, 215, 0.12)" }

def upload_file
document.file.attach(io: File.open(Decidim::Dev.asset("Exampledocument.pdf")), filename: "Exampledocument.pdf")
end

include_context "when managing a component as an admin"

context "when document is not created" do
Expand Down

0 comments on commit 04c2b0a

Please sign in to comment.