Feature: Contact form As a visitor In order to keep in touch with the site I want to be able to send them a message Background: Given I enable the CSRF protection for public submission requests Given I have the site: "test site" set up And I have a custom model named "Messages" with | label | type | required | | Email | string | true | | Message | text | true | And I enable the public submission of the "Messages" model And a page named "contact" with the template: """
{% csrf_param %} {% if message.errors.email %}Email is required{% endif %}
""" And a page named "success" with the template: """ Thanks {{ message.email }} """ Scenario: Setting the right url for the contact form When I view the rendered page at "/contact" Then the rendered output should look like: """
""" Scenario: Prevents users to post messages if the public submission option is disabled Given I disable the public submission of the "Messages" model When I view the rendered page at "/contact" And I fill in "E-Mail Address" with "did@locomotivecms.com" And I fill in "Message" with "LocomotiveCMS rocks" And I press "Submit" Then I should not see "Thanks did@locomotivecms.com" Scenario: Sending a message with success When I view the rendered page at "/contact" And I fill in "E-Mail Address" with "did@locomotivecms.com" And I fill in "Message" with "LocomotiveCMS rocks" And I press "Submit" Then I should see "Thanks did@locomotivecms.com" Scenario: Can not send a message if the csrf tag is missing Given I delete the following code "{% csrf_param %}" from the "contact" page When I view the rendered page at "/contact" And I press "Submit" Then I should see "Content of the home page" Scenario: Can send a message if the csrf protection is disabled Given I disable the CSRF protection for public submission requests And I view the rendered page at "/contact" And I fill in "E-Mail Address" with "did@locomotivecms.com" And I fill in "Message" with "LocomotiveCMS rocks" And I press "Submit" Then I should see "Thanks did@locomotivecms.com" Scenario: Display errors When I view the rendered page at "/contact" And I fill in "Message" with "LocomotiveCMS rocks" And I press "Submit" Then I should see "Email is required"