From d095c2cee79fc32488088fce2e5f697f10df204f Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 13 Nov 2019 23:45:09 +0000 Subject: [PATCH] FIX: Allow importing themes with subdirectories in extra_js The folder/file detection was broken by 9fea43e46a7bb9ee1f8a3ce9d22bb41664f0852a. This commit fixes and adds relevant specs --- lib/theme_store/git_importer.rb | 2 +- lib/theme_store/zip_importer.rb | 2 +- spec/models/remote_theme_spec.rb | 7 ++++--- spec/requests/admin/themes_controller_spec.rb | 3 ++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/theme_store/git_importer.rb b/lib/theme_store/git_importer.rb index 2eebf58370..0fccf3886c 100644 --- a/lib/theme_store/git_importer.rb +++ b/lib/theme_store/git_importer.rb @@ -80,7 +80,7 @@ class ThemeStore::GitImporter end def all_files - Dir.glob("**/*", base: @temp_folder).reject { |f| File.directory?(f) } + Dir.glob("**/*", base: @temp_folder).reject { |f| File.directory?(File.join(@temp_folder, f)) } end def [](value) diff --git a/lib/theme_store/zip_importer.rb b/lib/theme_store/zip_importer.rb index 81ce6222aa..deff98d3df 100644 --- a/lib/theme_store/zip_importer.rb +++ b/lib/theme_store/zip_importer.rb @@ -51,7 +51,7 @@ class ThemeStore::ZipImporter end def all_files - Dir.glob("**/**", base: @temp_folder).reject { |f| File.directory?(f) } + Dir.glob("**/**", base: @temp_folder).reject { |f| File.directory?(File.join(@temp_folder, f)) } end def [](value) diff --git a/spec/models/remote_theme_spec.rb b/spec/models/remote_theme_spec.rb index e1e8af9fb4..0c467e962e 100644 --- a/spec/models/remote_theme_spec.rb +++ b/spec/models/remote_theme_spec.rb @@ -11,8 +11,8 @@ describe RemoteTheme do `cd #{repo_dir} && git init . ` `cd #{repo_dir} && git config user.email 'someone@cool.com'` `cd #{repo_dir} && git config user.name 'The Cool One'` - `cd #{repo_dir} && mkdir desktop mobile common assets locales scss stylesheets` files.each do |name, data| + FileUtils.mkdir_p(Pathname.new("#{repo_dir}/#{name}").dirname) File.write("#{repo_dir}/#{name}", data) `cd #{repo_dir} && git add #{name}` end @@ -52,6 +52,7 @@ describe RemoteTheme do "scss/oldpath.scss" => ".class2{color:blue}", "stylesheets/file.scss" => ".class1{color:red}", "stylesheets/empty.scss" => "", + "javascripts/discourse/controllers/test.js.es6" => "console.log('test');", "common/header.html" => "I AM HEADER", "common/random.html" => "I AM SILLY", "common/embedded.scss" => "EMBED", @@ -83,7 +84,7 @@ describe RemoteTheme do expect(remote.theme_version).to eq("1.0") expect(remote.minimum_discourse_version).to eq("1.0.0") - expect(@theme.theme_fields.length).to eq(8) + expect(@theme.theme_fields.length).to eq(9) mapped = Hash[*@theme.theme_fields.map { |f| ["#{f.target_id}-#{f.name}", f.value] }.flatten] expect(mapped["0-header"]).to eq("I AM HEADER") @@ -96,7 +97,7 @@ describe RemoteTheme do expect(mapped["4-en"]).to eq("sometranslations") - expect(mapped.length).to eq(8) + expect(mapped.length).to eq(9) expect(@theme.settings.length).to eq(1) expect(@theme.settings.first.value).to eq(true) diff --git a/spec/requests/admin/themes_controller_spec.rb b/spec/requests/admin/themes_controller_spec.rb index 8e6f83a276..17cdf9ea9f 100644 --- a/spec/requests/admin/themes_controller_spec.rb +++ b/spec/requests/admin/themes_controller_spec.rb @@ -44,6 +44,7 @@ describe Admin::ThemesController do theme = Fabricate(:theme, name: "Awesome Theme") theme.set_field(target: :common, name: :scss, value: '.body{color: black;}') theme.set_field(target: :desktop, name: :after_header, value: 'test') + theme.set_field(target: :extra_js, name: "discourse/controller/blah", value: 'console.log("test");') theme.save! get "/admin/customize/themes/#{theme.id}/export" @@ -64,7 +65,7 @@ describe Admin::ThemesController do json = ::JSON.parse(response.body) expect(json["theme"]["name"]).to eq("Awesome Theme") - expect(json["theme"]["theme_fields"].length).to eq(2) + expect(json["theme"]["theme_fields"].length).to eq(3) end end