2018-11-30 19:40:34 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe ConfirmPassport do
|
2018-12-01 21:28:34 -05:00
|
|
|
subject { described_class.call passport: passport, account: account }
|
2018-11-30 19:40:34 -05:00
|
|
|
|
2018-12-02 11:44:02 -05:00
|
|
|
let!(:passport) { create :passport_with_passport_map_and_image }
|
2018-12-02 05:38:22 -05:00
|
|
|
let!(:account) { create :account_with_user }
|
2018-11-30 19:40:34 -05:00
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject).to be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
2018-12-01 21:28:34 -05:00
|
|
|
expect(subject).to have_attributes passport: passport, account: account
|
2018-11-30 19:40:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject.passport_confirmation).to be_instance_of PassportConfirmation
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject.passport_confirmation).to \
|
2018-12-01 21:28:34 -05:00
|
|
|
have_attributes passport: passport, account: account
|
2018-11-30 19:40:34 -05:00
|
|
|
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-02 11:44:02 -05:00
|
|
|
context 'when passport is empty' do
|
|
|
|
let!(:passport) { create :empty_passport }
|
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,
|
2018-12-01 21:28:34 -05:00
|
|
|
account: account,
|
2018-12-01 06:05:50 -05:00
|
|
|
passport_confirmation: nil,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-02 11:44:02 -05:00
|
|
|
context 'when passport has a passport map' do
|
|
|
|
let!(:passport) { create :passport_with_passport_map }
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject).to be_failure
|
2018-11-30 19:40:34 -05:00
|
|
|
end
|
|
|
|
|
2018-12-02 11:44:02 -05:00
|
|
|
specify do
|
|
|
|
expect(subject).to have_attributes(
|
|
|
|
passport: passport,
|
|
|
|
account: account,
|
|
|
|
passport_confirmation: nil,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when passport has an image' do
|
|
|
|
let!(:passport) { create :passport_with_image }
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject).to be_failure
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject).to have_attributes(
|
|
|
|
passport: passport,
|
|
|
|
account: account,
|
|
|
|
passport_confirmation: nil,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when passport has a passport map and an image' do
|
|
|
|
let!(:passport) { create :passport_with_passport_map_and_image }
|
|
|
|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when passport has almost enough confirmations' do
|
|
|
|
let!(:passport) { create :passport_with_almost_enough_confirmations }
|
|
|
|
|
2018-11-30 19:40:34 -05:00
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2018-12-02 11:44:02 -05:00
|
|
|
context 'when passport has enough confirmationsh' do
|
|
|
|
let!(:passport) { create :passport_with_enough_confirmations }
|
2018-11-30 19:40:34 -05:00
|
|
|
|
|
|
|
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
|
2018-12-02 11:44:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when passport is already confimed' do
|
|
|
|
let!(:passport) { create :confirmed_passport }
|
2018-11-30 19:40:34 -05:00
|
|
|
|
2018-12-02 11:44:02 -05:00
|
|
|
specify do
|
|
|
|
expect { subject }.to \
|
|
|
|
change { passport.reload.passport_confirmations.count }
|
|
|
|
.from(Passport::REQUIRED_CONFIRMATIONS)
|
|
|
|
.to(Passport::REQUIRED_CONFIRMATIONS + 1)
|
|
|
|
end
|
2018-11-30 19:40:34 -05:00
|
|
|
|
2018-12-02 11:44:02 -05:00
|
|
|
specify do
|
|
|
|
expect { subject }.not_to \
|
|
|
|
change { passport.reload.confirmed? }.from(true)
|
2018-11-30 19:40:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|