Merge branch 'master' of github.com:domify/registry

This commit is contained in:
Priit Tark 2015-07-03 13:47:30 +03:00
commit 2eece9301a
6 changed files with 61 additions and 51 deletions

View file

@ -18,16 +18,18 @@ class Epp::DomainsController < EppController
render_epp_response '/epp/domains/info'
end
# rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/CyclomaticComplexity
def create
authorize! :create, Epp::Domain
@domain = Epp::Domain.new_from_epp(params[:parsed_frame], current_user)
@domain.valid?
handle_errors(@domain) and return if @domain.errors.any?
handle_errors(@domain) and return if @domain.valid? && @domain.errors.any?
handle_errors and return unless balance_ok?('create')
ActiveRecord::Base.transaction do
if @domain.save
if @domain.save # TODO: Maybe use validate: false here because we have already validated the domain?
current_user.registrar.debit!(@domain_price, "#{I18n.t('create')} #{@domain.name}")
render_epp_response '/epp/domains/create'
else
@ -35,6 +37,8 @@ class Epp::DomainsController < EppController
end
end
end
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity
def update
authorize! :update, @domain, @password

View file

@ -0,0 +1,5 @@
class IncreasePrecisionOfPricelist < ActiveRecord::Migration
def change
change_column :pricelists, :price_cents, :decimal, precision: 10, scale: 2
end
end

View file

@ -74,7 +74,7 @@ CREATE FUNCTION generate_zonefile(i_origin character varying) RETURNS text
SELECT concat(d.name_puny, '. IN NS ', ns.hostname, '.')
FROM domains d
JOIN nameservers ns ON ns.domain_id = d.id
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter OR d.name = i_origin
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter
ORDER BY d.name
),
chr(10)
@ -2366,7 +2366,7 @@ CREATE TABLE pricelists (
id integer NOT NULL,
"desc" character varying,
category character varying,
price_cents numeric(8,2) DEFAULT 0.0 NOT NULL,
price_cents numeric(10,2) DEFAULT 0.0 NOT NULL,
price_currency character varying DEFAULT 'EUR'::character varying NOT NULL,
valid_from timestamp without time zone,
valid_to timestamp without time zone,
@ -2404,8 +2404,8 @@ ALTER SEQUENCE pricelists_id_seq OWNED BY pricelists.id;
CREATE TABLE que_jobs (
priority smallint DEFAULT 100 NOT NULL,
run_at timestamp with time zone DEFAULT now() NOT NULL,
job_id bigint NOT NULL,
run_at timestamp without time zone DEFAULT '2015-06-30 14:16:50.905537'::timestamp without time zone NOT NULL,
job_id bigint DEFAULT 0 NOT NULL,
job_class text NOT NULL,
args json DEFAULT '[]'::json NOT NULL,
error_count integer DEFAULT 0 NOT NULL,
@ -2414,32 +2414,6 @@ CREATE TABLE que_jobs (
);
--
-- Name: TABLE que_jobs; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON TABLE que_jobs IS '3';
--
-- Name: que_jobs_job_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE que_jobs_job_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: que_jobs_job_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE que_jobs_job_id_seq OWNED BY que_jobs.job_id;
--
-- Name: registrant_verifications; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
@ -3195,13 +3169,6 @@ ALTER TABLE ONLY people ALTER COLUMN id SET DEFAULT nextval('people_id_seq'::reg
ALTER TABLE ONLY pricelists ALTER COLUMN id SET DEFAULT nextval('pricelists_id_seq'::regclass);
--
-- Name: job_id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY que_jobs ALTER COLUMN job_id SET DEFAULT nextval('que_jobs_job_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
@ -3721,14 +3688,6 @@ ALTER TABLE ONLY pricelists
ADD CONSTRAINT pricelists_pkey PRIMARY KEY (id);
--
-- Name: que_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY que_jobs
ADD CONSTRAINT que_jobs_pkey PRIMARY KEY (queue, priority, run_at, job_id);
--
-- Name: registrant_verifications_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
@ -4855,3 +4814,5 @@ INSERT INTO schema_migrations (version) VALUES ('20150703074448');
INSERT INTO schema_migrations (version) VALUES ('20150703090039');
INSERT INTO schema_migrations (version) VALUES ('20150703084632');

View file

@ -19,11 +19,24 @@ describe 'EPP Domain', epp: true do
Fabricate(:contact, code: 'FIXED:JURIDICAL_1234', ident_type: 'bic')
Fabricate(:reserved_domain)
Fabricate(:blocked_domain)
Fabricate(:pricelist)
Fabricate(:pricelist, valid_to: nil)
@uniq_no = proc { @i ||= 0; @i += 1 }
end
it 'should return error if balance low' do
f = Fabricate(:pricelist, valid_to: Time.zone.now + 1.day, price: 100000)
dn = next_domain_name
response = epp_plain_request(domain_create_xml({
name: { value: dn }
}))
response[:msg].should == "Billing failure - credit balance low"
response[:result_code].should == '2104'
f.delete
end
it 'returns error if contact does not exists' do
response = epp_plain_request(domain_create_xml({
registrant: { value: 'FIXED:CITIZEN_1234' },
@ -325,15 +338,24 @@ describe 'EPP Domain', epp: true do
end
it 'creates a domain with period in days' do
old_balance = @registrar1.balance
old_activities = @registrar1.cash_account.account_activities.count
xml = domain_create_xml(period_value: 365, period_unit: 'd')
response = epp_plain_request(xml)
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
Domain.first.valid_to.should be_within(60).of(1.year.since)
Domain.last.valid_to.should be_within(60).of(1.year.since)
@registrar1.balance.should be < old_balance
@registrar1.cash_account.account_activities.count.should == old_activities + 1
a = @registrar1.cash_account.account_activities.last
a.description.should == "Create #{Domain.last.name}"
a.sum.should == -BigDecimal.new('10.0')
end
it 'does not create a domain with invalid period' do
old_balance = @registrar1.balance
old_activities = @registrar1.cash_account.account_activities.count
xml = domain_create_xml({
period: { value: '367', attrs: { unit: 'd' } }
})
@ -342,6 +364,8 @@ describe 'EPP Domain', epp: true do
response[:results][0][:result_code].should == '2306'
response[:results][0][:msg].should == 'Period must add up to 1, 2 or 3 years [period]'
response[:results][0][:value].should == '367'
@registrar1.balance.should == old_balance
@registrar1.cash_account.account_activities.count.should == old_activities
end
it 'creates a domain with multiple dnskeys' do

View file

@ -55,7 +55,7 @@ describe Pricelist do
end
it 'should have name' do
@pricelist.name.should == 'new .ee'
@pricelist.name.should == 'create ee'
end
it 'should have one version' do

View file

@ -144,5 +144,21 @@ describe Registrar do
it 'should not have priv contacts' do
@registrar.priv_contacts.size.should == 0
end
it 'should credit and debit registrar cash account' do
@registrar.credit!(13.32, 'Add money')
@registrar.balance.should == BigDecimal.new('13.32')
@registrar.cash_account.account_activities.count.should == 1
a = @registrar.cash_account.account_activities.last
a.description.should == 'Add money'
a.sum.should == BigDecimal.new('13.32')
@registrar.debit!(10.31, 'Remove money')
@registrar.balance.should == BigDecimal.new('3.01')
@registrar.cash_account.account_activities.count.should == 2
a = @registrar.cash_account.account_activities.last
a.description.should == 'Remove money'
a.sum.should == -BigDecimal.new('10.31')
end
end
end