Merge pull request #624 from internetee/registry-343

Registry 343
This commit is contained in:
Timo Võhmar 2017-12-06 18:09:38 +02:00 committed by GitHub
commit eb763be8e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 254 additions and 88 deletions

View file

@ -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:

View file

@ -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)

View file

@ -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

View file

@ -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){

View file

@ -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))

View file

@ -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

View file

@ -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

View file

@ -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'])

View file

@ -0,0 +1,5 @@
class RemoveRegistrarExcludeInMonthlyDirecto < ActiveRecord::Migration
def change
remove_column :registrars, :exclude_in_monthly_directo, :string
end
end

View file

@ -0,0 +1,5 @@
class RenameRegistrarDirectoHandleToAccountingCustomerCode < ActiveRecord::Migration
def change
rename_column :registrars, :directo_handle, :accounting_customer_code
end
end

View file

@ -0,0 +1,5 @@
class ChangeRegistrarAccountingCustomerCodeToNotNull < ActiveRecord::Migration
def change
change_column_null :registrars, :accounting_customer_code, false
end
end

View file

@ -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');

View file

@ -1581,7 +1581,6 @@
<text text-anchor="start" x="1600.5" y="-2399.3" font-family="Times,serif" font-size="14.00">zip :string</text>
<text text-anchor="start" x="1600.5" y="-2384.3" font-family="Times,serif" font-size="14.00">code :string</text>
<text text-anchor="start" x="1600.5" y="-2369.3" font-family="Times,serif" font-size="14.00">url :string</text>
<text text-anchor="start" x="1600.5" y="-2354.3" font-family="Times,serif" font-size="14.00">directo_handle :string</text>
<text text-anchor="start" x="1600.5" y="-2339.3" font-family="Times,serif" font-size="14.00">vat :boolean</text>
<text text-anchor="start" x="1600.5" y="-2324.3" font-family="Times,serif" font-size="14.00">legacy_id :integer</text>
<text text-anchor="start" x="1600.5" y="-2309.3" font-family="Times,serif" font-size="14.00">reference_no :string</text>

Before

Width:  |  Height:  |  Size: 232 KiB

After

Width:  |  Height:  |  Size: 232 KiB

Before After
Before After

View file

@ -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,

View file

@ -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|

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

7
test/fixtures/account_activities.yml vendored Normal file
View file

@ -0,0 +1,7 @@
DEFAULTS: &DEFAULTS
account_id: 1
one:
<<: *DEFAULTS
invoice: paid
bank_transaction: one

3
test/fixtures/bank_transactions.yml vendored Normal file
View file

@ -0,0 +1,3 @@
one:
sum: 1
currency: EUR

13
test/fixtures/invoice_items.yml vendored Normal file
View file

@ -0,0 +1,13 @@
DEFAULTS: &DEFAULTS
description: Acme services
amount: 2
unit: pc
price: 5
valid:
<<: *DEFAULTS
invoice: valid
another:
<<: *DEFAULTS
invoice: valid

32
test/fixtures/invoices.yml vendored Normal file
View file

@ -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' %>

View file

@ -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

View file

@ -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

View file

@ -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

25
test/test_helper.rb Normal file
View file

@ -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