Skip to content

Commit

Permalink
Merge pull request #23 from nestauk/accept-terms-of-service
Browse files Browse the repository at this point in the history
Make users check terms of service
  • Loading branch information
cdccollins authored Oct 7, 2024
2 parents 29debcb + 7e52787 commit 5ae1ab8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
6 changes: 6 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ body {
.form-checkbox {
margin-right: .5rem !important;
}

.boolean.field_with_errors {
.error {
display: block;
}
}
2 changes: 2 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def new
def create
@user = User.new(user_params.except(:interest_ids))

@user.terms_agreed_at = Time.now if user_params[:terms_agreed_at] == "1"

if @user.save
user_params[:interest_ids].split(",").each do |interest_id|
@user.interests << Interest.find(interest_id)
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class User < ApplicationRecord
has_many :interests
has_many :messages, dependent: :destroy
has_many :contents, through: :messages
validates :phone_number, :first_name, :last_name, :child_birthday, presence: true
validates :phone_number, :first_name, :last_name, :child_birthday, :terms_agreed_at, presence: true
validates_uniqueness_of :phone_number
phony_normalize :phone_number, default_country_code: "UK"

Expand Down
8 changes: 2 additions & 6 deletions app/views/users/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,9 @@
</div>

<%= form.input :interest_ids, as: :hidden, input_html: { value: params["interest_ids"] } %>
<%= form.input :terms_agreed_at, as: :hidden, input_html: { value: Time.now } %>
<%= form.input :terms_agreed_at, as: :boolean, label: "I accept the terms of service and privacy policy", input_html: { class: "form-checkbox" }, wrapper_html: { class: "mt-5" } %>
<p class="mt-6 text-s">
By submitting this form, you consent to us using your details to provide you with an update about Tiny Happy People. We will keep your details safe, and you can change your mind about hearing from us by getting in touch.
</p>

<%= form.submit "Sign up", class: "btn btn-primary mt-5 bg-purple-600 text-white w-full" %>
<%= form.submit "Sign up", class: "btn btn-primary mt-2 bg-purple-600 text-white w-full" %>
<% end %>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions test/system/users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class UsersTest < ApplicationSystemTestCase
select "Morning"
check "Do you have family support in bringing up your child(ren)?"
check "Would you like to be added to a Slack channel with other parents to discuss the programme?"
check "I accept the terms of service and privacy policy"

Message.any_instance.stubs(:generate_token).returns("123")
message = "Hi Jo, welcome to Tiny Happy People. Here's a video to get you started: http://localhost:3000/m/123"
Expand Down Expand Up @@ -44,5 +45,6 @@ class UsersTest < ApplicationSystemTestCase
assert_field_has_errors("First name")
assert_field_has_errors("Last name")
assert_field_has_errors("Phone number")
assert_field_has_errors("I accept the terms of service and privacy policy")
end
end

0 comments on commit 5ae1ab8

Please sign in to comment.