mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Apply syntax_tree formatting to spec/*
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
# encoding: utf-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'theme_store/git_importer'
|
||||
require "theme_store/git_importer"
|
||||
|
||||
RSpec.describe ThemeStore::GitImporter do
|
||||
describe "#import" do
|
||||
let(:url) { "https://github.com/example/example.git" }
|
||||
let(:first_fetch_url) { "https://github.com/example/example.git/info/refs?service=git-upload-pack" }
|
||||
let(:first_fetch_url) do
|
||||
"https://github.com/example/example.git/info/refs?service=git-upload-pack"
|
||||
end
|
||||
let(:trailing_slash_url) { "https://github.com/example/example/" }
|
||||
let(:ssh_url) { "git@github.com:example/example.git" }
|
||||
let(:branch) { "dev" }
|
||||
@@ -25,24 +27,37 @@ RSpec.describe ThemeStore::GitImporter do
|
||||
end
|
||||
|
||||
it "imports ssh urls" do
|
||||
Discourse::Utils
|
||||
.expects(:execute_command)
|
||||
.with(
|
||||
{ "GIT_SSH_COMMAND" => "ssh -i #{@ssh_folder}/id_rsa -o IdentitiesOnly=yes -o IdentityFile=#{@ssh_folder}/id_rsa -o StrictHostKeyChecking=no" },
|
||||
"git", "clone", "ssh://git@github.com/example/example.git", @temp_folder, timeout: 20
|
||||
)
|
||||
Discourse::Utils.expects(:execute_command).with(
|
||||
{
|
||||
"GIT_SSH_COMMAND" =>
|
||||
"ssh -i #{@ssh_folder}/id_rsa -o IdentitiesOnly=yes -o IdentityFile=#{@ssh_folder}/id_rsa -o StrictHostKeyChecking=no",
|
||||
},
|
||||
"git",
|
||||
"clone",
|
||||
"ssh://git@github.com/example/example.git",
|
||||
@temp_folder,
|
||||
timeout: 20,
|
||||
)
|
||||
|
||||
importer = ThemeStore::GitImporter.new(ssh_url, private_key: "private_key")
|
||||
importer.import!
|
||||
end
|
||||
|
||||
it "imports ssh urls with a particular branch" do
|
||||
Discourse::Utils
|
||||
.expects(:execute_command)
|
||||
.with(
|
||||
{ "GIT_SSH_COMMAND" => "ssh -i #{@ssh_folder}/id_rsa -o IdentitiesOnly=yes -o IdentityFile=#{@ssh_folder}/id_rsa -o StrictHostKeyChecking=no" },
|
||||
"git", "clone", "--single-branch", "-b", branch, "ssh://git@github.com/example/example.git", @temp_folder, timeout: 20
|
||||
)
|
||||
Discourse::Utils.expects(:execute_command).with(
|
||||
{
|
||||
"GIT_SSH_COMMAND" =>
|
||||
"ssh -i #{@ssh_folder}/id_rsa -o IdentitiesOnly=yes -o IdentityFile=#{@ssh_folder}/id_rsa -o StrictHostKeyChecking=no",
|
||||
},
|
||||
"git",
|
||||
"clone",
|
||||
"--single-branch",
|
||||
"-b",
|
||||
branch,
|
||||
"ssh://git@github.com/example/example.git",
|
||||
@temp_folder,
|
||||
timeout: 20,
|
||||
)
|
||||
|
||||
importer = ThemeStore::GitImporter.new(ssh_url, private_key: "private_key", branch: branch)
|
||||
importer.import!
|
||||
@@ -53,16 +68,26 @@ RSpec.describe ThemeStore::GitImporter do
|
||||
FinalDestination
|
||||
.stubs(:resolve)
|
||||
.with(first_fetch_url, http_verb: :get)
|
||||
.returns(URI.parse("https://github.com/redirected/example.git/info/refs?service=git-upload-pack"))
|
||||
.returns(
|
||||
URI.parse(
|
||||
"https://github.com/redirected/example.git/info/refs?service=git-upload-pack",
|
||||
),
|
||||
)
|
||||
end
|
||||
|
||||
it "imports http urls" do
|
||||
Discourse::Utils
|
||||
.expects(:execute_command)
|
||||
.with(
|
||||
{ "GIT_TERMINAL_PROMPT" => "0" },
|
||||
"git", "-c", "http.followRedirects=false", "-c", "http.curloptResolve=github.com:443:192.0.2.100", "clone", "https://github.com/redirected/example.git", @temp_folder, timeout: 20
|
||||
)
|
||||
Discourse::Utils.expects(:execute_command).with(
|
||||
{ "GIT_TERMINAL_PROMPT" => "0" },
|
||||
"git",
|
||||
"-c",
|
||||
"http.followRedirects=false",
|
||||
"-c",
|
||||
"http.curloptResolve=github.com:443:192.0.2.100",
|
||||
"clone",
|
||||
"https://github.com/redirected/example.git",
|
||||
@temp_folder,
|
||||
timeout: 20,
|
||||
)
|
||||
|
||||
importer = ThemeStore::GitImporter.new(url)
|
||||
importer.import!
|
||||
@@ -80,36 +105,57 @@ RSpec.describe ThemeStore::GitImporter do
|
||||
end
|
||||
|
||||
it "imports http urls" do
|
||||
Discourse::Utils
|
||||
.expects(:execute_command)
|
||||
.with(
|
||||
{ "GIT_TERMINAL_PROMPT" => "0" },
|
||||
"git", "-c", "http.followRedirects=false", "-c", "http.curloptResolve=github.com:443:192.0.2.100", "clone", "https://github.com/example/example.git", @temp_folder, timeout: 20
|
||||
)
|
||||
Discourse::Utils.expects(:execute_command).with(
|
||||
{ "GIT_TERMINAL_PROMPT" => "0" },
|
||||
"git",
|
||||
"-c",
|
||||
"http.followRedirects=false",
|
||||
"-c",
|
||||
"http.curloptResolve=github.com:443:192.0.2.100",
|
||||
"clone",
|
||||
"https://github.com/example/example.git",
|
||||
@temp_folder,
|
||||
timeout: 20,
|
||||
)
|
||||
|
||||
importer = ThemeStore::GitImporter.new(url)
|
||||
importer.import!
|
||||
end
|
||||
|
||||
it "imports when the url has a trailing slash" do
|
||||
Discourse::Utils
|
||||
.expects(:execute_command)
|
||||
.with(
|
||||
{ "GIT_TERMINAL_PROMPT" => "0" },
|
||||
"git", "-c", "http.followRedirects=false", "-c", "http.curloptResolve=github.com:443:192.0.2.100", "clone", "https://github.com/example/example.git", @temp_folder, timeout: 20
|
||||
)
|
||||
Discourse::Utils.expects(:execute_command).with(
|
||||
{ "GIT_TERMINAL_PROMPT" => "0" },
|
||||
"git",
|
||||
"-c",
|
||||
"http.followRedirects=false",
|
||||
"-c",
|
||||
"http.curloptResolve=github.com:443:192.0.2.100",
|
||||
"clone",
|
||||
"https://github.com/example/example.git",
|
||||
@temp_folder,
|
||||
timeout: 20,
|
||||
)
|
||||
|
||||
importer = ThemeStore::GitImporter.new(trailing_slash_url)
|
||||
importer.import!
|
||||
end
|
||||
|
||||
it "imports http urls with a particular branch" do
|
||||
Discourse::Utils
|
||||
.expects(:execute_command)
|
||||
.with(
|
||||
{ "GIT_TERMINAL_PROMPT" => "0" },
|
||||
"git", "-c", "http.followRedirects=false", "-c", "http.curloptResolve=github.com:443:192.0.2.100", "clone", "--single-branch", "-b", branch, "https://github.com/example/example.git", @temp_folder, timeout: 20
|
||||
)
|
||||
Discourse::Utils.expects(:execute_command).with(
|
||||
{ "GIT_TERMINAL_PROMPT" => "0" },
|
||||
"git",
|
||||
"-c",
|
||||
"http.followRedirects=false",
|
||||
"-c",
|
||||
"http.curloptResolve=github.com:443:192.0.2.100",
|
||||
"clone",
|
||||
"--single-branch",
|
||||
"-b",
|
||||
branch,
|
||||
"https://github.com/example/example.git",
|
||||
@temp_folder,
|
||||
timeout: 20,
|
||||
)
|
||||
|
||||
importer = ThemeStore::GitImporter.new(url, branch: branch)
|
||||
importer.import!
|
||||
|
||||
@@ -1,38 +1,65 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'theme_store/zip_exporter'
|
||||
require "theme_store/zip_exporter"
|
||||
|
||||
RSpec.describe ThemeStore::ZipExporter do
|
||||
let(:rand_hex) do
|
||||
+"X" << SecureRandom.hex
|
||||
end
|
||||
let(:rand_hex) { +"X" << SecureRandom.hex }
|
||||
let!(:theme) do
|
||||
Fabricate(:theme, name: "Header Icons").tap do |theme|
|
||||
theme.set_field(target: :common, name: :body_tag, value: "<b>testtheme1</b>")
|
||||
theme.set_field(target: :settings, name: :yaml, value: "somesetting: #{rand_hex}")
|
||||
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)
|
||||
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(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")
|
||||
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",
|
||||
)
|
||||
|
||||
cs1 = Fabricate(:color_scheme, name: 'Orphan Color Scheme', color_scheme_colors: [
|
||||
Fabricate(:color_scheme_color, name: 'header_primary', hex: 'F0F0F0'),
|
||||
Fabricate(:color_scheme_color, name: 'header_background', hex: '1E1E1E'),
|
||||
Fabricate(:color_scheme_color, name: 'tertiary', hex: '858585')
|
||||
])
|
||||
cs1 =
|
||||
Fabricate(
|
||||
:color_scheme,
|
||||
name: "Orphan Color Scheme",
|
||||
color_scheme_colors: [
|
||||
Fabricate(:color_scheme_color, name: "header_primary", hex: "F0F0F0"),
|
||||
Fabricate(:color_scheme_color, name: "header_background", hex: "1E1E1E"),
|
||||
Fabricate(:color_scheme_color, name: "tertiary", hex: "858585"),
|
||||
],
|
||||
)
|
||||
|
||||
cs2 = Fabricate(:color_scheme, name: 'Theme Color Scheme', color_scheme_colors: [
|
||||
Fabricate(:color_scheme_color, name: 'header_primary', hex: 'F0F0F0'),
|
||||
Fabricate(:color_scheme_color, name: 'header_background', hex: '1E1E1E'),
|
||||
Fabricate(:color_scheme_color, name: 'tertiary', hex: '858585')
|
||||
])
|
||||
cs2 =
|
||||
Fabricate(
|
||||
:color_scheme,
|
||||
name: "Theme Color Scheme",
|
||||
color_scheme_colors: [
|
||||
Fabricate(:color_scheme_color, name: "header_primary", hex: "F0F0F0"),
|
||||
Fabricate(:color_scheme_color, name: "header_background", hex: "1E1E1E"),
|
||||
Fabricate(:color_scheme_color, name: "tertiary", hex: "858585"),
|
||||
],
|
||||
)
|
||||
|
||||
theme.color_scheme = cs1
|
||||
cs2.update(theme_id: theme.id)
|
||||
@@ -48,9 +75,7 @@ RSpec.describe ThemeStore::ZipExporter do
|
||||
dir
|
||||
end
|
||||
|
||||
after do
|
||||
FileUtils.rm_rf(dir)
|
||||
end
|
||||
after { FileUtils.rm_rf(dir) }
|
||||
|
||||
let(:package) do
|
||||
exporter = ThemeStore::ZipExporter.new(theme)
|
||||
@@ -62,7 +87,7 @@ RSpec.describe ThemeStore::ZipExporter do
|
||||
|
||||
it "exports the theme correctly" do
|
||||
package
|
||||
file = 'discourse-header-icons.zip'
|
||||
file = "discourse-header-icons.zip"
|
||||
Dir.chdir(dir) do
|
||||
available_size = SiteSetting.decompressed_theme_max_file_size_mb
|
||||
Compression::Zip.new.decompress(dir, file, available_size)
|
||||
@@ -72,41 +97,54 @@ RSpec.describe ThemeStore::ZipExporter 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", "assets/other_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",
|
||||
"about_url": "abouturl",
|
||||
"license_url": "licenseurl",
|
||||
"component": false,
|
||||
"assets": {
|
||||
"logo": "assets/logo.png",
|
||||
"other_logo": "assets/other_logo.png"
|
||||
expect(JSON.parse(File.read("about.json")).deep_symbolize_keys).to eq(
|
||||
name: "Header Icons",
|
||||
about_url: "abouturl",
|
||||
license_url: "licenseurl",
|
||||
component: false,
|
||||
assets: {
|
||||
logo: "assets/logo.png",
|
||||
other_logo: "assets/other_logo.png",
|
||||
},
|
||||
"authors": "David Taylor",
|
||||
"minimum_discourse_version": "1.0.0",
|
||||
"maximum_discourse_version": "3.0.0.beta1",
|
||||
"theme_version": "1.0",
|
||||
"color_schemes": {
|
||||
authors: "David Taylor",
|
||||
minimum_discourse_version: "1.0.0",
|
||||
maximum_discourse_version: "3.0.0.beta1",
|
||||
theme_version: "1.0",
|
||||
color_schemes: {
|
||||
"Orphan Color Scheme": {
|
||||
"header_primary": "F0F0F0",
|
||||
"header_background": "1E1E1E",
|
||||
"tertiary": "858585"
|
||||
header_primary: "F0F0F0",
|
||||
header_background: "1E1E1E",
|
||||
tertiary: "858585",
|
||||
},
|
||||
"Theme Color Scheme": {
|
||||
"header_primary": "F0F0F0",
|
||||
"header_background": "1E1E1E",
|
||||
"tertiary": "858585"
|
||||
}
|
||||
header_primary: "F0F0F0",
|
||||
header_background: "1E1E1E",
|
||||
tertiary: "858585",
|
||||
},
|
||||
},
|
||||
"modifiers": {},
|
||||
"learn_more": "https://meta.discourse.org/t/beginners-guide-to-using-discourse-themes/91966"
|
||||
modifiers: {
|
||||
},
|
||||
learn_more: "https://meta.discourse.org/t/beginners-guide-to-using-discourse-themes/91966",
|
||||
)
|
||||
|
||||
expect(File.read("common/body_tag.html")).to eq("<b>testtheme1</b>")
|
||||
expect(File.read("mobile/mobile.scss")).to eq("body {background-color: $background_color; font-size: $font-size}")
|
||||
expect(File.read("mobile/mobile.scss")).to eq(
|
||||
"body {background-color: $background_color; font-size: $font-size}",
|
||||
)
|
||||
expect(File.read("settings.yml")).to eq("somesetting: #{rand_hex}")
|
||||
expect(File.read("locales/en.yml")).to eq({ en: { key: "value" } }.deep_stringify_keys.to_yaml)
|
||||
expect(File.read("locales/en.yml")).to eq(
|
||||
{ en: { key: "value" } }.deep_stringify_keys.to_yaml,
|
||||
)
|
||||
|
||||
theme.update!(name: "Discourse Header Icons")
|
||||
exporter = ThemeStore::ZipExporter.new(theme)
|
||||
@@ -126,5 +164,4 @@ RSpec.describe ThemeStore::ZipExporter do
|
||||
package
|
||||
end.to raise_error(RuntimeError)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
|
||||
# encoding: utf-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'theme_store/zip_importer'
|
||||
require "theme_store/zip_importer"
|
||||
|
||||
RSpec.describe ThemeStore::ZipImporter do
|
||||
before do
|
||||
@@ -10,23 +9,21 @@ RSpec.describe ThemeStore::ZipImporter do
|
||||
|
||||
FileUtils.mkdir(@temp_folder)
|
||||
Dir.chdir(@temp_folder) do
|
||||
FileUtils.mkdir_p('test/a')
|
||||
FileUtils.mkdir_p("test/a")
|
||||
File.write("test/hello.txt", "hello world")
|
||||
File.write("test/a/inner", "hello world inner")
|
||||
end
|
||||
end
|
||||
|
||||
after do
|
||||
FileUtils.rm_rf @temp_folder
|
||||
end
|
||||
after { FileUtils.rm_rf @temp_folder }
|
||||
|
||||
it "can import a simple zipped theme" do
|
||||
Dir.chdir(@temp_folder) do
|
||||
Compression::Zip.new.compress(@temp_folder, 'test')
|
||||
FileUtils.rm_rf('test/')
|
||||
Compression::Zip.new.compress(@temp_folder, "test")
|
||||
FileUtils.rm_rf("test/")
|
||||
end
|
||||
|
||||
file_name = 'test.zip'
|
||||
file_name = "test.zip"
|
||||
importer = ThemeStore::ZipImporter.new("#{@temp_folder}/#{file_name}", file_name)
|
||||
importer.import!
|
||||
|
||||
@@ -37,11 +34,9 @@ RSpec.describe ThemeStore::ZipImporter do
|
||||
end
|
||||
|
||||
it "can import a simple gzipped theme" do
|
||||
Dir.chdir(@temp_folder) do
|
||||
`tar -cvzf test.tar.gz test/* 2> /dev/null`
|
||||
end
|
||||
Dir.chdir(@temp_folder) { `tar -cvzf test.tar.gz test/* 2> /dev/null` }
|
||||
|
||||
file_name = 'test.tar.gz'
|
||||
file_name = "test.tar.gz"
|
||||
importer = ThemeStore::ZipImporter.new("#{@temp_folder}/#{file_name}", file_name)
|
||||
importer.import!
|
||||
|
||||
|
||||
Reference in New Issue
Block a user