From 282f9948cbf17f9e713f2d385e20f0b941fddda4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 9 Aug 2016 20:14:49 +0200 Subject: [PATCH] FIX: wasn't able to update category's settings --- lib/validators/upload_url_validator.rb | 2 +- spec/models/category_spec.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/validators/upload_url_validator.rb b/lib/validators/upload_url_validator.rb index 527ad2d4e..da9c27d1f 100644 --- a/lib/validators/upload_url_validator.rb +++ b/lib/validators/upload_url_validator.rb @@ -3,7 +3,7 @@ class UploadUrlValidator < ActiveModel::EachValidator if value.present? uri = URI.parse(value) rescue nil - unless uri && Upload.exists?(url: value) + unless uri && Discourse.store.has_been_uploaded?(value) record.errors[attribute] << (options[:message] || I18n.t('errors.messages.invalid')) end end diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index d603077eb..ac5689578 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -14,19 +14,20 @@ describe Category do context "url validation" do let(:user) { Fabricate(:user) } - let(:upload) { Fabricate(:upload) } it "ensures logo_url is valid" do expect(Fabricate.build(:category, user: user, logo_url: "---%")).not_to be_valid expect(Fabricate.build(:category, user: user, logo_url: "http://example.com/made-up.jpg")).not_to be_valid expect(Fabricate.build(:category, user: user, logo_url: upload.url)).to be_valid + expect(Fabricate.build(:category, user: user, logo_url: UrlHelper.schemaless(UrlHelper.absolute(upload.url)))).to be_valid end it "ensures background_url is valid" do expect(Fabricate.build(:category, user: user, background_url: ";test")).not_to be_valid expect(Fabricate.build(:category, user: user, background_url: "http://example.com/no.jpg")).not_to be_valid expect(Fabricate.build(:category, user: user, background_url: upload.url)).to be_valid + expect(Fabricate.build(:category, user: user, background_url: UrlHelper.schemaless(UrlHelper.absolute(upload.url)))).to be_valid end end