From f68a7a16a4b5440c28115003ce640fb001b5085c Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Wed, 27 Feb 2019 11:45:22 +0200 Subject: [PATCH] FIX: Use field name to name files in theme export. (#7009) --- app/models/theme.rb | 2 +- app/models/theme_field.rb | 2 +- spec/components/theme_store/tgz_exporter_spec.rb | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/models/theme.rb b/app/models/theme.rb index 6cef53eead1..7a2c3c1e477 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -444,7 +444,7 @@ class Theme < ActiveRecord::Base meta[:assets] = {}.tap do |hash| theme_fields.where(type_id: ThemeField.types[:theme_upload_var]).each do |field| - hash[field.name] = "assets/#{field.upload.original_filename}" + hash[field.name] = field.file_path end end diff --git a/app/models/theme_field.rb b/app/models/theme_field.rb index 420d161bf99..d68d24b9c42 100644 --- a/app/models/theme_field.rb +++ b/app/models/theme_field.rb @@ -340,7 +340,7 @@ class ThemeField < ActiveRecord::Base canonical: -> (h) { "locales/#{h[:name]}.yml" }), ThemeFileMatcher.new(regex: /(?!)/, # Never match uploads by filename, they must be named in about.json names: nil, types: :theme_upload_var, targets: :common, - canonical: -> (h) { "assets/#{h[:filename]}" }), + canonical: -> (h) { "assets/#{h[:name]}#{File.extname(h[:filename])}" }), ] # For now just work for standard fields diff --git a/spec/components/theme_store/tgz_exporter_spec.rb b/spec/components/theme_store/tgz_exporter_spec.rb index 94df8a88262..4110203d91c 100644 --- a/spec/components/theme_store/tgz_exporter_spec.rb +++ b/spec/components/theme_store/tgz_exporter_spec.rb @@ -9,8 +9,11 @@ describe ThemeStore::TgzExporter do theme.set_field(target: :mobile, name: :scss, value: 'body {background-color: $background_color; font-size: $font-size}') theme.set_field(target: :translations, name: :en, value: { en: { key: "value" } }.deep_stringify_keys.to_yaml) image = file_from_fixtures("logo.png") - upload = UploadCreator.new(image, "logo.png").create_for(-1) + upload = UploadCreator.new(image, "logo.png").create_for(Discourse::SYSTEM_USER_ID) theme.set_field(target: :common, name: :logo, upload_id: upload.id, type: :theme_upload_var) + image = file_from_fixtures("logo.png") + other_upload = UploadCreator.new(image, "logo.png").create_for(Discourse::SYSTEM_USER_ID) + theme.set_field(target: :common, name: "other_logo", upload_id: upload.id, type: :theme_upload_var) theme.build_remote_theme(remote_url: "", about_url: "abouturl", license_url: "licenseurl", authors: "David Taylor", theme_version: "1.0", minimum_discourse_version: "1.0.0", maximum_discourse_version: "3.0.0.beta1") @@ -63,7 +66,7 @@ describe ThemeStore::TgzExporter do expect(folders).to contain_exactly("assets", "common", "locales", "mobile") files = Dir.glob("**/*").reject { |f| File.directory?(f) } - expect(files).to contain_exactly("about.json", "assets/logo.png", "common/body_tag.html", "locales/en.yml", "mobile/mobile.scss", "settings.yml") + expect(files).to contain_exactly("about.json", "assets/logo.png", "assets/other_logo.png", "common/body_tag.html", "locales/en.yml", "mobile/mobile.scss", "settings.yml") expect(JSON.parse(File.read('about.json')).deep_symbolize_keys).to eq( "name": "Header Icons", @@ -71,7 +74,8 @@ describe ThemeStore::TgzExporter do "license_url": "licenseurl", "component": false, "assets": { - "logo": "assets/logo.png" + "logo": "assets/logo.png", + "other_logo": "assets/other_logo.png" }, "authors": "David Taylor", "minimum_discourse_version": "1.0.0",