From eb2796483d7ee754ff5bcfac77bafb6a353d07bf Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 1 May 2017 21:31:54 +0300 Subject: [PATCH 01/23] Improve zone specs #475 --- spec/requests/admin/dns/zones/create_spec.rb | 6 +++--- spec/requests/admin/dns/zones/update_spec.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/requests/admin/dns/zones/create_spec.rb b/spec/requests/admin/dns/zones/create_spec.rb index 991bd60bc..898359ed2 100644 --- a/spec/requests/admin/dns/zones/create_spec.rb +++ b/spec/requests/admin/dns/zones/create_spec.rb @@ -17,20 +17,20 @@ RSpec.describe 'admin zone create', settings: false do text_attributes.each do |attr_name| it "saves #{attr_name}" do - post admin_zones_path, { zone: attributes_for(:zone, attr_name => 'test') } + post admin_zones_path, zone: attributes_for(:zone, attr_name => 'test') expect(zone.send(attr_name)).to eq('test') end end integer_attributes.each do |attr_name| it "saves #{attr_name}" do - post admin_zones_path, { zone: attributes_for(:zone, attr_name => '1') } + post admin_zones_path, zone: attributes_for(:zone, attr_name => '1') expect(zone.send(attr_name)).to eq(1) end end it 'redirects to :index' do - post admin_zones_path, { zone: attributes_for(:zone) } + post admin_zones_path, zone: attributes_for(:zone) expect(response).to redirect_to admin_zones_url end end diff --git a/spec/requests/admin/dns/zones/update_spec.rb b/spec/requests/admin/dns/zones/update_spec.rb index f9b25a3cf..df0f4bab2 100644 --- a/spec/requests/admin/dns/zones/update_spec.rb +++ b/spec/requests/admin/dns/zones/update_spec.rb @@ -33,7 +33,7 @@ RSpec.describe 'admin zone update', settings: false do it 'redirects to :index' do zone = create(:zone) - patch admin_zone_path(zone), { zone: attributes_for(:zone) } + patch admin_zone_path(zone), zone: attributes_for(:zone) expect(response).to redirect_to admin_zones_url end From 31f39d92b29f25a0a9171321887e54832495352c Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 6 May 2017 18:03:54 +0300 Subject: [PATCH 02/23] Remove "prices.desc" column #475 --- db/migrate/20170506144743_remove_price_desc.rb | 5 +++++ db/structure.sql | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20170506144743_remove_price_desc.rb diff --git a/db/migrate/20170506144743_remove_price_desc.rb b/db/migrate/20170506144743_remove_price_desc.rb new file mode 100644 index 000000000..67b38ff96 --- /dev/null +++ b/db/migrate/20170506144743_remove_price_desc.rb @@ -0,0 +1,5 @@ +class RemovePriceDesc < ActiveRecord::Migration + def change + remove_column :prices, :desc, :string + end +end diff --git a/db/structure.sql b/db/structure.sql index 2b4890030..858909103 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2532,7 +2532,6 @@ ALTER SEQUENCE people_id_seq OWNED BY people.id; CREATE TABLE prices ( id integer NOT NULL, - "desc" character varying, price_cents integer NOT NULL, valid_from timestamp without time zone, valid_to timestamp without time zone, @@ -5257,3 +5256,5 @@ INSERT INTO schema_migrations (version) VALUES ('20170423225333'); INSERT INTO schema_migrations (version) VALUES ('20170424115801'); +INSERT INTO schema_migrations (version) VALUES ('20170506144743'); + From 3afd542b1a9b3f8e1a91296341cef71690d33ef3 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 7 May 2017 00:03:10 +0300 Subject: [PATCH 03/23] Improve "account_activities" DB table structure #475 --- ...t_activity_log_pricelist_id_to_price_id.rb | 6 +++ ...account_activity_account_id_foreign_key.rb | 6 +++ ...5356_add_account_activity_invoice_id_fk.rb | 5 +++ ...account_activity_bank_transaction_id_fk.rb | 5 +++ db/structure.sql | 44 ++++++++++++++++++- 5 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20170506155009_rename_account_activity_log_pricelist_id_to_price_id.rb create mode 100644 db/migrate/20170506162952_add_account_activity_account_id_foreign_key.rb create mode 100644 db/migrate/20170506205356_add_account_activity_invoice_id_fk.rb create mode 100644 db/migrate/20170506205946_add_account_activity_bank_transaction_id_fk.rb diff --git a/db/migrate/20170506155009_rename_account_activity_log_pricelist_id_to_price_id.rb b/db/migrate/20170506155009_rename_account_activity_log_pricelist_id_to_price_id.rb new file mode 100644 index 000000000..28969059d --- /dev/null +++ b/db/migrate/20170506155009_rename_account_activity_log_pricelist_id_to_price_id.rb @@ -0,0 +1,6 @@ +class RenameAccountActivityLogPricelistIdToPriceId < ActiveRecord::Migration + def change + rename_column :account_activities, :log_pricelist_id, :price_id + add_foreign_key :account_activities, :prices + end +end diff --git a/db/migrate/20170506162952_add_account_activity_account_id_foreign_key.rb b/db/migrate/20170506162952_add_account_activity_account_id_foreign_key.rb new file mode 100644 index 000000000..8d40e8041 --- /dev/null +++ b/db/migrate/20170506162952_add_account_activity_account_id_foreign_key.rb @@ -0,0 +1,6 @@ +class AddAccountActivityAccountIdForeignKey < ActiveRecord::Migration + def change + change_column :account_activities, :account_id, :integer, null: false + add_foreign_key :account_activities, :accounts + end +end diff --git a/db/migrate/20170506205356_add_account_activity_invoice_id_fk.rb b/db/migrate/20170506205356_add_account_activity_invoice_id_fk.rb new file mode 100644 index 000000000..43a54fde2 --- /dev/null +++ b/db/migrate/20170506205356_add_account_activity_invoice_id_fk.rb @@ -0,0 +1,5 @@ +class AddAccountActivityInvoiceIdFk < ActiveRecord::Migration + def change + add_foreign_key :account_activities, :invoices + end +end diff --git a/db/migrate/20170506205946_add_account_activity_bank_transaction_id_fk.rb b/db/migrate/20170506205946_add_account_activity_bank_transaction_id_fk.rb new file mode 100644 index 000000000..c0e69aabe --- /dev/null +++ b/db/migrate/20170506205946_add_account_activity_bank_transaction_id_fk.rb @@ -0,0 +1,5 @@ +class AddAccountActivityBankTransactionIdFk < ActiveRecord::Migration + def change + add_foreign_key :account_activities, :bank_transactions + end +end diff --git a/db/structure.sql b/db/structure.sql index 858909103..429b23f73 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -287,7 +287,7 @@ SET default_with_oids = false; CREATE TABLE account_activities ( id integer NOT NULL, - account_id integer, + account_id integer NOT NULL, invoice_id integer, sum numeric(10,2), currency character varying, @@ -298,7 +298,7 @@ CREATE TABLE account_activities ( creator_str character varying, updator_str character varying, activity_type character varying, - log_pricelist_id integer + price_id integer ); @@ -4776,6 +4776,38 @@ ALTER TABLE ONLY prices ADD CONSTRAINT fk_rails_78c376257f FOREIGN KEY (zone_id) REFERENCES zones(id); +-- +-- Name: fk_rails_86cd2b09f5; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY account_activities + ADD CONSTRAINT fk_rails_86cd2b09f5 FOREIGN KEY (account_id) REFERENCES accounts(id); + + +-- +-- Name: fk_rails_b80dbb973d; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY account_activities + ADD CONSTRAINT fk_rails_b80dbb973d FOREIGN KEY (bank_transaction_id) REFERENCES bank_transactions(id); + + +-- +-- Name: fk_rails_ce38d749f6; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY account_activities + ADD CONSTRAINT fk_rails_ce38d749f6 FOREIGN KEY (invoice_id) REFERENCES invoices(id); + + +-- +-- Name: fk_rails_d2cc3c2fa9; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY account_activities + ADD CONSTRAINT fk_rails_d2cc3c2fa9 FOREIGN KEY (price_id) REFERENCES prices(id); + + -- -- PostgreSQL database dump complete -- @@ -5258,3 +5290,11 @@ INSERT INTO schema_migrations (version) VALUES ('20170424115801'); INSERT INTO schema_migrations (version) VALUES ('20170506144743'); +INSERT INTO schema_migrations (version) VALUES ('20170506155009'); + +INSERT INTO schema_migrations (version) VALUES ('20170506162952'); + +INSERT INTO schema_migrations (version) VALUES ('20170506205356'); + +INSERT INTO schema_migrations (version) VALUES ('20170506205946'); + From ae64c7cbed5edd6bd8613f65f2a1374e9c5b0295 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 7 May 2017 00:23:40 +0300 Subject: [PATCH 04/23] Improve Price - AccountActivity model relation #475 --- app/models/account_activity.rb | 4 ++-- app/models/billing/price.rb | 1 + spec/models/account_activity_spec.rb | 13 +++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 spec/models/account_activity_spec.rb diff --git a/app/models/account_activity.rb b/app/models/account_activity.rb index c6523be33..3bc21a0d8 100644 --- a/app/models/account_activity.rb +++ b/app/models/account_activity.rb @@ -2,10 +2,10 @@ require 'csv' class AccountActivity < ActiveRecord::Base include Versions - belongs_to :account + belongs_to :account, required: true belongs_to :bank_transaction belongs_to :invoice - + belongs_to :price, class_name: 'Billing::Price' CREATE = 'create' RENEW = 'renew' diff --git a/app/models/billing/price.rb b/app/models/billing/price.rb index c12cffffe..7924bbd6c 100644 --- a/app/models/billing/price.rb +++ b/app/models/billing/price.rb @@ -6,6 +6,7 @@ module Billing self.auto_html5_validation = false belongs_to :zone, class_name: 'DNS::Zone', required: true + has_many :account_activities validates :price, :valid_from, :operation_category, :duration, presence: true validates :operation_category, inclusion: { in: Proc.new { |price| price.class.operation_categories } } diff --git a/spec/models/account_activity_spec.rb b/spec/models/account_activity_spec.rb new file mode 100644 index 000000000..59e88c98b --- /dev/null +++ b/spec/models/account_activity_spec.rb @@ -0,0 +1,13 @@ +require 'rails_helper' + +RSpec.describe AccountActivity do + describe 'account validation', db: false do + subject(:account_activity) { described_class.new } + + it 'rejects absent' do + account_activity.account = nil + account_activity.validate + expect(account_activity.errors).to have_key(:account) + end + end +end From 3162c76bbf14e8b6fd7c32204417d57221fafc66 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 7 May 2017 00:26:32 +0300 Subject: [PATCH 05/23] Require account registrar to be present #475 --- app/models/account.rb | 3 ++- spec/models/account_spec.rb | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index bee11833b..b7c43eab3 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -1,6 +1,7 @@ class Account < ActiveRecord::Base include Versions - belongs_to :registrar + + belongs_to :registrar, required: true has_many :account_activities validates :account_type, presence: true diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 292ccfa6a..f3ba1fdb5 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe Account do +RSpec.describe Account do context 'with invalid attribute' do before :all do @account = Account.new @@ -45,4 +45,14 @@ describe Account do end end end + + describe 'registrar validation', db: false do + subject(:account) { described_class.new } + + it 'rejects absent' do + account.registrar = nil + account.validate + expect(account.errors).to have_key(:registrar) + end + end end From 261c3cc157e5bbf7881e193d03c6dd75bd60b0ba Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 7 May 2017 00:26:47 +0300 Subject: [PATCH 06/23] Improve "accounts" DB table structure #475 --- .../20170506212014_add_account_registrar_fk.rb | 6 ++++++ db/structure.sql | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20170506212014_add_account_registrar_fk.rb diff --git a/db/migrate/20170506212014_add_account_registrar_fk.rb b/db/migrate/20170506212014_add_account_registrar_fk.rb new file mode 100644 index 000000000..3f73cb83f --- /dev/null +++ b/db/migrate/20170506212014_add_account_registrar_fk.rb @@ -0,0 +1,6 @@ +class AddAccountRegistrarFk < ActiveRecord::Migration + def change + change_column :accounts, :registrar_id, :integer, null: false + add_foreign_key :accounts, :registrars + end +end diff --git a/db/structure.sql b/db/structure.sql index 429b23f73..612f58532 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -327,7 +327,7 @@ ALTER SEQUENCE account_activities_id_seq OWNED BY account_activities.id; CREATE TABLE accounts ( id integer NOT NULL, - registrar_id integer, + registrar_id integer NOT NULL, account_type character varying, balance numeric(10,2) DEFAULT 0.0 NOT NULL, created_at timestamp without time zone, @@ -4792,6 +4792,14 @@ ALTER TABLE ONLY account_activities ADD CONSTRAINT fk_rails_b80dbb973d FOREIGN KEY (bank_transaction_id) REFERENCES bank_transactions(id); +-- +-- Name: fk_rails_c9f635c0b3; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY accounts + ADD CONSTRAINT fk_rails_c9f635c0b3 FOREIGN KEY (registrar_id) REFERENCES registrars(id); + + -- -- Name: fk_rails_ce38d749f6; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -5298,3 +5306,5 @@ INSERT INTO schema_migrations (version) VALUES ('20170506205356'); INSERT INTO schema_migrations (version) VALUES ('20170506205946'); +INSERT INTO schema_migrations (version) VALUES ('20170506212014'); + From e778ed59630da3563146612935c71ba75890ccfc Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 7 May 2017 01:20:21 +0300 Subject: [PATCH 07/23] Remove unused fabricators #475 --- spec/fabricators/account_activity_fabricator.rb | 5 ----- spec/fabricators/account_fabricator.rb | 6 ------ 2 files changed, 11 deletions(-) delete mode 100644 spec/fabricators/account_activity_fabricator.rb delete mode 100644 spec/fabricators/account_fabricator.rb diff --git a/spec/fabricators/account_activity_fabricator.rb b/spec/fabricators/account_activity_fabricator.rb deleted file mode 100644 index 4b9e71603..000000000 --- a/spec/fabricators/account_activity_fabricator.rb +++ /dev/null @@ -1,5 +0,0 @@ -Fabricator(:account_activity) do - invoice - currency 'EUR' - sum 110.0 -end diff --git a/spec/fabricators/account_fabricator.rb b/spec/fabricators/account_fabricator.rb deleted file mode 100644 index 496f8b900..000000000 --- a/spec/fabricators/account_fabricator.rb +++ /dev/null @@ -1,6 +0,0 @@ -Fabricator(:account) do - account_type { Account::CASH } - balance 0.0 - currency 'EUR' - # account_activities(count: 2) -end From 9425fed7aeaceae7f16c39698eb5daa5f271e4d2 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 7 May 2017 01:20:43 +0300 Subject: [PATCH 08/23] Fix account factory #475 --- spec/factories/account.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/factories/account.rb b/spec/factories/account.rb index 19ed7f9c7..65f40a433 100644 --- a/spec/factories/account.rb +++ b/spec/factories/account.rb @@ -3,5 +3,6 @@ FactoryGirl.define do account_type Account::CASH balance 1 currency 'EUR' + registrar end end From c64f7742fa9551d4f6fdc22346af400a47d84afd Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 7 May 2017 01:31:36 +0300 Subject: [PATCH 09/23] Revert "Remove unused fabricators" This reverts commit e778ed59630da3563146612935c71ba75890ccfc. --- spec/fabricators/account_activity_fabricator.rb | 5 +++++ spec/fabricators/account_fabricator.rb | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 spec/fabricators/account_activity_fabricator.rb create mode 100644 spec/fabricators/account_fabricator.rb diff --git a/spec/fabricators/account_activity_fabricator.rb b/spec/fabricators/account_activity_fabricator.rb new file mode 100644 index 000000000..4b9e71603 --- /dev/null +++ b/spec/fabricators/account_activity_fabricator.rb @@ -0,0 +1,5 @@ +Fabricator(:account_activity) do + invoice + currency 'EUR' + sum 110.0 +end diff --git a/spec/fabricators/account_fabricator.rb b/spec/fabricators/account_fabricator.rb new file mode 100644 index 000000000..496f8b900 --- /dev/null +++ b/spec/fabricators/account_fabricator.rb @@ -0,0 +1,6 @@ +Fabricator(:account) do + account_type { Account::CASH } + balance 0.0 + currency 'EUR' + # account_activities(count: 2) +end From 38e5aaeaaa06c05f4cd16623a6f1d854e824331b Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 7 May 2017 14:02:56 +0300 Subject: [PATCH 10/23] Remove unused fabricator #475 --- spec/fabricators/account_activity_fabricator.rb | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 spec/fabricators/account_activity_fabricator.rb diff --git a/spec/fabricators/account_activity_fabricator.rb b/spec/fabricators/account_activity_fabricator.rb deleted file mode 100644 index 4b9e71603..000000000 --- a/spec/fabricators/account_activity_fabricator.rb +++ /dev/null @@ -1,5 +0,0 @@ -Fabricator(:account_activity) do - invoice - currency 'EUR' - sum 110.0 -end From 1891a6305b12c2a5f8e767da2b2064c63b3e2f15 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 7 May 2017 14:03:16 +0300 Subject: [PATCH 11/23] Fix account fabricator #475 --- spec/fabricators/account_fabricator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/fabricators/account_fabricator.rb b/spec/fabricators/account_fabricator.rb index 496f8b900..683d98739 100644 --- a/spec/fabricators/account_fabricator.rb +++ b/spec/fabricators/account_fabricator.rb @@ -2,5 +2,5 @@ Fabricator(:account) do account_type { Account::CASH } balance 0.0 currency 'EUR' - # account_activities(count: 2) + registrar end From f55169c2b4a206b6de186655045007d17a0525e6 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 7 May 2017 14:05:32 +0300 Subject: [PATCH 12/23] Improve "account_activities" DB table structure #475 --- app/controllers/epp/domains_controller.rb | 4 +- spec/models/account_spec.rb | 47 +++-------------------- 2 files changed, 7 insertions(+), 44 deletions(-) diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index 6962f42c8..02c75c7da 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -37,7 +37,7 @@ class Epp::DomainsController < EppController sum: @domain_pricelist.price.amount, description: "#{I18n.t('create')} #{@domain.name}", activity_type: AccountActivity::CREATE, - log_pricelist_id: @domain_pricelist.id + price: @domain_pricelist }) render_epp_response '/epp/domains/create' @@ -124,7 +124,7 @@ class Epp::DomainsController < EppController sum: @domain_pricelist.price.amount, description: "#{I18n.t('renew')} #{@domain.name}", activity_type: AccountActivity::RENEW, - log_pricelist_id: @domain_pricelist.id + price: @domain_pricelist }) render_epp_response '/epp/domains/renew' diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index f3ba1fdb5..83e40b86e 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -1,48 +1,11 @@ require 'rails_helper' RSpec.describe Account do - context 'with invalid attribute' do - before :all do - @account = Account.new - end - - it 'should not be valid' do - @account.valid? - @account.errors.full_messages.should match_array(["Account type is missing"]) - end - - it 'should not have any versions' do - @account.versions.should == [] - end - end - - context 'with valid attributes' do - before :all do - @account = Fabricate(:account) - end - - it 'should be valid' do - @account.valid? - @account.errors.full_messages.should match_array([]) - s = 0.0 - @account.activities.map { |x| s += x.sum } - @account.balance.should == s - end - - it 'should be valid twice' do - @account = Fabricate(:account) - @account.valid? - @account.errors.full_messages.should match_array([]) - end - - it 'should have one version' do - with_versioning do - @account.versions.should == [] - @account.account_type = 'new_type' - @account.save - @account.errors.full_messages.should match_array([]) - @account.versions.size.should == 1 - end + it 'has versions' do + with_versioning do + price = build(:account) + price.save! + expect(price.versions.size).to be(1) end end From 885f28e34e71da854b32dbc060c906888126b2ca Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 8 May 2017 01:09:29 +0300 Subject: [PATCH 13/23] Add "Directo.send_monthly_invoices" to schedule #475 --- config/schedule.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/schedule.rb b/config/schedule.rb index a2676ef65..a136ba5c3 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -54,6 +54,10 @@ if @cron_group == 'registry' runner 'DomainCron.start_redemption_grace_period' end + every '0 0 1 * *' do + runner 'Directo.send_monthly_invoices' + end + every :day, at: '19:00pm' do runner 'Directo.send_receipts' end if @environment == 'production' From fd1f475925b0c589d9d374c8b4ea62da4c88364f Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 8 May 2017 01:11:20 +0300 Subject: [PATCH 14/23] Fix Directo monthly invoice generation #475 --- app/models/billing/price.rb | 12 +---- app/models/directo.rb | 90 +++++++++++++++++++------------------ 2 files changed, 48 insertions(+), 54 deletions(-) diff --git a/app/models/billing/price.rb b/app/models/billing/price.rb index 7924bbd6c..a5a76bc77 100644 --- a/app/models/billing/price.rb +++ b/app/models/billing/price.rb @@ -52,24 +52,16 @@ module Billing "#{operation_category} #{zone_name}" end - def years_amount - duration.to_i - end - - def price_decimal - price_cents / BigDecimal.new('100') - end - def zone_name zone.origin end - private - def to_partial_path 'price' end + private + def init_values return unless new_record? self.valid_from = Time.zone.now.beginning_of_year unless valid_from diff --git a/app/models/directo.rb b/app/models/directo.rb index fc1ad270a..bf93e6d70 100644 --- a/app/models/directo.rb +++ b/app/models/directo.rb @@ -61,7 +61,6 @@ class Directo < ActiveRecord::Base def self.send_monthly_invoices(debug: false) - @debug = debug I18n.locale = :et month = Time.now - 1.month invoices_until = month.end_of_month @@ -76,51 +75,61 @@ class Directo < ActiveRecord::Base end directo_next = last_directo - Registrar.where.not(test_registrar: true).find_each do |registrar| - unless registrar.cash_account - Rails.logger.info("[DIRECTO] Monthly invoice for registrar #{registrar.id} has been skipped as it doesn't has cash_account") - next - end + + Registrar.where(test_registrar: false).each do |registrar| counter = Counter.new(1) items = {} - registrar_activities = AccountActivity.where(account_id: registrar.account_ids).where("created_at BETWEEN ? AND ?",month.beginning_of_month, month.end_of_month) + registrar_activities = AccountActivity + .where(account_id: registrar.account_ids) + .where(created_at: month.beginning_of_month..month.end_of_month) + .where(activity_type: [AccountActivity::CREATE, AccountActivity::RENEW]) - # adding domains items - registrar_activities.where(activity_type: [AccountActivity::CREATE, AccountActivity::RENEW]).each do |activity| - pricelist = load_activity_pricelist(activity) - unless pricelist - Rails.logger.error("[DIRECTO] Skipping activity #{activity.id} as pricelist not found") - next + # Adding domains items + registrar_activities.each do |account_activity| + price = load_price(account_activity) + quantity = price.account_activities + .where(account_id: registrar.account_ids) + .where(created_at: month.beginning_of_month..month.end_of_month) + .where(activity_type: [AccountActivity::CREATE, AccountActivity::RENEW]) + .count + + if price.duration.include?('years') + line_count = price.duration.to_i + else + line_count = 1 end - pricelist.years_amount.times do |i| - year = i+1 - hash = { - "ProductID" => DOMAIN_TO_PRODUCT[pricelist.category], - "Unit" => "tk", - "ProductName" => ".#{pricelist.category} registreerimine: #{pricelist.years_amount} aasta", - "UnitPriceWoVAT" => pricelist.price_decimal/pricelist.years_amount - } - hash["StartDate"] = (activity.created_at + (year-1).year).end_of_month.strftime(date_format) if year > 1 - hash["EndDate"] = (activity.created_at + (year-1).year + 1).end_of_month.strftime(date_format) if year > 1 + localized_duration = price.duration + localized_duration.sub!(/mons/, 'kuud') + localized_duration.sub!(/years/, 'aastat') + localized_duration.sub!(/year/, 'aasta') - if items.has_key?(hash) - items[hash]["Quantity"] += 1 - else - items[hash] = {"RN"=>counter.next, "RR" => counter.now - i, "Quantity"=> 1} + line_count.times do |i| + year = i + 1 + hash = { + "ProductID" => DOMAIN_TO_PRODUCT[price.zone_name], + "Unit" => "tk", + "ProductName" => ".#{price.zone_name} registreerimine: #{price.duration}", + "UnitPriceWoVAT" => price.price, + } + hash["StartDate"] = (account_activity.created_at + (year-1).year).end_of_month.strftime(date_format) if year > 1 + hash["EndDate"] = (account_activity.created_at + (year-1).year + 1).end_of_month.strftime(date_format) if year > 1 + + unless items.has_key?(hash) + items[hash] = {"RN"=>counter.next, "RR" => counter.now - i, "Quantity"=> quantity} end end end - #adding prepaiments + # Adding prepayments if items.any? - total = 0 + total = Money.new(0) items.each{ |key, val| total += val["Quantity"] * key["UnitPriceWoVAT"] } hash = {"ProductID" => Setting.directo_receipt_product_name, "Unit" => "tk", "ProductName" => "Domeenide ettemaks", "UnitPriceWoVAT"=>total} items[hash] = {"RN"=>counter.next, "RR" => counter.now, "Quantity"=> -1} end - # generating XML + # Generating XML if items.any? directo_next += 1 invoice_counter.next @@ -136,6 +145,7 @@ class Directo < ActiveRecord::Base "SalesAgent" =>Setting.directo_sales_agent){ xml.line("RN" => 1, "RR"=>1, "ProductName"=> "Domeenide registreerimine - #{I18n.l(invoices_until, format: "%B %Y").titleize}") items.each do |line, val| + line['UnitPriceWoVAT'] = line['UnitPriceWoVAT'].amount.to_s xml.line(val.merge(line)) end } @@ -143,10 +153,11 @@ class Directo < ActiveRecord::Base end data = builder.to_xml.gsub("\n",'') - response = RestClient::Request.execute(url: ENV['directo_invoice_url'], method: :post, payload: {put: "1", what: "invoice", xmldata: data}, verify_ssl: false).to_s - if @debug + + if debug STDOUT << "#{Time.zone.now.utc} - Directo xml had to be sent #{data}\n" else + response = RestClient::Request.execute(url: ENV['directo_invoice_url'], method: :post, payload: {put: "1", what: "invoice", xmldata: data}, verify_ssl: false).to_s Setting.directo_monthly_number_last = directo_next Nokogiri::XML(response).css("Result").each do |res| Directo.create!(request: data, response: res.as_json.to_h, invoice_number: directo_next) @@ -161,19 +172,10 @@ class Directo < ActiveRecord::Base STDOUT << "#{Time.zone.now.utc} - Directo invoices sending finished. #{invoice_counter.now} are sent\n" end - - def self.load_activity_pricelist activity + def self.load_price(account_activity) @pricelists ||= {} - return @pricelists[activity.log_pricelist_id] if @pricelists.has_key?(activity.log_pricelist_id) - - pricelist = Pricelist.find_by(id: activity.log_pricelist_id) || PricelistVersion.find_by(item_id: activity.log_pricelist_id).try(:reify) - unless pricelist - @pricelists[activity.log_pricelist_id] = nil - Rails.logger.info("[DIRECTO] AccountActivity #{activity.id} cannot be sent as pricelist wasn't found #{activity.log_pricelist_id}") - return - end - - @pricelists[activity.log_pricelist_id] = pricelist.version_at(activity.created_at) || pricelist + return @pricelists[account_activity.price_id] if @pricelists.has_key?(account_activity.price_id) + @pricelists[account_activity.price_id] = account_activity.price end end From 4b9d5360f61e4b4efb9404053607687d7cef53b0 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 8 May 2017 01:12:43 +0300 Subject: [PATCH 15/23] Add month names to et locale --- config/locales/et.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/locales/et.yml b/config/locales/et.yml index 6f8a51040..860af2450 100644 --- a/config/locales/et.yml +++ b/config/locales/et.yml @@ -5,3 +5,7 @@ et: registrant: registreerija tech: tehniline kontakt admin: halduskontakt + + date: + # Don't forget the nil at the beginning; there's no such thing as a 0th month + month_names: [~, Jaanuar, Veebruar, Märts, Aprill, Mai, Juuni, Juuli, August, September, Oktoober, November, Detsember] From 5425a9ed7f6dccb3084d7143a6060b2742621fee Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 4 Jun 2017 21:39:45 +0300 Subject: [PATCH 16/23] Remove PriceVersion #475 --- app/models/billing/price.rb | 1 - app/models/version/price_version.rb | 4 -- .../20170604182521_remove_log_pricelists.rb | 5 ++ db/structure.sql | 54 +------------------ doc/models_brief.svg | 18 ------- doc/models_complete.svg | 28 ---------- 6 files changed, 7 insertions(+), 103 deletions(-) delete mode 100644 app/models/version/price_version.rb create mode 100644 db/migrate/20170604182521_remove_log_pricelists.rb diff --git a/app/models/billing/price.rb b/app/models/billing/price.rb index a5a76bc77..2e4610466 100644 --- a/app/models/billing/price.rb +++ b/app/models/billing/price.rb @@ -1,7 +1,6 @@ module Billing class Price < ActiveRecord::Base include Versions - has_paper_trail class_name: '::PriceVersion' self.auto_html5_validation = false diff --git a/app/models/version/price_version.rb b/app/models/version/price_version.rb deleted file mode 100644 index c60cd508e..000000000 --- a/app/models/version/price_version.rb +++ /dev/null @@ -1,4 +0,0 @@ -class PriceVersion < PaperTrail::Version - self.table_name = :log_pricelists - self.sequence_name = :log_pricelists_id_seq -end diff --git a/db/migrate/20170604182521_remove_log_pricelists.rb b/db/migrate/20170604182521_remove_log_pricelists.rb new file mode 100644 index 000000000..c46921764 --- /dev/null +++ b/db/migrate/20170604182521_remove_log_pricelists.rb @@ -0,0 +1,5 @@ +class RemoveLogPricelists < ActiveRecord::Migration + def change + drop_table :log_pricelists + end +end diff --git a/db/structure.sql b/db/structure.sql index 612f58532..9d0b2d766 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2147,43 +2147,6 @@ CREATE SEQUENCE log_nameservers_id_seq ALTER SEQUENCE log_nameservers_id_seq OWNED BY log_nameservers.id; --- --- Name: log_pricelists; Type: TABLE; Schema: public; Owner: -; Tablespace: --- - -CREATE TABLE log_pricelists ( - id integer NOT NULL, - item_type character varying NOT NULL, - item_id integer NOT NULL, - event character varying NOT NULL, - whodunnit character varying, - object json, - object_changes json, - created_at timestamp without time zone, - session character varying, - uuid character varying -); - - --- --- Name: log_pricelists_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE log_pricelists_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: log_pricelists_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE log_pricelists_id_seq OWNED BY log_pricelists.id; - - -- -- Name: log_registrars; Type: TABLE; Schema: public; Owner: -; Tablespace: -- @@ -3299,13 +3262,6 @@ ALTER TABLE ONLY log_messages ALTER COLUMN id SET DEFAULT nextval('log_messages_ ALTER TABLE ONLY log_nameservers ALTER COLUMN id SET DEFAULT nextval('log_nameservers_id_seq'::regclass); --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY log_pricelists ALTER COLUMN id SET DEFAULT nextval('log_pricelists_id_seq'::regclass); - - -- -- Name: id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3822,14 +3778,6 @@ ALTER TABLE ONLY log_nameservers ADD CONSTRAINT log_nameservers_pkey PRIMARY KEY (id); --- --- Name: log_pricelists_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: --- - -ALTER TABLE ONLY log_pricelists - ADD CONSTRAINT log_pricelists_pkey PRIMARY KEY (id); - - -- -- Name: log_registrars_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- @@ -5308,3 +5256,5 @@ INSERT INTO schema_migrations (version) VALUES ('20170506205946'); INSERT INTO schema_migrations (version) VALUES ('20170506212014'); +INSERT INTO schema_migrations (version) VALUES ('20170604182521'); + diff --git a/doc/models_brief.svg b/doc/models_brief.svg index e7e51b56d..f1cc6a8e0 100644 --- a/doc/models_brief.svg +++ b/doc/models_brief.svg @@ -166,17 +166,6 @@ - -PricelistVersion - -PricelistVersion - - -PricelistVersion->VersionAssociation - - - - MessageVersion @@ -1240,13 +1229,6 @@ EppSession - -Pricelist->PricelistVersion - - - -versions - InvoiceItem diff --git a/doc/models_complete.svg b/doc/models_complete.svg index d7150a9e8..d7b966dbc 100644 --- a/doc/models_complete.svg +++ b/doc/models_complete.svg @@ -330,27 +330,6 @@ - -PricelistVersion - -PricelistVersion - -id :integer -item_type :string -item_id :integer -event :string -whodunnit :string -object :json -object_changes :json -created_at :datetime -session :string - - -PricelistVersion->VersionAssociation - - - - MessageVersion @@ -1998,13 +1977,6 @@ updated_at :datetime registrar_id :integer - -Pricelist->PricelistVersion - - - -versions - InvoiceItem From 073a057408911a1b660e9fbe90c1cc3803c943ed Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 5 Jun 2017 01:08:07 +0300 Subject: [PATCH 17/23] Remove PriceVersion #475 --- spec/models/billing/price_spec.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/spec/models/billing/price_spec.rb b/spec/models/billing/price_spec.rb index f9d6c8fc8..566b05359 100644 --- a/spec/models/billing/price_spec.rb +++ b/spec/models/billing/price_spec.rb @@ -2,15 +2,6 @@ require 'rails_helper' RSpec.describe Billing::Price do it { is_expected.to monetize(:price) } - it { is_expected.to be_versioned } - - it 'should have one version' do - with_versioning do - price = build(:price) - price.save! - price.versions.size.should == 1 - end - end describe '::operation_categories', db: false do it 'returns available operation categories' do From 7862ee7d8ec93eb80c1c90b2c8550154e99b7bf7 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 8 Jun 2017 23:49:32 +0300 Subject: [PATCH 18/23] Remove PriceVersion #475 --- app/models/billing/price.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/billing/price.rb b/app/models/billing/price.rb index 2e4610466..0d2b659de 100644 --- a/app/models/billing/price.rb +++ b/app/models/billing/price.rb @@ -1,7 +1,5 @@ module Billing class Price < ActiveRecord::Base - include Versions - self.auto_html5_validation = false belongs_to :zone, class_name: 'DNS::Zone', required: true From b9efdf470600ba4ba8e7bad5e11636de2e3e1820 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 10 Jun 2017 14:32:00 +0300 Subject: [PATCH 19/23] Reformat code #475 --- db/structure.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/structure.sql b/db/structure.sql index 976e28ad5..be366e71a 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -5166,3 +5166,4 @@ INSERT INTO schema_migrations (version) VALUES ('20170606133501'); INSERT INTO schema_migrations (version) VALUES ('20170606150352'); INSERT INTO schema_migrations (version) VALUES ('20170606202859'); + From 92c3c86c94136f3865b034d7d6fbe009e23d9cdb Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 12 Jun 2017 00:42:11 +0300 Subject: [PATCH 20/23] Add factories --- spec/factories/account_activity.rb | 5 +++++ spec/factories/epp_session.rb | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 spec/factories/account_activity.rb create mode 100644 spec/factories/epp_session.rb diff --git a/spec/factories/account_activity.rb b/spec/factories/account_activity.rb new file mode 100644 index 000000000..5f87f7674 --- /dev/null +++ b/spec/factories/account_activity.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :account_activity do + account + end +end diff --git a/spec/factories/epp_session.rb b/spec/factories/epp_session.rb new file mode 100644 index 000000000..61fa06151 --- /dev/null +++ b/spec/factories/epp_session.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :epp_session do + + end +end From b1bf725e27cbfa112e0b3f5ac1e0650b6d020775 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 12 Jun 2017 03:11:31 +0300 Subject: [PATCH 21/23] Fix directo #475 --- app/models/directo.rb | 88 ++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/app/models/directo.rb b/app/models/directo.rb index bf93e6d70..a381033c4 100644 --- a/app/models/directo.rb +++ b/app/models/directo.rb @@ -75,61 +75,72 @@ class Directo < ActiveRecord::Base end directo_next = last_directo - - Registrar.where(test_registrar: false).each do |registrar| + Registrar.where.not(test_registrar: true).find_each do |registrar| + unless registrar.cash_account + Rails.logger.info("[DIRECTO] Monthly invoice for registrar #{registrar.id} has been skipped as it doesn't has cash_account") + next + end counter = Counter.new(1) items = {} - registrar_activities = AccountActivity - .where(account_id: registrar.account_ids) - .where(created_at: month.beginning_of_month..month.end_of_month) - .where(activity_type: [AccountActivity::CREATE, AccountActivity::RENEW]) + registrar_activities = AccountActivity.where(account_id: registrar.account_ids).where("created_at BETWEEN ? AND ?",month.beginning_of_month, month.end_of_month) - # Adding domains items - registrar_activities.each do |account_activity| - price = load_price(account_activity) - quantity = price.account_activities - .where(account_id: registrar.account_ids) - .where(created_at: month.beginning_of_month..month.end_of_month) - .where(activity_type: [AccountActivity::CREATE, AccountActivity::RENEW]) - .count + # adding domains items + registrar_activities.where(activity_type: [AccountActivity::CREATE, AccountActivity::RENEW]).each do |activity| + price = load_price(activity) - if price.duration.include?('years') - line_count = price.duration.to_i + if price.duration.include?('year') + price.duration.to_i.times do |i| + year = i+1 + hash = { + "ProductID" => DOMAIN_TO_PRODUCT[price.zone_name], + "Unit" => "tk", + "ProductName" => ".#{price.zone_name} registreerimine: #{price.duration.to_i} aasta", + "UnitPriceWoVAT" => price.price.amount / price.duration.to_i + } + hash["StartDate"] = (activity.created_at + (year-1).year).end_of_month.strftime(date_format) if year > 1 + hash["EndDate"] = (activity.created_at + (year-1).year + 1).end_of_month.strftime(date_format) if year > 1 + + if items.has_key?(hash) + items[hash]["Quantity"] += 1 + else + items[hash] = { "RN" => counter.next, "RR" => counter.now - i, "Quantity" => 1 } + end + end else - line_count = 1 - end + 1.times do |i| + quantity = price.account_activities + .where(account_id: registrar.account_ids) + .where(created_at: month.beginning_of_month..month.end_of_month) + .where(activity_type: [AccountActivity::CREATE, AccountActivity::RENEW]) + .count - localized_duration = price.duration - localized_duration.sub!(/mons/, 'kuud') - localized_duration.sub!(/years/, 'aastat') - localized_duration.sub!(/year/, 'aasta') + hash = { + "ProductID" => DOMAIN_TO_PRODUCT[price.zone_name], + "Unit" => "tk", + "ProductName" => ".#{price.zone_name} registreerimine: #{price.duration.to_i} kuud", + "UnitPriceWoVAT" => price.price.amount, + } - line_count.times do |i| - year = i + 1 - hash = { - "ProductID" => DOMAIN_TO_PRODUCT[price.zone_name], - "Unit" => "tk", - "ProductName" => ".#{price.zone_name} registreerimine: #{price.duration}", - "UnitPriceWoVAT" => price.price, - } - hash["StartDate"] = (account_activity.created_at + (year-1).year).end_of_month.strftime(date_format) if year > 1 - hash["EndDate"] = (account_activity.created_at + (year-1).year + 1).end_of_month.strftime(date_format) if year > 1 - - unless items.has_key?(hash) - items[hash] = {"RN"=>counter.next, "RR" => counter.now - i, "Quantity"=> quantity} + if items.has_key?(hash) + #items[hash]["Quantity"] += 1 + else + items[hash] = { "RN" => counter.next, "RR" => counter.now - i, "Quantity" => quantity } + end end end + + end - # Adding prepayments + #adding prepaiments if items.any? - total = Money.new(0) + total = 0 items.each{ |key, val| total += val["Quantity"] * key["UnitPriceWoVAT"] } hash = {"ProductID" => Setting.directo_receipt_product_name, "Unit" => "tk", "ProductName" => "Domeenide ettemaks", "UnitPriceWoVAT"=>total} items[hash] = {"RN"=>counter.next, "RR" => counter.now, "Quantity"=> -1} end - # Generating XML + # generating XML if items.any? directo_next += 1 invoice_counter.next @@ -145,7 +156,6 @@ class Directo < ActiveRecord::Base "SalesAgent" =>Setting.directo_sales_agent){ xml.line("RN" => 1, "RR"=>1, "ProductName"=> "Domeenide registreerimine - #{I18n.l(invoices_until, format: "%B %Y").titleize}") items.each do |line, val| - line['UnitPriceWoVAT'] = line['UnitPriceWoVAT'].amount.to_s xml.line(val.merge(line)) end } From 72d0c74b0f08725cb2f16269066be37a19febc15 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 12 Jun 2017 03:11:59 +0300 Subject: [PATCH 22/23] Improve dev:prime rake task #475 --- lib/tasks/dev.rake | 90 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 18 deletions(-) diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index 0820550bd..67cf856a2 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -10,8 +10,37 @@ namespace :dev do FactoryGirl.find_definitions PaperTrail.enabled = false + Domain.paper_trail_on! + Contact.paper_trail_on! + with_random_data = args[:random].present? + def create_domain(name:, registrar:, registrant:, account:, price:, reg_time:) + duration = price.duration.sub('mons', 'months').split("\s") + period = duration.first.to_i + period_unit = duration.second[0] + + create(:domain, + name: name, + period: period, + period_unit: period_unit, + registered_at: reg_time, + valid_from: reg_time, + expire_time: reg_time + period.send(duration.second.to_sym), + created_at: reg_time, + updated_at: reg_time, + registrar: registrar, + registrant: registrant) + + create(:account_activity, + account: account, + sum: -price.price.amount, + activity_type: AccountActivity::CREATE, + created_at: reg_time, + updated_at: reg_time, + price: price) + end + def generate_default_data create(:admin_user, username: 'test', password: 'testtest', password_confirmation: 'testtest') @@ -19,29 +48,54 @@ namespace :dev do registrar = create(:registrar, name: 'test') registrant = create(:registrant, name: 'test', registrar: registrar) - create(:account, registrar: registrar, balance: 1_000_000) - create(:api_user, username: 'test', password: 'testtest', registrar: registrar) - create(:domain, - name: 'test.test', - period: 1, - period_unit: 'y', - registered_at: Time.zone.now, - valid_from: Time.zone.now, - expire_time: Time.zone.now + 10.years, - registrar: registrar, - registrant: registrant) + account = create(:account, registrar: registrar, balance: 1_000_000) + api_user = create(:api_user, username: 'test', password: 'testtest', registrar: registrar) + + epp_session = build(:epp_session, registrar: registrar) + epp_session[:api_user_id] = api_user.id + epp_session.registrar_id = registrar.id + epp_session.save! + + domain_counter = 1.step Billing::Price.durations.each do |duration| Billing::Price.operation_categories.each do |operation_category| - create(:price, - price: Money.from_amount(1), - valid_from: Time.zone.now.beginning_of_day, - valid_to: Time.zone.now + 10.years, - duration: duration, - operation_category: operation_category, - zone: zone) + price = create(:price, + price: Money.from_amount(duration.to_i * 10), + valid_from: Time.zone.now - rand(1).months, + valid_to: Time.zone.now + rand(1).months, + duration: duration, + operation_category: operation_category, + zone: zone) + + next if operation_category == 'renew' + + (rand(3) + 1).times do + create_domain(name: "test#{domain_counter.next}.test", + registrar: registrar, + registrant: registrant, + account: account, + price: price, + reg_time: 1.month.ago) + end + + (rand(3) + 1).times do + create_domain(name: "test#{domain_counter.next}.test", + registrar: registrar, + registrant: registrant, + account: account, + price: price, + reg_time: Time.zone.now) + end end end + + create_domain(name: 'test.test', + registrar: registrar, + registrant: registrant, + account: account, + price: Billing::Price.first, + reg_time: Time.zone.now) end def generate_random_data From a61b1679a08b1898ac90b8ffbe655bb3a0531f16 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 12 Jun 2017 10:22:45 +0300 Subject: [PATCH 23/23] Fix account_activity factory --- spec/factories/account_activity.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/factories/account_activity.rb b/spec/factories/account_activity.rb index 5f87f7674..3735349b9 100644 --- a/spec/factories/account_activity.rb +++ b/spec/factories/account_activity.rb @@ -1,5 +1,6 @@ FactoryGirl.define do factory :account_activity do + sum 1.0 account end end