From 187c6ba75ee2f8a5485f5b48b8d9ddd8aa6b809e Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Wed, 19 Jun 2019 16:05:52 +1200 Subject: [PATCH 01/59] remove extra puts --- app/services/rates_importer_service.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/services/rates_importer_service.rb b/app/services/rates_importer_service.rb index 6c77748d..4ef13735 100644 --- a/app/services/rates_importer_service.rb +++ b/app/services/rates_importer_service.rb @@ -8,7 +8,6 @@ def clear!(rating_year, council) end def import(row, rating_year, council) - puts row valuation, _rating_year, location, suburb, town_city, total_rates, total_water_rates, _order, _council_owner_id, _surname, _first_names, _confidential, current_owner_start_date = row From bc46a60cf14039119be0a0150ea1068949641027 Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Thu, 20 Jun 2019 11:08:41 +1200 Subject: [PATCH 02/59] Added new customer id and application id fields to rebate form. --- ...49_add_customer_id_and_application_id_to_rebate_forms.rb | 6 ++++++ db/schema.rb | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20190619225849_add_customer_id_and_application_id_to_rebate_forms.rb diff --git a/db/migrate/20190619225849_add_customer_id_and_application_id_to_rebate_forms.rb b/db/migrate/20190619225849_add_customer_id_and_application_id_to_rebate_forms.rb new file mode 100644 index 00000000..42b50ba5 --- /dev/null +++ b/db/migrate/20190619225849_add_customer_id_and_application_id_to_rebate_forms.rb @@ -0,0 +1,6 @@ +class AddCustomerIdAndApplicationIdToRebateForms < ActiveRecord::Migration[5.2] + def change + add_column :rebate_forms, :customer_id, :string + add_column :rebate_forms, :application_id, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 7dec7f8e..5a6eff1e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_06_18_231804) do +ActiveRecord::Schema.define(version: 2019_06_19_225849) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -101,6 +101,8 @@ t.integer "batch_id" t.integer "updated_by" t.string "status", default: "not signed" + t.string "customer_id" + t.string "application_id" end create_table "roles", force: :cascade do |t| From 2f819175831648a035ec9fc2f16cd8670c975d01 Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Thu, 20 Jun 2019 12:29:06 +1200 Subject: [PATCH 03/59] Removed valuation id and customer id from javascript, moved around headers and edit buttons, started council details section of show page. Removed unneeded view and code related to PDF version of rebate form show page. --- app/assets/stylesheets/admin/rebate_form.css | 15 ++++++++++++++- app/controllers/admin/rebate_forms_controller.rb | 11 ++++++----- app/javascript/helpers/data.js | 16 +++------------- app/policies/rebate_form_policy.rb | 6 +++++- .../rebate_forms/_council_details_show.html.haml | 9 +++++++++ .../admin/rebate_forms/_show_header.html.haml | 4 +--- app/views/admin/rebate_forms/show.html.haml | 7 ++++++- app/views/admin/rebate_forms/show.pdf.haml | 1 - config/routes.rb | 1 + 9 files changed, 45 insertions(+), 25 deletions(-) create mode 100644 app/views/admin/rebate_forms/_council_details_show.html.haml delete mode 100644 app/views/admin/rebate_forms/show.pdf.haml diff --git a/app/assets/stylesheets/admin/rebate_form.css b/app/assets/stylesheets/admin/rebate_form.css index 79abf69b..fa4aceec 100644 --- a/app/assets/stylesheets/admin/rebate_form.css +++ b/app/assets/stylesheets/admin/rebate_form.css @@ -75,11 +75,24 @@ width: 1.75em; } +.rebate-details-header { + margin: 0 200px; +} + +.customer-details-header { + margin-top: 30px; +} + +.rebate-details-title, +.rebate-edit { + display: inline-block; +} + .rebate-edit { background-color: var(--blue); border-radius: .2em; color: var(--white); - float: right; + margin-bottom: 10px; width: 5em; } diff --git a/app/controllers/admin/rebate_forms_controller.rb b/app/controllers/admin/rebate_forms_controller.rb index 181aa03c..f47a3032 100644 --- a/app/controllers/admin/rebate_forms_controller.rb +++ b/app/controllers/admin/rebate_forms_controller.rb @@ -11,6 +11,11 @@ def generateqr @image_data = GenerateQrService.new(@rebate_form, current_user).generate_qr end + def edit_council_fields + @rebate_form = RebateForm.find(params[:id]) + authorize @rebate_form + end + def edit; end # GET /admin/rebate_forms @@ -40,11 +45,7 @@ def show @updated_by = User.find(@rebate_form.updated_by) unless @rebate_form.updated_by.nil? - respond_with(@rebate_form) do |format| - format.pdf do - render pdf: pdf_filename, page_size: 'A4', layout: 'pdf', margin: { top: 0, bottom: 0, left: 0, right: 0 }, dpi: '300' - end - end + respond_with(@rebate_form) end # PATCH/PUT /admin/rebate_forms/1 diff --git a/app/javascript/helpers/data.js b/app/javascript/helpers/data.js index 2743a985..791d5b94 100644 --- a/app/javascript/helpers/data.js +++ b/app/javascript/helpers/data.js @@ -68,16 +68,6 @@ export const customerDetailFields = [ id: 'full_name', label: 'Name', }, - { - id: 'customer_id', - label: 'Customer ID (optional)', - placeholder: '0000000', - }, - { - id: 'location', - label: 'Address', - fullWidth: true - }, { id: 'total_rates', label: 'Total rates', @@ -85,9 +75,9 @@ export const customerDetailFields = [ step: 0.01 }, { - id: 'valuation_id', - label: 'Valuation ID (optional)', - placeholder: '00000 000 00', + id: 'location', + label: 'Address', + fullWidth: true }, { id: 'email', diff --git a/app/policies/rebate_form_policy.rb b/app/policies/rebate_form_policy.rb index d54ea0ca..1b64aa3c 100644 --- a/app/policies/rebate_form_policy.rb +++ b/app/policies/rebate_form_policy.rb @@ -13,8 +13,12 @@ def show? dia? || same_council? end + def edit_council_fields? + dia? || same_council? + end + def update? - (dia? || same_council?) + dia? || same_council? end def destroy? diff --git a/app/views/admin/rebate_forms/_council_details_show.html.haml b/app/views/admin/rebate_forms/_council_details_show.html.haml new file mode 100644 index 00000000..3cfc6ea5 --- /dev/null +++ b/app/views/admin/rebate_forms/_council_details_show.html.haml @@ -0,0 +1,9 @@ +.rebate-details-header.council-details-header + %h3.rebate-details-title Council Details + - unless @rebate_form.processed_state? || @rebate_form.batched_state? + = link_to 'EDIT', admin_rebate_form_edit_council_fields_path(@rebate_form), class: 'pure-button rebate-edit council-edit' + +.rebate-edit-form + %label Valuation ID + %div + = @rebate_form.valuation_id diff --git a/app/views/admin/rebate_forms/_show_header.html.haml b/app/views/admin/rebate_forms/_show_header.html.haml index 930ef58a..563965f9 100644 --- a/app/views/admin/rebate_forms/_show_header.html.haml +++ b/app/views/admin/rebate_forms/_show_header.html.haml @@ -3,12 +3,10 @@ =image_tag("search.svg", class: 'rebate-header-icon') = link_to admin_rebate_form_path(@rebate_form), id: 'reload' do =image_tag("blue-reload.svg", class: 'rebate-header-icon') - - unless @rebate_form.processed_state? || @rebate_form.batched_state? - = link_to 'EDIT', edit_admin_rebate_form_path, id: 'edit', class: 'pure-button rebate-edit' .rebate-header %h2.rebate-title - Customer details + Application details - if @rebate_form.not_signed_state? = link_to admin_rebate_form_generateqr_path(@rebate_form), id: 'generate_qr' do =image_tag("signature1.svg", class: 'rebate-generate-qr') diff --git a/app/views/admin/rebate_forms/show.html.haml b/app/views/admin/rebate_forms/show.html.haml index 1de05fbb..ad7fe79b 100644 --- a/app/views/admin/rebate_forms/show.html.haml +++ b/app/views/admin/rebate_forms/show.html.haml @@ -1,6 +1,11 @@ - - content_for :title, "RatesRebate #{@rebate_form.property.location}" = render 'show_header' += render 'council_details_show', rebate_form: @rebate_form + +.rebate-details-header.customer-details-header + %h3.rebate-details-title Customer Details + - unless @rebate_form.processed_state? || @rebate_form.batched_state? + = link_to 'EDIT', edit_admin_rebate_form_path, id: 'edit', class: 'pure-button rebate-edit' = react_component("RebateForm", {isReadOnly: true, rebateForm: @rebate_form, property: @rebate_form.property, ratesBills: @rebate_form.property.rates_bills}) diff --git a/app/views/admin/rebate_forms/show.pdf.haml b/app/views/admin/rebate_forms/show.pdf.haml deleted file mode 100644 index 8cb269d0..00000000 --- a/app/views/admin/rebate_forms/show.pdf.haml +++ /dev/null @@ -1 +0,0 @@ -.pdf= render 'artefact', rebate_form: @rebate_form diff --git a/config/routes.rb b/config/routes.rb index d023db7d..b6f203ec 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,6 +17,7 @@ resources :rebate_forms do get 'generateqr' + get 'edit_council_fields' end resources :attachments, only: %i[destroy] resources :councils do From 2f55eba2148cd7597f36166370cb6f3966e93b0e Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Thu, 20 Jun 2019 15:21:10 +1200 Subject: [PATCH 04/59] clean up import service --- app/services/rates_importer_service.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/services/rates_importer_service.rb b/app/services/rates_importer_service.rb index 4ef13735..447ccd4d 100644 --- a/app/services/rates_importer_service.rb +++ b/app/services/rates_importer_service.rb @@ -21,18 +21,19 @@ def import(row, rating_year, council) property = Property.create!( council: council, valuation_id: valuation, - location: location, + location: ("#{location.gsub /"/, ''} " + "#{suburb} " + town_city.to_s).strip, suburb: suburb, town_city: town_city, rating_year: rating_year, meta: row.to_s ) end - rates_bill = RatesBill.find_by(property: property, rating_year: rating_year) + if rates_bill.present? - raise 'mismatch total_rates' unless rates_bill.total_rates.to_f == total_rates.to_f + total_water_rates.to_f - raise 'mismatch current_owner_start_date' unless rates_bill.current_owner_start_date == current_owner_start_date + current_rates = rates_bill.total_rates.to_f.round(2) + new_rates = (total_rates.to_f + total_water_rates.to_f).round(2) + raise 'mismatch total_rates' unless current_rates == new_rates else RatesBill.create!( property: property, From fbe2fbd8dddfac2d865c6ebeb1fa2d9cf77b401d Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Thu, 20 Jun 2019 15:22:12 +1200 Subject: [PATCH 05/59] turn on kapiti rake tast --- bin/docker_web_aws | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/docker_web_aws b/bin/docker_web_aws index 87374e04..2bae7174 100755 --- a/bin/docker_web_aws +++ b/bin/docker_web_aws @@ -10,8 +10,8 @@ fi echo "Migrating and refreshing reference data" bundle exec rake db:migrate -# bundle exec rake rates:kapiti -bundle exec rake rates:tauranga +bundle exec rake rates:kapiti +# bundle exec rake rates:tauranga echo "Running the server..." rm -f tmp/pids/server.pid From ade1dc51820cf647e3059ea6e05b8160e51592cf Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Thu, 20 Jun 2019 15:46:19 +1200 Subject: [PATCH 06/59] override with latest rates data for property --- app/services/rates_importer_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/rates_importer_service.rb b/app/services/rates_importer_service.rb index 447ccd4d..ad494305 100644 --- a/app/services/rates_importer_service.rb +++ b/app/services/rates_importer_service.rb @@ -33,7 +33,7 @@ def import(row, rating_year, council) if rates_bill.present? current_rates = rates_bill.total_rates.to_f.round(2) new_rates = (total_rates.to_f + total_water_rates.to_f).round(2) - raise 'mismatch total_rates' unless current_rates == new_rates + # raise 'mismatch total_rates' unless current_rates == new_rates else RatesBill.create!( property: property, From 1d6ee0bcdd89df296a89ca902c485c3299aa748c Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Thu, 20 Jun 2019 16:05:01 +1200 Subject: [PATCH 07/59] Built new edit council fields form and updated controller and service. --- app/assets/stylesheets/admin/rebate_form.css | 8 +++++++ .../admin/rebate_forms_controller.rb | 11 +++++----- app/services/rebate_forms_service.rb | 9 ++++++++ .../_council_details_show.html.haml | 18 ++++++++++++---- .../admin/rebate_forms/_edit_header.html.haml | 8 +------ app/views/admin/rebate_forms/edit.html.haml | 2 ++ .../edit_council_fields.html.haml | 21 +++++++++++++++++++ 7 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 app/views/admin/rebate_forms/edit_council_fields.html.haml diff --git a/app/assets/stylesheets/admin/rebate_form.css b/app/assets/stylesheets/admin/rebate_form.css index fa4aceec..28373aeb 100644 --- a/app/assets/stylesheets/admin/rebate_form.css +++ b/app/assets/stylesheets/admin/rebate_form.css @@ -151,6 +151,10 @@ align-items: center } +.council-row { + align-items: normal; +} + .flex-column { display: flex; flex-direction: column @@ -190,6 +194,10 @@ margin-top: -5em; } +.council-buttons { + margin-top: -10em; +} + .rebate-cancel-button { background-color: var(--white); border-radius: .2em; diff --git a/app/controllers/admin/rebate_forms_controller.rb b/app/controllers/admin/rebate_forms_controller.rb index f47a3032..63766e20 100644 --- a/app/controllers/admin/rebate_forms_controller.rb +++ b/app/controllers/admin/rebate_forms_controller.rb @@ -12,7 +12,7 @@ def generateqr end def edit_council_fields - @rebate_form = RebateForm.find(params[:id]) + @rebate_form = RebateForm.find(params[:rebate_form_id]) authorize @rebate_form end @@ -50,7 +50,8 @@ def show # PATCH/PUT /admin/rebate_forms/1 def update - @rebate_form = RebateFormsService.new(rebate_form_fields_params).update! + @rebate_form = RebateFormsService.new(rebate_form_council_details_params).update_council_details! if params[:council_details] + @rebate_form = RebateFormsService.new(rebate_form_fields_params).update! unless params[:council_details] @rebate_form.update(updated_by: current_user.id) respond_with @rebate_form, location: admin_rebate_form_url(@rebate_form), notice: 'Rebate form was successfully updated.' end @@ -73,11 +74,11 @@ def set_rebate_form end def rebate_form_fields_params - params.permit(:id, :valuation_id, :total_rates, :location, :council, fields: {}) + params.permit(:id, :total_rates, :location, :council, fields: {}) end - def rebate_form_params - params.require(:rebate_form).permit(attachments: []) + def rebate_form_council_details_params + params.permit([:id, :council_details, rebate_form: {}]) end def pdf_filename diff --git a/app/services/rebate_forms_service.rb b/app/services/rebate_forms_service.rb index 2d90146a..599d28ad 100644 --- a/app/services/rebate_forms_service.rb +++ b/app/services/rebate_forms_service.rb @@ -4,10 +4,19 @@ class RebateFormsService class Error < StandardError; end def initialize(rebate_form_attributes) + @rebate_form_council_details = rebate_form_attributes if rebate_form_attributes['council_details'] rebate_form_attributes['fields']['location'] = rebate_form_attributes['location'] if rebate_form_attributes['fields'] @rebate_form_attributes = rebate_form_attributes end + def update_council_details! + rebate_form = RebateForm.find(@rebate_form_council_details['id']) + rebate_form.update!(valuation_id: @rebate_form_council_details['rebate_form']['valuation_id'], + customer_id: @rebate_form_council_details['rebate_form']['customer_id'], + application_id: @rebate_form_council_details['rebate_form']['application_id']) + rebate_form + end + def update! council = find_council! property = create_or_update_property!(council) diff --git a/app/views/admin/rebate_forms/_council_details_show.html.haml b/app/views/admin/rebate_forms/_council_details_show.html.haml index 3cfc6ea5..fb84b4f6 100644 --- a/app/views/admin/rebate_forms/_council_details_show.html.haml +++ b/app/views/admin/rebate_forms/_council_details_show.html.haml @@ -1,9 +1,19 @@ .rebate-details-header.council-details-header %h3.rebate-details-title Council Details - unless @rebate_form.processed_state? || @rebate_form.batched_state? - = link_to 'EDIT', admin_rebate_form_edit_council_fields_path(@rebate_form), class: 'pure-button rebate-edit council-edit' + = link_to 'EDIT', admin_rebate_form_edit_council_fields_path(rebate_form_id: @rebate_form.id), class: 'pure-button rebate-edit council-edit' .rebate-edit-form - %label Valuation ID - %div - = @rebate_form.valuation_id + .flex-row.council-row + .flex-item + %label Valuation ID + .rebate-search-input + = @rebate_form.valuation_id + .flex-item + %label Application ID (optional) + .rebate-search-input + = @rebate_form.application_id + .flex-item + %label Customer ID (optional) + .rebate-search-input + = @rebate_form.customer_id diff --git a/app/views/admin/rebate_forms/_edit_header.html.haml b/app/views/admin/rebate_forms/_edit_header.html.haml index eede962a..267ea66e 100644 --- a/app/views/admin/rebate_forms/_edit_header.html.haml +++ b/app/views/admin/rebate_forms/_edit_header.html.haml @@ -1,9 +1,3 @@ -.rebate-header-buttons - = link_to admin_rebate_forms_path, id: 'back' do - =image_tag("search.svg", class: 'rebate-header-icon') - = link_to edit_admin_rebate_form_path, id: 'reload' do - =image_tag("blue-reload.svg", class: 'rebate-header-icon') - - if @rebate_form.signed_state? .rebate-banner#rebate-banner =image_tag("alert1.svg", class: 'rebate-banner-icon') @@ -15,7 +9,7 @@ .rebate-header %h2.rebate-title - Customer details + Application details %h3.rebate-subtitle - if @rebate_form.signed_state? diff --git a/app/views/admin/rebate_forms/edit.html.haml b/app/views/admin/rebate_forms/edit.html.haml index f458886d..a8171655 100644 --- a/app/views/admin/rebate_forms/edit.html.haml +++ b/app/views/admin/rebate_forms/edit.html.haml @@ -1,3 +1,5 @@ = render 'edit_header' +.rebate-details-header.customer-details-header + %h3.rebate-details-title Customer Details = react_component("RebateForm", {isReadOnly: false, rebateForm: @rebate_form, property: @rebate_form.property, council: @rebate_form.council, ratesBills: @rebate_form.property.rates_bills}) diff --git a/app/views/admin/rebate_forms/edit_council_fields.html.haml b/app/views/admin/rebate_forms/edit_council_fields.html.haml new file mode 100644 index 00000000..f3c37a07 --- /dev/null +++ b/app/views/admin/rebate_forms/edit_council_fields.html.haml @@ -0,0 +1,21 @@ += render 'edit_header' + +.rebate-details-header.customer-details-header + %h3.rebate-details-title Council Details +.rebate-edit-form + = form_for(@rebate_form, url: admin_rebate_form_path(@rebate_form), html: { method: 'patch' }) do |f| + = hidden_field_tag :council_details, true + .flex-row + .button-container.council-buttons + = link_to 'Cancel', admin_rebate_form_path(@rebate_form), class: 'pure-button rebate-cancel-button' + = f.submit 'Save', class: 'pure-button rebate-submit-button' + .flex-row.council-row + .flex-item.with-margin + = f.label :valuation_id + = f.text_field :valuation_id, class: 'rebate-search-input' + .flex-item + = f.label :application_id + = f.text_field :application_id, class: 'rebate-search-input' + .flex-item + = f.label :customer_id + = f.text_field :customer_id, class: 'rebate-search-input' From 9f3b6ddcdc41315e9bf0b280733b9b9c7cb0d636 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 20 Jun 2019 19:49:53 +0000 Subject: [PATCH 08/59] Bump final-form from 4.15.0 to 4.16.1 (#415) --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index a301c626..8c889e85 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "@rails/webpacker": "^4.0.7", "babel-plugin-transform-react-remove-prop-types": "^0.4.24", "date-fns": "^1.30.1", - "final-form": "^4.15.0", + "final-form": "^4.16.1", "final-form-arrays": "^1.1.2", "final-form-calculate": "^1.3.1", "isomorphic-fetch": "^2.2.1", diff --git a/yarn.lock b/yarn.lock index dfce2a80..fa778010 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3145,10 +3145,10 @@ final-form-calculate@^1.3.1: resolved "https://registry.yarnpkg.com/final-form-calculate/-/final-form-calculate-1.3.1.tgz#463089114245afa97fea94712bfbfca11da8413e" integrity sha512-vZCvQ08w9FIoHLkZMcJSIXQr5TAVLxHfLD0thmm50zcNyJESruqhgvurSjWYPLoJGnIgbIb94Rumdg5ZXX5WiQ== -final-form@^4.15.0: - version "4.15.0" - resolved "https://registry.yarnpkg.com/final-form/-/final-form-4.15.0.tgz#8bce40c65138d0dd464c705880bbdc273320438a" - integrity sha512-A7pvzFAZ/mswLfU4pMKnB+otx3ttv8dO6/X+gWqhUSP+EpNsMenY88PHuGNJ9bIkhYcwF1ErXB8b2E2EMHKBLg== +final-form@^4.16.1: + version "4.16.1" + resolved "https://registry.yarnpkg.com/final-form/-/final-form-4.16.1.tgz#1a4047e55d375ae65c799a676c59e85ffeccb4d3" + integrity sha512-nUY6ZyFRvnOhSukqpmzm6pt38qYjCA6zSeW630CcfOvy0tBM+Wy0ZLIE36y/QiUfuAtMEJWp8k7GK5LqrqubEw== dependencies: "@babel/runtime" "^7.3.1" From 760a3774e0a523e59af2fc86e76f90cce37841a0 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Fri, 21 Jun 2019 07:56:45 +1200 Subject: [PATCH 09/59] rake in some tauranga data --- bin/docker_web_aws | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/docker_web_aws b/bin/docker_web_aws index 2bae7174..87374e04 100755 --- a/bin/docker_web_aws +++ b/bin/docker_web_aws @@ -10,8 +10,8 @@ fi echo "Migrating and refreshing reference data" bundle exec rake db:migrate -bundle exec rake rates:kapiti -# bundle exec rake rates:tauranga +# bundle exec rake rates:kapiti +bundle exec rake rates:tauranga echo "Running the server..." rm -f tmp/pids/server.pid From 6dce532f9b25a86776fa025dca79b1d5b77fbc11 Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Fri, 21 Jun 2019 10:05:13 +1200 Subject: [PATCH 10/59] Modified the update council details section to have new routes, controller view and policy. --- .../admin/rebate_forms_controller.rb | 7 +----- ...rebate_forms_council_details_controller.rb | 23 +++++++++++++++++++ app/policies/rebate_form_policy.rb | 4 ---- .../rebate_forms_council_details_policy.rb | 19 +++++++++++++++ app/services/rebate_forms_service.rb | 9 -------- .../_council_details_show.html.haml | 2 +- .../edit.html.haml} | 2 +- config/routes.rb | 3 ++- 8 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 app/controllers/admin/rebate_forms_council_details_controller.rb create mode 100644 app/policies/rebate_forms_council_details_policy.rb rename app/views/admin/{rebate_forms/edit_council_fields.html.haml => rebate_forms_council_details/edit.html.haml} (95%) diff --git a/app/controllers/admin/rebate_forms_controller.rb b/app/controllers/admin/rebate_forms_controller.rb index 63766e20..8ed8d958 100644 --- a/app/controllers/admin/rebate_forms_controller.rb +++ b/app/controllers/admin/rebate_forms_controller.rb @@ -50,8 +50,7 @@ def show # PATCH/PUT /admin/rebate_forms/1 def update - @rebate_form = RebateFormsService.new(rebate_form_council_details_params).update_council_details! if params[:council_details] - @rebate_form = RebateFormsService.new(rebate_form_fields_params).update! unless params[:council_details] + @rebate_form = RebateFormsService.new(rebate_form_fields_params).update! @rebate_form.update(updated_by: current_user.id) respond_with @rebate_form, location: admin_rebate_form_url(@rebate_form), notice: 'Rebate form was successfully updated.' end @@ -77,10 +76,6 @@ def rebate_form_fields_params params.permit(:id, :total_rates, :location, :council, fields: {}) end - def rebate_form_council_details_params - params.permit([:id, :council_details, rebate_form: {}]) - end - def pdf_filename "#{@rebate_form.council.short_name}-(#{@rebate_form.valuation_id})-#{@rebate_form.id}" end diff --git a/app/controllers/admin/rebate_forms_council_details_controller.rb b/app/controllers/admin/rebate_forms_council_details_controller.rb new file mode 100644 index 00000000..9e066a19 --- /dev/null +++ b/app/controllers/admin/rebate_forms_council_details_controller.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class Admin::RebateFormsCouncilDetailsController < Admin::BaseController + def edit + @rebate_form = RebateForm.find(params[:rebate_form_id]) + authorize @rebate_form + end + + def update + rebate_form = RebateForm.find(params['id']) + rebate_form.update!(valuation_id: rebate_form_council_details_params['valuation_id'], + customer_id: rebate_form_council_details_params['customer_id'], + application_id: rebate_form_council_details_params['application_id']) + + redirect_to admin_rebate_form_path(rebate_form) + end + + private + + def rebate_form_council_details_params + params.require(:rebate_form).permit(:customer_id, :valuation_id, :application_id) + end +end diff --git a/app/policies/rebate_form_policy.rb b/app/policies/rebate_form_policy.rb index 1b64aa3c..6fc4ba19 100644 --- a/app/policies/rebate_form_policy.rb +++ b/app/policies/rebate_form_policy.rb @@ -13,10 +13,6 @@ def show? dia? || same_council? end - def edit_council_fields? - dia? || same_council? - end - def update? dia? || same_council? end diff --git a/app/policies/rebate_forms_council_details_policy.rb b/app/policies/rebate_forms_council_details_policy.rb new file mode 100644 index 00000000..a2b207a5 --- /dev/null +++ b/app/policies/rebate_forms_council_details_policy.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class RebateFormsCouncilDetailsPolicy < ApplicationPolicy + def update? + dia? || same_council? + end + + class Scope < Scope + def resolve + if user.dia? + scope.all + elsif user.present? + scope.joins(:property).where("properties.council_id": user.council_id) + else + scope.none + end + end + end +end diff --git a/app/services/rebate_forms_service.rb b/app/services/rebate_forms_service.rb index 599d28ad..2d90146a 100644 --- a/app/services/rebate_forms_service.rb +++ b/app/services/rebate_forms_service.rb @@ -4,19 +4,10 @@ class RebateFormsService class Error < StandardError; end def initialize(rebate_form_attributes) - @rebate_form_council_details = rebate_form_attributes if rebate_form_attributes['council_details'] rebate_form_attributes['fields']['location'] = rebate_form_attributes['location'] if rebate_form_attributes['fields'] @rebate_form_attributes = rebate_form_attributes end - def update_council_details! - rebate_form = RebateForm.find(@rebate_form_council_details['id']) - rebate_form.update!(valuation_id: @rebate_form_council_details['rebate_form']['valuation_id'], - customer_id: @rebate_form_council_details['rebate_form']['customer_id'], - application_id: @rebate_form_council_details['rebate_form']['application_id']) - rebate_form - end - def update! council = find_council! property = create_or_update_property!(council) diff --git a/app/views/admin/rebate_forms/_council_details_show.html.haml b/app/views/admin/rebate_forms/_council_details_show.html.haml index fb84b4f6..9c23d796 100644 --- a/app/views/admin/rebate_forms/_council_details_show.html.haml +++ b/app/views/admin/rebate_forms/_council_details_show.html.haml @@ -1,7 +1,7 @@ .rebate-details-header.council-details-header %h3.rebate-details-title Council Details - unless @rebate_form.processed_state? || @rebate_form.batched_state? - = link_to 'EDIT', admin_rebate_form_edit_council_fields_path(rebate_form_id: @rebate_form.id), class: 'pure-button rebate-edit council-edit' + = link_to 'EDIT', admin_rebate_forms_edit_council_details_path(rebate_form_id: @rebate_form.id), class: 'pure-button rebate-edit council-edit' .rebate-edit-form .flex-row.council-row diff --git a/app/views/admin/rebate_forms/edit_council_fields.html.haml b/app/views/admin/rebate_forms_council_details/edit.html.haml similarity index 95% rename from app/views/admin/rebate_forms/edit_council_fields.html.haml rename to app/views/admin/rebate_forms_council_details/edit.html.haml index f3c37a07..f2804965 100644 --- a/app/views/admin/rebate_forms/edit_council_fields.html.haml +++ b/app/views/admin/rebate_forms_council_details/edit.html.haml @@ -1,4 +1,4 @@ -= render 'edit_header' += render 'admin/rebate_forms/edit_header' .rebate-details-header.customer-details-header %h3.rebate-details-title Council Details diff --git a/config/routes.rb b/config/routes.rb index b6f203ec..25bbf7da 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,8 @@ end namespace :admin do + get 'rebate_forms/edit_council_details', to: 'rebate_forms_council_details#edit' + patch 'rebate_forms/update_council_details', to: 'rebate_forms_council_details#update' get 'rebate_forms/signed', to: 'signed_rebate_forms#index' get 'rebate_forms/processed', to: 'processed_rebate_forms#index' post 'process_rebate_form', to: 'processed_rebate_forms#create' @@ -17,7 +19,6 @@ resources :rebate_forms do get 'generateqr' - get 'edit_council_fields' end resources :attachments, only: %i[destroy] resources :councils do From 9029bd4f4054879b24540a7f95aced0e7127b02f Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Fri, 21 Jun 2019 10:12:01 +1200 Subject: [PATCH 11/59] Fixed up header so that warning banner doesn't show up in council details edit. --- .../admin/rebate_forms_council_details/edit.html.haml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/views/admin/rebate_forms_council_details/edit.html.haml b/app/views/admin/rebate_forms_council_details/edit.html.haml index f2804965..4c5e1605 100644 --- a/app/views/admin/rebate_forms_council_details/edit.html.haml +++ b/app/views/admin/rebate_forms_council_details/edit.html.haml @@ -1,4 +1,12 @@ -= render 'admin/rebate_forms/edit_header' +.rebate-header + %h2.rebate-title + Application details + + %h3.rebate-subtitle + - if @rebate_form.signed_state? + Signed and ready to process + - else + Signature required .rebate-details-header.customer-details-header %h3.rebate-details-title Council Details From e479e8e3f0369b3eac37b5895baa11968ecca935 Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Fri, 21 Jun 2019 11:03:41 +1200 Subject: [PATCH 12/59] Fixed up existing tests that were failing. Added new rebate form show specs for the new council details section. --- ...rebate_forms_council_details_controller.rb | 2 + .../_council_details_show.html.haml | 4 +- app/views/admin/rebate_forms/edit.html.haml | 2 +- app/views/admin/rebate_forms/show.html.haml | 4 +- .../edit.html.haml | 2 +- spec/factories/rebate_forms.rb | 4 +- spec/features/admin/batches/index_spec.rb | 2 - spec/features/admin/rebate_forms/edit_spec.rb | 41 ---------- spec/features/admin/rebate_forms/show_spec.rb | 76 +++++++++++++++---- 9 files changed, 74 insertions(+), 63 deletions(-) diff --git a/app/controllers/admin/rebate_forms_council_details_controller.rb b/app/controllers/admin/rebate_forms_council_details_controller.rb index 9e066a19..0ad9a851 100644 --- a/app/controllers/admin/rebate_forms_council_details_controller.rb +++ b/app/controllers/admin/rebate_forms_council_details_controller.rb @@ -8,6 +8,8 @@ def edit def update rebate_form = RebateForm.find(params['id']) + authorize rebate_form + rebate_form.update!(valuation_id: rebate_form_council_details_params['valuation_id'], customer_id: rebate_form_council_details_params['customer_id'], application_id: rebate_form_council_details_params['application_id']) diff --git a/app/views/admin/rebate_forms/_council_details_show.html.haml b/app/views/admin/rebate_forms/_council_details_show.html.haml index 9c23d796..5a93f18c 100644 --- a/app/views/admin/rebate_forms/_council_details_show.html.haml +++ b/app/views/admin/rebate_forms/_council_details_show.html.haml @@ -1,7 +1,7 @@ .rebate-details-header.council-details-header - %h3.rebate-details-title Council Details + %h3.rebate-details-title Council details - unless @rebate_form.processed_state? || @rebate_form.batched_state? - = link_to 'EDIT', admin_rebate_forms_edit_council_details_path(rebate_form_id: @rebate_form.id), class: 'pure-button rebate-edit council-edit' + = link_to 'EDIT', admin_rebate_forms_edit_council_details_path(rebate_form_id: @rebate_form.id), id: 'edit-council', class: 'pure-button rebate-edit council-edit' .rebate-edit-form .flex-row.council-row diff --git a/app/views/admin/rebate_forms/edit.html.haml b/app/views/admin/rebate_forms/edit.html.haml index a8171655..8980576b 100644 --- a/app/views/admin/rebate_forms/edit.html.haml +++ b/app/views/admin/rebate_forms/edit.html.haml @@ -1,5 +1,5 @@ = render 'edit_header' .rebate-details-header.customer-details-header - %h3.rebate-details-title Customer Details + %h3.rebate-details-title Customer details = react_component("RebateForm", {isReadOnly: false, rebateForm: @rebate_form, property: @rebate_form.property, council: @rebate_form.council, ratesBills: @rebate_form.property.rates_bills}) diff --git a/app/views/admin/rebate_forms/show.html.haml b/app/views/admin/rebate_forms/show.html.haml index ad7fe79b..6a019638 100644 --- a/app/views/admin/rebate_forms/show.html.haml +++ b/app/views/admin/rebate_forms/show.html.haml @@ -5,7 +5,7 @@ = render 'council_details_show', rebate_form: @rebate_form .rebate-details-header.customer-details-header - %h3.rebate-details-title Customer Details + %h3.rebate-details-title Customer details - unless @rebate_form.processed_state? || @rebate_form.batched_state? - = link_to 'EDIT', edit_admin_rebate_form_path, id: 'edit', class: 'pure-button rebate-edit' + = link_to 'EDIT', edit_admin_rebate_form_path, id: 'edit-customer', class: 'pure-button rebate-edit' = react_component("RebateForm", {isReadOnly: true, rebateForm: @rebate_form, property: @rebate_form.property, ratesBills: @rebate_form.property.rates_bills}) diff --git a/app/views/admin/rebate_forms_council_details/edit.html.haml b/app/views/admin/rebate_forms_council_details/edit.html.haml index 4c5e1605..dcbd1e5e 100644 --- a/app/views/admin/rebate_forms_council_details/edit.html.haml +++ b/app/views/admin/rebate_forms_council_details/edit.html.haml @@ -9,7 +9,7 @@ Signature required .rebate-details-header.customer-details-header - %h3.rebate-details-title Council Details + %h3.rebate-details-title Council details .rebate-edit-form = form_for(@rebate_form, url: admin_rebate_form_path(@rebate_form), html: { method: 'patch' }) do |f| = hidden_field_tag :council_details, true diff --git a/spec/factories/rebate_forms.rb b/spec/factories/rebate_forms.rb index 29b3cd13..5d725015 100644 --- a/spec/factories/rebate_forms.rb +++ b/spec/factories/rebate_forms.rb @@ -2,7 +2,9 @@ FactoryBot.define do factory :rebate_form do - valuation_id { Faker::Vehicle.vin } + valuation_id { Faker::Alphanumeric.alphanumeric 10 } + customer_id { Faker::Alphanumeric.alphanumeric 10 } + application_id { Faker::Alphanumeric.alphanumeric 10 } property { Property.find_by(valuation_id: valuation_id, rating_year: ENV['YEAR']) } # token <-- auto generated. Don't set in factory fields do diff --git a/spec/features/admin/batches/index_spec.rb b/spec/features/admin/batches/index_spec.rb index 0d8c3f2c..01db072f 100644 --- a/spec/features/admin/batches/index_spec.rb +++ b/spec/features/admin/batches/index_spec.rb @@ -25,7 +25,6 @@ expect(page).to have_text(batched_form.batch.name) expect(page).to have_text('HEADER SHEET REQUIRED') expect(page).to have_text(batch_other_council.name) - expect(page).to have_text(batch_other_council.created_at.strftime('%d %b %Y')) expect(page).not_to have_text('EDIT') end @@ -62,7 +61,6 @@ expect(page).to have_text(batched_form.batch.name) expect(page).to have_text('HEADER SHEET REQUIRED') expect(page).not_to have_text(batch_other_council.name) - expect(page).to have_text(batch_other_council.created_at.strftime('%d %b %Y')) expect(page).to have_text('EDIT') end diff --git a/spec/features/admin/rebate_forms/edit_spec.rb b/spec/features/admin/rebate_forms/edit_spec.rb index 86786a63..6b69a022 100644 --- a/spec/features/admin/rebate_forms/edit_spec.rb +++ b/spec/features/admin/rebate_forms/edit_spec.rb @@ -27,17 +27,6 @@ end end - describe '#show' do - it 'can see edit link' do - visit "/admin/rebate_forms/#{rebate_form.id}" - expect(page).to have_field(with: rebate_form.full_name) - click_link 'EDIT' - expect(page).to have_text('Customer details') - expect(page).to have_field(with: rebate_form.full_name) - end - include_examples 'percy snapshot' - end - describe '#cancel' do it 'can see the CANCEL button' do visit "admin/rebate_forms/#{rebate_form.id}/edit" @@ -51,36 +40,6 @@ end end - describe '#show' do - it 'cannot see edit link on processed form' do - visit "/admin/rebate_forms/#{processed_form.id}" - expect(page).to have_field(with: processed_form.full_name) - expect(page).not_to have_text('EDIT') - end - include_examples 'percy snapshot' - end - - describe 'header buttons' do - context 'when the back button is clicked' do - it 'goes to the right place' do - visit "/admin/rebate_forms/#{rebate_form.id}/edit" - click_link('back') - expect(page).to have_text('Rates Rebate 2018/2019') - expect(page).to have_text('Customer search') - end - end - - context 'when the reload button is clicked' do - it 'goes to the right place' do - visit "/admin/rebate_forms/#{rebate_form.id}/edit" - click_link('reload') - expect(page).to have_current_path("/admin/rebate_forms/#{rebate_form.id}/edit") - expect(page).to have_text('Customer details') - expect(page).to have_text('Income declaration (before tax)') - end - end - end - describe 'edit banner message for signed rebate forms' do context 'when the rebate form is not signed' do it 'does not show the banner' do diff --git a/spec/features/admin/rebate_forms/show_spec.rb b/spec/features/admin/rebate_forms/show_spec.rb index 267acb58..27d7bd8d 100644 --- a/spec/features/admin/rebate_forms/show_spec.rb +++ b/spec/features/admin/rebate_forms/show_spec.rb @@ -20,11 +20,28 @@ context 'and the rebate form is not completed' do before { visit "/admin/rebate_forms/#{rebate_form.id}" } - it 'viewing a customer details' do - expect(page).to have_text('Customer details') + it 'viewing council details' do + expect(page).to have_text(user.email) + expect(page).to have_text('LOG OUT x') + expect(page).to have_text('Rates Rebate') + expect(page).to have_text('Application details') expect(page).to have_text('Signature required') + expect(page).to have_text('Council details') + expect(page).to have_text('Valuation ID') + expect(page).to have_text(rebate_form.valuation_id) + expect(page).to have_text('Customer ID') + expect(page).to have_text(rebate_form.customer_id) + expect(page).to have_text('Application ID') + expect(page).to have_text(rebate_form.application_id) + end + include_examples 'percy snapshot' + + it 'viewing customer details' do expect(page).to have_text(user.email) expect(page).to have_text('LOG OUT x') + expect(page).to have_text('Application details') + expect(page).to have_text('Signature required') + expect(page).to have_text('Customer details') expect(page).to have_field('fields.full_name', with: rebate_form.full_name) expect(page).to have_field('fields.email', with: rebate_form.email) expect(page).to have_field('fields.occupation', with: rebate_form.occupation) @@ -51,13 +68,29 @@ end end - context 'when the edit button is clicked' do - it 'goes to the right place' do - visit "/admin/rebate_forms/#{rebate_form.id}" - click_link('edit') - expect(page).to_not have_text('EDIT') - expect(page).to have_text('Customer details') - expect(page).to have_text('Signature required') + context 'when the edit buttons are clicked' do + context 'editing council details' do + it 'goes to the right place' do + visit "/admin/rebate_forms/#{rebate_form.id}" + click_link('edit-council') + expect(page).to_not have_text('EDIT') + expect(page).to have_text('Council details') + expect(page).to_not have_text('Customer details') + expect(page).to have_text('Signature required') + expect(page).to have_field(with: rebate_form.valuation_id) + end + end + + context 'editing customer details' do + it 'goes to the right place' do + visit "/admin/rebate_forms/#{rebate_form.id}" + click_link('edit-customer') + expect(page).to_not have_text('EDIT') + expect(page).to_not have_text('Council details') + expect(page).to have_text('Customer details') + expect(page).to have_text('Signature required') + expect(page).to have_field(with: rebate_form.full_name) + end end end end @@ -65,6 +98,20 @@ context 'when the rebate form is signed' do before { rebate_form.transition_to_signed_state } + describe ' Can see council details' do + before { visit "/admin/rebate_forms/#{rebate_form.id}" } + it { expect(page).to have_text('Council details') } + it { expect(page).to have_text('Signed and ready to process') } + it { expect(page).to have_text('Process') } + it { expect(page).to have_field('fields.full_name', with: rebate_form.full_name) } + it { expect(page).to have_text('Valuation ID') } + it { expect(page).to have_text(rebate_form.valuation_id) } + it { expect(page).to have_text('Customer ID') } + it { expect(page).to have_text(rebate_form.customer_id) } + it { expect(page).to have_text('Application ID') } + it { expect(page).to have_text(rebate_form.application_id) } + end + describe ' Can see customer details' do before { visit "/admin/rebate_forms/#{rebate_form.id}" } it { expect(page).to have_text('Customer details') } @@ -73,7 +120,6 @@ it { expect(page).to have_field('fields.full_name', with: rebate_form.full_name) } it { expect(page).to have_field('fields.email', with: rebate_form.email) } it { expect(page).to have_field('fields.occupation', with: rebate_form.occupation) } - it { expect(page).to have_field('fields.valuation_id', with: rebate_form.valuation_id) } end describe 'can process an application' do @@ -93,7 +139,8 @@ it 'cannot be edited' do expect(page).to have_text('Processed') expect(page).to have_text('Unprocess') - expect(page).to_not have_text('Edit') + expect(page).to_not have_text('EDIT') + expect(page).to have_field(with: processed_rebate_form.full_name) end it 'can be unprocessed' do @@ -102,6 +149,7 @@ click_link('Unprocess') expect(page).to have_text('Signed and ready to process') expect(page).to_not have_text('Processed') + expect(page).to have_text('EDIT') end end @@ -112,7 +160,7 @@ it 'cannot be edited' do expect(page).to_not have_text('Processed') expect(page).to_not have_text('Unprocess') - expect(page).to_not have_text('Edit') + expect(page).to_not have_text('EDIT') end end include_examples 'percy snapshot' @@ -126,9 +174,11 @@ # Freeze time when we generate the qr find("img[class='rebate-generate-qr']").click end + it { expect(page).to have_link 'DONE' } + xit 'displays the qr code' do - expect(page).to have_image(class: 'rebate-qrcode') + expect(page).to have_css('rebate-qrcode') end include_examples 'percy snapshot' after { Timecop.return } From 7dfdc3dfcfc459164e391267357099acb8bf78dd Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Fri, 21 Jun 2019 11:08:59 +1200 Subject: [PATCH 13/59] add migration to add location, total_rates to rebate_form --- ...add_total_rates_location_to_rebate_form.rb | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb diff --git a/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb b/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb new file mode 100644 index 00000000..0901ceb6 --- /dev/null +++ b/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb @@ -0,0 +1,51 @@ +class AddTotalRatesLocationToRebateForm < ActiveRecord::Migration[5.2] + def up + add_column :rebate_forms, :location, :string + add_column :rebate_forms, :total_rates, :decimal, precision: 8, scale: 2 + update_existing_rebate_forms_up + end + + def down + update_existing_rebate_forms_down + remove_column :rebate_forms, :location, :string + remove_column :rebate_forms, :total_rates, :decimal, precision: 8, scale: 2 + end + + private + + def update_existing_rebate_forms_up + RebateForm.all.each do |rebate_form| + property = rebate_form.property + rebate_form.update(location: property.location, + total_rates: property.rates_bills[0].total_rates, + valuation_id: rebate_form.fields['valuation_id'] || property.valuation_id || nil) + end + end + + def update_existing_rebate_forms_down + RebateForm.all.each do |rebate_form| + @rebate_form = rebate_form + property = update_property! + create_or_update_rates_bill!(property) + end + end + + def update_property! + property = @rebate_form.property + + property.update!(location: @rebate_form.location, + valuation_id: @rebate_form.valuation_id) + property + end + + def create_or_update_rates_bill!(property) + rates_bill = RatesBill.find_or_create_by(property: property, + rating_year: property.rating_year) + rates_bill.update!(total_rates: total_rates) + rates_bill + end + + def total_rates + @rebate_form.total_rates || 0 + end +end From b3f1b8ce8e00f0b89a6ef40a8da519b7c35957f6 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Fri, 21 Jun 2019 11:09:51 +1200 Subject: [PATCH 14/59] run migration --- db/schema.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index 7dec7f8e..51a49746 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_06_18_231804) do +ActiveRecord::Schema.define(version: 2019_06_20_204258) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -101,6 +101,8 @@ t.integer "batch_id" t.integer "updated_by" t.string "status", default: "not signed" + t.string "location" + t.decimal "total_rates", precision: 8, scale: 2 end create_table "roles", force: :cascade do |t| From a548003899c272673d8f4f3021caca6041b00211 Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Fri, 21 Jun 2019 11:41:46 +1200 Subject: [PATCH 15/59] Features specs for the council details edit form. --- .../edit.html.haml | 13 ++-- .../rebate_forms_council_details/edit_spec.rb | 73 +++++++++++++++++++ 2 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 spec/features/admin/rebate_forms_council_details/edit_spec.rb diff --git a/app/views/admin/rebate_forms_council_details/edit.html.haml b/app/views/admin/rebate_forms_council_details/edit.html.haml index dcbd1e5e..1cf75e30 100644 --- a/app/views/admin/rebate_forms_council_details/edit.html.haml +++ b/app/views/admin/rebate_forms_council_details/edit.html.haml @@ -11,19 +11,20 @@ .rebate-details-header.customer-details-header %h3.rebate-details-title Council details .rebate-edit-form - = form_for(@rebate_form, url: admin_rebate_form_path(@rebate_form), html: { method: 'patch' }) do |f| + = form_for(@rebate_form, url: admin_rebate_forms_update_council_details_path, html: { method: 'patch' }) do |f| = hidden_field_tag :council_details, true + = hidden_field_tag :id, @rebate_form.id .flex-row .button-container.council-buttons - = link_to 'Cancel', admin_rebate_form_path(@rebate_form), class: 'pure-button rebate-cancel-button' - = f.submit 'Save', class: 'pure-button rebate-submit-button' + = link_to 'CANCEL', admin_rebate_form_path(@rebate_form), id: 'cancel', class: 'pure-button rebate-cancel-button' + = f.submit 'SAVE', class: 'pure-button rebate-submit-button' .flex-row.council-row .flex-item.with-margin - = f.label :valuation_id + = f.label :valuation_id, 'Valuation ID' = f.text_field :valuation_id, class: 'rebate-search-input' .flex-item - = f.label :application_id + = f.label :application_id, 'Application ID' = f.text_field :application_id, class: 'rebate-search-input' .flex-item - = f.label :customer_id + = f.label :customer_id, 'Customer ID' = f.text_field :customer_id, class: 'rebate-search-input' diff --git a/spec/features/admin/rebate_forms_council_details/edit_spec.rb b/spec/features/admin/rebate_forms_council_details/edit_spec.rb new file mode 100644 index 00000000..b0cc2850 --- /dev/null +++ b/spec/features/admin/rebate_forms_council_details/edit_spec.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'RebateFormsCouncilDetails', type: :feature, js: true do + let(:property) { FactoryBot.create :property_with_rates, rating_year: ENV['YEAR'] } + let!(:rebate_form) { FactoryBot.create :rebate_form, status: RebateForm::NOT_SIGNED_STATUS, property: property } + + context 'anonymous' do + it "can't see it" do + visit "/admin/rebate_forms/edit_council_details?rebate_form_id=#{rebate_form.id}" + expect(page).to have_text('Rates Rebate 2018/2019') + expect(page).to have_text('Log in') + end + end + + shared_examples 'can edit' do + describe '#edit' do + it 'can modify the council details section of the rebate_form' do + visit "/admin/rebate_forms/edit_council_details?rebate_form_id=#{rebate_form.id}" + expect(page).to have_text('Council details') + expect(page).to have_text('Valuation ID') + expect(page).to have_text('Application ID') + expect(page).to have_text('Customer ID') + fill_in('Valuation ID', with: '123Iamawesome', fill_options: { clear: :backspace }) + fill_in('Application ID', with: '456Youaretoo', fill_options: { clear: :backspace }) + fill_in('Customer ID', with: '789Wearethebest', fill_options: { clear: :backspace }) + click_button 'SAVE' + expect(page).to have_text('123Iamawesome') + expect(page).to have_text('456Youaretoo') + expect(page).to have_text('789Wearethebest') + rebate_form.reload + expect(rebate_form.valuation_id).to eq '123Iamawesome' + expect(rebate_form.application_id).to eq '456Youaretoo' + expect(rebate_form.customer_id).to eq '789Wearethebest' + end + end + + describe '#cancel' do + it 'can see the CANCEL button' do + visit "/admin/rebate_forms/edit_council_details?rebate_form_id=#{rebate_form.id}" + expect(page).to have_text('CANCEL') + expect(page).to have_text('Council details') + expect(page).to have_text('Valuation ID') + expect(page).to have_text('Application ID') + expect(page).to have_text('Customer ID') + expect(page).to have_field(with: rebate_form.valuation_id) + fill_in('Valuation ID', with: '123Iamawesome', fill_options: { clear: :backspace }) + click_link 'cancel' + expect(page).to have_text('EDIT') + expect(page).to_not have_text('CANCEL') + expect(page).to have_text('Council details') + expect(page).to have_text(rebate_form.valuation_id) + end + end + end + + context 'signed in as dia' do + let(:user) { FactoryBot.create :admin_user } + + before { login_as(user, scope: :user) } + + include_examples 'can edit' + end + + context 'signed in as council' do + let(:user) { FactoryBot.create :user, council_id: rebate_form.property.council_id } + + before { login_as(user, scope: :user) } + + include_examples 'can edit' + end +end From 4bf0411f3ee9bcb014d76fa0435cb6bc006602b3 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Fri, 21 Jun 2019 11:59:03 +1200 Subject: [PATCH 16/59] Update docker_web_aws --- bin/docker_web_aws | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/docker_web_aws b/bin/docker_web_aws index 87374e04..dffd33a0 100755 --- a/bin/docker_web_aws +++ b/bin/docker_web_aws @@ -11,7 +11,7 @@ echo "Migrating and refreshing reference data" bundle exec rake db:migrate # bundle exec rake rates:kapiti -bundle exec rake rates:tauranga +# bundle exec rake rates:tauranga echo "Running the server..." rm -f tmp/pids/server.pid From 141e06d3277df9bbaea20732a0abc9ac91123b83 Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Fri, 21 Jun 2019 11:59:42 +1200 Subject: [PATCH 17/59] Controller tests for rebate forms council details. --- .../edit.html.haml | 1 - ...e_forms_council_details_controller_spec.rb | 48 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 spec/controllers/admin/rebate_forms_council_details_controller_spec.rb diff --git a/app/views/admin/rebate_forms_council_details/edit.html.haml b/app/views/admin/rebate_forms_council_details/edit.html.haml index 1cf75e30..353a5471 100644 --- a/app/views/admin/rebate_forms_council_details/edit.html.haml +++ b/app/views/admin/rebate_forms_council_details/edit.html.haml @@ -12,7 +12,6 @@ %h3.rebate-details-title Council details .rebate-edit-form = form_for(@rebate_form, url: admin_rebate_forms_update_council_details_path, html: { method: 'patch' }) do |f| - = hidden_field_tag :council_details, true = hidden_field_tag :id, @rebate_form.id .flex-row .button-container.council-buttons diff --git a/spec/controllers/admin/rebate_forms_council_details_controller_spec.rb b/spec/controllers/admin/rebate_forms_council_details_controller_spec.rb new file mode 100644 index 00000000..a6b8835a --- /dev/null +++ b/spec/controllers/admin/rebate_forms_council_details_controller_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Admin::RebateFormsCouncilDetailsController, type: :controller do + let(:property) { FactoryBot.create :property_with_rates, rating_year: ENV['YEAR'] } + let!(:rebate_form) { FactoryBot.create :rebate_form, status: RebateForm::NOT_SIGNED_STATUS, property: property } + + shared_examples 'can update council details' do + describe '#update' do + let(:params) do + { id: rebate_form.id, + rebate_form: { + valuation_id: '123Iamawesome', + application_id: '456Youaretoo', + customer_id: '789Wearethebest' + } } + end + + before do + patch :update, params: params + rebate_form.reload + end + + it 'updates the rebate form' do + expect(rebate_form.valuation_id).to eq '123Iamawesome' + expect(rebate_form.application_id).to eq '456Youaretoo' + expect(rebate_form.customer_id).to eq '789Wearethebest' + end + end + end + + context 'signed in as council users' do + let(:user) { FactoryBot.create :user, council: rebate_form.council } + + before { sign_in user } + + include_examples 'can update council details' + end + + context 'signed in as admin' do + let(:user) { FactoryBot.create :admin_user } + + before { sign_in user } + + include_examples 'can update council details' + end +end From 90c893121daa954155d6986922cb0b21e9f99f7c Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Fri, 21 Jun 2019 12:04:09 +1200 Subject: [PATCH 18/59] add include in address lookup migration --- app/services/rates_importer_service.rb | 2 ++ ...190620235127_add_include_in_auto_suggest_to_properties.rb | 5 +++++ db/schema.rb | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20190620235127_add_include_in_auto_suggest_to_properties.rb diff --git a/app/services/rates_importer_service.rb b/app/services/rates_importer_service.rb index ad494305..6500db47 100644 --- a/app/services/rates_importer_service.rb +++ b/app/services/rates_importer_service.rb @@ -25,8 +25,10 @@ def import(row, rating_year, council) suburb: suburb, town_city: town_city, rating_year: rating_year, + include_in_address_lookups: true, meta: row.to_s ) + else property.update(include_in_address_lookups: true) end rates_bill = RatesBill.find_by(property: property, rating_year: rating_year) diff --git a/db/migrate/20190620235127_add_include_in_auto_suggest_to_properties.rb b/db/migrate/20190620235127_add_include_in_auto_suggest_to_properties.rb new file mode 100644 index 00000000..dbfb7831 --- /dev/null +++ b/db/migrate/20190620235127_add_include_in_auto_suggest_to_properties.rb @@ -0,0 +1,5 @@ +class AddIncludeInAutoSuggestToProperties < ActiveRecord::Migration[5.2] + def change + add_column :properties, :include_in_address_lookups, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 51a49746..5a4c5490 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_06_20_204258) do +ActiveRecord::Schema.define(version: 2019_06_20_235127) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -67,6 +67,7 @@ t.text "meta" t.integer "council_id" t.text "rating_year" + t.boolean "include_in_address_lookups", default: false t.index ["council_id"], name: "index_properties_on_council_id" t.index ["valuation_id", "rating_year"], name: "index_properties_on_valuation_id_and_rating_year" end From 58aafd8bd402da86cfe708dfb2812354c9e3b164 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Fri, 21 Jun 2019 12:39:27 +1200 Subject: [PATCH 19/59] update controllers and services --- .../admin/production-deployment-how-to.md | 22 --- .../admin/rebate_forms_controller.rb | 9 +- app/controllers/rebate_forms_controller.rb | 8 +- app/services/rates_importer_service.rb | 4 +- app/services/rebate_forms_service.rb | 53 ++---- app/services/rebate_forms_update_service.rb | 42 +++++ spec/services/rebate_forms_service_spec.rb | 178 +----------------- .../rebate_forms_update_service_spec.rb | 175 +++++++++++++++++ 8 files changed, 246 insertions(+), 245 deletions(-) delete mode 100644 app/controllers/admin/production-deployment-how-to.md create mode 100644 app/services/rebate_forms_update_service.rb create mode 100644 spec/services/rebate_forms_update_service_spec.rb diff --git a/app/controllers/admin/production-deployment-how-to.md b/app/controllers/admin/production-deployment-how-to.md deleted file mode 100644 index a9dfc950..00000000 --- a/app/controllers/admin/production-deployment-how-to.md +++ /dev/null @@ -1,22 +0,0 @@ -- login to `AWS` -- go to `ECR` (https://ap-southeast-2.console.aws.amazon.com/ecr/repositories?region=ap-southeast-2) -- click repository name `pancake` -- determine `image tag` you wish to deploy e.g `prod-1fsdf23` -- go to `ECS` -- click `Task Definitions` on left panel -- select `pancake-task-defintion` checkbox -- click `Create new revision` -- scroll down to `Container Definitions` -- click `Container Name` -- change `364010606639.dkr.ecr.ap-southeast-2.amazonaws.com/pancake:[image-tag]` to use your `image tag` -- click `Update` -- click `Create` -- select `Clusters` on left menu below heading `Amazon ECS` -- click `pancake-cluster` -- select `pancake-cluster-service-lb` checkbox -- click `Update` -- select latest revision (`[highest number](latest)`) -- select force new deployment `checkbox` -- click `Skip to review` -- click `update service` -- check `https://ap-southeast-2.console.aws.amazon.com/cloudwatch/home?region=ap-southeast-2#logs:` for updates diff --git a/app/controllers/admin/rebate_forms_controller.rb b/app/controllers/admin/rebate_forms_controller.rb index 181aa03c..5170e2c4 100644 --- a/app/controllers/admin/rebate_forms_controller.rb +++ b/app/controllers/admin/rebate_forms_controller.rb @@ -49,7 +49,7 @@ def show # PATCH/PUT /admin/rebate_forms/1 def update - @rebate_form = RebateFormsService.new(rebate_form_fields_params).update! + @rebate_form = RebateFormsUpdateService.new(rebate_form_fields_params).update! @rebate_form.update(updated_by: current_user.id) respond_with @rebate_form, location: admin_rebate_form_url(@rebate_form), notice: 'Rebate form was successfully updated.' end @@ -72,7 +72,12 @@ def set_rebate_form end def rebate_form_fields_params - params.permit(:id, :valuation_id, :total_rates, :location, :council, fields: {}) + params.permit(:id, + :valuation_id, + :total_rates, + :location, + :council, + fields: {}) end def rebate_form_params diff --git a/app/controllers/rebate_forms_controller.rb b/app/controllers/rebate_forms_controller.rb index f938d0c4..bdddff82 100644 --- a/app/controllers/rebate_forms_controller.rb +++ b/app/controllers/rebate_forms_controller.rb @@ -25,7 +25,7 @@ def show_by_jwt end def create - rebate_form = RebateFormsService.new(rebate_form_params).update! + rebate_form = RebateFormsService.new(rebate_form_params).create! render_jsonapi(rebate_form, scope: false) rescue RebateFormsService::Error @@ -39,10 +39,8 @@ def rebate_form_params .require(:api) .require(:data) .require(:attributes) - .permit(:id, - :valuation_id, - :council, - :total_rates, + .permit(:valuation_id, + :council_id, :location, fields: {}, applicant_signature: {}, diff --git a/app/services/rates_importer_service.rb b/app/services/rates_importer_service.rb index 6500db47..611feb7a 100644 --- a/app/services/rates_importer_service.rb +++ b/app/services/rates_importer_service.rb @@ -33,8 +33,8 @@ def import(row, rating_year, council) rates_bill = RatesBill.find_by(property: property, rating_year: rating_year) if rates_bill.present? - current_rates = rates_bill.total_rates.to_f.round(2) - new_rates = (total_rates.to_f + total_water_rates.to_f).round(2) + # current_rates = rates_bill.total_rates.to_f.round(2) + # new_rates = (total_rates.to_f + total_water_rates.to_f).round(2) # raise 'mismatch total_rates' unless current_rates == new_rates else RatesBill.create!( diff --git a/app/services/rebate_forms_service.rb b/app/services/rebate_forms_service.rb index 2d90146a..24664998 100644 --- a/app/services/rebate_forms_service.rb +++ b/app/services/rebate_forms_service.rb @@ -8,66 +8,35 @@ def initialize(rebate_form_attributes) @rebate_form_attributes = rebate_form_attributes end - def update! + def create! council = find_council! - property = create_or_update_property!(council) - rebate_form = create_or_update_rebate_form!(property) - create_or_update_rates_bill!(property) - rebate_form.calc_rebate_amount! - raise Error if rebate_form.rebate.blank? + property = find_or_create_property!(council) + rebate_form = create_rebate_form!(property) rebate_form end private - def create_or_update_rebate_form!(property) - return update_rebate_form!(property) if @rebate_form_attributes['id'] - - create_rebate_form!(property) - end - - def update_rebate_form!(property) - rebate_form = RebateForm.find_by(id: @rebate_form_attributes['id']) - property = rebate_form.property if property.id.nil? - remove_signatures_if_signed(rebate_form) - fields_to_update = rebate_form.fields.merge(fields_to_merge) - rebate_form.update!(property: property, valuation_id: property.valuation_id, fields: fields_to_update) - rebate_form - end - - def remove_signatures_if_signed(rebate_form) - rebate_form.signatures.destroy_all && rebate_form.transition_to_not_signed_state if rebate_form.signed_state? - end - - def update_fields - @rebate_form_attributes['fields'] - end - - def fields_to_merge - return update_fields unless update_fields.nil? - - {} - end - def create_rebate_form!(property) RebateForm.create!(property: property, valuation_id: property.valuation_id, + location: property.location, + total_rates: total_rates(property), rebate: 0, fields: @rebate_form_attributes['fields']) end - def create_or_update_property!(council) - return create_or_update_property_with_valuation_id!(council) if @rebate_form_attributes['valuation_id'] + def find_or_create_property!(council) + return find_or_create_property_with_valuation_id!(council) if @rebate_form_attributes['valuation_id'] find_or_create_property_with_no_valuation_id!(council) end - def create_or_update_property_with_valuation_id!(council) + def find_or_create_property_with_valuation_id!(council) property = Property.find_or_create_by(valuation_id: @rebate_form_attributes['valuation_id'], rating_year: ENV['YEAR'], council: council) - property.update!(location: @rebate_form_attributes['location']) property end @@ -84,11 +53,11 @@ def find_council! def create_or_update_rates_bill!(property) rates_bill = RatesBill.find_or_create_by(property: property, rating_year: property.rating_year) - rates_bill.update!(total_rates: total_rates) + rates_bill.update!(total_rates: total_rates(property)) rates_bill end - def total_rates - @rebate_form_attributes['total_rates'] || 0 + def total_rates(property) + property.rates_bills[0]&.total_rates || 0 end end diff --git a/app/services/rebate_forms_update_service.rb b/app/services/rebate_forms_update_service.rb new file mode 100644 index 00000000..0a1daecf --- /dev/null +++ b/app/services/rebate_forms_update_service.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +class RebateFormsUpdateService + class Error < StandardError; end + + def initialize(rebate_form_attributes) + @rebate_form_attributes = rebate_form_attributes + end + + def update! + rebate_form = update_rebate_form! + + rebate_form + end + + private + + def update_rebate_form! + rebate_form = RebateForm.find_by(id: @rebate_form_attributes['id']) + remove_signatures_if_signed(rebate_form) + fields_to_update = rebate_form.fields.merge(fields_to_merge) + rebate_form.update!(valuation_id: @rebate_form_attributes['valuation_id'], + total_rates: @rebate_form_attributes['total_rates'], + location: @rebate_form_attributes['location'], + fields: fields_to_update) + rebate_form + end + + def remove_signatures_if_signed(rebate_form) + rebate_form.signatures.destroy_all && rebate_form.transition_to_not_signed_state if rebate_form.signed_state? + end + + def update_fields + @rebate_form_attributes['fields'] + end + + def fields_to_merge + return update_fields unless update_fields.nil? + + {} + end +end diff --git a/spec/services/rebate_forms_service_spec.rb b/spec/services/rebate_forms_service_spec.rb index f0430d27..ea0cb269 100644 --- a/spec/services/rebate_forms_service_spec.rb +++ b/spec/services/rebate_forms_service_spec.rb @@ -26,42 +26,6 @@ } end - describe '#update!' do - context 'with valid params' do - it 'creates a new rebate form' do - subject.update! - expect(RebateForm.count).to eq 1 - expect(RebateForm.first.fields['location']).to eq property.location - end - end - end - end - - describe 'existing rebate form' do - subject { described_class.new(update_params) } - let!(:property2) { FactoryBot.create(:property_with_rates) } - let!(:rebate_form) { FactoryBot.create(:rebate_form, valuation_id: property.valuation_id, property: property) } - let(:update_params) do - { - 'id' => rebate_form.id, - 'valuation_id' => property2.valuation_id, - 'total_rates' => '12345', - 'location' => property2.location, - 'council' => property2.council.name, - 'fields' => { - 'full_name' => 'Best Witch', - 'customer_id' => '12345', - 'phone' => '022123-4567', - 'email' => 'hermione.granger@potterworld.com', - 'has_partner' => 'true', - 'dependants' => '3', - 'occupation' => 'witch', - '50_percent_claimed' => 'true', - 'income' => {} - } - } - end - describe '#update!' do context 'with invalid params' do let(:update_params) do @@ -69,6 +33,7 @@ 'id' => rebate_form.id, 'valuation_id' => property2.valuation_id, 'total_rates' => '12345', + 'completely_invalid' => true, 'location' => property2.location, 'rebate_form' => { 'fields' => {} @@ -77,146 +42,15 @@ end it 'raises an error' do - expect { subject.update! }.to raise_error(ActiveRecord::RecordNotFound) + expect { subject.create! }.to raise_error(ActiveRecord::RecordNotFound) end end context 'with valid params' do - it 'updates a rebate form' do - subject.update! - expect(RebateForm.first.fields['full_name']).to eq 'Best Witch' - expect(RebateForm.first.fields['email']).to eq 'hermione.granger@potterworld.com' - expect(RebateForm.first.fields['dependants']).to eq '3' - expect(RebateForm.first.property.council.name).to eq property2.council.name - end - - context 'without a valuation id' do - let(:update_params) do - { - 'id' => rebate_form.id, - 'total_rates' => '12345', - 'location' => property2.location, - 'council' => property2.council.name, - 'rebate_form' => { - 'fields' => { - 'full_name' => 'Best Witch', - 'customer_id' => '12345', - 'phone' => '022123-4567', - 'email' => 'hermione.granger@potterworld.com', - 'has_partner' => 'true', - 'dependants' => '3', - 'occupation' => 'witch', - '50_percent_claimed' => 'true', - 'income' => {} - } - } - } - end - - it 'finds the correct property and updates the rebate form accordingly' do - expect(RebateForm.first.property).to eq property - subject.update! - expect(RebateForm.first.property).to eq property2 - end - end - - context 'when it receives an address that doesn\'t belong to an existing property' do - let(:update_params) do - { - 'id' => rebate_form.id, - 'total_rates' => '12345', - 'location' => 'This is a different address than property2', - 'council' => property2.council.name, - 'rebate_form' => { - 'fields' => { - 'full_name' => 'Best Witch', - 'customer_id' => '12345', - 'phone' => '022123-4567', - 'email' => 'hermione.granger@potterworld.com', - 'has_partner' => 'true', - 'dependants' => '3', - 'occupation' => 'witch', - '50_percent_claimed' => 'true', - 'income' => {} - } - } - } - end - - it 'creates a new property object' do - expect(Property.count).to eq 2 - subject.update! - expect(Property.count).to eq 3 - expect(Property.last.location).to eq 'This is a different address than property2' - end - end - - context 'when it receives an address that is slightly different than that of an existing property' do - # property2 address is '999 Lambton quay' - let(:update_params) do - { - 'id' => rebate_form.id, - 'total_rates' => '12345', - 'location' => '999 Lambton Quay', - 'council' => property2.council.name, - 'rebate_form' => { - 'fields' => { - 'full_name' => 'Best Witch', - 'customer_id' => '12345', - 'phone' => '022123-4567', - 'email' => 'hermione.granger@potterworld.com', - 'has_partner' => 'true', - 'dependants' => '3', - 'occupation' => 'witch', - '50_percent_claimed' => 'true', - 'income' => {} - } - } - } - end - - it 'creates a new property object' do - expect(Property.count).to eq 2 - subject.update! - expect(Property.count).to eq 3 - expect(Property.last.location).to eq '999 Lambton Quay' - end - end - - context 'when the rebate form is signed with signatures attached' do - let!(:rebate_form) do - FactoryBot.create(:signed_form, valuation_id: property.valuation_id, property: property, status: RebateForm::SIGNED_STATUS) - end - - let(:update_params) do - { - 'id' => rebate_form.id, - 'total_rates' => '12345', - 'location' => '999 Lambton Quay', - 'council' => property2.council.name, - 'rebate_form' => { - 'fields' => { - 'full_name' => 'Best Witch', - 'customer_id' => '12345', - 'phone' => '022123-4567', - 'email' => 'hermione.granger@potterworld.com', - 'has_partner' => 'true', - 'dependants' => '3', - 'occupation' => 'witch', - '50_percent_claimed' => 'true', - 'income' => {} - } - } - } - end - - it 'removes the signatures and sets status to not signed' do - expect(RebateForm.first.status).to eq RebateForm::SIGNED_STATUS - expect(RebateForm.first.signatures).to_not be_empty - subject.update! - expect(RebateForm.first.status).to eq RebateForm::NOT_SIGNED_STATUS - expect(RebateForm.first.signatures).to be_empty - end + it 'creates a new rebate form' do + subject.create! + expect(RebateForm.count).to eq 1 + expect(RebateForm.first.fields['location']).to eq property.location end end end diff --git a/spec/services/rebate_forms_update_service_spec.rb b/spec/services/rebate_forms_update_service_spec.rb new file mode 100644 index 00000000..692d208c --- /dev/null +++ b/spec/services/rebate_forms_update_service_spec.rb @@ -0,0 +1,175 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe RebateFormsUpdateService do + let!(:property) { FactoryBot.create(:property_with_rates) } + + describe 'existing rebate form' do + subject { described_class.new(update_params) } + let!(:property2) { FactoryBot.create(:property_with_rates) } + let!(:rebate_form) { FactoryBot.create(:rebate_form, valuation_id: property.valuation_id, property: property) } + let(:update_params) do + { + 'id' => rebate_form.id, + 'valuation_id' => property2.valuation_id, + 'total_rates' => '12345', + 'location' => property2.location, + 'fields' => { + 'full_name' => 'Best Witch', + 'customer_id' => '12345', + 'phone' => '022123-4567', + 'email' => 'hermione.granger@potterworld.com', + 'has_partner' => 'true', + 'dependants' => '3', + 'occupation' => 'witch', + '50_percent_claimed' => 'true', + 'income' => {} + } + } + end + + describe '#update!' do + context 'with valid params' do + it 'updates a rebate form' do + subject.update! + expect(RebateForm.first.fields['full_name']).to eq 'Best Witch' + expect(RebateForm.first.fields['email']).to eq 'hermione.granger@potterworld.com' + expect(RebateForm.first.fields['dependants']).to eq '3' + expect(RebateForm.first.location).to eq property2.location + expect(RebateForm.first.total_rates).to eq 12345 + expect(RebateForm.first.valuation_id).to eq property2.valuation_id + end + + context 'without a valuation id' do + let(:update_params) do + { + 'id' => rebate_form.id, + 'total_rates' => '12345', + 'location' => property2.location, + 'council' => property2.council.name, + 'rebate_form' => { + 'fields' => { + 'full_name' => 'Best Witch', + 'customer_id' => '12345', + 'phone' => '022123-4567', + 'email' => 'hermione.granger@potterworld.com', + 'has_partner' => 'true', + 'dependants' => '3', + 'occupation' => 'witch', + '50_percent_claimed' => 'true', + 'income' => {} + } + } + } + end + + it 'finds the correct property and updates the rebate form accordingly' do + expect(RebateForm.first.property).to eq property + subject.update! + expect(RebateForm.first.location).to eq property2.location + end + end + + context 'when it receives an address that doesn\'t belong to an existing property' do + let(:update_params) do + { + 'id' => rebate_form.id, + 'total_rates' => '12345', + 'location' => 'This is a different address than property2', + 'council' => property2.council.name, + 'rebate_form' => { + 'fields' => { + 'full_name' => 'Best Witch', + 'customer_id' => '12345', + 'phone' => '022123-4567', + 'email' => 'hermione.granger@potterworld.com', + 'has_partner' => 'true', + 'dependants' => '3', + 'occupation' => 'witch', + '50_percent_claimed' => 'true', + 'income' => {} + } + } + } + end + + it 'updates the rebate form but does not a new property object' do + expect(Property.count).to eq 2 + subject.update! + expect(Property.count).to eq 2 + expect(RebateForm.first.location).to eq 'This is a different address than property2' + end + end + + context 'when it receives an address that is slightly different than that of an existing property' do + # property2 address is '999 Lambton quay' + let(:update_params) do + { + 'id' => rebate_form.id, + 'total_rates' => '12345', + 'location' => '999 Lambton Quay', + 'council' => property2.council.name, + 'rebate_form' => { + 'fields' => { + 'full_name' => 'Best Witch', + 'customer_id' => '12345', + 'phone' => '022123-4567', + 'email' => 'hermione.granger@potterworld.com', + 'has_partner' => 'true', + 'dependants' => '3', + 'occupation' => 'witch', + '50_percent_claimed' => 'true', + 'income' => {} + } + } + } + end + + it 'updates the rebate form but does not create a new property object' do + expect(Property.count).to eq 2 + subject.update! + expect(Property.count).to eq 2 + expect(RebateForm.first.location).to eq '999 Lambton Quay' + end + end + + context 'when the rebate form is signed with signatures attached' do + let!(:rebate_form) do + FactoryBot.create(:signed_form, valuation_id: property.valuation_id, property: property, status: RebateForm::SIGNED_STATUS) + end + + let(:update_params) do + { + 'id' => rebate_form.id, + 'total_rates' => '12345', + 'location' => '999 Lambton Quay', + 'council' => property2.council.name, + 'rebate_form' => { + 'fields' => { + 'full_name' => 'Best Witch', + 'customer_id' => '12345', + 'phone' => '022123-4567', + 'email' => 'hermione.granger@potterworld.com', + 'has_partner' => 'true', + 'dependants' => '3', + 'occupation' => 'witch', + '50_percent_claimed' => 'true', + 'income' => {} + } + } + } + end + + it 'removes the signatures and sets status to not signed' do + expect(RebateForm.first.status).to eq RebateForm::SIGNED_STATUS + expect(RebateForm.first.signatures).to_not be_empty + subject.update! + expect(RebateForm.first.status).to eq RebateForm::NOT_SIGNED_STATUS + expect(RebateForm.first.signatures).to be_empty + end + end + end + end + end +end From 7d7ff377e17ec99652ca281c9dfe05993eace194 Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Fri, 21 Jun 2019 13:39:11 +1200 Subject: [PATCH 20/59] bit more styling for the wonky buttons --- app/assets/stylesheets/admin/rebate_form.css | 13 +++++++++++-- .../rebate_forms_council_details/edit.html.haml | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/admin/rebate_form.css b/app/assets/stylesheets/admin/rebate_form.css index 28373aeb..1c57920e 100644 --- a/app/assets/stylesheets/admin/rebate_form.css +++ b/app/assets/stylesheets/admin/rebate_form.css @@ -196,6 +196,7 @@ .council-buttons { margin-top: -10em; + min-width: 0; } .rebate-cancel-button { @@ -204,19 +205,27 @@ border: 1px solid var(--black); color: var(--black); margin: 0 1em 1.5em 5em; - /* margin: auto; */ float: right; } +.rebate-council-cancel-button { + float: none; + height: 39px; + margin: 0 1em 0 0; +} + .rebate-submit-button { background-color: var(--blue); border-radius: .2em; color: var(--white); margin-bottom: 1.5em; - /* margin: auto; */ float: right; } +.rebate-council-submit-button { + margin-top: 0 !important; +} + .rebate-add-income-button { line-height: 2em; margin: 0 auto .5em auto; diff --git a/app/views/admin/rebate_forms_council_details/edit.html.haml b/app/views/admin/rebate_forms_council_details/edit.html.haml index 353a5471..942a93c4 100644 --- a/app/views/admin/rebate_forms_council_details/edit.html.haml +++ b/app/views/admin/rebate_forms_council_details/edit.html.haml @@ -15,8 +15,8 @@ = hidden_field_tag :id, @rebate_form.id .flex-row .button-container.council-buttons - = link_to 'CANCEL', admin_rebate_form_path(@rebate_form), id: 'cancel', class: 'pure-button rebate-cancel-button' - = f.submit 'SAVE', class: 'pure-button rebate-submit-button' + = link_to 'CANCEL', admin_rebate_form_path(@rebate_form), id: 'cancel', class: 'pure-button rebate-cancel-button rebate-council-cancel-button' + = f.submit 'SAVE', class: 'pure-button rebate-submit-button rebate-council-submit-button' .flex-row.council-row .flex-item.with-margin = f.label :valuation_id, 'Valuation ID' From 3b0d6b3255f5f055fee87be639eb1ea08b2fd2e5 Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Fri, 21 Jun 2019 13:42:03 +1200 Subject: [PATCH 21/59] Removed unneeded controller action. --- app/controllers/admin/rebate_forms_controller.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/controllers/admin/rebate_forms_controller.rb b/app/controllers/admin/rebate_forms_controller.rb index 8ed8d958..156771c4 100644 --- a/app/controllers/admin/rebate_forms_controller.rb +++ b/app/controllers/admin/rebate_forms_controller.rb @@ -11,11 +11,6 @@ def generateqr @image_data = GenerateQrService.new(@rebate_form, current_user).generate_qr end - def edit_council_fields - @rebate_form = RebateForm.find(params[:rebate_form_id]) - authorize @rebate_form - end - def edit; end # GET /admin/rebate_forms From 4051a49f1e0c54e804274e3289ac77e78848c616 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Fri, 21 Jun 2019 15:08:33 +1200 Subject: [PATCH 22/59] refactor the frontend to only use data from the rebate form itself --- app/controllers/admin/batches_controller.rb | 2 +- .../admin/processed_rebate_forms_controller.rb | 3 +-- app/controllers/admin/rebate_forms_controller.rb | 2 +- .../admin/signed_rebate_forms_controller.rb | 4 ++-- app/javascript/components/SummaryRow.js | 10 +++++----- app/javascript/containers/CustomersSummary.js | 4 ++-- app/javascript/containers/RebateForm.js | 4 +--- app/javascript/helpers/formatRebateForm.js | 6 ++---- app/views/admin/rebate_forms/edit.html.haml | 2 +- app/views/admin/rebate_forms/show.html.haml | 4 ++-- spec/controllers/admin/batches_controller_spec.rb | 2 +- .../admin/processed_rebate_forms_controller_spec.rb | 2 +- .../admin/signed_rebate_forms_controller_spec.rb | 2 +- .../admin/processed_rebate_forms/index_spec.rb | 12 +++++------- spec/features/admin/rebate_forms/index_spec.rb | 6 +++--- 15 files changed, 29 insertions(+), 36 deletions(-) diff --git a/app/controllers/admin/batches_controller.rb b/app/controllers/admin/batches_controller.rb index 27135f57..12cfb3d2 100644 --- a/app/controllers/admin/batches_controller.rb +++ b/app/controllers/admin/batches_controller.rb @@ -7,7 +7,7 @@ def index @batches = policy_scope(Batch) .all .order(created_at: :desc) - .to_json(include: { rebate_forms: { include: :property } }) + .to_json(include: [:rebate_forms]) end def edit diff --git a/app/controllers/admin/processed_rebate_forms_controller.rb b/app/controllers/admin/processed_rebate_forms_controller.rb index 9ed141b5..6692cf99 100644 --- a/app/controllers/admin/processed_rebate_forms_controller.rb +++ b/app/controllers/admin/processed_rebate_forms_controller.rb @@ -7,9 +7,8 @@ def index @processed_rebate_forms = policy_scope(RebateForm) .where(status: RebateForm::PROCESSED_STATUS) .order(created_at: :asc) - .to_json(include: [:property]) - respond_with json: @processed_rebate_forms.to_json(include: [:property]) + respond_with json: @processed_rebate_forms end def create diff --git a/app/controllers/admin/rebate_forms_controller.rb b/app/controllers/admin/rebate_forms_controller.rb index 5170e2c4..cd53ecca 100644 --- a/app/controllers/admin/rebate_forms_controller.rb +++ b/app/controllers/admin/rebate_forms_controller.rb @@ -24,7 +24,7 @@ def index # filter by the search form fields @rebate_forms = @rebate_forms.where("fields ->> 'full_name' iLIKE ?", "%#{@name}%") if @name.present? - respond_with json: @rebate_forms.to_json(include: [:property]) + respond_with json: @rebate_forms end # GET /admin/rebate_forms/1 diff --git a/app/controllers/admin/signed_rebate_forms_controller.rb b/app/controllers/admin/signed_rebate_forms_controller.rb index 4d192b9b..8751cad8 100644 --- a/app/controllers/admin/signed_rebate_forms_controller.rb +++ b/app/controllers/admin/signed_rebate_forms_controller.rb @@ -7,7 +7,7 @@ def index @signed_rebate_forms = policy_scope(RebateForm) .where(status: RebateForm::SIGNED_STATUS) .order(created_at: :asc) - .to_json(include: [:property]) - respond_with json: @signed_rebate_forms.to_json(include: [:property]) + + respond_with json: @signed_rebate_forms end end diff --git a/app/javascript/components/SummaryRow.js b/app/javascript/components/SummaryRow.js index 6e67afd4..93fc2727 100644 --- a/app/javascript/components/SummaryRow.js +++ b/app/javascript/components/SummaryRow.js @@ -1,7 +1,7 @@ import React from 'react'; export function SummaryRow(rebateForm, key, checked, checkIt) { - const { property, fields, id } = rebateForm; + const { location, valuation_id, fields, id } = rebateForm; const { full_name } = fields; const isChecked = checked.indexOf(id) >= 0; @@ -18,14 +18,14 @@ export function SummaryRow(rebateForm, key, checked, checkIt) { } {fields.full_name} - {checkIt && property.valuation_id && - {property.valuation_id} + {checkIt && valuation_id && + {valuation_id} } - {checkIt && !property.valuation_id && + {checkIt && !valuation_id && } {!checkIt && - {property.location}
{property.suburb}
{property.town_city} + {location} } { diff --git a/app/javascript/containers/CustomersSummary.js b/app/javascript/containers/CustomersSummary.js index 12c58f8c..822908de 100644 --- a/app/javascript/containers/CustomersSummary.js +++ b/app/javascript/containers/CustomersSummary.js @@ -28,7 +28,7 @@ class CustomersSummary extends React.Component { hasSearched: false, checked: [], batches: batches && JSON.parse(batches), - rebateForms: rebateForms && JSON.parse(rebateForms), + rebateForms: rebateForms, isDiaUser: !!find(current_user_roles, role => role.name === 'dia'), isCouncilUser: !!find(current_user_roles, role => role.name === 'rates' || role.name === 'frontline') }; @@ -78,7 +78,7 @@ class CustomersSummary extends React.Component { return response.json(); }) .then(data => { - this.setState({ rebateForms: JSON.parse(data.json), hasSearched: true, name }); + this.setState({ rebateForms: data.json, hasSearched: true, name }); }) .catch(error => { console.error(error); diff --git a/app/javascript/containers/RebateForm.js b/app/javascript/containers/RebateForm.js index e9fe6e27..c29df2e4 100644 --- a/app/javascript/containers/RebateForm.js +++ b/app/javascript/containers/RebateForm.js @@ -59,12 +59,10 @@ class EditRebateForm extends React.Component { render () { const { rebateForm, - property, - ratesBills, isReadOnly } = this.props; - const fields = parseFromAPI(rebateForm, property, ratesBills); + const fields = parseFromAPI(rebateForm); const initialValues = {fields}; diff --git a/app/javascript/helpers/formatRebateForm.js b/app/javascript/helpers/formatRebateForm.js index 1e55dabc..04b9666e 100644 --- a/app/javascript/helpers/formatRebateForm.js +++ b/app/javascript/helpers/formatRebateForm.js @@ -1,8 +1,6 @@ -export function parseFromAPI (rebateForm, property, ratesBills) { - const { location, valuation_id } = property; - const { total_rates } = ratesBills[0]; - const { fields } = rebateForm; +export function parseFromAPI (rebateForm) { + const { fields, location, valuation_id, total_rates } = rebateForm; return { ...fields, location, valuation_id, total_rates }; } diff --git a/app/views/admin/rebate_forms/edit.html.haml b/app/views/admin/rebate_forms/edit.html.haml index f458886d..ae347a4e 100644 --- a/app/views/admin/rebate_forms/edit.html.haml +++ b/app/views/admin/rebate_forms/edit.html.haml @@ -1,3 +1,3 @@ = render 'edit_header' -= react_component("RebateForm", {isReadOnly: false, rebateForm: @rebate_form, property: @rebate_form.property, council: @rebate_form.council, ratesBills: @rebate_form.property.rates_bills}) += react_component("RebateForm", {isReadOnly: false, rebateForm: @rebate_form, council: @rebate_form.council}) diff --git a/app/views/admin/rebate_forms/show.html.haml b/app/views/admin/rebate_forms/show.html.haml index 1de05fbb..d1cff9e9 100644 --- a/app/views/admin/rebate_forms/show.html.haml +++ b/app/views/admin/rebate_forms/show.html.haml @@ -1,6 +1,6 @@ -- content_for :title, "RatesRebate #{@rebate_form.property.location}" +- content_for :title, "RatesRebate #{@rebate_form.location}" = render 'show_header' -= react_component("RebateForm", {isReadOnly: true, rebateForm: @rebate_form, property: @rebate_form.property, ratesBills: @rebate_form.property.rates_bills}) += react_component("RebateForm", {isReadOnly: true, rebateForm: @rebate_form}) diff --git a/spec/controllers/admin/batches_controller_spec.rb b/spec/controllers/admin/batches_controller_spec.rb index b5962cfc..c805968e 100644 --- a/spec/controllers/admin/batches_controller_spec.rb +++ b/spec/controllers/admin/batches_controller_spec.rb @@ -14,7 +14,7 @@ it 'assigns all batches to @batches' do get :index - expect(assigns(:batches)).to eq([batched_form.batch].to_json(include: { rebate_forms: { include: :property } })) + expect(assigns(:batches)).to eq([batched_form.batch].to_json(include: [:rebate_forms])) expect(response.status).to eq(200) end end diff --git a/spec/controllers/admin/processed_rebate_forms_controller_spec.rb b/spec/controllers/admin/processed_rebate_forms_controller_spec.rb index f7cbd7ad..d8944e98 100644 --- a/spec/controllers/admin/processed_rebate_forms_controller_spec.rb +++ b/spec/controllers/admin/processed_rebate_forms_controller_spec.rb @@ -12,7 +12,7 @@ it 'assigns all processed rebate forms to @processed_rebate_forms' do get :index - expect(assigns(:processed_rebate_forms)).to eq processed_forms.to_json(include: [:property]) + expect(assigns(:processed_rebate_forms).to_json).to eq processed_forms.to_json expect(response.status).to eq(200) end end diff --git a/spec/controllers/admin/signed_rebate_forms_controller_spec.rb b/spec/controllers/admin/signed_rebate_forms_controller_spec.rb index d34eef68..46524811 100644 --- a/spec/controllers/admin/signed_rebate_forms_controller_spec.rb +++ b/spec/controllers/admin/signed_rebate_forms_controller_spec.rb @@ -12,7 +12,7 @@ it 'assigns all signed rebate forms to @signed_rebate_forms' do get :index - expect(assigns(:signed_rebate_forms)).to eq signed_forms.to_json(include: [:property]) + expect(assigns(:signed_rebate_forms)).to eq signed_forms expect(response.status).to eq(200) end end diff --git a/spec/features/admin/processed_rebate_forms/index_spec.rb b/spec/features/admin/processed_rebate_forms/index_spec.rb index b63d3d11..ae4a16c7 100644 --- a/spec/features/admin/processed_rebate_forms/index_spec.rb +++ b/spec/features/admin/processed_rebate_forms/index_spec.rb @@ -28,20 +28,18 @@ expect(page).to have_text(processed_forms.first.fields['full_name']) expect(page).to have_text(processed_forms.second.fields['full_name']) expect(page).to have_text(processed_forms.third.fields['full_name']) - expect(page).to have_text(processed_forms.first.property.valuation_id) - expect(page).to have_text(processed_forms.second.property.valuation_id) - expect(page).to have_text(processed_forms.third.property.valuation_id) + expect(page).to have_text(processed_forms.first.valuation_id) + expect(page).to have_text(processed_forms.second.valuation_id) + expect(page).to have_text(processed_forms.third.valuation_id) end context 'when there is no valuation id' do before do - property.update!(valuation_id: '') + processed_forms.first.update!(valuation_id: '') end it 'the cell is left blank' do - expect(processed_forms.first.property.valuation_id).to eq '' - expect(processed_forms.second.property.valuation_id).to eq '' - expect(processed_forms.third.property.valuation_id).to eq '' + expect(processed_forms.first.valuation_id).to eq '' expect(page).to have_css('#valuation-id', text: '') end end diff --git a/spec/features/admin/rebate_forms/index_spec.rb b/spec/features/admin/rebate_forms/index_spec.rb index 4ff27de2..28a55738 100644 --- a/spec/features/admin/rebate_forms/index_spec.rb +++ b/spec/features/admin/rebate_forms/index_spec.rb @@ -8,19 +8,19 @@ FactoryBot.create(:rebate_form, property: FactoryBot.create(:property, council: council)) end let(:expected_name) { rebate_form.full_name } - let(:expected_location) { rebate_form.property.location } + let(:expected_location) { rebate_form.location } let!(:signed_form) do FactoryBot.create(:signed_form, property: FactoryBot.create(:property, council: council)) end let(:signed_name) { signed_form.full_name } - let(:signed_location) { signed_form.property.location } + let(:signed_location) { signed_form.location } let!(:processed_form) do FactoryBot.create(:processed_form, property: FactoryBot.create(:property, council: council)) end let(:processed_name) { processed_form.full_name } - let(:processed_valuation_id) { processed_form.property.valuation_id } + let(:processed_valuation_id) { processed_form.valuation_id } context 'anonymous' do it "can't see it" do From a898adc7b99b9123a5b145e22c1ecf7f18f1a2b1 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Fri, 21 Jun 2019 15:17:27 +1200 Subject: [PATCH 23/59] get last test passing --- spec/services/rebate_forms_service_spec.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/spec/services/rebate_forms_service_spec.rb b/spec/services/rebate_forms_service_spec.rb index ea0cb269..30c91a1f 100644 --- a/spec/services/rebate_forms_service_spec.rb +++ b/spec/services/rebate_forms_service_spec.rb @@ -26,15 +26,11 @@ } end - describe '#update!' do + describe '#create!' do context 'with invalid params' do - let(:update_params) do + let(:create_params) do { - 'id' => rebate_form.id, - 'valuation_id' => property2.valuation_id, 'total_rates' => '12345', - 'completely_invalid' => true, - 'location' => property2.location, 'rebate_form' => { 'fields' => {} } From a072eb2e2189bbde36654098a14104b1bba70a01 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Fri, 21 Jun 2019 15:25:52 +1200 Subject: [PATCH 24/59] add total rates back in so as to not break API --- app/controllers/rebate_forms_controller.rb | 1 + db/schema.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/app/controllers/rebate_forms_controller.rb b/app/controllers/rebate_forms_controller.rb index bdddff82..6e729466 100644 --- a/app/controllers/rebate_forms_controller.rb +++ b/app/controllers/rebate_forms_controller.rb @@ -42,6 +42,7 @@ def rebate_form_params .permit(:valuation_id, :council_id, :location, + :total_rates, fields: {}, applicant_signature: {}, witness_signature: {}) diff --git a/db/schema.rb b/db/schema.rb index 5a4c5490..7745f30b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -104,6 +104,8 @@ t.string "status", default: "not signed" t.string "location" t.decimal "total_rates", precision: 8, scale: 2 + t.string "customer_id" + t.string "application_id" end create_table "roles", force: :cascade do |t| From de38c0d4c4e2e1f1b8b7f7814734d69544a985f7 Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Fri, 21 Jun 2019 15:29:46 +1200 Subject: [PATCH 25/59] Added extra column to processed tab, wrote tests. --- app/javascript/components/SummaryRow.js | 8 ++++++++ app/javascript/components/SummaryTable.js | 1 + spec/features/admin/rebate_forms/index_spec.rb | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/app/javascript/components/SummaryRow.js b/app/javascript/components/SummaryRow.js index 6e67afd4..925b0faa 100644 --- a/app/javascript/components/SummaryRow.js +++ b/app/javascript/components/SummaryRow.js @@ -27,6 +27,14 @@ export function SummaryRow(rebateForm, key, checked, checkIt) { {!checkIt && {property.location}
{property.suburb}
{property.town_city} } + {checkIt && + + { rebateForm.application_id + ? rebateForm.application_id + : '' + } + + }
{ window.location = `/admin/rebate_forms/${id}`; diff --git a/app/javascript/components/SummaryTable.js b/app/javascript/components/SummaryTable.js index 4bb54607..94d73cfc 100644 --- a/app/javascript/components/SummaryTable.js +++ b/app/javascript/components/SummaryTable.js @@ -12,6 +12,7 @@ export function SummaryTable(rebateForms, checked, checkIt) { {checkIt && } Name {checkIt ? 'Valuation ID' : 'Address'} + {checkIt && Application ID} diff --git a/spec/features/admin/rebate_forms/index_spec.rb b/spec/features/admin/rebate_forms/index_spec.rb index 4ff27de2..aec6dfd9 100644 --- a/spec/features/admin/rebate_forms/index_spec.rb +++ b/spec/features/admin/rebate_forms/index_spec.rb @@ -61,6 +61,7 @@ expect(page).to have_field('name') expect(page).to have_text(expected_name) expect(page).to have_text(expected_location) + expect(page).to_not have_text('Application ID') end include_examples 'percy snapshot' end @@ -102,6 +103,7 @@ expect(page).not_to have_field('name') expect(page).to have_text(signed_name) expect(page).to have_text(signed_location) + expect(page).to_not have_text('Application ID') end include_examples 'percy snapshot' end @@ -116,6 +118,8 @@ expect(page).to have_text('Processed') expect(page).to have_text('Batched') expect(page).to have_text(processed_name) + expect(page).to have_text('Application ID') + expect(page).to have_text(processed_form.application_id) end include_examples 'percy snapshot' end From 8c288d70adfb9f918808ffac405241fcc82b7fd9 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Fri, 21 Jun 2019 15:37:58 +1200 Subject: [PATCH 26/59] change customer to application in tests --- spec/features/admin/rebate_forms/show_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/features/admin/rebate_forms/show_spec.rb b/spec/features/admin/rebate_forms/show_spec.rb index 27d7bd8d..1ec29b95 100644 --- a/spec/features/admin/rebate_forms/show_spec.rb +++ b/spec/features/admin/rebate_forms/show_spec.rb @@ -29,7 +29,7 @@ expect(page).to have_text('Council details') expect(page).to have_text('Valuation ID') expect(page).to have_text(rebate_form.valuation_id) - expect(page).to have_text('Customer ID') + expect(page).to have_text('Application ID') expect(page).to have_text(rebate_form.customer_id) expect(page).to have_text('Application ID') expect(page).to have_text(rebate_form.application_id) @@ -41,7 +41,7 @@ expect(page).to have_text('LOG OUT x') expect(page).to have_text('Application details') expect(page).to have_text('Signature required') - expect(page).to have_text('Customer details') + expect(page).to have_text('Application details') expect(page).to have_field('fields.full_name', with: rebate_form.full_name) expect(page).to have_field('fields.email', with: rebate_form.email) expect(page).to have_field('fields.occupation', with: rebate_form.occupation) @@ -75,7 +75,7 @@ click_link('edit-council') expect(page).to_not have_text('EDIT') expect(page).to have_text('Council details') - expect(page).to_not have_text('Customer details') + expect(page).to_not have_text('Application details') expect(page).to have_text('Signature required') expect(page).to have_field(with: rebate_form.valuation_id) end @@ -87,7 +87,7 @@ click_link('edit-customer') expect(page).to_not have_text('EDIT') expect(page).to_not have_text('Council details') - expect(page).to have_text('Customer details') + expect(page).to have_text('Application details') expect(page).to have_text('Signature required') expect(page).to have_field(with: rebate_form.full_name) end @@ -106,7 +106,7 @@ it { expect(page).to have_field('fields.full_name', with: rebate_form.full_name) } it { expect(page).to have_text('Valuation ID') } it { expect(page).to have_text(rebate_form.valuation_id) } - it { expect(page).to have_text('Customer ID') } + it { expect(page).to have_text('Application ID') } it { expect(page).to have_text(rebate_form.customer_id) } it { expect(page).to have_text('Application ID') } it { expect(page).to have_text(rebate_form.application_id) } @@ -114,7 +114,7 @@ describe ' Can see customer details' do before { visit "/admin/rebate_forms/#{rebate_form.id}" } - it { expect(page).to have_text('Customer details') } + it { expect(page).to have_text('Application details') } it { expect(page).to have_text('Signed and ready to process') } it { expect(page).to have_text('Process') } it { expect(page).to have_field('fields.full_name', with: rebate_form.full_name) } @@ -195,7 +195,7 @@ it ' Can see customer details' do visit "/admin/rebate_forms/#{rebate_form.id}" - expect(page).to have_text('Customer details') + expect(page).to have_text('Application details') expect(page).to have_text('Signature required') expect(page).to have_text(user.name) expect(page).to have_text('LOG OUT x') From 9557b0691009b60dccccbb5be30f5e583ba41901 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Fri, 21 Jun 2019 15:39:39 +1200 Subject: [PATCH 27/59] change customer to application in tests --- spec/features/admin/rebate_forms/show_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/features/admin/rebate_forms/show_spec.rb b/spec/features/admin/rebate_forms/show_spec.rb index 27d7bd8d..8dcf6d7d 100644 --- a/spec/features/admin/rebate_forms/show_spec.rb +++ b/spec/features/admin/rebate_forms/show_spec.rb @@ -41,7 +41,7 @@ expect(page).to have_text('LOG OUT x') expect(page).to have_text('Application details') expect(page).to have_text('Signature required') - expect(page).to have_text('Customer details') + expect(page).to have_text('Application details') expect(page).to have_field('fields.full_name', with: rebate_form.full_name) expect(page).to have_field('fields.email', with: rebate_form.email) expect(page).to have_field('fields.occupation', with: rebate_form.occupation) @@ -75,7 +75,7 @@ click_link('edit-council') expect(page).to_not have_text('EDIT') expect(page).to have_text('Council details') - expect(page).to_not have_text('Customer details') + expect(page).to_not have_text('Application details') expect(page).to have_text('Signature required') expect(page).to have_field(with: rebate_form.valuation_id) end @@ -87,7 +87,7 @@ click_link('edit-customer') expect(page).to_not have_text('EDIT') expect(page).to_not have_text('Council details') - expect(page).to have_text('Customer details') + expect(page).to have_text('Application details') expect(page).to have_text('Signature required') expect(page).to have_field(with: rebate_form.full_name) end @@ -114,7 +114,7 @@ describe ' Can see customer details' do before { visit "/admin/rebate_forms/#{rebate_form.id}" } - it { expect(page).to have_text('Customer details') } + it { expect(page).to have_text('Application details') } it { expect(page).to have_text('Signed and ready to process') } it { expect(page).to have_text('Process') } it { expect(page).to have_field('fields.full_name', with: rebate_form.full_name) } @@ -195,7 +195,7 @@ it ' Can see customer details' do visit "/admin/rebate_forms/#{rebate_form.id}" - expect(page).to have_text('Customer details') + expect(page).to have_text('Application details') expect(page).to have_text('Signature required') expect(page).to have_text(user.name) expect(page).to have_text('LOG OUT x') From 7b282254cc1101640228ab96740e0ef51de4432a Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Fri, 21 Jun 2019 15:43:02 +1200 Subject: [PATCH 28/59] last one! --- spec/features/admin/rebate_forms/show_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/features/admin/rebate_forms/show_spec.rb b/spec/features/admin/rebate_forms/show_spec.rb index 1ec29b95..9089905e 100644 --- a/spec/features/admin/rebate_forms/show_spec.rb +++ b/spec/features/admin/rebate_forms/show_spec.rb @@ -75,7 +75,6 @@ click_link('edit-council') expect(page).to_not have_text('EDIT') expect(page).to have_text('Council details') - expect(page).to_not have_text('Application details') expect(page).to have_text('Signature required') expect(page).to have_field(with: rebate_form.valuation_id) end From dd13174b041ca4360599eedf98792d78c8f7fa89 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Fri, 21 Jun 2019 15:52:03 +1200 Subject: [PATCH 29/59] make changes from pr reveiew --- app/controllers/admin/rebate_forms_controller.rb | 5 ----- app/services/rebate_forms_update_service.rb | 13 +++---------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/app/controllers/admin/rebate_forms_controller.rb b/app/controllers/admin/rebate_forms_controller.rb index bfc77553..3245676d 100644 --- a/app/controllers/admin/rebate_forms_controller.rb +++ b/app/controllers/admin/rebate_forms_controller.rb @@ -69,17 +69,12 @@ def set_rebate_form def rebate_form_fields_params params.permit(:id, - :valuation_id, :total_rates, :location, :council, fields: {}) end - def rebate_form_params - params.require(:rebate_form).permit(attachments: []) - end - def pdf_filename "#{@rebate_form.council.short_name}-(#{@rebate_form.valuation_id})-#{@rebate_form.id}" end diff --git a/app/services/rebate_forms_update_service.rb b/app/services/rebate_forms_update_service.rb index 0a1daecf..bfdbb8c1 100644 --- a/app/services/rebate_forms_update_service.rb +++ b/app/services/rebate_forms_update_service.rb @@ -8,24 +8,17 @@ def initialize(rebate_form_attributes) end def update! - rebate_form = update_rebate_form! - - rebate_form - end - - private - - def update_rebate_form! rebate_form = RebateForm.find_by(id: @rebate_form_attributes['id']) remove_signatures_if_signed(rebate_form) fields_to_update = rebate_form.fields.merge(fields_to_merge) - rebate_form.update!(valuation_id: @rebate_form_attributes['valuation_id'], - total_rates: @rebate_form_attributes['total_rates'], + rebate_form.update!(total_rates: @rebate_form_attributes['total_rates'], location: @rebate_form_attributes['location'], fields: fields_to_update) rebate_form end + private + def remove_signatures_if_signed(rebate_form) rebate_form.signatures.destroy_all && rebate_form.transition_to_not_signed_state if rebate_form.signed_state? end From 58d3aa851561053af60434969532f25e5c301646 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Mon, 24 Jun 2019 09:48:36 +1200 Subject: [PATCH 30/59] scope api to only include properties with address_lookup true --- app/controllers/properties_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/properties_controller.rb b/app/controllers/properties_controller.rb index ff2357af..7658edf7 100644 --- a/app/controllers/properties_controller.rb +++ b/app/controllers/properties_controller.rb @@ -19,6 +19,7 @@ def index Property.where('location ILIKE ?', "%#{params[:q]}%") .where(rating_year: Rails.configuration.rating_year) .where(council_id: params[:council_id]) + .where(include_in_address_lookups: true) ) end end From 61b258afe177f4190b7656fbdae460c9317a2622 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Mon, 24 Jun 2019 09:56:04 +1200 Subject: [PATCH 31/59] update tests --- app/views/admin/rebate_forms/edit.html.haml | 3 +++ spec/api/v1/properties/index_spec.rb | 6 +++--- spec/features/admin/rebate_forms/show_spec.rb | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/views/admin/rebate_forms/edit.html.haml b/app/views/admin/rebate_forms/edit.html.haml index ae347a4e..6a2e05c5 100644 --- a/app/views/admin/rebate_forms/edit.html.haml +++ b/app/views/admin/rebate_forms/edit.html.haml @@ -1,3 +1,6 @@ = render 'edit_header' +.rebate-details-header.customer-details-header + %h3.rebate-details-title Customer details + = react_component("RebateForm", {isReadOnly: false, rebateForm: @rebate_form, council: @rebate_form.council}) diff --git a/spec/api/v1/properties/index_spec.rb b/spec/api/v1/properties/index_spec.rb index 48866a11..8a97d01d 100644 --- a/spec/api/v1/properties/index_spec.rb +++ b/spec/api/v1/properties/index_spec.rb @@ -13,9 +13,9 @@ let(:council) { FactoryBot.create :council } describe 'basic fetch' do - let!(:matching_property) { create(:property, location: '1 main street', council: council, rating_year: year) } - let!(:matching_property_wrong_year) { create(:property, location: '1 main street', council: council, rating_year: '1840') } - let!(:unrelated_property) { create(:property, location: '22 tawa road', council: council, rating_year: year) } + let!(:matching_property) { create(:property, location: '1 main street', council: council, rating_year: year, include_in_address_lookups: true) } + let!(:matching_property_wrong_year) { create(:property, location: '1 main street', council: council, rating_year: '1840', include_in_address_lookups: true,) } + let!(:unrelated_property) { create(:property, location: '22 tawa road', council: council, rating_year: year, include_in_address_lookups: true) } before { make_request } diff --git a/spec/features/admin/rebate_forms/show_spec.rb b/spec/features/admin/rebate_forms/show_spec.rb index 9089905e..198ba770 100644 --- a/spec/features/admin/rebate_forms/show_spec.rb +++ b/spec/features/admin/rebate_forms/show_spec.rb @@ -29,7 +29,7 @@ expect(page).to have_text('Council details') expect(page).to have_text('Valuation ID') expect(page).to have_text(rebate_form.valuation_id) - expect(page).to have_text('Application ID') + expect(page).to have_text('Customer ID') expect(page).to have_text(rebate_form.customer_id) expect(page).to have_text('Application ID') expect(page).to have_text(rebate_form.application_id) @@ -41,7 +41,7 @@ expect(page).to have_text('LOG OUT x') expect(page).to have_text('Application details') expect(page).to have_text('Signature required') - expect(page).to have_text('Application details') + expect(page).to have_text('Customer details') expect(page).to have_field('fields.full_name', with: rebate_form.full_name) expect(page).to have_field('fields.email', with: rebate_form.email) expect(page).to have_field('fields.occupation', with: rebate_form.occupation) From 6a35ada97c80e1715a97ea9061a822f6924b4b40 Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Mon, 24 Jun 2019 09:56:20 +1200 Subject: [PATCH 32/59] Updated headings to correct wordings. --- app/views/admin/rebate_forms/_edit_header.html.haml | 2 +- app/views/admin/rebate_forms/edit.html.haml | 2 -- app/views/admin/rebate_forms_council_details/edit.html.haml | 4 +--- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/views/admin/rebate_forms/_edit_header.html.haml b/app/views/admin/rebate_forms/_edit_header.html.haml index 267ea66e..2ba84921 100644 --- a/app/views/admin/rebate_forms/_edit_header.html.haml +++ b/app/views/admin/rebate_forms/_edit_header.html.haml @@ -9,7 +9,7 @@ .rebate-header %h2.rebate-title - Application details + Customer details %h3.rebate-subtitle - if @rebate_form.signed_state? diff --git a/app/views/admin/rebate_forms/edit.html.haml b/app/views/admin/rebate_forms/edit.html.haml index 8980576b..f458886d 100644 --- a/app/views/admin/rebate_forms/edit.html.haml +++ b/app/views/admin/rebate_forms/edit.html.haml @@ -1,5 +1,3 @@ = render 'edit_header' -.rebate-details-header.customer-details-header - %h3.rebate-details-title Customer details = react_component("RebateForm", {isReadOnly: false, rebateForm: @rebate_form, property: @rebate_form.property, council: @rebate_form.council, ratesBills: @rebate_form.property.rates_bills}) diff --git a/app/views/admin/rebate_forms_council_details/edit.html.haml b/app/views/admin/rebate_forms_council_details/edit.html.haml index 942a93c4..43e55a4a 100644 --- a/app/views/admin/rebate_forms_council_details/edit.html.haml +++ b/app/views/admin/rebate_forms_council_details/edit.html.haml @@ -1,6 +1,6 @@ .rebate-header %h2.rebate-title - Application details + Council details %h3.rebate-subtitle - if @rebate_form.signed_state? @@ -8,8 +8,6 @@ - else Signature required -.rebate-details-header.customer-details-header - %h3.rebate-details-title Council details .rebate-edit-form = form_for(@rebate_form, url: admin_rebate_forms_update_council_details_path, html: { method: 'patch' }) do |f| = hidden_field_tag :id, @rebate_form.id From fc68b0fc918fda3ea926f7ea54e4a7279cab4126 Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Mon, 24 Jun 2019 10:05:42 +1200 Subject: [PATCH 33/59] Updated test to have new header text. --- spec/features/admin/rebate_forms/edit_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/features/admin/rebate_forms/edit_spec.rb b/spec/features/admin/rebate_forms/edit_spec.rb index 6b69a022..a089e12f 100644 --- a/spec/features/admin/rebate_forms/edit_spec.rb +++ b/spec/features/admin/rebate_forms/edit_spec.rb @@ -18,6 +18,7 @@ describe '#edit' do it 'can modify the rebate_form' do visit "/admin/rebate_forms/#{rebate_form.id}/edit" + expect(page).to have_text('Customer details') expect(page).to have_text('Name') fill_in('fields.full_name', with: 'arnold', fill_options: { clear: :backspace }) click_button 'SAVE' From a10d5859be7d1c997ed92754bb812a845863367e Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Mon, 24 Jun 2019 10:52:57 +1200 Subject: [PATCH 34/59] ensure all tests passing --- app/services/rates_importer_service.rb | 2 +- spec/controllers/properties_controller_spec.rb | 6 +++--- spec/features/admin/rebate_forms/show_spec.rb | 3 +-- spec/services/rebate_forms_service_spec.rb | 1 + spec/services/rebate_forms_update_service_spec.rb | 2 -- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/services/rates_importer_service.rb b/app/services/rates_importer_service.rb index 611feb7a..1b5a71f9 100644 --- a/app/services/rates_importer_service.rb +++ b/app/services/rates_importer_service.rb @@ -21,7 +21,7 @@ def import(row, rating_year, council) property = Property.create!( council: council, valuation_id: valuation, - location: ("#{location.gsub /"/, ''} " + "#{suburb} " + town_city.to_s).strip, + location: ("#{location.gsub /"/, ''} " + "#{suburb} " + town_city.to_s).strip.capitalize, suburb: suburb, town_city: town_city, rating_year: rating_year, diff --git a/spec/controllers/properties_controller_spec.rb b/spec/controllers/properties_controller_spec.rb index b40d8495..4ed98e5e 100644 --- a/spec/controllers/properties_controller_spec.rb +++ b/spec/controllers/properties_controller_spec.rb @@ -10,14 +10,14 @@ # Property to not find, address doesn't match let!(:property_1) do - FactoryBot.create :property, location: '11 MAIN ROAD', council: council, rating_year: ENV['YEAR'] + FactoryBot.create :property, location: '11 MAIN ROAD', council: council, rating_year: ENV['YEAR'], include_in_address_lookups: true end # Property we hope to find let!(:property_2) do - FactoryBot.create :property, location: '11 MOANA ROAD', council: council, rating_year: ENV['YEAR'] + FactoryBot.create :property, location: '11 MOANA ROAD', council: council, rating_year: ENV['YEAR'], include_in_address_lookups: true end # Property we should not find, it's for a different year - let!(:property_3) { FactoryBot.create :property, location: '11 MOANA ROAD', council: council, rating_year: '1840' } + let!(:property_3) { FactoryBot.create :property, location: '11 MOANA ROAD', council: council, rating_year: '1840', include_in_address_lookups: true } shared_examples 'finds property' do before { get :index, format: :json, params: { q: query, council_id: council.id } } diff --git a/spec/features/admin/rebate_forms/show_spec.rb b/spec/features/admin/rebate_forms/show_spec.rb index 198ba770..ea84336d 100644 --- a/spec/features/admin/rebate_forms/show_spec.rb +++ b/spec/features/admin/rebate_forms/show_spec.rb @@ -86,7 +86,6 @@ click_link('edit-customer') expect(page).to_not have_text('EDIT') expect(page).to_not have_text('Council details') - expect(page).to have_text('Application details') expect(page).to have_text('Signature required') expect(page).to have_field(with: rebate_form.full_name) end @@ -105,7 +104,7 @@ it { expect(page).to have_field('fields.full_name', with: rebate_form.full_name) } it { expect(page).to have_text('Valuation ID') } it { expect(page).to have_text(rebate_form.valuation_id) } - it { expect(page).to have_text('Application ID') } + it { expect(page).to have_text('Customer ID') } it { expect(page).to have_text(rebate_form.customer_id) } it { expect(page).to have_text('Application ID') } it { expect(page).to have_text(rebate_form.application_id) } diff --git a/spec/services/rebate_forms_service_spec.rb b/spec/services/rebate_forms_service_spec.rb index 30c91a1f..de0e20cf 100644 --- a/spec/services/rebate_forms_service_spec.rb +++ b/spec/services/rebate_forms_service_spec.rb @@ -47,6 +47,7 @@ subject.create! expect(RebateForm.count).to eq 1 expect(RebateForm.first.fields['location']).to eq property.location + expect(RebateForm.first.total_rates).to eq property.rates_bills.first.total_rates end end end diff --git a/spec/services/rebate_forms_update_service_spec.rb b/spec/services/rebate_forms_update_service_spec.rb index 692d208c..a6b7ad73 100644 --- a/spec/services/rebate_forms_update_service_spec.rb +++ b/spec/services/rebate_forms_update_service_spec.rb @@ -12,7 +12,6 @@ let(:update_params) do { 'id' => rebate_form.id, - 'valuation_id' => property2.valuation_id, 'total_rates' => '12345', 'location' => property2.location, 'fields' => { @@ -38,7 +37,6 @@ expect(RebateForm.first.fields['dependants']).to eq '3' expect(RebateForm.first.location).to eq property2.location expect(RebateForm.first.total_rates).to eq 12345 - expect(RebateForm.first.valuation_id).to eq property2.valuation_id end context 'without a valuation id' do From c267f955a10442b9e5a06e18740854fdfc45f468 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Mon, 24 Jun 2019 11:23:32 +1200 Subject: [PATCH 35/59] remove updates from migrate down --- ...add_total_rates_location_to_rebate_form.rb | 39 ------------------- lib/tasks/rates.rake | 2 +- 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb b/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb index 0901ceb6..d403cea7 100644 --- a/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb +++ b/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb @@ -6,46 +6,7 @@ def up end def down - update_existing_rebate_forms_down remove_column :rebate_forms, :location, :string remove_column :rebate_forms, :total_rates, :decimal, precision: 8, scale: 2 end - - private - - def update_existing_rebate_forms_up - RebateForm.all.each do |rebate_form| - property = rebate_form.property - rebate_form.update(location: property.location, - total_rates: property.rates_bills[0].total_rates, - valuation_id: rebate_form.fields['valuation_id'] || property.valuation_id || nil) - end - end - - def update_existing_rebate_forms_down - RebateForm.all.each do |rebate_form| - @rebate_form = rebate_form - property = update_property! - create_or_update_rates_bill!(property) - end - end - - def update_property! - property = @rebate_form.property - - property.update!(location: @rebate_form.location, - valuation_id: @rebate_form.valuation_id) - property - end - - def create_or_update_rates_bill!(property) - rates_bill = RatesBill.find_or_create_by(property: property, - rating_year: property.rating_year) - rates_bill.update!(total_rates: total_rates) - rates_bill - end - - def total_rates - @rebate_form.total_rates || 0 - end end diff --git a/lib/tasks/rates.rake b/lib/tasks/rates.rake index 3a029b0a..1fd8e977 100644 --- a/lib/tasks/rates.rake +++ b/lib/tasks/rates.rake @@ -20,7 +20,7 @@ namespace :rates do end task kapiti: :environment do - council = Council.find_or_create_by(name: 'Kāpiti Coast District Council') + council = Council.find_or_create_by!(name: 'Kāpiti Coast District Council', short_name: 'kcd', email: '123fake@email.com') rates_file = Rails.root.join('db', 'seeds', 'kapiti.csv') Property.transaction do From 95c8929f571deed2fd28d2dbb23cb018f963981b Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Mon, 24 Jun 2019 11:26:17 +1200 Subject: [PATCH 36/59] include update up --- ...20204258_add_total_rates_location_to_rebate_form.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb b/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb index d403cea7..a3bb1f40 100644 --- a/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb +++ b/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb @@ -9,4 +9,14 @@ def down remove_column :rebate_forms, :location, :string remove_column :rebate_forms, :total_rates, :decimal, precision: 8, scale: 2 end + + private + +def update_existing_rebate_forms_up + RebateForm.all.each do |rebate_form| + property = rebate_form.property + rebate_form.update(location: property.location, + total_rates: property.rates_bills[0].total_rates, + valuation_id: rebate_form.fields['valuation_id'] || property.valuation_id || nil) + end end From f866516ddd2138baa3268696e2d17991b71639ae Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Mon, 24 Jun 2019 11:36:48 +1200 Subject: [PATCH 37/59] rollback migration --- app/services/rates_importer_service.rb | 2 +- lib/tasks/rates.rake | 2 +- spec/controllers/properties_controller_spec.rb | 6 +++--- spec/features/admin/rebate_forms/show_spec.rb | 3 +-- spec/services/rebate_forms_service_spec.rb | 1 + spec/services/rebate_forms_update_service_spec.rb | 2 -- 6 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/services/rates_importer_service.rb b/app/services/rates_importer_service.rb index 611feb7a..1b5a71f9 100644 --- a/app/services/rates_importer_service.rb +++ b/app/services/rates_importer_service.rb @@ -21,7 +21,7 @@ def import(row, rating_year, council) property = Property.create!( council: council, valuation_id: valuation, - location: ("#{location.gsub /"/, ''} " + "#{suburb} " + town_city.to_s).strip, + location: ("#{location.gsub /"/, ''} " + "#{suburb} " + town_city.to_s).strip.capitalize, suburb: suburb, town_city: town_city, rating_year: rating_year, diff --git a/lib/tasks/rates.rake b/lib/tasks/rates.rake index 3a029b0a..1fd8e977 100644 --- a/lib/tasks/rates.rake +++ b/lib/tasks/rates.rake @@ -20,7 +20,7 @@ namespace :rates do end task kapiti: :environment do - council = Council.find_or_create_by(name: 'Kāpiti Coast District Council') + council = Council.find_or_create_by!(name: 'Kāpiti Coast District Council', short_name: 'kcd', email: '123fake@email.com') rates_file = Rails.root.join('db', 'seeds', 'kapiti.csv') Property.transaction do diff --git a/spec/controllers/properties_controller_spec.rb b/spec/controllers/properties_controller_spec.rb index b40d8495..4ed98e5e 100644 --- a/spec/controllers/properties_controller_spec.rb +++ b/spec/controllers/properties_controller_spec.rb @@ -10,14 +10,14 @@ # Property to not find, address doesn't match let!(:property_1) do - FactoryBot.create :property, location: '11 MAIN ROAD', council: council, rating_year: ENV['YEAR'] + FactoryBot.create :property, location: '11 MAIN ROAD', council: council, rating_year: ENV['YEAR'], include_in_address_lookups: true end # Property we hope to find let!(:property_2) do - FactoryBot.create :property, location: '11 MOANA ROAD', council: council, rating_year: ENV['YEAR'] + FactoryBot.create :property, location: '11 MOANA ROAD', council: council, rating_year: ENV['YEAR'], include_in_address_lookups: true end # Property we should not find, it's for a different year - let!(:property_3) { FactoryBot.create :property, location: '11 MOANA ROAD', council: council, rating_year: '1840' } + let!(:property_3) { FactoryBot.create :property, location: '11 MOANA ROAD', council: council, rating_year: '1840', include_in_address_lookups: true } shared_examples 'finds property' do before { get :index, format: :json, params: { q: query, council_id: council.id } } diff --git a/spec/features/admin/rebate_forms/show_spec.rb b/spec/features/admin/rebate_forms/show_spec.rb index 198ba770..ea84336d 100644 --- a/spec/features/admin/rebate_forms/show_spec.rb +++ b/spec/features/admin/rebate_forms/show_spec.rb @@ -86,7 +86,6 @@ click_link('edit-customer') expect(page).to_not have_text('EDIT') expect(page).to_not have_text('Council details') - expect(page).to have_text('Application details') expect(page).to have_text('Signature required') expect(page).to have_field(with: rebate_form.full_name) end @@ -105,7 +104,7 @@ it { expect(page).to have_field('fields.full_name', with: rebate_form.full_name) } it { expect(page).to have_text('Valuation ID') } it { expect(page).to have_text(rebate_form.valuation_id) } - it { expect(page).to have_text('Application ID') } + it { expect(page).to have_text('Customer ID') } it { expect(page).to have_text(rebate_form.customer_id) } it { expect(page).to have_text('Application ID') } it { expect(page).to have_text(rebate_form.application_id) } diff --git a/spec/services/rebate_forms_service_spec.rb b/spec/services/rebate_forms_service_spec.rb index 30c91a1f..de0e20cf 100644 --- a/spec/services/rebate_forms_service_spec.rb +++ b/spec/services/rebate_forms_service_spec.rb @@ -47,6 +47,7 @@ subject.create! expect(RebateForm.count).to eq 1 expect(RebateForm.first.fields['location']).to eq property.location + expect(RebateForm.first.total_rates).to eq property.rates_bills.first.total_rates end end end diff --git a/spec/services/rebate_forms_update_service_spec.rb b/spec/services/rebate_forms_update_service_spec.rb index 692d208c..a6b7ad73 100644 --- a/spec/services/rebate_forms_update_service_spec.rb +++ b/spec/services/rebate_forms_update_service_spec.rb @@ -12,7 +12,6 @@ let(:update_params) do { 'id' => rebate_form.id, - 'valuation_id' => property2.valuation_id, 'total_rates' => '12345', 'location' => property2.location, 'fields' => { @@ -38,7 +37,6 @@ expect(RebateForm.first.fields['dependants']).to eq '3' expect(RebateForm.first.location).to eq property2.location expect(RebateForm.first.total_rates).to eq 12345 - expect(RebateForm.first.valuation_id).to eq property2.valuation_id end context 'without a valuation id' do From d7172e80d72d82d323beeffa7ad686f153ca0994 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Mon, 24 Jun 2019 11:39:32 +1200 Subject: [PATCH 38/59] update schema to latest --- ...add_total_rates_location_to_rebate_form.rb | 28 ------------------- db/schema.rb | 4 +-- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb b/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb index 0901ceb6..e5d9d19a 100644 --- a/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb +++ b/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb @@ -6,7 +6,6 @@ def up end def down - update_existing_rebate_forms_down remove_column :rebate_forms, :location, :string remove_column :rebate_forms, :total_rates, :decimal, precision: 8, scale: 2 end @@ -21,31 +20,4 @@ def update_existing_rebate_forms_up valuation_id: rebate_form.fields['valuation_id'] || property.valuation_id || nil) end end - - def update_existing_rebate_forms_down - RebateForm.all.each do |rebate_form| - @rebate_form = rebate_form - property = update_property! - create_or_update_rates_bill!(property) - end - end - - def update_property! - property = @rebate_form.property - - property.update!(location: @rebate_form.location, - valuation_id: @rebate_form.valuation_id) - property - end - - def create_or_update_rates_bill!(property) - rates_bill = RatesBill.find_or_create_by(property: property, - rating_year: property.rating_year) - rates_bill.update!(total_rates: total_rates) - rates_bill - end - - def total_rates - @rebate_form.total_rates || 0 - end end diff --git a/db/schema.rb b/db/schema.rb index 7745f30b..e0d05190 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -102,10 +102,10 @@ t.integer "batch_id" t.integer "updated_by" t.string "status", default: "not signed" - t.string "location" - t.decimal "total_rates", precision: 8, scale: 2 t.string "customer_id" t.string "application_id" + t.string "location" + t.decimal "total_rates", precision: 8, scale: 2 end create_table "roles", force: :cascade do |t| From 61d7dc750f214566ef5acf4eec4592c4dfef5fbe Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Mon, 24 Jun 2019 11:58:45 +1200 Subject: [PATCH 39/59] Changes for council view as per story/design. --- app/assets/images/blue-download.svg | 1 + app/assets/stylesheets/admin/batches.css | 33 ++++++++++++++++++--- app/javascript/components/BatchesSummary.js | 9 +++--- 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 app/assets/images/blue-download.svg diff --git a/app/assets/images/blue-download.svg b/app/assets/images/blue-download.svg new file mode 100644 index 00000000..490c347c --- /dev/null +++ b/app/assets/images/blue-download.svg @@ -0,0 +1 @@ +download1 diff --git a/app/assets/stylesheets/admin/batches.css b/app/assets/stylesheets/admin/batches.css index cf43a7e1..a489532b 100644 --- a/app/assets/stylesheets/admin/batches.css +++ b/app/assets/stylesheets/admin/batches.css @@ -25,21 +25,26 @@ letter-spacing: normal; width: 770px } + .batches-flex-table-row { padding: 1em 1.75em; display: flex; border-top: 2px solid var(--dove); } + .batches-flex-table-cell { width: 30% } + .batches-flex-table-first-cell { width: 40% } + .batches-accordion-header-row { width: 100%; color: var(--dark-gray) } + .batches-accordion-header-title { display: flex; align-items: center; @@ -47,6 +52,7 @@ font-weight: bold; color: var(--black) } + .batches-accordion-header-button { font-size: 18px; text-transform: uppercase; @@ -57,11 +63,31 @@ border-radius: .2em; margin-left: auto; padding: .5em 2em; +} + +.batches-header-sheet-download-button { + color: var(--blue); + font-family: "Fira-Bold", Helvetica, Arial, sans-serif; + font-size: 18px; +} +.batches-download-icon { + width: 20px; + margin-right: 10px; } + .batches-accordion-header-button:hover { background-color: var(--blue-hover); } + +.batches-applications-header { + color: var(--blue); + font-family: "Fira-Bold", Helvetica, Arial, sans-serif; + font-size: 18px; + margin-left: 500px; + position: absolute; +} + .batch-details-link { display: flex; align-items: center; @@ -70,13 +96,16 @@ font-weight: bold; color: var(--blue) } + .batch-details-link:hover { border: 1px solid var(--blue); } + .accordion { border: 1px solid rgba(0, 0, 0, 0.1); border-radius: 2px; } + .accordion__item { margin-bottom: .5em } @@ -91,10 +120,6 @@ border: 2px solid var(--dove); } -.accordion__button:hover { - background-color: var(--gray); -} - .accordion__button:after { color: var(--blue); display: inline-block; diff --git a/app/javascript/components/BatchesSummary.js b/app/javascript/components/BatchesSummary.js index 18a4e9c3..14b250a0 100644 --- a/app/javascript/components/BatchesSummary.js +++ b/app/javascript/components/BatchesSummary.js @@ -45,17 +45,17 @@ export function BatchesSummary(batches, isDiaUser, isCouncilUser) {
{cover_sheet_attached - ? isDiaUser - ? + blue download icon HEADER SHEET - : 'HEADER SHEET' - : 'HEADER SHEET REQUIRED' + : 'Header sheet required' } {isDiaUser &&
+
APPLICATIONS
From 423bd42a1192ab456aceadd4750c7056a025da48 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Mon, 24 Jun 2019 12:02:37 +1200 Subject: [PATCH 40/59] run rake tasks kapiti and tauranga on UAT with latest data --- app/services/rates_importer_service.rb | 4 ++-- bin/docker_web_aws | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/services/rates_importer_service.rb b/app/services/rates_importer_service.rb index 1b5a71f9..053f8223 100644 --- a/app/services/rates_importer_service.rb +++ b/app/services/rates_importer_service.rb @@ -21,14 +21,14 @@ def import(row, rating_year, council) property = Property.create!( council: council, valuation_id: valuation, - location: ("#{location.gsub /"/, ''} " + "#{suburb} " + town_city.to_s).strip.capitalize, + location: ("#{location.gsub /"/, ''} " + "#{suburb} " + town_city.to_s).strip.titleize, suburb: suburb, town_city: town_city, rating_year: rating_year, include_in_address_lookups: true, meta: row.to_s ) - else property.update(include_in_address_lookups: true) + else property.update!(council: council, include_in_address_lookups: true, location: property.location.strip.titleize) end rates_bill = RatesBill.find_by(property: property, rating_year: rating_year) diff --git a/bin/docker_web_aws b/bin/docker_web_aws index dffd33a0..e3e53ef8 100755 --- a/bin/docker_web_aws +++ b/bin/docker_web_aws @@ -10,8 +10,8 @@ fi echo "Migrating and refreshing reference data" bundle exec rake db:migrate -# bundle exec rake rates:kapiti -# bundle exec rake rates:tauranga +bundle exec rake rates:kapiti +bundle exec rake rates:tauranga echo "Running the server..." rm -f tmp/pids/server.pid From ac76050fbadb8006c4c385fa5da13df886c2dc5b Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Mon, 24 Jun 2019 12:30:50 +1200 Subject: [PATCH 41/59] add gaurd to total rates in migration --- .../20190620204258_add_total_rates_location_to_rebate_form.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb b/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb index e5d9d19a..80d7b7ce 100644 --- a/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb +++ b/db/migrate/20190620204258_add_total_rates_location_to_rebate_form.rb @@ -16,7 +16,7 @@ def update_existing_rebate_forms_up RebateForm.all.each do |rebate_form| property = rebate_form.property rebate_form.update(location: property.location, - total_rates: property.rates_bills[0].total_rates, + total_rates: property.rates_bills[0]&.total_rates, valuation_id: rebate_form.fields['valuation_id'] || property.valuation_id || nil) end end From f6dc26359fb97524d406321f24b2fbe57e9e801e Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Mon, 24 Jun 2019 12:54:54 +1200 Subject: [PATCH 42/59] remove extra data from kapiti rake task --- lib/tasks/rates.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/rates.rake b/lib/tasks/rates.rake index 1fd8e977..08d9aed2 100644 --- a/lib/tasks/rates.rake +++ b/lib/tasks/rates.rake @@ -20,7 +20,7 @@ namespace :rates do end task kapiti: :environment do - council = Council.find_or_create_by!(name: 'Kāpiti Coast District Council', short_name: 'kcd', email: '123fake@email.com') + council = Council.find_or_create_by!(name: 'Kāpiti Coast District Council') rates_file = Rails.root.join('db', 'seeds', 'kapiti.csv') Property.transaction do From 215a1805df009fe6c98bb379cf5abdbce6113c0b Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Mon, 24 Jun 2019 13:30:31 +1200 Subject: [PATCH 43/59] commnet out running rake tasks from aws --- bin/docker_web_aws | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/docker_web_aws b/bin/docker_web_aws index e3e53ef8..dffd33a0 100755 --- a/bin/docker_web_aws +++ b/bin/docker_web_aws @@ -10,8 +10,8 @@ fi echo "Migrating and refreshing reference data" bundle exec rake db:migrate -bundle exec rake rates:kapiti -bundle exec rake rates:tauranga +# bundle exec rake rates:kapiti +# bundle exec rake rates:tauranga echo "Running the server..." rm -f tmp/pids/server.pid From dd84c477bc954ef5ffb856b6ac2d2c87a938db79 Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Mon, 24 Jun 2019 13:48:50 +1200 Subject: [PATCH 44/59] made batch button appear properly for dia user view. --- app/assets/stylesheets/admin/batches.css | 12 +++++++++++- app/javascript/components/BatchesSummary.js | 9 +++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/admin/batches.css b/app/assets/stylesheets/admin/batches.css index a489532b..23db81d9 100644 --- a/app/assets/stylesheets/admin/batches.css +++ b/app/assets/stylesheets/admin/batches.css @@ -65,12 +65,22 @@ padding: .5em 2em; } -.batches-header-sheet-download-button { +.batches-header-sheet-download-button, +.batches-applications-button { color: var(--blue); font-family: "Fira-Bold", Helvetica, Arial, sans-serif; font-size: 18px; } +.batches-header-sheet-download-button { + margin-right: 64px; +} + +.batches-header-sheet-required { + display: inline; + margin-right: 50px; +} + .batches-download-icon { width: 20px; margin-right: 10px; diff --git a/app/javascript/components/BatchesSummary.js b/app/javascript/components/BatchesSummary.js index 14b250a0..ca5b0916 100644 --- a/app/javascript/components/BatchesSummary.js +++ b/app/javascript/components/BatchesSummary.js @@ -55,17 +55,18 @@ export function BatchesSummary(batches, isDiaUser, isCouncilUser) { blue download icon HEADER SHEET - : 'Header sheet required' + :
Header sheet required
} - {isDiaUser && } + }
APPLICATIONS
From cb454cdf949a50f924e7295f6ce0591be564b282 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Mon, 24 Jun 2019 13:55:52 +1200 Subject: [PATCH 45/59] just rake kapiti rates --- bin/docker_web_aws | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/docker_web_aws b/bin/docker_web_aws index dffd33a0..2bae7174 100755 --- a/bin/docker_web_aws +++ b/bin/docker_web_aws @@ -10,7 +10,7 @@ fi echo "Migrating and refreshing reference data" bundle exec rake db:migrate -# bundle exec rake rates:kapiti +bundle exec rake rates:kapiti # bundle exec rake rates:tauranga echo "Running the server..." From d3cf05770e0746fb0806190fc01767b375e5f614 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Mon, 24 Jun 2019 13:58:54 +1200 Subject: [PATCH 46/59] lookup kapiti by shortname --- lib/tasks/rates.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/rates.rake b/lib/tasks/rates.rake index 08d9aed2..b0d0064b 100644 --- a/lib/tasks/rates.rake +++ b/lib/tasks/rates.rake @@ -20,7 +20,7 @@ namespace :rates do end task kapiti: :environment do - council = Council.find_or_create_by!(name: 'Kāpiti Coast District Council') + council = Council.find_or_create_by!(short_name: 'KCDC') rates_file = Rails.root.join('db', 'seeds', 'kapiti.csv') Property.transaction do From d88d205071e3200daeb803d5d8420952494ba95b Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Mon, 24 Jun 2019 14:13:33 +1200 Subject: [PATCH 47/59] Fixed alignment on the rebate form show view. --- app/assets/stylesheets/admin/rebate_form.css | 8 +++++++- .../admin/rebate_forms/_council_details_show.html.haml | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/admin/rebate_form.css b/app/assets/stylesheets/admin/rebate_form.css index 1c57920e..08ae9709 100644 --- a/app/assets/stylesheets/admin/rebate_form.css +++ b/app/assets/stylesheets/admin/rebate_form.css @@ -76,7 +76,13 @@ } .rebate-details-header { - margin: 0 200px; + align-items: center; + display: flex; + justify-content: space-between; + margin: auto; + max-width: 1000px; + min-width: 500px; + width: 90vw; } .customer-details-header { diff --git a/app/views/admin/rebate_forms/_council_details_show.html.haml b/app/views/admin/rebate_forms/_council_details_show.html.haml index 5a93f18c..337d0627 100644 --- a/app/views/admin/rebate_forms/_council_details_show.html.haml +++ b/app/views/admin/rebate_forms/_council_details_show.html.haml @@ -1,7 +1,7 @@ -.rebate-details-header.council-details-header +.rebate-details-header %h3.rebate-details-title Council details - unless @rebate_form.processed_state? || @rebate_form.batched_state? - = link_to 'EDIT', admin_rebate_forms_edit_council_details_path(rebate_form_id: @rebate_form.id), id: 'edit-council', class: 'pure-button rebate-edit council-edit' + = link_to 'EDIT', admin_rebate_forms_edit_council_details_path(rebate_form_id: @rebate_form.id), id: 'edit-council', class: 'pure-button rebate-edit' .rebate-edit-form .flex-row.council-row From e65b2e5f9a25e2a1be6d2507951ecde2d53b16f3 Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Mon, 24 Jun 2019 14:19:24 +1200 Subject: [PATCH 48/59] Consolidated CSS. --- app/assets/stylesheets/admin/batches.css | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/admin/batches.css b/app/assets/stylesheets/admin/batches.css index 23db81d9..0e488ee4 100644 --- a/app/assets/stylesheets/admin/batches.css +++ b/app/assets/stylesheets/admin/batches.css @@ -66,7 +66,8 @@ } .batches-header-sheet-download-button, -.batches-applications-button { +.batches-applications-button, +.batches-applications-header { color: var(--blue); font-family: "Fira-Bold", Helvetica, Arial, sans-serif; font-size: 18px; @@ -91,9 +92,6 @@ } .batches-applications-header { - color: var(--blue); - font-family: "Fira-Bold", Helvetica, Arial, sans-serif; - font-size: 18px; margin-left: 500px; position: absolute; } From 27f022f17f43a45ee6eb1e7b3fd40c9196b0a2b5 Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Mon, 24 Jun 2019 14:29:47 +1200 Subject: [PATCH 49/59] CodeClimate fixes. --- app/javascript/components/BatchesSummary.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/javascript/components/BatchesSummary.js b/app/javascript/components/BatchesSummary.js index ca5b0916..8f95eb10 100644 --- a/app/javascript/components/BatchesSummary.js +++ b/app/javascript/components/BatchesSummary.js @@ -46,15 +46,15 @@ export function BatchesSummary(batches, isDiaUser, isCouncilUser) {
{cover_sheet_attached ? - blue download icon + target='_blank' + rel='noopener' + href={download_link} + id='header-sheet' + className='batches-header-sheet-download-button' + download> + blue download icon HEADER SHEET - + :
Header sheet required
} {isDiaUser && Date: Mon, 24 Jun 2019 14:34:12 +1200 Subject: [PATCH 50/59] Another CodeClimate fix. --- app/javascript/components/BatchesSummary.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/javascript/components/BatchesSummary.js b/app/javascript/components/BatchesSummary.js index 8f95eb10..7f5cd567 100644 --- a/app/javascript/components/BatchesSummary.js +++ b/app/javascript/components/BatchesSummary.js @@ -52,7 +52,7 @@ export function BatchesSummary(batches, isDiaUser, isCouncilUser) { id='header-sheet' className='batches-header-sheet-download-button' download> - blue download icon + blue download icon HEADER SHEET :
Header sheet required
From 272f56eb6cc8b87c4f039250927db74ec9f92b9f Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Mon, 24 Jun 2019 14:37:22 +1200 Subject: [PATCH 51/59] Still playing with indentation to please CodeClimate.' --- app/javascript/components/BatchesSummary.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/javascript/components/BatchesSummary.js b/app/javascript/components/BatchesSummary.js index 7f5cd567..f31f0d98 100644 --- a/app/javascript/components/BatchesSummary.js +++ b/app/javascript/components/BatchesSummary.js @@ -52,7 +52,7 @@ export function BatchesSummary(batches, isDiaUser, isCouncilUser) { id='header-sheet' className='batches-header-sheet-download-button' download> - blue download icon + blue download icon HEADER SHEET :
Header sheet required
@@ -64,7 +64,7 @@ export function BatchesSummary(batches, isDiaUser, isCouncilUser) { onClick={() => { window.open(`/admin/batches/${id}.pdf`); }}> - blue download icon + blue download icon BATCH }
From a9b00654851092efadf8bad564e16e935c78d7d3 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Mon, 24 Jun 2019 14:46:13 +1200 Subject: [PATCH 52/59] remove quotes from kapiti blah --- app/services/rates_importer_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/rates_importer_service.rb b/app/services/rates_importer_service.rb index 053f8223..bad7340f 100644 --- a/app/services/rates_importer_service.rb +++ b/app/services/rates_importer_service.rb @@ -28,7 +28,7 @@ def import(row, rating_year, council) include_in_address_lookups: true, meta: row.to_s ) - else property.update!(council: council, include_in_address_lookups: true, location: property.location.strip.titleize) + else property.update!(council: council, include_in_address_lookups: true, location: "#{location.gsub /"/, ''}".strip.titleize) end rates_bill = RatesBill.find_by(property: property, rating_year: rating_year) From df6615b2a6e6be03cf7c8461362e95e8fe66e095 Mon Sep 17 00:00:00 2001 From: Cara Hill Date: Mon, 24 Jun 2019 15:09:50 +1200 Subject: [PATCH 53/59] Fixed failing tests. --- spec/features/admin/batches/index_spec.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/spec/features/admin/batches/index_spec.rb b/spec/features/admin/batches/index_spec.rb index 01db072f..041bf46b 100644 --- a/spec/features/admin/batches/index_spec.rb +++ b/spec/features/admin/batches/index_spec.rb @@ -23,7 +23,7 @@ it ' Can see all batches' do visit '/admin/batches' expect(page).to have_text(batched_form.batch.name) - expect(page).to have_text('HEADER SHEET REQUIRED') + expect(page).to have_text('Header sheet required') expect(page).to have_text(batch_other_council.name) expect(page).not_to have_text('EDIT') end @@ -36,16 +36,16 @@ it 'updates the display accordingly' do visit '/admin/batches' - expect(page).to_not have_text('HEADER SHEET REQUIRED') + expect(page).to_not have_text('Header sheet required') expect(page).to have_text('HEADER SHEET') expect(page).to have_css('#header-sheet') end end - it ' opens a new window when the APPLICATIONS button is clicked' do + it ' opens a new window when the BATCH button is clicked' do visit '/admin/batches' expect(page.windows.count).to eq 1 - find('.applications-button', match: :first).click + find('.batches-applications-button', match: :first).click expect(page.windows.count).to eq 2 end include_examples 'percy snapshot' @@ -59,7 +59,7 @@ it 'can only see batches from my council' do visit '/admin/batches' expect(page).to have_text(batched_form.batch.name) - expect(page).to have_text('HEADER SHEET REQUIRED') + expect(page).to have_text('Header sheet required') expect(page).not_to have_text(batch_other_council.name) expect(page).to have_text('EDIT') end @@ -71,9 +71,8 @@ it 'updates the display accordingly' do visit '/admin/batches' - expect(page).to_not have_text('HEADER SHEET REQUIRED') + expect(page).to_not have_text('Header sheet required') expect(page).to have_text('HEADER SHEET') - expect(page).to_not have_css('#header-sheet') end end include_examples 'percy snapshot' From ccba037355fc01719839a3ff25868fabe22bf9d5 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Mon, 24 Jun 2019 15:23:40 +1200 Subject: [PATCH 54/59] use council not council_id --- app/controllers/rebate_forms_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/rebate_forms_controller.rb b/app/controllers/rebate_forms_controller.rb index 6e729466..7c065b91 100644 --- a/app/controllers/rebate_forms_controller.rb +++ b/app/controllers/rebate_forms_controller.rb @@ -40,7 +40,7 @@ def rebate_form_params .require(:data) .require(:attributes) .permit(:valuation_id, - :council_id, + :council, :location, :total_rates, fields: {}, From 697a814c6412b20bebaeff3bc2563a71e8bd02e7 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Mon, 24 Jun 2019 15:39:20 +1200 Subject: [PATCH 55/59] Update docker_web_aws --- bin/docker_web_aws | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/docker_web_aws b/bin/docker_web_aws index 2bae7174..dffd33a0 100755 --- a/bin/docker_web_aws +++ b/bin/docker_web_aws @@ -10,7 +10,7 @@ fi echo "Migrating and refreshing reference data" bundle exec rake db:migrate -bundle exec rake rates:kapiti +# bundle exec rake rates:kapiti # bundle exec rake rates:tauranga echo "Running the server..." From 13c72991763944fb516e5bab19d9453065689d92 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Mon, 24 Jun 2019 17:08:32 +1200 Subject: [PATCH 56/59] Update docker_web_aws --- bin/docker_web_aws | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/docker_web_aws b/bin/docker_web_aws index dffd33a0..e3e53ef8 100755 --- a/bin/docker_web_aws +++ b/bin/docker_web_aws @@ -10,8 +10,8 @@ fi echo "Migrating and refreshing reference data" bundle exec rake db:migrate -# bundle exec rake rates:kapiti -# bundle exec rake rates:tauranga +bundle exec rake rates:kapiti +bundle exec rake rates:tauranga echo "Running the server..." rm -f tmp/pids/server.pid From f016de12fd74585a7c0db9c15a9dfcaa173a4898 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Tue, 25 Jun 2019 09:18:49 +1200 Subject: [PATCH 57/59] add 31 july to email --- app/views/rebate_forms_mailer/_default.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/rebate_forms_mailer/_default.haml b/app/views/rebate_forms_mailer/_default.haml index 8be55d47..14db973e 100644 --- a/app/views/rebate_forms_mailer/_default.haml +++ b/app/views/rebate_forms_mailer/_default.haml @@ -9,7 +9,7 @@ %p %ul - %li Go to the #{@council.name} + %li Before 31 July, go to the #{@council.name} %li Tell the Service Centre staff you're there to sign your rates rebate application. %p From e4c386c907f75f4a66eb578b9110ff49bf8d4fd9 Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Tue, 25 Jun 2019 09:50:49 +1200 Subject: [PATCH 58/59] update test --- spec/mailers/rebate_forms_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/mailers/rebate_forms_spec.rb b/spec/mailers/rebate_forms_spec.rb index 4db37fa4..3825bc85 100644 --- a/spec/mailers/rebate_forms_spec.rb +++ b/spec/mailers/rebate_forms_spec.rb @@ -20,7 +20,7 @@ expect(text_body).to include "– 30 June #{rebate_form.rating_year} rates year" expect(text_body).to include "has been sent to the #{rebate_form.council.name}." expect(text_body).to include 'What you need to do now' - expect(text_body).to include "Go to the #{rebate_form.council.name}" + expect(text_body).to include "Before 31 July, go to the #{rebate_form.council.name}" expect(text_body).to include 'Tell the Service Centre staff you\'re there to sign your rates rebate application.' expect(text_body).to include 'Make sure you complete your application by getting your signature witnessed' expect(text_body).to include 'at the council offices as soon as you can.' From 7462a23ee93e1d85efeef2c2197c600605c7d57f Mon Sep 17 00:00:00 2001 From: Mischa Saunders Date: Tue, 25 Jun 2019 11:01:58 +1200 Subject: [PATCH 59/59] update for prod --- app/services/rates_importer_service.rb | 8 +++----- app/services/rebate_forms_service.rb | 4 +--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/services/rates_importer_service.rb b/app/services/rates_importer_service.rb index bad7340f..3de7bf78 100644 --- a/app/services/rates_importer_service.rb +++ b/app/services/rates_importer_service.rb @@ -32,11 +32,9 @@ def import(row, rating_year, council) end rates_bill = RatesBill.find_by(property: property, rating_year: rating_year) - if rates_bill.present? - # current_rates = rates_bill.total_rates.to_f.round(2) - # new_rates = (total_rates.to_f + total_water_rates.to_f).round(2) - # raise 'mismatch total_rates' unless current_rates == new_rates - else + # future work is required to handle when rates change for a property + # this is complicated by the fact we use rates_bills[0] throughout the code + unless rates_bill.present? RatesBill.create!( property: property, rating_year: rating_year, diff --git a/app/services/rebate_forms_service.rb b/app/services/rebate_forms_service.rb index 24664998..0e156da6 100644 --- a/app/services/rebate_forms_service.rb +++ b/app/services/rebate_forms_service.rb @@ -11,9 +11,7 @@ def initialize(rebate_form_attributes) def create! council = find_council! property = find_or_create_property!(council) - rebate_form = create_rebate_form!(property) - - rebate_form + create_rebate_form!(property) end private