From 809fbb25ce39c72aaff143f805035b3008f20e75 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 13 Apr 2017 17:24:15 -0400 Subject: [PATCH] FIX: blanking theme field was not properly removing it --- app/models/theme.rb | 2 +- spec/controllers/admin/themes_controller_spec.rb | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/models/theme.rb b/app/models/theme.rb index f04cace13a5..28c7b09cb71 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -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 diff --git a/spec/controllers/admin/themes_controller_spec.rb b/spec/controllers/admin/themes_controller_spec.rb index 7595b546520..4280c4d5caf 100644 --- a/spec/controllers/admin/themes_controller_spec.rb +++ b/spec/controllers/admin/themes_controller_spec.rb @@ -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)