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/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/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 2475363b4..559c53f83 100644
--- a/app/models/billing/price.rb
+++ b/app/models/billing/price.rb
@@ -1,12 +1,11 @@
module Billing
class Price < ActiveRecord::Base
- include Versions
include Concerns::Billing::Price::Expirable
- has_paper_trail class_name: '::PriceVersion'
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 } }
@@ -69,24 +68,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..a381033c4 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
@@ -87,29 +86,50 @@ class Directo < ActiveRecord::Base
# 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
- end
+ price = load_price(activity)
- 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
+ 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}
+ if items.has_key?(hash)
+ items[hash]["Quantity"] += 1
+ else
+ items[hash] = { "RN" => counter.next, "RR" => counter.now - i, "Quantity" => 1 }
+ end
+ end
+ else
+ 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
+
+ hash = {
+ "ProductID" => DOMAIN_TO_PRODUCT[price.zone_name],
+ "Unit" => "tk",
+ "ProductName" => ".#{price.zone_name} registreerimine: #{price.duration.to_i} kuud",
+ "UnitPriceWoVAT" => price.price.amount,
+ }
+
+ 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 prepaiments
@@ -143,10 +163,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 +182,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
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/config/locales/et.yml b/config/locales/et.yml
index 37e1e9dea..96839e4c1 100644
--- a/config/locales/et.yml
+++ b/config/locales/et.yml
@@ -2,3 +2,7 @@ et:
username: 'Kasutajanimi'
password: 'Parool'
log_in: 'Logi sisse'
+
+ 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]
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'
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/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/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/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 e01885fa8..be366e71a 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
);
@@ -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,
@@ -2068,43 +2068,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:
--
@@ -2453,7 +2416,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,
@@ -3207,13 +3169,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: -
--
@@ -3714,14 +3669,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:
--
@@ -4678,6 +4625,46 @@ 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_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: -
+--
+
+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
--
@@ -5158,8 +5145,22 @@ INSERT INTO schema_migrations (version) VALUES ('20170423225333');
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');
+
+INSERT INTO schema_migrations (version) VALUES ('20170506212014');
+
INSERT INTO schema_migrations (version) VALUES ('20170509215614');
+INSERT INTO schema_migrations (version) VALUES ('20170604182521');
+
INSERT INTO schema_migrations (version) VALUES ('20170606133501');
INSERT INTO schema_migrations (version) VALUES ('20170606150352');
diff --git a/doc/models_brief.svg b/doc/models_brief.svg
index a99210ea9..6a2b3f428 100644
--- a/doc/models_brief.svg
+++ b/doc/models_brief.svg
@@ -166,17 +166,6 @@
-
-PricelistVersion
-
-PricelistVersion
-
-
-PricelistVersion->VersionAssociation
-
-
-
-
MessageVersion
@@ -1229,13 +1218,6 @@
EppSession
-
-Pricelist->PricelistVersion
-
-
-
-versions
-
InvoiceItem
diff --git a/doc/models_complete.svg b/doc/models_complete.svg
index 8a1d39a65..2a67d0970 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
@@ -1976,13 +1955,6 @@
updated_at :datetime
registrar_id :integer
-
-Pricelist->PricelistVersion
-
-
-
-versions
-
InvoiceItem
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
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
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
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
diff --git a/spec/factories/account_activity.rb b/spec/factories/account_activity.rb
new file mode 100644
index 000000000..3735349b9
--- /dev/null
+++ b/spec/factories/account_activity.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :account_activity do
+ sum 1.0
+ 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
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
diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb
index 292ccfa6a..83e40b86e 100644
--- a/spec/models/account_spec.rb
+++ b/spec/models/account_spec.rb
@@ -1,48 +1,21 @@
require 'rails_helper'
-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 == []
+RSpec.describe Account do
+ it 'has versions' do
+ with_versioning do
+ price = build(:account)
+ price.save!
+ expect(price.versions.size).to be(1)
end
end
- context 'with valid attributes' do
- before :all do
- @account = Fabricate(:account)
- end
+ describe 'registrar validation', db: false do
+ subject(:account) { described_class.new }
- 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 'rejects absent' do
+ account.registrar = nil
+ account.validate
+ expect(account.errors).to have_key(:registrar)
end
end
end
diff --git a/spec/models/billing/price_spec.rb b/spec/models/billing/price_spec.rb
index 7ee2277cc..2854fb6b6 100644
--- a/spec/models/billing/price_spec.rb
+++ b/spec/models/billing/price_spec.rb
@@ -2,18 +2,9 @@ require 'rails_helper'
RSpec.describe Billing::Price do
it { is_expected.to monetize(:price) }
- it { is_expected.to be_versioned }
it { is_expected.to alias_attribute(:effect_time, :valid_from) }
it { is_expected.to alias_attribute(:expire_time, :valid_to) }
- 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 operation categories' do
categories = %w[create renew]
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