1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/spec/interactors/confirm_passport_spec.rb

95 lines
2.3 KiB
Ruby
Raw Normal View History

2018-11-30 19:40:34 -05:00
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe ConfirmPassport do
subject { described_class.call passport: passport, user: user }
let!(:passport) { create :passport }
let!(:user) { create :user }
specify do
expect(subject).to be_success
end
specify do
expect(subject).to have_attributes passport: passport, user: user
end
specify do
expect(subject.passport_confirmation).to be_instance_of PassportConfirmation
end
specify do
expect(subject.passport_confirmation).to \
have_attributes passport: passport, user: user
end
specify do
expect { subject }.to \
change { passport.reload.passport_confirmations.count }.from(0).to(1)
end
specify do
expect { subject }.not_to change { passport.reload.confirmed? }.from(false)
end
context 'when confirmations count is almost enough' do
before do
(Passport::REQUIRED_CONFIRMATIONS - 1).times do
create :passport_confirmation, passport: passport
end
end
specify do
expect { subject }.to \
change { passport.reload.passport_confirmations.count }
.from(Passport::REQUIRED_CONFIRMATIONS - 1)
.to(Passport::REQUIRED_CONFIRMATIONS)
end
specify do
expect { subject }.to \
change { passport.reload.confirmed? }.from(false).to(true)
end
context 'and passport is already confirmed' do
let!(:passport) { create :confirmed_passport }
specify do
expect { subject }.not_to \
change { passport.reload.confirmed? }.from(true)
end
end
end
context 'when confirmations count is already enough' do
before do
Passport::REQUIRED_CONFIRMATIONS.times do
create :passport_confirmation, passport: passport
end
end
specify do
expect { subject }.to \
change { passport.reload.passport_confirmations.count }
.from(Passport::REQUIRED_CONFIRMATIONS)
.to(Passport::REQUIRED_CONFIRMATIONS + 1)
end
specify do
expect { subject }.to \
change { passport.reload.confirmed? }.from(false).to(true)
end
context 'and passport is already confirmed' do
let!(:passport) { create :confirmed_passport }
specify do
expect { subject }.not_to \
change { passport.reload.confirmed? }.from(true)
end
end
end
end