Skip to content

Commit

Permalink
allow contact form class to be overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
jpowell committed Mar 5, 2020
1 parent e5295fa commit 4c44d25
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Expand Up @@ -24,11 +24,15 @@ def create
def form_model
raise ArgumentError, 'missing form ID' unless params[:id]

@form_model ||= WCC::Contentful::Model::SectionContactForm.find(
@form_model ||= form_class.find(
params[:id], options: { preview: preview? }
)
end

def form_class
WCC::Contentful::Model.resolve_constant('section-contact-form')
end

def form_params
params.slice(*form_model.fields.map(&:title))
end
Expand Down
Expand Up @@ -2,6 +2,9 @@

require 'rails_helper'

class MyContactForm < WCC::Contentful::Model::SectionContactForm
end

RSpec.describe WCC::Contentful::App::ContactFormController, type: :request do
let(:mailer) {
double(deliver: nil)
Expand Down Expand Up @@ -44,6 +47,27 @@
}
end

context 'section model is extended' do
before do
MyContactForm.register_for_content_type('section-contact-form')
end

after do
WCC::Contentful::Model.class_variable_get('@@registry').clear
end

it 'resolves to the descendant contact form override' do
form = contentful_stub('section-contact-form')

expect(::MyContactForm).to receive(:find)
.with(form.id, { options: { preview: false } })
.and_return(form)
expect(form).to receive(:send_email)

post '/contact_form', params: { id: form.id }
end
end

context 'preview: true' do
before do
expect(WCC::Contentful::Model::SectionContactForm)
Expand Down

0 comments on commit 4c44d25

Please sign in to comment.