internetee-registry/spec/models/whois_record_spec.rb
Artur Beljajev 2da578a437 Migrate fabricators to factory bot factories (#626)
* Remove factory_girl include from dev rake task

No longer needed after 92b125b4a7

* Add missing factories

* Use FactoryBot factories instead of fabricators

* Remove all fabricators

* Remove unused method

* Remove fabrication gem

* Rename FactoryGirl to FactoryBot

https://robots.thoughtbot.com/factory_bot
2017-11-16 10:18:53 +02:00

67 lines
1.9 KiB
Ruby

require 'rails_helper'
RSpec.describe WhoisRecord do
describe '::generate_json', db: false do
let(:registrant) { build_stubbed(:registrant) }
let(:domain) { build_stubbed(:domain, registrant: registrant) }
let(:whois_record) { described_class.new }
subject(:generated_json) { whois_record.generate_json }
before do
allow(whois_record).to receive(:domain).and_return(domain)
end
it 'generates registrant kind' do
expect(registrant).to receive(:kind).and_return('test kind')
expect(generated_json[:registrant_kind]).to eq('test kind')
end
describe 'reg no' do
subject(:reg_no) { generated_json[:registrant_reg_no] }
before do
allow(registrant).to receive(:reg_no).and_return('test reg no')
end
context 'when registrant is legal entity' do
let(:registrant) { build_stubbed(:registrant_legal_entity) }
it 'is present' do
expect(reg_no).to eq('test reg no')
end
end
context 'when registrant is private entity' do
let(:registrant) { build_stubbed(:registrant_private_entity) }
it 'is absent' do
expect(reg_no).to be_nil
end
end
end
describe 'country code' do
subject(:country_code) { generated_json[:registrant_ident_country_code] }
before do
allow(registrant).to receive(:ident_country_code).and_return('test country code')
end
context 'when registrant is legal entity' do
let(:registrant) { build_stubbed(:registrant_legal_entity) }
it 'is present' do
expect(country_code).to eq('test country code')
end
end
context 'when registrant is private entity' do
let(:registrant) { build_stubbed(:registrant_private_entity) }
it 'is absent' do
expect(country_code).to be_nil
end
end
end
end
end