Last active
September 10, 2015 06:41
-
-
Save yesnik/0203f05e3a8ae9f0ff5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
class PayerDecorator < Draper::Decorator | |
delegate_all | |
decorates :payer | |
def inn_unique?(inn) | |
Payer.where { (major_requisite.eq 'INN') & (major_requisite_value.eq inn) & (id.not_eq id) }.exists? | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require 'spec_helper' | |
describe PayerDecorator do | |
describe '#inn_unique?' do | |
subject { payer.decorate.inn_unique?(inn) } | |
let(:inn) { '1231231230' } | |
let(:payer) { create :payer, major_requisite: 'INN', major_requisite_value: inn } | |
before { create :payer, major_requisite: 'INN', major_requisite_value: '1231230000' } | |
context 'when exists only one payer with such inn' do | |
it { expect(subject).to be_true } | |
end | |
context 'when exists two payers with the same inn' do | |
before { create :payer, major_requisite: 'INN', major_requisite_value: inn } | |
it { expect(subject).to be_false } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment