2017-04-20 04:46:28 +08:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ThemeField do
|
|
|
|
it "correctly generates errors for transpiled js" do
|
|
|
|
html = <<HTML
|
|
|
|
<script type="text/discourse-plugin" version="0.8">
|
|
|
|
badJavaScript(;
|
|
|
|
</script>
|
|
|
|
HTML
|
2017-08-31 12:06:56 +08:00
|
|
|
|
2017-05-03 04:01:01 +08:00
|
|
|
field = ThemeField.create!(theme_id: 1, target_id: 0, name: "header", value: html)
|
2017-04-20 04:46:28 +08:00
|
|
|
expect(field.error).not_to eq(nil)
|
2017-08-31 12:06:56 +08:00
|
|
|
|
|
|
|
field.update!(value: '')
|
2017-04-20 04:46:28 +08:00
|
|
|
expect(field.error).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "correctly generates errors for transpiled css" do
|
|
|
|
css = "body {"
|
2017-05-03 04:01:01 +08:00
|
|
|
field = ThemeField.create!(theme_id: 1, target_id: 0, name: "scss", value: css)
|
2017-04-20 04:46:28 +08:00
|
|
|
field.reload
|
|
|
|
expect(field.error).not_to eq(nil)
|
2017-04-21 04:55:09 +08:00
|
|
|
field.value = "body {color: blue};"
|
2017-04-20 04:46:28 +08:00
|
|
|
field.save!
|
2017-04-21 04:55:09 +08:00
|
|
|
field.reload
|
|
|
|
|
2017-04-20 04:46:28 +08:00
|
|
|
expect(field.error).to eq(nil)
|
|
|
|
end
|
2017-05-11 02:43:05 +08:00
|
|
|
|
2017-12-19 23:10:44 +08:00
|
|
|
def create_upload_theme_field!(name)
|
|
|
|
ThemeField.create!(
|
|
|
|
theme_id: 1,
|
|
|
|
target_id: 0,
|
|
|
|
value: "",
|
|
|
|
type_id: ThemeField.types[:theme_upload_var],
|
|
|
|
name: name,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ensures we don't use invalid SCSS variable names" do
|
|
|
|
expect { create_upload_theme_field!("42") }.to raise_error(ActiveRecord::RecordInvalid)
|
|
|
|
expect { create_upload_theme_field!("a42") }.not_to raise_error
|
|
|
|
end
|
|
|
|
|
2017-04-20 04:46:28 +08:00
|
|
|
end
|