FIX: Use field name to name files in theme export. (#7009)

FIX: Use field name to name files in theme export. (#7009)

diff --git a/app/models/theme.rb b/app/models/theme.rb
index 6cef53e..7a2c3c1 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 420d161..d68d24b 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 94df8a8..4110203 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",

GitHub sha: f68a7a16