Skip to content

Commit

Permalink
Merge pull request #276 from dmitry-sinina/1.6_cp
Browse files Browse the repository at this point in the history
CDR database seed fix
make smallint validators accept 32767 (#272)
  • Loading branch information
dmitry-sinina authored Mar 27, 2018
2 parents afcd323 + e9fd9c1 commit 03b49be
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 55 deletions.
2 changes: 1 addition & 1 deletion app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Account < Yeti::ActiveRecord
validates_presence_of :name, :contractor, :timezone
validates_numericality_of :max_balance, greater_than_or_equal_to: ->(account) { account.min_balance }

validates_numericality_of :termination_capacity, :origination_capacity, greater_than: 0, less_than: PG_MAX_SMALLINT, allow_nil: true, only_integer: true
validates_numericality_of :termination_capacity, :origination_capacity, greater_than: 0, less_than_or_equal_to: PG_MAX_SMALLINT, allow_nil: true, only_integer: true

validates_uniqueness_of :external_id, allow_blank: true

Expand Down
2 changes: 1 addition & 1 deletion app/models/customers_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ module CONST
validates_numericality_of :dst_number_min_length, greater_than_or_equal_to: 0, less_than_or_equal_to: 100, allow_nil: false, only_integer: true
validates_numericality_of :dst_number_max_length, greater_than_or_equal_to: 0, less_than_or_equal_to: 100, allow_nil: false, only_integer: true

validates_numericality_of :capacity, greater_than: 0, less_than: PG_MAX_SMALLINT, allow_nil: true, only_integer: true
validates_numericality_of :capacity, greater_than: 0, less_than_or_equal_to: PG_MAX_SMALLINT, allow_nil: true, only_integer: true

validate :ip_is_valid
validate :gateway_supports_incoming_auth
Expand Down
2 changes: 1 addition & 1 deletion app/models/dialpeer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Dialpeer < Yeti::ActiveRecord
validates_numericality_of :short_calls_limit, greater_than_or_equal_to: 0.00, less_than_or_equal_to: 1.00

validates_numericality_of :force_hit_rate, greater_than_or_equal_to: 0.00, less_than_or_equal_to: 1.00, allow_blank: true
validates_numericality_of :capacity, greater_than: 0, less_than: PG_MAX_SMALLINT, allow_nil: true, only_integer: true
validates_numericality_of :capacity, greater_than: 0, less_than_or_equal_to: PG_MAX_SMALLINT, allow_nil: true, only_integer: true

validates_presence_of :dst_number_min_length, :dst_number_max_length
validates_numericality_of :dst_number_min_length, greater_than_or_equal_to: 0, less_than_or_equal_to: 100, allow_nil: false, only_integer: true
Expand Down
4 changes: 2 additions & 2 deletions app/models/equipment/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class Equipment::Registration < Yeti::ActiveRecord
#validates_format_of :contact, :with => /\Asip:(.*)\z/
validates :contact, :format => URI::regexp(%w(sip))

validates_numericality_of :retry_delay, greater_than: 0, less_than: PG_MAX_SMALLINT, allow_nil: false, only_integer: true
validates_numericality_of :max_attempts, greater_than: 0, less_than: PG_MAX_SMALLINT, allow_nil: true, only_integer: true
validates_numericality_of :retry_delay, greater_than: 0, less_than_or_equal_to: PG_MAX_SMALLINT, allow_nil: false, only_integer: true
validates_numericality_of :max_attempts, greater_than: 0, less_than_or_equal_to: PG_MAX_SMALLINT, allow_nil: true, only_integer: true


has_paper_trail class_name: 'AuditLogItem'
Expand Down
6 changes: 3 additions & 3 deletions app/models/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ class Gateway < Yeti::ActiveRecord
validates_numericality_of :asr_limit, greater_than_or_equal_to: 0.00, less_than_or_equal_to: 1.00
validates_numericality_of :short_calls_limit, greater_than_or_equal_to: 0.00, less_than_or_equal_to: 1.00

validates_numericality_of :max_30x_redirects, :max_transfers, greater_than_or_equal_to: 0, less_than: PG_MAX_SMALLINT, allow_nil: true, only_integer: true
validates_numericality_of :max_30x_redirects, :max_transfers, greater_than_or_equal_to: 0, less_than_or_equal_to: PG_MAX_SMALLINT, allow_nil: true, only_integer: true

validates_numericality_of :origination_capacity, :termination_capacity, greater_than: 0, less_than: PG_MAX_SMALLINT, allow_nil: true, only_integer: true
validates_numericality_of :origination_capacity, :termination_capacity, greater_than: 0, less_than_or_equal_to: PG_MAX_SMALLINT, allow_nil: true, only_integer: true
validates_numericality_of :port, greater_than_or_equal_to: Yeti::ActiveRecord::L4_PORT_MIN, less_than_or_equal_to: Yeti::ActiveRecord::L4_PORT_MAX, allow_nil: true, only_integer: true

validates_numericality_of :fake_180_timer, greater_than: 0, less_than: PG_MAX_SMALLINT, allow_nil: true, only_integer: true
validates_numericality_of :fake_180_timer, greater_than: 0, less_than_or_equal_to: PG_MAX_SMALLINT, allow_nil: true, only_integer: true
validates_presence_of :transport_protocol, :term_proxy_transport_protocol, :orig_proxy_transport_protocol
validates_presence_of :incoming_auth_username, :incoming_auth_password,
if: Proc.new { |gw|
Expand Down
4 changes: 2 additions & 2 deletions app/models/lnp/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
# csv_file :string
#

class Lnp::Database< Yeti::ActiveRecord
class Lnp::Database < Yeti::ActiveRecord
self.table_name = 'class4.lnp_databases'

belongs_to :driver, class_name: Lnp::DatabaseDriver, foreign_key: :driver_id
validates_presence_of :driver, :name, :host
validates_uniqueness_of :name

validates_numericality_of :timeout, greater_than: 0, less_than: PG_MAX_SMALLINT, allow_nil: true, only_integer: true
validates_numericality_of :timeout, greater_than: 0, less_than_or_equal_to: PG_MAX_SMALLINT, allow_nil: true, only_integer: true


def display_name
Expand Down
1 change: 1 addition & 0 deletions db/seeds/cdr/pgq.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
select pgq.create_queue('cdr_billing');
select pgq.register_consumer('cdr_billing','cdr_billing');
select pgq.create_queue('cdr_streaming');
8 changes: 6 additions & 2 deletions db/seeds/cdr/sys.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ INSERT INTO cdr_tables VALUES (5, 'cdr.cdr_201411', true, true, '2014-11-01', '2
INSERT INTO cdr_tables VALUES (6, 'cdr.cdr_201710', true, true, '2017-10-01', '2017-11-01', true);
INSERT INTO cdr_tables VALUES (7, 'cdr.cdr_201709', true, true, '2017-09-01', '2017-10-01', true);
INSERT INTO cdr_tables VALUES (8, 'cdr.cdr_201708', true, true, '2017-08-01', '2017-09-01', true);

INSERT INTO cdr_tables VALUES (9, 'cdr.cdr_201712', true, true, '2017-12-01', '2018-01-01', true);
INSERT INTO cdr_tables VALUES (10, 'cdr.cdr_201801', true, true, '2018-01-01', '2018-02-01', true);
INSERT INTO cdr_tables VALUES (11, 'cdr.cdr_201802', true, true, '2018-02-01', '2018-03-01', true);
INSERT INTO cdr_tables VALUES (12, 'cdr.cdr_201803', true, true, '2018-03-01', '2018-04-01', true);
INSERT INTO cdr_tables VALUES (13, 'cdr.cdr_201804', true, true, '2018-04-01', '2018-05-01', true);

--
-- TOC entry 2514 (class 0 OID 0)
-- Dependencies: 295
-- Name: cdr_tables_id_seq; Type: SEQUENCE SET; Schema: sys; Owner: yeti
--

SELECT pg_catalog.setval('cdr_tables_id_seq', 8, true);
SELECT pg_catalog.setval('cdr_tables_id_seq', 13, true);


--
Expand Down
28 changes: 16 additions & 12 deletions spec/models/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@

describe Account, type: :model do

let!(:account) {}

subject do
account.destroy!
it do
should validate_numericality_of(:origination_capacity).is_less_than_or_equal_to(Yeti::ActiveRecord::PG_MAX_SMALLINT)
should validate_numericality_of(:termination_capacity).is_less_than_or_equal_to(Yeti::ActiveRecord::PG_MAX_SMALLINT)
end

context '#destroy' do
let!(:account) { create(:account) }

subject do
account.destroy!
end

context 'wihtout linked ApiAccess records' do
let!(:api_access) { create(:api_access) }
let(:account) { create(:account) }


it 'removes Account successfully' do
expect { subject }.to change { described_class.count }.by(-1)
Expand Down Expand Up @@ -73,17 +77,17 @@
end

context 'when Account has Payments' do
let(:account) { create(:account) }

before do
$p1 = create(:payment, account: account)
$p2 = create(:payment) # for another account
let!(:p1) do
create(:payment, account: account)
end
let!(:p2) do
create(:payment) # for another account
end

it 'removes all related Payments' do
expect { subject }.to change {
Payment.pluck(:id)
}.from([$p1.id, $p2.id]).to([$p2.id])
}.from([p1.id, p2.id]).to([p2.id])
end
end

Expand Down
5 changes: 5 additions & 0 deletions spec/models/customers_auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@

context '#validations' do

it do
should validate_numericality_of(:capacity).is_less_than_or_equal_to(Yeti::ActiveRecord::PG_MAX_SMALLINT)
end


context 'validate Routing Tag' do
include_examples :test_model_with_tag_action
end
Expand Down
66 changes: 35 additions & 31 deletions spec/models/dialpeer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,52 +48,56 @@

describe 'validations' do

let(:record) { described_class.new(attributes) }

before { record.validate }

subject do
record.errors.to_h
it do
should validate_numericality_of(:capacity).is_less_than_or_equal_to(Yeti::ActiveRecord::PG_MAX_SMALLINT)
end

context 'without Gateway' do
let(:attributes) {}
describe '.errors' do
let(:record) { described_class.new(attributes) }

include_examples :validation_error_on_field, :base, 'Specify a gateway_group or a gateway'
include_examples :validation_no_error_on_field, :gateway
end
before { record.validate }
subject do
record.errors.to_h
end

context 'without Gateway' do
let(:attributes) {}

context 'with Gateway' do
let(:attributes) { { gateway: g, vendor_id: vendor.id, gateway_id: g.id } }
let(:vendor) { g.contractor }
let(:g) { create(:gateway, g_attr) }
let(:g_attr) do
{}
include_examples :validation_error_on_field, :base, 'Specify a gateway_group or a gateway'
include_examples :validation_no_error_on_field, :gateway
end

context 'not allow_termination' do
let(:g_attr) { { allow_termination: false } }
context 'with Gateway' do
let(:attributes) { { gateway: g, vendor_id: vendor.id, gateway_id: g.id } }
let(:vendor) { g.contractor }
let(:g) { create(:gateway, g_attr) }
let(:g_attr) do
{}
end

include_examples :validation_error_on_field, :gateway, 'must be allowed for termination'
end
context 'not allow_termination' do
let(:g_attr) { { allow_termination: false } }

context 'different vendor' do
let(:vendor) { create(:vendor) }
let(:g_attr) { { allow_termination: true } }
include_examples :validation_error_on_field, :gateway, 'must be allowed for termination'
end

include_examples :validation_error_on_field, :gateway, 'must be owned by selected vendor or be shared'
end
context 'different vendor' do
let(:vendor) { create(:vendor) }
let(:g_attr) { { allow_termination: true } }

context 'different vendor, gateway is shared' do
let(:vendor) { create(:vendor) }
let(:g_attr) { { allow_termination: true, is_shared: true } }
include_examples :validation_error_on_field, :gateway, 'must be owned by selected vendor or be shared'
end

context 'different vendor, gateway is shared' do
let(:vendor) { create(:vendor) }
let(:g_attr) { { allow_termination: true, is_shared: true } }

include_examples :validation_no_error_on_field, :gateway
end

include_examples :validation_no_error_on_field, :gateway
end

end

end

context 'validate routing_tag_ids' do
Expand Down
33 changes: 33 additions & 0 deletions spec/models/equipment/reqistration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# == Schema Information
#
# Table name: registrations
#
# id :integer not null, primary key
# name :string not null
# enabled :boolean default(TRUE), not null
# pop_id :integer
# node_id :integer
# domain :string
# username :string not null
# display_username :string
# auth_user :string
# proxy :string
# contact :string
# auth_password :string
# expire :integer
# force_expire :boolean default(FALSE), not null
# retry_delay :integer default(5), not null
# max_attempts :integer
# transport_protocol_id :integer default(1), not null
# proxy_transport_protocol_id :integer default(1), not null
#


require 'spec_helper'

describe Equipment::Registration, type: :model do
it do
should validate_numericality_of(:retry_delay).is_less_than_or_equal_to(Yeti::ActiveRecord::PG_MAX_SMALLINT)
should validate_numericality_of(:max_attempts).is_less_than_or_equal_to(Yeti::ActiveRecord::PG_MAX_SMALLINT)
end
end
8 changes: 8 additions & 0 deletions spec/models/gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@

describe Gateway, type: :model do

it do
should validate_numericality_of(:max_30x_redirects).is_less_than_or_equal_to(Yeti::ActiveRecord::PG_MAX_SMALLINT)
should validate_numericality_of(:max_transfers).is_less_than_or_equal_to(Yeti::ActiveRecord::PG_MAX_SMALLINT)
should validate_numericality_of(:origination_capacity).is_less_than_or_equal_to(Yeti::ActiveRecord::PG_MAX_SMALLINT)
should validate_numericality_of(:termination_capacity).is_less_than_or_equal_to(Yeti::ActiveRecord::PG_MAX_SMALLINT)
should validate_numericality_of(:fake_180_timer).is_less_than_or_equal_to(Yeti::ActiveRecord::PG_MAX_SMALLINT)
end

shared_examples :validation_error_on_is_shared_change do
let(:expected_error_message) {}

Expand Down
23 changes: 23 additions & 0 deletions spec/models/lnp/database_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# == Schema Information
#
# Table name: class4.lnp_databases
#
# id :integer not null, primary key
# name :string not null
# host :string not null
# port :integer
# driver_id :integer not null
# created_at :datetime
# thinq_token :string
# thinq_username :string
# timeout :integer default(300), not null
# csv_file :string
#

require 'spec_helper'

describe Lnp::Database, type: :model do
it do
should validate_numericality_of(:timeout).is_less_than_or_equal_to(Yeti::ActiveRecord::PG_MAX_SMALLINT)
end
end

0 comments on commit 03b49be

Please sign in to comment.