From 13f4194061c48079d57f114ba2a24233f3f10f52 Mon Sep 17 00:00:00 2001 From: Scott Cytacki Date: Wed, 7 Aug 2019 15:03:18 -0400 Subject: [PATCH] fix wrapping plugins previous change to replace belongs_to relationship with a has_one relationship did not include autosave autosave causes the related object to be saved automatically when the main object is saved this is necessary for our delegation code. --- app/models/embeddable/embeddable_plugin.rb | 2 +- spec/models/embeddable/embeddable_plugin_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/embeddable/embeddable_plugin.rb b/app/models/embeddable/embeddable_plugin.rb index 043bae3b7..1edfb24ad 100644 --- a/app/models/embeddable/embeddable_plugin.rb +++ b/app/models/embeddable/embeddable_plugin.rb @@ -10,7 +10,7 @@ def self.table_name attr_accessible :plugin, :approved_script_id, :description, :author_data, :is_full_width, :is_hidden, :component_label - has_one :plugin, as: :plugin_scope + has_one :plugin, as: :plugin_scope, autosave: true has_many :page_items, :as => :embeddable, :dependent => :destroy has_many :interactive_pages, :through => :page_items diff --git a/spec/models/embeddable/embeddable_plugin_spec.rb b/spec/models/embeddable/embeddable_plugin_spec.rb index f29399029..9207ccc73 100644 --- a/spec/models/embeddable/embeddable_plugin_spec.rb +++ b/spec/models/embeddable/embeddable_plugin_spec.rb @@ -87,4 +87,14 @@ end end + + describe 'delegated to plugin methods' do + it 'should save value after a simple create, set, save, reload' do + embeddable = Embeddable::EmbeddablePlugin.create! + embeddable.approved_script_id = "123" + embeddable.save! + embeddable.reload + expect(embeddable.approved_script_id).to eq("123") + end + end end