diff --git a/.travis.yml b/.travis.yml index 4ac4cb87f..7c536088e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ before_script: - "RAILS_ENV=test bundle exec rake db:setup:all" script: - "RAILS_ENV=test bundle exec rspec" + - "bundle exec rake test" after_success: - "bundle exec codeclimate-test-reporter" services: diff --git a/Gemfile.lock b/Gemfile.lock index a41ece538..d4f0cf9fd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -266,7 +266,7 @@ GEM open4 (~> 1.3.4) rake mini_portile2 (2.3.0) - minitest (5.10.2) + minitest (5.10.3) monetize (1.6.0) money (~> 6.8) money (6.8.3) diff --git a/app/controllers/admin/registrars_controller.rb b/app/controllers/admin/registrars_controller.rb index 362b3747d..de8d099d2 100644 --- a/app/controllers/admin/registrars_controller.rb +++ b/app/controllers/admin/registrars_controller.rb @@ -63,10 +63,22 @@ 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, + :accounting_customer_code) end end end 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/app/models/registrar.rb b/app/models/registrar.rb index 3ad54279d..b410a1c76 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -15,7 +15,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/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/config/application.rb b/config/application.rb index 71920f3ea..57106c8ea 100644 --- a/config/application.rb +++ b/config/application.rb @@ -60,11 +60,7 @@ module Registry g.helper false g.template_engine :erb g.jbuilder false - g.test_framework :rspec, - controller_specs: false, - view_specs: false, - request_specs: false, - routing_specs: false + g.test_framework nil end registrant_portal_uri = URI.parse(ENV['registrant_url']) 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/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/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 ffce69261..860a85530 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2473,11 +2473,10 @@ CREATE TABLE registrars ( zip character varying, code character varying, website character varying, - directo_handle character varying, + accounting_customer_code character varying NOT NULL, vat boolean, legacy_id integer, reference_no character varying, - exclude_in_monthly_directo boolean DEFAULT false, test_registrar boolean DEFAULT false ); @@ -5052,3 +5051,9 @@ INSERT INTO schema_migrations (version) VALUES ('20171009080822'); INSERT INTO schema_migrations (version) VALUES ('20171009082321'); +INSERT INTO schema_migrations (version) VALUES ('20171025110933'); + +INSERT INTO schema_migrations (version) VALUES ('20171025113808'); + +INSERT INTO schema_migrations (version) VALUES ('20171025153841'); + diff --git a/doc/models_complete.svg b/doc/models_complete.svg index 255ddf0c9..a4b16517f 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, diff --git a/spec/factories/registrar.rb b/spec/factories/registrar.rb index df7d73690..ab46553a0 100644 --- a/spec/factories/registrar.rb +++ b/spec/factories/registrar.rb @@ -9,6 +9,7 @@ FactoryBot.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/spec/features/admin/registrars/create_spec.rb b/spec/features/admin/registrars/create_spec.rb deleted file mode 100644 index 24cc8bc2a..000000000 --- a/spec/features/admin/registrars/create_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'rails_helper' - -RSpec.feature 'New registrar' do - background do - sign_in_to_admin_area - end - - it 'creates registrar' do - visit admin_registrars_url - click_link_or_button 'New registrar' - - fill_in 'registrar[name]', with: 'test' - fill_in 'registrar[reg_no]', with: '1234567' - fill_in 'registrar[email]', with: 'test@test.com' - fill_in 'registrar[code]', with: 'test' - click_link_or_button 'Create registrar' - - expect(page).to have_text('Registrar has been successfully created') - end -end 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/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 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/fixtures/account_activities.yml b/test/fixtures/account_activities.yml new file mode 100644 index 000000000..06a5b4006 --- /dev/null +++ b/test/fixtures/account_activities.yml @@ -0,0 +1,7 @@ +DEFAULTS: &DEFAULTS + account_id: 1 + +one: + <<: *DEFAULTS + invoice: paid + bank_transaction: one diff --git a/test/fixtures/bank_transactions.yml b/test/fixtures/bank_transactions.yml new file mode 100644 index 000000000..b0b4d661c --- /dev/null +++ b/test/fixtures/bank_transactions.yml @@ -0,0 +1,3 @@ +one: + sum: 1 + currency: EUR diff --git a/test/fixtures/invoice_items.yml b/test/fixtures/invoice_items.yml new file mode 100644 index 000000000..417203a51 --- /dev/null +++ b/test/fixtures/invoice_items.yml @@ -0,0 +1,13 @@ +DEFAULTS: &DEFAULTS + description: Acme services + amount: 2 + unit: pc + price: 5 + +valid: + <<: *DEFAULTS + invoice: valid + +another: + <<: *DEFAULTS + invoice: valid diff --git a/test/fixtures/invoices.yml b/test/fixtures/invoices.yml new file mode 100644 index 000000000..7a1c85dd1 --- /dev/null +++ b/test/fixtures/invoices.yml @@ -0,0 +1,32 @@ +DEFAULTS: &DEFAULTS + created_at: <%= Date.parse '2010-07-05' %> + due_date: <%= Date.parse '2010-07-06' %> + invoice_type: DEB + currency: EUR + seller_name: John Doe + seller_iban: 1234 + buyer_name: Jane Doe + vat_prc: 0.2 + +valid: + <<: *DEFAULTS + +exported: + <<: *DEFAULTS + in_directo: true + +cancelled: + <<: *DEFAULTS + cancelled_at: <%= Date.parse '2010-07-05' %> + +paid: + <<: *DEFAULTS + sum_cache: 1 + +outstanding: + <<: *DEFAULTS + due_date: <%= Date.parse '2010-07-04' %> + +overdue: + <<: *DEFAULTS + due_date: <%= Date.parse '2010-07-03' %> 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/test/integration/admin/registrars/new_registrar_test.rb b/test/integration/admin/registrars/new_registrar_test.rb new file mode 100644 index 000000000..c0087e5e2 --- /dev/null +++ b/test/integration/admin/registrars/new_registrar_test.rb @@ -0,0 +1,21 @@ +require 'test_helper' + +class NewRegistrarTest < ActionDispatch::IntegrationTest + def setup + login_as create(:admin_user) + end + + def test_creates_registrar + visit admin_registrars_path + click_link_or_button 'New registrar' + + fill_in 'registrar[name]', with: 'test' + 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' + end +end 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 diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 000000000..98d6dcf8e --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,25 @@ +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../../config/environment', __FILE__) +require 'rails/test_help' +require 'minitest/mock' +require 'capybara/rails' +require 'capybara/minitest' + +class ActiveSupport::TestCase + include FactoryBot::Syntax::Methods + + ActiveRecord::Migration.check_pending! + fixtures :all +end + +class ActionDispatch::IntegrationTest + include Warden::Test::Helpers + include Capybara::DSL + include Capybara::Minitest::Assertions + include AbstractController::Translation + + def teardown + Capybara.reset_sessions! + Capybara.use_default_driver + end +end