FIX: importing a theme via file was broken

This commit is contained in:
Arpit Jalan 2017-05-08 11:57:09 +05:30
parent cfb30bca80
commit e89d0a6b20
3 changed files with 22 additions and 1 deletions

View File

@ -17,7 +17,7 @@ class Admin::ThemesController < Admin::AdminController
@theme = Theme.new(name: theme["name"], user_id: current_user.id)
theme["theme_fields"]&.each do |field|
@theme.set_field(field["target"], field["name"], field["value"])
@theme.set_field(target: field["target"], name: field["name"], value: field["value"])
end
if @theme.save

View File

@ -11,6 +11,26 @@ describe Admin::ThemesController do
@user = log_in(:admin)
end
context '.import' do
let(:theme_file) do
ActionDispatch::Http::UploadedFile.new({
filename: 'sam-s-simple-theme.dcstyle.json',
tempfile: file_from_fixtures("sam-s-simple-theme.dcstyle.json", "json")
})
end
it 'imports a theme' do
xhr :post, :import, theme: theme_file
expect(response).to be_success
json = ::JSON.parse(response.body)
expect(json["theme"]["name"]).to eq("Sam's Simple Theme")
expect(json["theme"]["theme_fields"].length).to eq(2)
expect(UserHistory.where(action: UserHistory.actions[:change_theme]).count).to eq(1)
end
end
context ' .index' do
it 'correctly returns themes' do

File diff suppressed because one or more lines are too long