Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add :contact_form_id to messages params in messages_controller #2403

Merged
merged 6 commits into from
Jan 18, 2023
Prev Previous commit
Next Next commit
add spec for MessageController#message_params
chiperific committed Dec 22, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit a53741a33b5debe3bd5f83a0e8710bf1c63242ee
29 changes: 29 additions & 0 deletions spec/controllers/alchemy/messages_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -226,5 +226,34 @@ module Alchemy
end
end
end

describe "#message_params" do
before do
allow(controller).to receive(:params).and_return(ActionController::Parameters.new( message: { email: "[email protected]", contact_form_id: "23" }).permit!)
end

context "when mailer_config['fields'] includes :contact_field_id" do
before do
allow(controller).to receive(:mailer_config).and_return({ page_layout_name: "contact", forward_to_page: false, mail_success_page: "thanks", mail_from: "[email protected]", mail_to: "[email protected]", subject: "A new contact form message", fields: ["salutation", "firstname", "lastname", "address", "zip", "city", "phone", "email", "message", "contact_field_id"], validate_fields: ["lastname", "email"] })
end

it "should permit :contact_form_id" do
expect(controller.send(:mailer_config)[:fields]).to include "contact_field_id"

msg_params = subject.send(:message_params)

expect(msg_params).to include :contact_form_id
end
end

context "when mailer_config['fields'] does not inlcude :contact_field_id" do
it "should permit :contact_form_id" do
expect(Alchemy::Config.get(:mailer)["fields"]).not_to include "contact_field_id"
msg_params = subject.send(:message_params)

expect(msg_params).to include :contact_form_id
end
end
end
end
end