Skip to content

Commit

Permalink
refactor: specs to use skip validations trait
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwr18 authored and roschaefer committed May 24, 2024
1 parent aaab488 commit 92d6141
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 28 deletions.
2 changes: 1 addition & 1 deletion spec/adapters/threema_adapter/inbound_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe ThreemaAdapter::Inbound do
let(:threema_id) { 'V5EA564T' }
let!(:contributor) { build(:contributor, threema_id: threema_id).tap { |contributor| contributor.save(validate: false) } }
let!(:contributor) { create(:contributor, :skip_validations, threema_id: threema_id) }

let(:adapter) { described_class.new }
let(:threema_message) do
Expand Down
4 changes: 1 addition & 3 deletions spec/adapters/threema_adapter/outbound/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
let(:adapter) { described_class.new }
let(:threema_double) { instance_double(Threema) }
let(:threema_id) { 'V5EA564T' }
let(:contributor) do
build(:contributor, threema_id: threema_id, email: nil).tap { |contributor| contributor.save(validate: false) }
end
let(:contributor) { create(:contributor, :skip_validations, threema_id: threema_id, email: nil) }
let(:message) { create(:message, :with_file, recipient: contributor) }
let(:file_path) { ActiveStorage::Blob.service.path_for(message.files.first.attachment.blob.key) }
let(:expected_params) do
Expand Down
4 changes: 1 addition & 3 deletions spec/adapters/threema_adapter/outbound/text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
RSpec.describe ThreemaAdapter::Outbound::Text do
let(:adapter) { described_class.new }
let(:threema_id) { 'V5EA564T' }
let(:contributor) do
build(:contributor, threema_id: threema_id, email: nil).tap { |contributor| contributor.save(validate: false) }
end
let(:contributor) { create(:contributor, :skip_validations, threema_id: threema_id, email: nil) }
let(:message) { create(:message, recipient: contributor) }
let(:threema_double) { instance_double(Threema) }
let(:threema_lookup_double) { instance_double(Threema::Lookup) }
Expand Down
4 changes: 1 addition & 3 deletions spec/adapters/threema_adapter/outbound_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

RSpec.describe ThreemaAdapter::Outbound do
let(:threema_id) { 'V5EA564T' }
let(:contributor) do
build(:contributor, threema_id: threema_id, email: nil).tap { |contributor| contributor.save(validate: false) }
end
let(:contributor) { create(:contributor, :skip_validations, threema_id: threema_id, email: nil) }
let(:message) { create(:message, recipient: contributor) }

describe '::send!' do
Expand Down
5 changes: 2 additions & 3 deletions spec/components/contributor_channel_settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
RSpec.describe ContributorChannelSettings::ContributorChannelSettings, type: :component do
subject { render_inline(described_class.new(**params)) }

let(:contributor) do
build(:contributor, email: nil, **attrs).tap { |contributor| contributor.save(validate: false) }
end
let(:contributor) { create(:contributor, email: nil, **attrs) }
let(:attrs) { {} }
let(:params) { { contributor: contributor } }

Expand All @@ -24,6 +22,7 @@
end

context 'given a Threema contributor' do
let(:contributor) { create(:contributor, :skip_validations, email: nil, **attrs) }
let(:attrs) { { threema_id: 12_345_678 } }
it { should have_css('h2', text: 'Threema') }
end
Expand Down
11 changes: 6 additions & 5 deletions spec/components/contributor_threema_settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
subject { render_inline(described_class.new(**params)) }

let(:contributor) do
build(:contributor,
first_name: 'Max',
last_name: 'Mustermann',
threema_id: '12345678',
created_at: '2021-01-01').tap { |contributor| contributor.save(validate: false) }
create(:contributor,
:skip_validations,
first_name: 'Max',
last_name: 'Mustermann',
threema_id: '12345678',
created_at: '2021-01-01')
end
let(:params) { { contributor: contributor } }

Expand Down
8 changes: 2 additions & 6 deletions spec/models/contributor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,7 @@
end
end
let(:threema_id) { 'V5EA564T' }
let!(:contributor) do
build(:contributor, threema_id: threema_id).tap { |contributor| contributor.save(validate: false) }
end
let!(:contributor) { create(:contributor, :skip_validations, threema_id: threema_id) }

before do
allow(Threema).to receive(:new).and_return(threema)
Expand Down Expand Up @@ -835,9 +833,7 @@

context 'signed up via threema' do
let(:expected_job_args) { { contributor_id: contributor.id, text: "*Welcome new contributor!*\nYou onboarded successfully." } }
let(:contributor) do
build(:contributor, threema_id: 'AAAAAAAA', email: nil, telegram_id: nil).tap { |contributor| contributor.save(validate: false) }
end
let(:contributor) { create(:contributor, :skip_validations, threema_id: 'AAAAAAAA', email: nil, telegram_id: nil) }
it { should enqueue_job(ThreemaAdapter::Outbound::Text).with(expected_job_args) }
end

Expand Down
4 changes: 2 additions & 2 deletions spec/requests/contributors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
end

context 'given a manually created contributor' do
let(:contributor) { build(:contributor, data_processing_consent: false, first_name: 'John').tap { |c| c.save(validate: false) } }
let(:contributor) { create(:contributor, :skip_validations, data_processing_consent: false, first_name: 'John') }

it 'updates contributor' do
expect { subject.call }.to(change { contributor.reload.first_name }.from('John').to('Zora'))
Expand All @@ -122,7 +122,7 @@
context 'given a Threema contributor' do
let(:threema) { instance_double(Threema) }
let(:threema_lookup_double) { instance_double(Threema::Lookup) }
let(:contributor) { build(:contributor, threema_id: 'VALID123').tap { |contributor| contributor.save(validate: false) } }
let(:contributor) { create(:contributor, :skip_validations, threema_id: 'VALID123') }
let(:new_attrs) { { threema_id: 'INVALID!' } }

before do
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/threema/webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
end

context 'With known contributor' do
let!(:contributor) { build(:contributor, threema_id: 'V5EA564T').tap { |contributor| contributor.save(validate: false) } }
let!(:contributor) { create(:contributor, :skip_validations, threema_id: 'V5EA564T') }
let!(:request) { create(:request) }

before do
Expand Down
2 changes: 1 addition & 1 deletion spec/system/requests/sending_images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
create(:contributor, email: 'adam@example.org')
create(:contributor, signal_phone_number: '+4912345678', signal_onboarding_completed_at: Time.current)
create(:contributor, telegram_id: 125_689)
build(:contributor, threema_id: '12345678').tap { |contributor| contributor.save(validate: false) }
create(:contributor, :skip_validations, threema_id: '12345678')
end

it 'sending a request with image files' do
Expand Down

0 comments on commit 92d6141

Please sign in to comment.