mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 00:32:52 +08:00
FEATURE: support uploads for themes
This allows themes to bundle various assets
This commit is contained in:
@ -11,6 +11,26 @@ describe Admin::ThemesController do
|
||||
@user = log_in(:admin)
|
||||
end
|
||||
|
||||
context '.upload_asset' do
|
||||
render_views
|
||||
|
||||
let(:upload) do
|
||||
ActionDispatch::Http::UploadedFile.new({
|
||||
filename: 'test.woff2',
|
||||
tempfile: file_from_fixtures("fake.woff2", "woff2")
|
||||
})
|
||||
end
|
||||
|
||||
it 'can create a theme upload' do
|
||||
xhr :post, :upload_asset, file: upload, original_filename: 'wooof.woff2'
|
||||
expect(response.status).to eq(201)
|
||||
upload = Upload.find_by(original_filename: "wooof.woff2")
|
||||
expect(upload.id).not_to be_nil
|
||||
expect(JSON.parse(response.body)["upload_id"]).to eq(upload.id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context '.import' do
|
||||
let(:theme_file) do
|
||||
ActionDispatch::Http::UploadedFile.new({
|
||||
@ -93,30 +113,35 @@ describe Admin::ThemesController do
|
||||
end
|
||||
|
||||
it 'updates a theme' do
|
||||
#focus
|
||||
theme = Theme.new(name: 'my name', user_id: -1)
|
||||
theme.set_field(target: :common, name: :scss, value: '.body{color: black;}')
|
||||
theme.save
|
||||
|
||||
child_theme = Theme.create(name: 'my name', user_id: -1)
|
||||
|
||||
upload = Fabricate(:upload)
|
||||
|
||||
xhr :put, :update, id: theme.id,
|
||||
theme: {
|
||||
child_theme_ids: [child_theme.id],
|
||||
name: 'my test name',
|
||||
theme_fields: [
|
||||
{ name: 'scss', target: 'common', value: '' },
|
||||
{ name: 'scss', target: 'desktop', value: 'body{color: blue;}' }
|
||||
{ name: 'scss', target: 'desktop', value: 'body{color: blue;}' },
|
||||
{ name: 'bob', target: 'common', value: '', type_id: 2, upload_id: upload.id },
|
||||
]
|
||||
}
|
||||
expect(response).to be_success
|
||||
|
||||
json = ::JSON.parse(response.body)
|
||||
|
||||
fields = json["theme"]["theme_fields"]
|
||||
fields = json["theme"]["theme_fields"].sort{|a,b| a["value"] <=> b["value"]}
|
||||
|
||||
expect(fields.first["value"]).to eq('body{color: blue;}')
|
||||
expect(fields.length).to eq(1)
|
||||
expect(fields[0]["value"]).to eq('')
|
||||
expect(fields[0]["upload_id"]).to eq(upload.id)
|
||||
expect(fields[1]["value"]).to eq('body{color: blue;}')
|
||||
|
||||
expect(fields.length).to eq(2)
|
||||
|
||||
expect(json["theme"]["child_themes"].length).to eq(1)
|
||||
|
||||
|
Reference in New Issue
Block a user