Skip to content

Commit

Permalink
Adapt specs to new address fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kronn committed Jun 3, 2024
1 parent b5063cb commit 7d3128b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
15 changes: 8 additions & 7 deletions spec/domain/person/address_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2021, Die Mitte Schweiz. This file is part of
# Copyright (c) 2021-2024, Die Mitte Schweiz. This file is part of
# hitobito_die_mitte and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_die_mitte.
Expand All @@ -14,35 +14,36 @@
person.update(
first_name: 'John',
last_name: 'Doe',
address: 'address',
street: 'address',
housenumber: '23',
zip_code: '0000',
town: 'towntown',
household_key: 'my-test-household-key'
)
end

it 'handles a single person' do
expect(address.for_household_letter([person])).to eq "John Doe\naddress\n0000 towntown\n"
expect(address.for_household_letter([person])).to eq "John Doe\naddress 23\n0000 towntown\n"
end

it 'handles two people with the same last name' do
person2 = Fabricate(:person, first_name: 'Jane', last_name: person.last_name, household_key: person.household_key)

expect(address.for_household_letter([person, person2])).to eq "John und Jane Doe\naddress\n0000 towntown\n"
expect(address.for_household_letter([person, person2])).to eq "John und Jane Doe\naddress 23\n0000 towntown\n"
end

it 'handles two people with different last name' do
person2 = Fabricate(:person, first_name: 'Jane', last_name: 'Foo', household_key: person.household_key)

expect(address.for_household_letter([person, person2])).to eq "John Doe\nJane Foo\naddress\n0000 towntown\n"
expect(address.for_household_letter([person, person2])).to eq "John Doe\nJane Foo\naddress 23\n0000 towntown\n"
end

it 'prefers people with complete name' do
person2 = Fabricate(:person, first_name: '', last_name: 'Bar', household_key: person.household_key)
person3 = Fabricate(:person, first_name: 'Alanis', last_name: '', household_key: person.household_key)
person4 = Fabricate(:person, first_name: 'Jane', last_name: 'Foo', household_key: person.household_key)

expect(address.for_household_letter([person, person2, person3, person4])).to eq "John Doe\nJane Foo\naddress\n0000 towntown\n"
expect(address.for_household_letter([person, person2, person3, person4])).to eq "John Doe\nJane Foo\naddress 23\n0000 towntown\n"
end

it 'prefers the most used last name' do
Expand All @@ -51,7 +52,7 @@
person4 = Fabricate(:person, first_name: 'Charlotte', last_name: 'Baz', household_key: person.household_key)
person5 = Fabricate(:person, first_name: 'Daniel', last_name: 'Baz', household_key: person.household_key)

expect(address.for_household_letter([person, person2, person3, person4, person5])).to eq "Betty und Charlotte Baz\naddress\n0000 towntown\n"
expect(address.for_household_letter([person, person2, person3, person4, person5])).to eq "Betty und Charlotte Baz\naddress 23\n0000 towntown\n"
end

end
7 changes: 4 additions & 3 deletions spec/jobs/export/message_job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2021, Die Mitte Schweiz. This file is part of
# Copyright (c) 2021-2024, Die Mitte Schweiz. This file is part of
# hitobito_die_mitte and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_die_mitte.
Expand Down Expand Up @@ -31,7 +31,7 @@
.create!(mailing_list: mailing_lists(:list),
body: 'Lorem ipsum',
subject: 'A Sunny Day')
end
end

before do
create_invoice(person1)
Expand All @@ -47,7 +47,8 @@
person4.update(household_key: 'asdf-asdf-asdf-asdf')
person2.update(
household_key: person4.household_key,
address: person4.address,
street: person4.street,
housenumber: person4.housenumber,
zip_code: person4.zip_code,
town: person4.town
)
Expand Down
5 changes: 4 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# frozen_string_literal: true

# Copyright (c) 2021, Die Mitte. This file is part of
# Copyright (c) 2021-2024, Die Mitte. This file is part of
# hitobito_die_mitte and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_die_mitte.

ENV['RAILS_STRUCTURED_ADDRESSES'] = '1'
ENV['RAILS_ADDRESS_MIGRATION'] = '0'

load File.expand_path('../../app_root.rb', __FILE__)
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

Expand Down

0 comments on commit 7d3128b

Please sign in to comment.