Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
180 additions
and
46 deletions.
There are no files selected for viewing
7 changes: 0 additions & 7 deletions
7
wcc-contentful-app/app/controllers/wcc/contentful/app/application_controller.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
wcc-contentful-app/app/models/concerns/wcc/contentful/app/preview_password.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module WCC::Contentful::App::PreviewPassword | ||
def preview? | ||
# check ApplicationController for a :preview? method | ||
return super if defined?(super) | ||
|
||
@preview ||= | ||
if preview_password.present? | ||
params[:preview]&.chomp == preview_password.chomp | ||
else | ||
false | ||
end | ||
end | ||
|
||
def preview_password | ||
WCC::Contentful::App.configuration.preview_password | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
wcc-contentful-app/spec/requests/wcc/contentful/app/contact_form_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe WCC::Contentful::App::ContactFormController, type: :request do | ||
let(:mailer) { | ||
double(deliver: nil) | ||
} | ||
|
||
let!(:form) { | ||
contentful_stub('section-contact-form', | ||
internal_title: 'Test') | ||
} | ||
|
||
before do | ||
allow(::WCC::Contentful::App::ContactMailer).to receive(:contact_form_email) | ||
.and_return(mailer) | ||
end | ||
|
||
it 'does not allow sending arbitrary email to :recipient_email' do | ||
expect(::WCC::Contentful::App::ContactMailer).to_not receive(:contact_form_email) | ||
.with('test@test.com', anything) | ||
|
||
post '/contact_form', params: { | ||
id: form.id, | ||
recipient_email: 'test@test.com' | ||
} | ||
end | ||
|
||
it 'sends email to person email address' do | ||
person = double(id: 'TestPerson', email: 'test-person@test.com') | ||
allow(::WCC::Contentful::Model).to receive(:find) | ||
.with('TestPerson', anything) | ||
.and_return(person) | ||
|
||
expect(::WCC::Contentful::App::ContactMailer).to receive(:contact_form_email) | ||
.with('test-person@test.com', anything) | ||
.and_return(mailer) | ||
expect(mailer).to receive(:deliver) | ||
|
||
post '/contact_form', params: { | ||
id: form.id, | ||
email_object_id: 'TestPerson' | ||
} | ||
end | ||
|
||
context 'preview: true' do | ||
before do | ||
expect(WCC::Contentful::Model::SectionContactForm) | ||
.to_not receive(:find) | ||
.with(form.id, hash_including(preview: false)) | ||
end | ||
|
||
it 'looks up person in preview API' do | ||
person = double(id: 'TestPerson', email: 'test-person@test.com') | ||
allow(::WCC::Contentful::Model).to receive(:find) | ||
.with('TestPerson', hash_including(preview: true)) | ||
.and_return(person) | ||
|
||
expect(::WCC::Contentful::App::ContactMailer).to receive(:contact_form_email) | ||
.with('test-person@test.com', anything) | ||
.and_return(mailer) | ||
expect(mailer).to receive(:deliver) | ||
|
||
post '/contact_form', params: { | ||
id: form.id, | ||
email_object_id: 'TestPerson', | ||
preview: WCC::Contentful::App.configuration.preview_password | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters