From e4bddd88d8e5441b37ee74ad674eab537ad963bf Mon Sep 17 00:00:00 2001 From: Daniel Illi Date: Mon, 16 Sep 2024 20:34:48 +0200 Subject: [PATCH 1/2] Add explicit #start_on/#end_on to Role, remove FutureRole, Role#delete_on (#88) fixes hitobito/hitobito#2775 --- spec/domain/people/cleanup_finder_spec.rb | 113 ++++++++++++---------- 1 file changed, 60 insertions(+), 53 deletions(-) diff --git a/spec/domain/people/cleanup_finder_spec.rb b/spec/domain/people/cleanup_finder_spec.rb index c4d38ac..76bbf7d 100644 --- a/spec/domain/people/cleanup_finder_spec.rb +++ b/spec/domain/people/cleanup_finder_spec.rb @@ -5,45 +5,52 @@ # or later. See the COPYING file at the top-level directory or at # https://github.com/hitobito/hitobito_youth. -require 'spec_helper' +require "spec_helper" describe People::CleanupFinder do - let(:people_without_roles) { 3.times.map { Fabricate(:person) } } - let(:people_with_expired_roles) { 3.times.map { Fabricate(Group::BottomGroup::Member.name.to_sym, - group: groups(:bottom_group_one_one), - created_at: 11.months.ago, - deleted_at: 10.months.ago).person } } - let(:people_with_roles) { 3.times.map { Fabricate(Group::BottomGroup::Member.name.to_sym, - group: groups(:bottom_group_one_one)).person } } + let(:people_with_expired_roles) { + 3.times.map { + Fabricate(Group::BottomGroup::Member.name.to_sym, + group: groups(:bottom_group_one_one), + start_on: 11.months.ago, + end_on: 10.months.ago).person + } + } + let(:people_with_roles) { + 3.times.map { + Fabricate(Group::BottomGroup::Member.name.to_sym, + group: groups(:bottom_group_one_one)).person + } + } subject { People::CleanupFinder.new.run } - context '#run' do - context 'people with expired roles outside cutoff duration' do + context "#run" do + context "people with expired roles outside cutoff duration" do let!(:people) { people_with_expired_roles } before do expect(Settings.people.cleanup_cutoff_duration).to receive(:regarding_roles).and_return(9) end - - context 'with people_manageds' do + + context "with people_manageds" do before do people.each do |p| p.manageds = [Fabricate(:person)] end end - context 'with current_sign_in_at outside cutoff duration' do + context "with current_sign_in_at outside cutoff duration" do before do expect(Settings.people.cleanup_cutoff_duration).to receive(:regarding_current_sign_in_at).and_return(12) people.each { |p| p.update!(current_sign_in_at: 13.months.ago) } end - it 'does not find them' do + it "does not find them" do expect(subject).to_not match_array(people) end - it 'does not find them with event participation in the future' do + it "does not find them with event participation in the future" do event = Fabricate(:event, dates: [Event::Date.new(start_at: 10.days.from_now)]) people.each do |p| Event::Participation.create!(event: event, person: p) @@ -52,7 +59,7 @@ expect(subject).to_not match_array(people) end - it 'does not find them with event participation in the past' do + it "does not find them with event participation in the past" do event = Fabricate(:event, dates: [Event::Date.new(start_at: 10.days.ago)]) people.each do |p| Event::Participation.create!(event: event, person: p) @@ -62,42 +69,42 @@ end end - context 'with current_sign_in_at nil' do + context "with current_sign_in_at nil" do before do expect(Settings.people.cleanup_cutoff_duration).to receive(:regarding_current_sign_in_at).and_return(12) people.each { |p| p.update!(current_sign_in_at: nil) } end - it 'does not finds them' do + it "does not finds them" do expect(subject).to_not match_array(people) end end - context 'with current_sign_in_at inside cutoff duration' do + context "with current_sign_in_at inside cutoff duration" do before do expect(Settings.people.cleanup_cutoff_duration).to receive(:regarding_current_sign_in_at).and_return(12) people.each { |p| p.update!(current_sign_in_at: 11.months.ago) } end - it 'does not find them' do + it "does not find them" do expect(subject).to_not match_array(people) end end end - context 'without people_manageds' do - context 'with current_sign_in_at outside cutoff duration' do + context "without people_manageds" do + context "with current_sign_in_at outside cutoff duration" do before do expect(Settings.people.cleanup_cutoff_duration).to receive(:regarding_current_sign_in_at).and_return(12) people.each { |p| p.update!(current_sign_in_at: 13.months.ago) } end - it 'finds them' do + it "finds them" do expect(subject).to match_array(people) end - it 'does not find them with event participation in the future' do + it "does not find them with event participation in the future" do event = Fabricate(:event, dates: [Event::Date.new(start_at: 10.days.from_now)]) people.each do |p| Event::Participation.create!(event: event, person: p) @@ -106,7 +113,7 @@ expect(subject).to_not match_array(people) end - it 'finds them with event participation in the past' do + it "finds them with event participation in the past" do event = Fabricate(:event, dates: [Event::Date.new(start_at: 10.days.ago)]) people.each do |p| Event::Participation.create!(event: event, person: p) @@ -116,60 +123,60 @@ end end - context 'with current_sign_in_at nil' do + context "with current_sign_in_at nil" do before do expect(Settings.people.cleanup_cutoff_duration).to receive(:regarding_current_sign_in_at).and_return(12) people.each { |p| p.update!(current_sign_in_at: nil) } end - it 'finds them' do + it "finds them" do expect(subject).to match_array(people) end end - context 'with current_sign_in_at inside cutoff duration' do + context "with current_sign_in_at inside cutoff duration" do before do expect(Settings.people.cleanup_cutoff_duration).to receive(:regarding_current_sign_in_at).and_return(12) people.each { |p| p.update!(current_sign_in_at: 11.months.ago) } end - it 'does not find them' do + it "does not find them" do expect(subject).to_not match_array(people) end end end end - context 'people with expired roles inside cutoff duration' do + context "people with expired roles inside cutoff duration" do let!(:people) { people_with_expired_roles } before do expect(Settings.people.cleanup_cutoff_duration).to receive(:regarding_roles).and_return(12) end - context 'with people_manageds' do + context "with people_manageds" do before do people.each do |p| p.manageds = [Fabricate(:person)] end end - context 'with current_sign_in_at outside cutoff duration' do + context "with current_sign_in_at outside cutoff duration" do before do expect(Settings.people.cleanup_cutoff_duration).to receive(:regarding_current_sign_in_at).and_return(12) people.each { |p| p.update!(current_sign_in_at: 13.months.ago) } end - it 'does not find them' do + it "does not find them" do expect(subject).to_not match_array(people) end - it 'does not find them' do + it "does not find them" do expect(subject).to_not match_array(people) end - it 'does not find them with event participation in the future' do + it "does not find them with event participation in the future" do event = Fabricate(:event, dates: [Event::Date.new(start_at: 10.days.from_now)]) people.each do |p| Event::Participation.create!(event: event, person: p) @@ -178,7 +185,7 @@ expect(subject).to_not match_array(people) end - it 'does not find them with event participation in the past' do + it "does not find them with event participation in the past" do event = Fabricate(:event, dates: [Event::Date.new(start_at: 10.days.ago, finish_at: 5.days.ago)]) people.each do |p| Event::Participation.create!(event: event, person: p) @@ -188,46 +195,46 @@ end end - context 'with current_sign_in_at nil' do + context "with current_sign_in_at nil" do before do expect(Settings.people.cleanup_cutoff_duration).to receive(:regarding_current_sign_in_at).and_return(12) people.each { |p| p.update!(current_sign_in_at: nil) } end - it 'does not find them' do + it "does not find them" do expect(subject).to_not match_array(people) end end - context 'with current_sign_in_at inside cutoff duration' do + context "with current_sign_in_at inside cutoff duration" do before do expect(Settings.people.cleanup_cutoff_duration).to receive(:regarding_current_sign_in_at).and_return(12) people.each { |p| p.update!(current_sign_in_at: 11.months.ago) } end - it 'does not find them' do + it "does not find them" do expect(subject).to_not match_array(people) end end end - context 'without people_manageds' do - context 'with current_sign_in_at outside cutoff duration' do + context "without people_manageds" do + context "with current_sign_in_at outside cutoff duration" do before do expect(Settings.people.cleanup_cutoff_duration).to receive(:regarding_current_sign_in_at).and_return(12) people.each { |p| p.update!(current_sign_in_at: 13.months.ago) } end - it 'does not find them' do + it "does not find them" do expect(subject).to_not match_array(people) end - it 'does not find them' do + it "does not find them" do expect(subject).to_not match_array(people) end - it 'does not find them with event participation in the future' do + it "does not find them with event participation in the future" do event = Fabricate(:event, dates: [Event::Date.new(start_at: 10.days.from_now)]) people.each do |p| Event::Participation.create!(event: event, person: p) @@ -236,7 +243,7 @@ expect(subject).to_not match_array(people) end - it 'does not find them with event participation in the past' do + it "does not find them with event participation in the past" do event = Fabricate(:event, dates: [Event::Date.new(start_at: 10.days.ago, finish_at: 5.days.ago)]) people.each do |p| Event::Participation.create!(event: event, person: p) @@ -246,40 +253,40 @@ end end - context 'with current_sign_in_at nil' do + context "with current_sign_in_at nil" do before do expect(Settings.people.cleanup_cutoff_duration).to receive(:regarding_current_sign_in_at).and_return(12) people.each { |p| p.update!(current_sign_in_at: nil) } end - it 'does not find them' do + it "does not find them" do expect(subject).to_not match_array(people) end end - context 'with current_sign_in_at inside cutoff duration' do + context "with current_sign_in_at inside cutoff duration" do before do expect(Settings.people.cleanup_cutoff_duration).to receive(:regarding_current_sign_in_at).and_return(12) people.each { |p| p.update!(current_sign_in_at: 11.months.ago) } end - it 'does not find them' do + it "does not find them" do expect(subject).to_not match_array(people) end end end end - context 'with people_manageds' do - it 'does not find people without any roles' do + context "with people_manageds" do + it "does not find people without any roles" do people_without_roles.each do |p| p.manageds += [Fabricate(:person)] end expect(subject).to_not match_array(people_without_roles) end - it 'does not find people with active roles' do + it "does not find people with active roles" do people_with_roles.each do |p| p.manageds += [Fabricate(:person)] end From 81daf643bcd58c096ba5473be05161e00d56ca10 Mon Sep 17 00:00:00 2001 From: Daniel Illi Date: Tue, 17 Sep 2024 11:24:01 +0200 Subject: [PATCH 2/2] Remove superfluous order statement, the relation is already ordered --- app/controllers/youth/event/lists_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/youth/event/lists_controller.rb b/app/controllers/youth/event/lists_controller.rb index 4eb12f3..2a8bb03 100644 --- a/app/controllers/youth/event/lists_controller.rb +++ b/app/controllers/youth/event/lists_controller.rb @@ -54,7 +54,6 @@ def courses_for_bsv_export course_filters .to_scope .includes(participations: [:roles, person: :location]) - .order("start_at") end def dates_from_to