Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Fix: Error in cloning page having formless plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
shivashankar-ror committed Apr 12, 2019
1 parent d72f971 commit 63054bd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
5 changes: 2 additions & 3 deletions app/services/page_cloner.rb
Expand Up @@ -79,11 +79,10 @@ def language
end

def update_form(plugin)
# plugins_with_forms = page.plugins.select { |p| p.try(:form).present? }
return unless plugin.respond_to?(:form=)
return unless plugin.try(:form).present?

default_form = DefaultFormBuilder.find_or_create(locale: cloned_page.language.code)
plugin.form = FormDuplicator.duplicate(default_form)
plugin.form = FormDuplicator.duplicate(default_form)
end

def images
Expand Down
21 changes: 21 additions & 0 deletions spec/services/page_cloner_spec.rb
Expand Up @@ -25,6 +25,7 @@
action_count: 12_345
)
end

let!(:image) { create(:image, page: page, id: 123) }
let!(:fb_share) do
create(:share_facebook,
Expand Down Expand Up @@ -282,4 +283,24 @@ def get_plugin(type)
end
end
end

context 'page with formless plugin' do
let(:formless_page) { create(:page, :with_call_tool) }

subject(:cloned_formless_page) do
VCR.use_cassette('page_cloner_caller_layout') do
PageCloner.clone(formless_page, 'Cloned Caller Page')
end
end

it 'clones formless page' do
expect(cloned_formless_page.id).not_to eq(formless_page.id)
end

it 'has the plugins indicated by the caller layout before the clone' do
plugins_array = [Plugins::CallTool]
expect(formless_page.plugins.count).to eq 1
expect(formless_page.plugins.map(&:class)).to match_array(plugins_array)
end
end
end

0 comments on commit 63054bd

Please sign in to comment.