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

All boolean attributes should be "yes" or "no" #218

Merged
merged 5 commits into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions app/forms/waste_carriers_engine/base_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ def submit(attributes, reg_identifier)

private

def convert_to_boolean(value)
if value == "true"
true
elsif value == "false"
false
end
end

def transient_registration_valid?
return if @transient_registration.valid?
@transient_registration.errors.each do |_attribute, message|
Expand Down
2 changes: 1 addition & 1 deletion app/forms/waste_carriers_engine/check_your_answers_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def contact_name
validates :company_no, "waste_carriers_engine/company_no": true
validates :contact_address, "waste_carriers_engine/address": true
validates :contact_email, "waste_carriers_engine/email": true
validates :declared_convictions, "waste_carriers_engine/boolean": true
validates :declared_convictions, "waste_carriers_engine/yes_no": true
validates :first_name, :last_name, "waste_carriers_engine/person_name": true
validates :location, "waste_carriers_engine/location": true
validates :phone_number, "waste_carriers_engine/phone_number": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ def initialize(transient_registration)

def submit(params)
# Assign the params for validation and pass them to the BaseForm method for updating
self.construction_waste = convert_to_boolean(params[:construction_waste])
self.construction_waste = params[:construction_waste]
attributes = { construction_waste: construction_waste }

super(attributes, params[:reg_identifier])
end

validates :construction_waste, "waste_carriers_engine/boolean": true
validates :construction_waste, "waste_carriers_engine/yes_no": true
end
end
4 changes: 2 additions & 2 deletions app/forms/waste_carriers_engine/declare_convictions_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ def initialize(transient_registration)

def submit(params)
# Assign the params for validation and pass them to the BaseForm method for updating
self.declared_convictions = convert_to_boolean(params[:declared_convictions])
self.declared_convictions = params[:declared_convictions]
attributes = { declared_convictions: declared_convictions }

super(attributes, params[:reg_identifier])
end

validates :declared_convictions, "waste_carriers_engine/boolean": true
validates :declared_convictions, "waste_carriers_engine/yes_no": true
end
end
4 changes: 2 additions & 2 deletions app/forms/waste_carriers_engine/other_businesses_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ def initialize(transient_registration)

def submit(params)
# Assign the params for validation and pass them to the BaseForm method for updating
self.other_businesses = convert_to_boolean(params[:other_businesses])
self.other_businesses = params[:other_businesses]
attributes = { other_businesses: other_businesses }

super(attributes, params[:reg_identifier])
end

validates :other_businesses, "waste_carriers_engine/boolean": true
validates :other_businesses, "waste_carriers_engine/yes_no": true
end
end
4 changes: 2 additions & 2 deletions app/forms/waste_carriers_engine/service_provided_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ def initialize(transient_registration)

def submit(params)
# Assign the params for validation and pass them to the BaseForm method for updating
self.is_main_service = convert_to_boolean(params[:is_main_service])
self.is_main_service = params[:is_main_service]
attributes = { is_main_service: is_main_service }

super(attributes, params[:reg_identifier])
end

validates :is_main_service, "waste_carriers_engine/boolean": true
validates :is_main_service, "waste_carriers_engine/yes_no": true
end
end
4 changes: 2 additions & 2 deletions app/forms/waste_carriers_engine/tier_check_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ def initialize(transient_registration)

def submit(params)
# Assign the params for validation and pass them to the BaseForm method for updating
self.temp_tier_check = convert_to_boolean(params[:temp_tier_check])
self.temp_tier_check = params[:temp_tier_check]
attributes = { temp_tier_check: temp_tier_check }

super(attributes, params[:reg_identifier])
end

validates :temp_tier_check, "waste_carriers_engine/boolean": true
validates :temp_tier_check, "waste_carriers_engine/yes_no": true
end
end
4 changes: 2 additions & 2 deletions app/forms/waste_carriers_engine/waste_types_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ def initialize(transient_registration)

def submit(params)
# Assign the params for validation and pass them to the BaseForm method for updating
self.only_amf = convert_to_boolean(params[:only_amf])
self.only_amf = params[:only_amf]
attributes = { only_amf: only_amf }

super(attributes, params[:reg_identifier])
end

validates :only_amf, "waste_carriers_engine/boolean": true
validates :only_amf, "waste_carriers_engine/yes_no": true
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,9 @@ def switch_to_lower_tier_based_on_business_type?
end

def switch_to_lower_tier_based_on_smart_answers?
return true if other_businesses == false && construction_waste == false
return true if other_businesses == true && is_main_service == false && construction_waste == false
return true if other_businesses == true && is_main_service == true && only_amf == true
return true if other_businesses == "no" && construction_waste == "no"
return true if other_businesses == "yes" && is_main_service == "no" && construction_waste == "no"
return true if other_businesses == "yes" && is_main_service == "yes" && only_amf == "yes"
false
end

Expand All @@ -498,15 +498,15 @@ def require_new_registration_based_on_company_no?
end

def skip_tier_check?
temp_tier_check == false
temp_tier_check == "no"
end

def only_carries_own_waste?
other_businesses == false
other_businesses == "no"
end

def waste_is_main_service?
is_main_service == true
is_main_service == "yes"
end

def based_overseas?
Expand Down Expand Up @@ -540,7 +540,7 @@ def should_register_in_wales?
end

def declared_convictions?
declared_convictions == true
declared_convictions == "yes"
end

def paying_by_card?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ module CanHaveRegistrationAttributes
field :registrationType, as: :registration_type, type: String
field :location, type: String
field :businessType, as: :business_type, type: String
field :otherBusinesses, as: :other_businesses, type: Boolean
field :isMainService, as: :is_main_service, type: Boolean
field :onlyAMF, as: :only_amf, type: Boolean
field :constructionWaste, as: :construction_waste, type: Boolean
field :otherBusinesses, as: :other_businesses, type: String # 'yes' or 'no' - should refactor to boolean
field :isMainService, as: :is_main_service, type: String # 'yes' or 'no' - should refactor to boolean
field :onlyAMF, as: :only_amf, type: String # 'yes' or 'no' - should refactor to boolean
field :constructionWaste, as: :construction_waste, type: String # 'yes' or 'no' - should refactor to boolean
field :companyName, as: :company_name, type: String
field :companyNo, as: :company_no, type: String # Despite its name, this can include letters
field :firstName, as: :first_name, type: String
field :lastName, as: :last_name, type: String
field :phoneNumber, as: :phone_number, type: String
field :contactEmail, as: :contact_email, type: String
field :accountEmail, as: :account_email, type: String
field :declaredConvictions, as: :declared_convictions, type: Boolean
field :declaration, type: Integer # Unsure of type
field :declaredConvictions, as: :declared_convictions, type: String # 'yes' or 'no' - should refactor to boolean
field :declaration, type: Integer
field :regIdentifier, as: :reg_identifier, type: String
field :expires_on, type: DateTime

Expand Down Expand Up @@ -65,7 +65,7 @@ def relevant_people
end

def conviction_check_required?
return true if declared_convictions == true
return true if declared_convictions == "yes"
business_has_matching_or_unknown_conviction? || key_person_has_matching_or_unknown_conviction?
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def enough_relevant_people?
end

def minimum_relevant_people
return 1 if @transient_registration.declared_convictions
return 1 if @transient_registration.declared_convictions == "yes"
0
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/waste_carriers_engine/transient_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class TransientRegistration
field :temp_cards, type: Integer
field :temp_company_postcode, type: String
field :temp_contact_postcode, type: String
field :temp_os_places_error, type: Boolean
field :temp_os_places_error, type: String # 'yes' or 'no' - should refactor to boolean
field :temp_payment_method, type: String
field :temp_tier_check, type: Boolean
field :temp_tier_check, type: String # 'yes' or 'no' - should refactor to boolean

# Check if the user has changed the registration type, as this incurs an additional 40GBP charge
def registration_type_changed?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module WasteCarriersEngine
class BooleanValidator < ActiveModel::EachValidator
class YesNoValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
valid_values = [true, false]
valid_values = %w[yes no]
return true if valid_values.include?(value)
record.errors[attribute] << error_message(record, attribute, "inclusion")
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
<% end %>

<div class="multiple-choice">
<%= f.radio_button :construction_waste, "true" %>
<%= f.label :construction_waste, t(".option_true"), value: "true" %>
<%= f.radio_button :construction_waste, "yes" %>
<%= f.label :construction_waste, t(".options.yes"), value: "yes" %>
</div>
<div class="multiple-choice">
<%= f.radio_button :construction_waste, "false" %>
<%= f.label :construction_waste, t(".option_false"), value: "false" %>
<%= f.radio_button :construction_waste, "no" %>
<%= f.label :construction_waste, t(".options.no"), value: "no" %>
</div>
</fieldset>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
<p class="strong"><%= t(".paragraph_1") %></p>

<div class="multiple-choice">
<%= f.radio_button :declared_convictions, "true" %>
<%= f.label :declared_convictions, t(".options.true"), value: "true" %>
<%= f.radio_button :declared_convictions, "yes" %>
<%= f.label :declared_convictions, t(".options.yes"), value: "yes" %>
</div>
<div class="multiple-choice">
<%= f.radio_button :declared_convictions, "false" %>
<%= f.label :declared_convictions, t(".options.false"), value: "false" %>
<%= f.radio_button :declared_convictions, "no" %>
<%= f.label :declared_convictions, t(".options.no"), value: "no" %>
</div>
</fieldset>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
<% end %>

<div class="multiple-choice">
<%= f.radio_button :other_businesses, "true" %>
<%= f.label :other_businesses, t(".option_true"), value: "true" %>
<%= f.radio_button :other_businesses, "yes" %>
<%= f.label :other_businesses, t(".options.yes"), value: "yes" %>
</div>
<div class="multiple-choice">
<%= f.radio_button :other_businesses, "false" %>
<%= f.label :other_businesses, t(".option_false"), value: "false" %>
<%= f.radio_button :other_businesses, "no" %>
<%= f.label :other_businesses, t(".options.no"), value: "no" %>
</div>
</fieldset>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
<% end %>

<div class="multiple-choice">
<%= f.radio_button :is_main_service, "false" %>
<%= f.label :is_main_service, t(".option_false"), value: "false" %>
<%= f.radio_button :is_main_service, "no" %>
<%= f.label :is_main_service, t(".options.no"), value: "no" %>
</div>
<div class="multiple-choice">
<%= f.radio_button :is_main_service, "true" %>
<%= f.label :is_main_service, t(".option_true"), value: "true" %>
<%= f.radio_button :is_main_service, "yes" %>
<%= f.label :is_main_service, t(".options.yes"), value: "yes" %>
</div>
</fieldset>
</div>
Expand Down
8 changes: 4 additions & 4 deletions app/views/waste_carriers_engine/tier_check_forms/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
<% end %>

<div class="multiple-choice">
<%= f.radio_button :temp_tier_check, "false" %>
<%= f.label :temp_tier_check, t(".options.false"), value: "false" %>
<%= f.radio_button :temp_tier_check, "no" %>
<%= f.label :temp_tier_check, t(".options.no"), value: "no" %>
</div>
<div class="multiple-choice">
<%= f.radio_button :temp_tier_check, "true" %>
<%= f.label :temp_tier_check, t(".options.true"), value: "true" %>
<%= f.radio_button :temp_tier_check, "yes" %>
<%= f.label :temp_tier_check, t(".options.yes"), value: "yes" %>
</div>
</fieldset>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
<% end %>

<div class="multiple-choice">
<%= f.radio_button :only_amf, "true" %>
<%= f.label :only_amf, t(".option_true_html"), value: "true" %>
<%= f.radio_button :only_amf, "yes" %>
<%= f.label :only_amf, t(".options.yes"), value: "yes" %>
</div>
<div class="multiple-choice">
<%= f.radio_button :only_amf, "false" %>
<%= f.label :only_amf, t(".option_false"), value: "false" %>
<%= f.radio_button :only_amf, "no" %>
<%= f.label :only_amf, t(".options.no"), value: "no" %>
</div>
</fieldset>
</div>
Expand Down
4 changes: 2 additions & 2 deletions config/locales/forms/check_your_answers_forms/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ en:
other: Business or organisation owners
subheading_7: Relevant convictions
declared_convictions:
"true": You told us you have relevant people with convictions in your business or organisation.
"false": You told us there are no relevant people with convictions in your business or organisation.
"yes": You told us you have relevant people with convictions in your business or organisation.
"no": You told us there are no relevant people with convictions in your business or organisation.
subheading_8: Contact details
next_button: Continue
activemodel:
Expand Down
5 changes: 3 additions & 2 deletions config/locales/forms/construction_demolition_forms/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ en:
new:
title: Building, construction and demolition waste
heading: Do you ever deal with building, construction or demolition waste?
option_true: "Yes"
option_false: "No"
options:
"yes": "Yes"
"no": "No"
waste_detail_subheading: What is building, construction and demolition waste?
waste_detail_paragraph_1: This waste is generated through building or renovation work, including soil, concrete, bricks, glass, wood, plasterboard, asbestos, metal and plastic.
waste_detail_paragraph_2: It can be produced as part of a large construction project or a smaller business activity (e.g. a builder replacing a bathroom, or a gardener replacing fence panels).
Expand Down
4 changes: 2 additions & 2 deletions config/locales/forms/declare_convictions_forms/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ en:
heading: Has anyone in the organisation's management been convicted of an environmental offence in the last 12 months?
paragraph_1: If you don’t tell us about any unspent environmental offences, you may not be able to register.
options:
"true": "Yes"
"false": "No"
"yes": "Yes"
"no": "No"
conviction_types_subheading: Offences you must tell us about
conviction_types_paragraph_1: If anyone involved in managing the business has been convicted of an environmental offence, it might affect this registration.
conviction_types_paragraph_2: "You only need to tell us about unspent convictions for offences under these areas of law:"
Expand Down
5 changes: 3 additions & 2 deletions config/locales/forms/other_businesses_forms/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ en:
new:
title: Waste from other people
heading: Do you ever deal with waste from other businesses or households?
option_true: "Yes"
option_false: "No"
options:
"yes": "Yes"
"no": "No"
error_heading: Something is wrong
next_button: Continue
activemodel:
Expand Down
5 changes: 3 additions & 2 deletions config/locales/forms/service_provided_forms/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ en:
title: Who creates the waste?
heading: Who creates the waste that you deal with?
error_heading: Something is wrong
option_true: Our customers create the waste, we just collect or move it for them
option_false: We create the waste as part of a service we provide to our customers, for example a gardener taking away grass cuttings
options:
"yes": Our customers create the waste, we just collect or move it for them
"no": We create the waste as part of a service we provide to our customers, for example a gardener taking away grass cuttings
next_button: Continue
activemodel:
errors:
Expand Down
4 changes: 2 additions & 2 deletions config/locales/forms/tier_check_forms/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ en:
- item: "You ONLY deal with waste you produce in the course of carrying out your business – for example, a hairdresser dealing with hair clippings. This does not include construction or demolition waste"
- item: "You ONLY deal with waste from mines or quarries, from agricultural premises, or animal by-products"
options:
"false": I know I need an upper tier registration (continue)
"true": I want to check my tier is correct before renewing
"no": I know I need an upper tier registration (continue)
"yes": I want to check my tier is correct before renewing
error_heading: Something is wrong
next_button: Continue
activemodel:
Expand Down
Loading