From bdb1090a405f73d94c5b7441343684f0f47c1373 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 25 Oct 2017 14:16:45 +0300 Subject: [PATCH 1/8] Remove unused db column #343 --- ...1025110933_remove_registrar_exclude_in_monthly_directo.rb | 5 +++++ db/structure.sql | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20171025110933_remove_registrar_exclude_in_monthly_directo.rb diff --git a/db/migrate/20171025110933_remove_registrar_exclude_in_monthly_directo.rb b/db/migrate/20171025110933_remove_registrar_exclude_in_monthly_directo.rb new file mode 100644 index 000000000..94edcd982 --- /dev/null +++ b/db/migrate/20171025110933_remove_registrar_exclude_in_monthly_directo.rb @@ -0,0 +1,5 @@ +class RemoveRegistrarExcludeInMonthlyDirecto < ActiveRecord::Migration + def change + remove_column :registrars, :exclude_in_monthly_directo, :string + end +end diff --git a/db/structure.sql b/db/structure.sql index ffce69261..7e4a669f2 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2477,7 +2477,6 @@ CREATE TABLE registrars ( vat boolean, legacy_id integer, reference_no character varying, - exclude_in_monthly_directo boolean DEFAULT false, test_registrar boolean DEFAULT false ); @@ -5052,3 +5051,5 @@ INSERT INTO schema_migrations (version) VALUES ('20171009080822'); INSERT INTO schema_migrations (version) VALUES ('20171009082321'); +INSERT INTO schema_migrations (version) VALUES ('20171025110933'); + From ff9372baeafe76bfc66c31b0c439c47521161af2 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 25 Oct 2017 18:33:11 +0300 Subject: [PATCH 2/8] Rename registrar "directo_handle" to "accounting_customer_code" #343 --- app/models/directo.rb | 4 ++-- ...e_registrar_directo_handle_to_accounting_customer_code.rb | 5 +++++ db/structure.sql | 4 +++- doc/models_complete.svg | 1 - lib/tasks/import.rake | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20171025113808_rename_registrar_directo_handle_to_accounting_customer_code.rb diff --git a/app/models/directo.rb b/app/models/directo.rb index 73574441e..62cf43804 100644 --- a/app/models/directo.rb +++ b/app/models/directo.rb @@ -29,7 +29,7 @@ class Directo < ActiveRecord::Base "InvoiceDate" => invoice.created_at.strftime("%Y-%m-%dT%H:%M:%S"), "PaymentTerm" => Setting.directo_receipt_payment_term, "Currency" => invoice.currency, - "CustomerCode"=> invoice.buyer.try(:directo_handle) + "CustomerCode"=> invoice.buyer.accounting_customer_code ){ xml.line( "ProductID" => Setting.directo_receipt_product_name, @@ -150,7 +150,7 @@ class Directo < ActiveRecord::Base xml.invoice("Number" =>directo_next, "InvoiceDate" =>invoices_until.strftime(date_format), "PaymentTerm" =>Setting.directo_receipt_payment_term, - "CustomerCode"=>registrar.directo_handle, + "CustomerCode"=>registrar.accounting_customer_code, "Language" =>"", "Currency" =>registrar_activities.first.currency, "SalesAgent" =>Setting.directo_sales_agent){ diff --git a/db/migrate/20171025113808_rename_registrar_directo_handle_to_accounting_customer_code.rb b/db/migrate/20171025113808_rename_registrar_directo_handle_to_accounting_customer_code.rb new file mode 100644 index 000000000..f834e14c1 --- /dev/null +++ b/db/migrate/20171025113808_rename_registrar_directo_handle_to_accounting_customer_code.rb @@ -0,0 +1,5 @@ +class RenameRegistrarDirectoHandleToAccountingCustomerCode < ActiveRecord::Migration + def change + rename_column :registrars, :directo_handle, :accounting_customer_code + end +end diff --git a/db/structure.sql b/db/structure.sql index 7e4a669f2..07b93417b 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2473,7 +2473,7 @@ CREATE TABLE registrars ( zip character varying, code character varying, website character varying, - directo_handle character varying, + accounting_customer_code character varying, vat boolean, legacy_id integer, reference_no character varying, @@ -5053,3 +5053,5 @@ INSERT INTO schema_migrations (version) VALUES ('20171009082321'); INSERT INTO schema_migrations (version) VALUES ('20171025110933'); +INSERT INTO schema_migrations (version) VALUES ('20171025113808'); + diff --git a/doc/models_complete.svg b/doc/models_complete.svg index 58b86b986..3c64e4a34 100644 --- a/doc/models_complete.svg +++ b/doc/models_complete.svg @@ -1581,7 +1581,6 @@ zip :string code :string url :string -directo_handle :string vat :boolean legacy_id :integer reference_no :string diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index cb37c0f1d..042515f33 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -87,7 +87,7 @@ namespace :import do street: x.street1.try(:strip), zip: x.postalcode.try(:strip), url: x.url.try(:strip), - directo_handle: x.directo_handle.try(:strip), + accounting_customer_code: x.directo_handle.try(:strip), vat: x.vat, legacy_id: x.id, creator_str: user, From 396f74cfb13e84e00f39b3cbfccd66c8bbe54f80 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 26 Oct 2017 19:35:08 +0300 Subject: [PATCH 3/8] Reformat code #343 --- .../admin/registrars_controller.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/registrars_controller.rb b/app/controllers/admin/registrars_controller.rb index 362b3747d..a52bdbb4e 100644 --- a/app/controllers/admin/registrars_controller.rb +++ b/app/controllers/admin/registrars_controller.rb @@ -63,10 +63,21 @@ module Admin end def registrar_params - params.require(:registrar).permit( - :name, :reg_no, :vat_no, :street, :city, :state, :zip, :billing_address, - :country_code, :email, :phone, :website, :billing_email, :code, :test_registrar - ) + params.require(:registrar).permit(:name, + :reg_no, + :vat_no, + :street, + :city, + :state, + :zip, + :billing_address, + :country_code, + :email, + :phone, + :website, + :billing_email, + :code, + :test_registrar) end end end From 579da84c5886ad86ba084750a6531feb90e3734f Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 27 Oct 2017 10:24:57 +0300 Subject: [PATCH 4/8] Convert specs to tests #343 --- spec/features/admin/registrars/edit_spec.rb | 18 --------- spec/requests/admin/registrars/create_spec.rb | 34 ---------------- .../admin/registrars/create_test.rb | 18 +++++++++ .../admin/registrars/update_test.rb | 40 +++++++++++++++++++ .../admin/registrars/edit_registrar_test.rb | 17 ++++++++ .../admin/registrars/new_registrar_test.rb | 14 +++---- 6 files changed, 82 insertions(+), 59 deletions(-) delete mode 100644 spec/features/admin/registrars/edit_spec.rb delete mode 100644 spec/requests/admin/registrars/create_spec.rb create mode 100644 test/controllers/admin/registrars/create_test.rb create mode 100644 test/controllers/admin/registrars/update_test.rb create mode 100644 test/integration/admin/registrars/edit_registrar_test.rb rename spec/features/admin/registrars/create_spec.rb => test/integration/admin/registrars/new_registrar_test.rb (54%) diff --git a/spec/features/admin/registrars/edit_spec.rb b/spec/features/admin/registrars/edit_spec.rb deleted file mode 100644 index f02164f91..000000000 --- a/spec/features/admin/registrars/edit_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'rails_helper' - -RSpec.feature 'Edit registrar' do - given!(:registrar) { create(:registrar) } - - background do - sign_in_to_admin_area - end - - it 'updates registrar' do - visit admin_registrar_url(registrar) - click_link_or_button 'Edit' - - click_link_or_button 'Update registrar' - - expect(page).to have_text('Registrar has been successfully updated') - end -end diff --git a/spec/requests/admin/registrars/create_spec.rb b/spec/requests/admin/registrars/create_spec.rb deleted file mode 100644 index e66fb0765..000000000 --- a/spec/requests/admin/registrars/create_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'admin registrar create' do - subject(:registrar) { Registrar.first } - - before :example do - sign_in_to_admin_area - end - - it 'creates new registrar' do - expect { post admin_registrars_path, registrar: attributes_for(:registrar) } - .to change { Registrar.count }.from(0).to(1) - end - - it 'saves website' do - post admin_registrars_path, { registrar: attributes_for(:registrar, website: 'test') } - expect(registrar.website).to eq('test') - end - - it 'saves email' do - post admin_registrars_path, { registrar: attributes_for(:registrar, email: 'test@test.com') } - expect(registrar.email).to eq('test@test.com') - end - - it 'saves billing email' do - post admin_registrars_path, { registrar: attributes_for(:registrar, billing_email: 'test@test.com') } - expect(registrar.billing_email).to eq('test@test.com') - end - - it 'redirects to :show' do - post admin_registrars_path, { registrar: attributes_for(:registrar) } - expect(response).to redirect_to admin_registrar_path(registrar) - end -end diff --git a/test/controllers/admin/registrars/create_test.rb b/test/controllers/admin/registrars/create_test.rb new file mode 100644 index 000000000..e7ee57011 --- /dev/null +++ b/test/controllers/admin/registrars/create_test.rb @@ -0,0 +1,18 @@ +require 'test_helper' + +class RegistrarsControllerTest < ActionDispatch::IntegrationTest + def setup + login_as create(:admin_user) + end + + def test_creates_new_registrar + assert_difference -> { Registrar.count } do + post admin_registrars_path, registrar: attributes_for(:registrar) + end + end + + def test_redirects_to_newly_created_registrar + post admin_registrars_path, registrar: attributes_for(:registrar) + assert_redirected_to admin_registrar_path(Registrar.first) + end +end diff --git a/test/controllers/admin/registrars/update_test.rb b/test/controllers/admin/registrars/update_test.rb new file mode 100644 index 000000000..bf79aca65 --- /dev/null +++ b/test/controllers/admin/registrars/update_test.rb @@ -0,0 +1,40 @@ +require 'test_helper' + +class RegistrarsControllerTest < ActionDispatch::IntegrationTest + def setup + login_as create(:admin_user) + end + + def test_updates_website + registrar = create(:registrar, website: 'test') + + patch admin_registrar_path(registrar), registrar: attributes_for(:registrar, website: 'new-website') + registrar.reload + + assert_equal 'new-website', registrar.website + end + + def test_updates_email + registrar = create(:registrar, email: 'test@test.com') + + patch admin_registrar_path(registrar), registrar: attributes_for(:registrar, email: 'new-test@test.com') + registrar.reload + + assert_equal 'new-test@test.com', registrar.email + end + + def test_updates_billing_email + registrar = create(:registrar, billing_email: 'test@test.com') + + patch admin_registrar_path(registrar), registrar: attributes_for(:registrar, billing_email: 'new-test@test.com') + registrar.reload + + assert_equal 'new-test@test.com', registrar.billing_email + end + + def test_redirects_to_registrar + registrar = create(:registrar) + patch admin_registrar_path(registrar), registrar: attributes_for(:registrar) + assert_redirected_to admin_registrar_path(registrar) + end +end diff --git a/test/integration/admin/registrars/edit_registrar_test.rb b/test/integration/admin/registrars/edit_registrar_test.rb new file mode 100644 index 000000000..6965cfd02 --- /dev/null +++ b/test/integration/admin/registrars/edit_registrar_test.rb @@ -0,0 +1,17 @@ +require 'test_helper' + +class EditRegistrarTest < ActionDispatch::IntegrationTest + def setup + login_as create(:admin_user) + end + + def test_updates_registrar + registrar = create(:registrar) + + visit admin_registrar_path(registrar) + click_link_or_button 'Edit' + click_link_or_button 'Update registrar' + + assert_text 'Registrar has been successfully updated' + end +end diff --git a/spec/features/admin/registrars/create_spec.rb b/test/integration/admin/registrars/new_registrar_test.rb similarity index 54% rename from spec/features/admin/registrars/create_spec.rb rename to test/integration/admin/registrars/new_registrar_test.rb index 24cc8bc2a..5c6395673 100644 --- a/spec/features/admin/registrars/create_spec.rb +++ b/test/integration/admin/registrars/new_registrar_test.rb @@ -1,12 +1,12 @@ -require 'rails_helper' +require 'test_helper' -RSpec.feature 'New registrar' do - background do - sign_in_to_admin_area +class NewRegistrarTest < ActionDispatch::IntegrationTest + def setup + login_as create(:admin_user) end - it 'creates registrar' do - visit admin_registrars_url + def test_creates_registrar + visit admin_registrars_path click_link_or_button 'New registrar' fill_in 'registrar[name]', with: 'test' @@ -15,6 +15,6 @@ RSpec.feature 'New registrar' do fill_in 'registrar[code]', with: 'test' click_link_or_button 'Create registrar' - expect(page).to have_text('Registrar has been successfully created') + assert_text 'Registrar has been successfully created' end end From 59e1e18d32b0933ada26f0fa885a112bc06a51bf Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 27 Oct 2017 11:56:54 +0300 Subject: [PATCH 5/8] Require registrar's accounting customer code #343 --- app/controllers/admin/registrars_controller.rb | 3 ++- app/models/registrar.rb | 2 ++ app/views/admin/registrars/_form.haml | 6 ++++++ ...nge_registrar_accounting_customer_code_to_not_null.rb | 5 +++++ db/structure.sql | 4 +++- spec/factories/registrar.rb | 1 + test/integration/admin/registrars/new_registrar_test.rb | 1 + test/models/registrar_test.rb | 9 +++++++++ 8 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20171025153841_change_registrar_accounting_customer_code_to_not_null.rb create mode 100644 test/models/registrar_test.rb diff --git a/app/controllers/admin/registrars_controller.rb b/app/controllers/admin/registrars_controller.rb index a52bdbb4e..de8d099d2 100644 --- a/app/controllers/admin/registrars_controller.rb +++ b/app/controllers/admin/registrars_controller.rb @@ -77,7 +77,8 @@ module Admin :website, :billing_email, :code, - :test_registrar) + :test_registrar, + :accounting_customer_code) end end end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index b906beee3..97ecfa32a 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -16,7 +16,9 @@ class Registrar < ActiveRecord::Base validates :name, :reg_no, :country_code, :email, :code, presence: true validates :name, :reg_no, :reference_no, :code, uniqueness: true + validates :accounting_customer_code, presence: true validate :forbidden_codes + def forbidden_codes return true unless ['CID'].include? code errors.add(:code, I18n.t(:forbidden_code)) diff --git a/app/views/admin/registrars/_form.haml b/app/views/admin/registrars/_form.haml index abf440921..2a80e7357 100644 --- a/app/views/admin/registrars/_form.haml +++ b/app/views/admin/registrars/_form.haml @@ -43,6 +43,12 @@ .col-md-7 = f.email_field :billing_email, class: 'form-control' + .form-group + .col-md-4.control-label + = f.label :accounting_customer_code + .col-md-7 + = f.text_field :accounting_customer_code, class: 'form-control', required: true + .row .col-md-8 .panel.panel-default diff --git a/db/migrate/20171025153841_change_registrar_accounting_customer_code_to_not_null.rb b/db/migrate/20171025153841_change_registrar_accounting_customer_code_to_not_null.rb new file mode 100644 index 000000000..f9d310305 --- /dev/null +++ b/db/migrate/20171025153841_change_registrar_accounting_customer_code_to_not_null.rb @@ -0,0 +1,5 @@ +class ChangeRegistrarAccountingCustomerCodeToNotNull < ActiveRecord::Migration + def change + change_column_null :registrars, :accounting_customer_code, false + end +end diff --git a/db/structure.sql b/db/structure.sql index 07b93417b..860a85530 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2473,7 +2473,7 @@ CREATE TABLE registrars ( zip character varying, code character varying, website character varying, - accounting_customer_code character varying, + accounting_customer_code character varying NOT NULL, vat boolean, legacy_id integer, reference_no character varying, @@ -5055,3 +5055,5 @@ INSERT INTO schema_migrations (version) VALUES ('20171025110933'); INSERT INTO schema_migrations (version) VALUES ('20171025113808'); +INSERT INTO schema_migrations (version) VALUES ('20171025153841'); + diff --git a/spec/factories/registrar.rb b/spec/factories/registrar.rb index 426561dda..443a41342 100644 --- a/spec/factories/registrar.rb +++ b/spec/factories/registrar.rb @@ -9,6 +9,7 @@ FactoryGirl.define do zip 'test' email 'test@test.com' country_code 'EE' + accounting_customer_code 'test' factory :registrar_with_unlimited_balance do after :create do |registrar| diff --git a/test/integration/admin/registrars/new_registrar_test.rb b/test/integration/admin/registrars/new_registrar_test.rb index 5c6395673..c0087e5e2 100644 --- a/test/integration/admin/registrars/new_registrar_test.rb +++ b/test/integration/admin/registrars/new_registrar_test.rb @@ -13,6 +13,7 @@ class NewRegistrarTest < ActionDispatch::IntegrationTest fill_in 'registrar[reg_no]', with: '1234567' fill_in 'registrar[email]', with: 'test@test.com' fill_in 'registrar[code]', with: 'test' + fill_in 'registrar[accounting_customer_code]', with: 'test' click_link_or_button 'Create registrar' assert_text 'Registrar has been successfully created' diff --git a/test/models/registrar_test.rb b/test/models/registrar_test.rb new file mode 100644 index 000000000..f5012b099 --- /dev/null +++ b/test/models/registrar_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class RegistrarTest < ActiveSupport::TestCase + def test_rejects_absent_accounting_customer_code + registrar = Registrar.new(accounting_customer_code: nil) + registrar.validate + assert registrar.errors.added?(:accounting_customer_code, :blank) + end +end From 74cb51f2e37f9eb9303c17ac3924572dbeac83fe Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 27 Oct 2017 11:57:37 +0300 Subject: [PATCH 6/8] Show registrar's accounting customer code in UI #343 --- app/views/admin/registrars/show.haml | 3 +++ test/controllers/admin/registrars/show_test.rb | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 test/controllers/admin/registrars/show_test.rb diff --git a/app/views/admin/registrars/show.haml b/app/views/admin/registrars/show.haml index 1907a63ed..7bd49f058 100644 --- a/app/views/admin/registrars/show.haml +++ b/app/views/admin/registrars/show.haml @@ -42,6 +42,9 @@ %dt= Registrar.human_attribute_name :website %dd= @registrar.website + %dt= Registrar.human_attribute_name :accounting_customer_code + %dd= @registrar.accounting_customer_code + .col-md-6 .panel.panel-default .panel-heading diff --git a/test/controllers/admin/registrars/show_test.rb b/test/controllers/admin/registrars/show_test.rb new file mode 100644 index 000000000..a3868dded --- /dev/null +++ b/test/controllers/admin/registrars/show_test.rb @@ -0,0 +1,13 @@ +require 'test_helper' + +class RegistrarsControllerTest < ActionDispatch::IntegrationTest + def setup + login_as create(:admin_user) + end + + def test_accounting_customer_code + registrar = create(:registrar, accounting_customer_code: 'test accounting customer code') + visit admin_registrar_path(registrar) + assert_text 'test accounting customer code' + end +end From f68cf8a5a15fa43ad9454052c2e39df9bf09f437 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 28 Oct 2017 22:03:53 +0300 Subject: [PATCH 7/8] Rename FactoryGirl to FactoryBot https://robots.thoughtbot.com/factory_bot --- test/test_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 55d51cd4c..e395016a8 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -5,7 +5,7 @@ require 'capybara/rails' require 'capybara/minitest' class ActiveSupport::TestCase - include FactoryGirl::Syntax::Methods + include FactoryBot::Syntax::Methods end class ActionDispatch::IntegrationTest From e658a7b094bbfc33687cfb323f9e42fda7d4e3a0 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 1 Nov 2017 15:57:13 +0200 Subject: [PATCH 8/8] Revert "Rename FactoryGirl to FactoryBot" This reverts commit f68cf8a --- test/test_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index e395016a8..55d51cd4c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -5,7 +5,7 @@ require 'capybara/rails' require 'capybara/minitest' class ActiveSupport::TestCase - include FactoryBot::Syntax::Methods + include FactoryGirl::Syntax::Methods end class ActionDispatch::IntegrationTest