FIX: blanking theme field was not properly removing it

This commit is contained in:
Sam 2017-04-13 17:24:15 -04:00
parent 9927489f4e
commit 809fbb25ce
2 changed files with 7 additions and 4 deletions

View File

@ -213,7 +213,7 @@ class Theme < ActiveRecord::Base
field = theme_fields.find{|f| f.name==name && f.target == target_id}
if field
if value.blank?
field.destroy
theme_fields.delete field.destroy
else
if field.value != value
field.value = value

View File

@ -69,7 +69,7 @@ describe Admin::ThemesController do
end
it 'updates a theme' do
#focus
theme = Theme.new(name: 'my name', user_id: -1)
theme.set_field(:common, :scss, '.body{color: black;}')
theme.save
@ -80,7 +80,10 @@ describe Admin::ThemesController do
theme: {
child_theme_ids: [child_theme.id],
name: 'my test name',
theme_fields: [name: 'scss', target: 'common', value: 'body{color: red;}']
theme_fields: [
{ name: 'scss', target: 'common', value: '' },
{ name: 'scss', target: 'desktop', value: 'body{color: blue;}' }
]
}
expect(response).to be_success
@ -88,8 +91,8 @@ describe Admin::ThemesController do
fields = json["theme"]["theme_fields"]
expect(fields.first["value"]).to eq('body{color: blue;}')
expect(fields.length).to eq(1)
expect(fields.first["value"]).to eq('body{color: red;}')
expect(json["theme"]["child_themes"].length).to eq(1)