Skip to content

Commit

Permalink
Forms Refactoring - Service Provider form (#508)
Browse files Browse the repository at this point in the history
From: https://eaflood.atlassian.net/browse/RUBY-693

Implement delegate and strong parameters strategy in Service Provider form
  • Loading branch information
cintamani committed Oct 10, 2019
1 parent 666b0af commit a8531ed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@ def new
def create
super(ServiceProvidedForm, "service_provided_form")
end

private

def transient_registration_attributes
params.require(:service_provided_form).permit(:is_main_service)
end
end
end
16 changes: 1 addition & 15 deletions app/forms/waste_carriers_engine/service_provided_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,8 @@

module WasteCarriersEngine
class ServiceProvidedForm < BaseForm
attr_accessor :is_main_service
delegate :is_main_service, to: :transient_registration

validates :is_main_service, "waste_carriers_engine/yes_no": true

def initialize(transient_registration)
super

self.is_main_service = transient_registration.is_main_service
end

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

super(attributes)
end
end
end
13 changes: 10 additions & 3 deletions spec/factories/forms/service_provided_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
FactoryBot.define do
factory :service_provided_form, class: WasteCarriersEngine::ServiceProvidedForm do
trait :has_required_data do
is_main_service { "yes" }

initialize_with { new(create(:transient_registration, :has_required_data, workflow_state: "service_provided_form")) }
initialize_with do
new(
create(
:transient_registration,
:has_required_data,
workflow_state: "service_provided_form",
is_main_service: "yes"
)
)
end
end
end
end

0 comments on commit a8531ed

Please sign in to comment.