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

111 lines
2.7 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 }
2018-12-01 06:05:50 -05:00
let!(:passport) { create :passport_with_image }
2018-11-30 19:40:34 -05:00
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
2018-12-01 06:05:50 -05:00
context 'when passport has no image' do
let!(:passport) { create :passport_without_image }
2018-12-01 06:05:50 -05:00
specify do
expect(subject).to be_failure
end
specify do
expect(subject).to have_attributes(
passport: passport,
user: user,
passport_confirmation: nil,
)
end
end
2018-11-30 19:40:34 -05:00
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