Skip to content

Instantly share code, notes, and snippets.

@yesnik
Last active September 10, 2015 06:41
Show Gist options
  • Save yesnik/0203f05e3a8ae9f0ff5f to your computer and use it in GitHub Desktop.
Save yesnik/0203f05e3a8ae9f0ff5f to your computer and use it in GitHub Desktop.
# 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
# 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