FIX: Allow importing themes with subdirectories in extra_js

The folder/file detection was broken by 9fea43e46a. This commit fixes and adds relevant specs
This commit is contained in:
David Taylor 2019-11-13 23:45:09 +00:00
parent 0ba0aa00e7
commit d095c2cee7
4 changed files with 8 additions and 6 deletions

View File

@ -80,7 +80,7 @@ class ThemeStore::GitImporter
end end
def all_files 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 end
def [](value) def [](value)

View File

@ -51,7 +51,7 @@ class ThemeStore::ZipImporter
end end
def all_files 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 end
def [](value) def [](value)

View File

@ -11,8 +11,8 @@ describe RemoteTheme do
`cd #{repo_dir} && git init . ` `cd #{repo_dir} && git init . `
`cd #{repo_dir} && git config user.email 'someone@cool.com'` `cd #{repo_dir} && git config user.email 'someone@cool.com'`
`cd #{repo_dir} && git config user.name 'The Cool One'` `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| files.each do |name, data|
FileUtils.mkdir_p(Pathname.new("#{repo_dir}/#{name}").dirname)
File.write("#{repo_dir}/#{name}", data) File.write("#{repo_dir}/#{name}", data)
`cd #{repo_dir} && git add #{name}` `cd #{repo_dir} && git add #{name}`
end end
@ -52,6 +52,7 @@ describe RemoteTheme do
"scss/oldpath.scss" => ".class2{color:blue}", "scss/oldpath.scss" => ".class2{color:blue}",
"stylesheets/file.scss" => ".class1{color:red}", "stylesheets/file.scss" => ".class1{color:red}",
"stylesheets/empty.scss" => "", "stylesheets/empty.scss" => "",
"javascripts/discourse/controllers/test.js.es6" => "console.log('test');",
"common/header.html" => "I AM HEADER", "common/header.html" => "I AM HEADER",
"common/random.html" => "I AM SILLY", "common/random.html" => "I AM SILLY",
"common/embedded.scss" => "EMBED", "common/embedded.scss" => "EMBED",
@ -83,7 +84,7 @@ describe RemoteTheme do
expect(remote.theme_version).to eq("1.0") expect(remote.theme_version).to eq("1.0")
expect(remote.minimum_discourse_version).to eq("1.0.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] mapped = Hash[*@theme.theme_fields.map { |f| ["#{f.target_id}-#{f.name}", f.value] }.flatten]
expect(mapped["0-header"]).to eq("I AM HEADER") 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["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.length).to eq(1)
expect(@theme.settings.first.value).to eq(true) expect(@theme.settings.first.value).to eq(true)

View File

@ -44,6 +44,7 @@ describe Admin::ThemesController do
theme = Fabricate(:theme, name: "Awesome Theme") theme = Fabricate(:theme, name: "Awesome Theme")
theme.set_field(target: :common, name: :scss, value: '.body{color: black;}') theme.set_field(target: :common, name: :scss, value: '.body{color: black;}')
theme.set_field(target: :desktop, name: :after_header, value: '<b>test</b>') theme.set_field(target: :desktop, name: :after_header, value: '<b>test</b>')
theme.set_field(target: :extra_js, name: "discourse/controller/blah", value: 'console.log("test");')
theme.save! theme.save!
get "/admin/customize/themes/#{theme.id}/export" get "/admin/customize/themes/#{theme.id}/export"
@ -64,7 +65,7 @@ describe Admin::ThemesController do
json = ::JSON.parse(response.body) json = ::JSON.parse(response.body)
expect(json["theme"]["name"]).to eq("Awesome Theme") 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
end end