Commit 2fc9f1e9 authored by Jiri Strojil's avatar Jiri Strojil

Merge branch 'features/uniq-semesters' into 'develop'

Features/uniq semesters

See merge request !887
parents 63f74e35 ebbb8b93
Pipeline #32627 passed with stage
in 48 minutes and 6 seconds
......@@ -36,6 +36,10 @@ class Semester
MONTH_NUMBER_MAP[date.month]
end
def taken_semesters
SemesterProcess.all.pluck(:semester)
end
def year(date = nil)
date = to_process_date(date)
date.month == 12 ? date.year + 1 : date.year
......@@ -77,7 +81,7 @@ class Semester
def semester_range_from_start(date_time)
date_time = date_time.to_date
date_time..date_time.advance(months: 5).end_of_month
date_time...date_time.advance(months: 5).end_of_month
end
end
......@@ -155,6 +159,17 @@ class Semester
def collection(count = 3, direction: :previous, with_current: true)
list(count, direction: direction, with_current: with_current).map do |semester|
if block_given?
yield semester
else
[Semester.i18n_t(semester, short: false), to_s(semester)]
end
end.compact
end
def unique_collection(count = 3)
collection(count) do |semester|
next if Semester.taken_semesters.include?(semester)
[Semester.i18n_t(semester, short: false), to_s(semester)]
end
end
......
......@@ -3,7 +3,7 @@
= f.input_field :kind, value: @semester_process.kind, as: :hidden
.row:.col-xs-12.col-md-4
= f.input :semester, collection: @semester&.collection || [Semester.i18n_t(@semester_process.semester, short: false)],
= f.input :semester, collection: @semester&.unique_collection || [Semester.i18n_t(@semester_process.semester, short: false)],
selected: params[:semester], input_html: { class: 'semester-selector' }, disabled: !@semester
.row
......@@ -33,4 +33,4 @@
td= l(fv.object.volunteer.accepted_at.to_date) if fv.object.volunteer.accepted_at
.row:.col-xs-12
= f.button :submit
= f.button :submit, disabled: @semester && @semester.unique_collection.empty?
......@@ -48,31 +48,31 @@ class SemesterServiceTest < ActionView::TestCase
test '#current' do
travel_to time_z(2018, 8, 10)
subject = Semester.new
assert_equal time_z(2018, 6, 1).to_date..time_z(2018, 11, 1).end_of_month.to_date, subject.current
assert_equal time_z(2018, 6, 1).to_date...time_z(2018, 11, 1).end_of_month.to_date, subject.current
subject = Semester.new(2017, 2)
assert_equal time_z(2017, 6, 1).to_date..time_z(2017, 11, 1).end_of_month.to_date, subject.current
assert_equal time_z(2017, 6, 1).to_date...time_z(2017, 11, 1).end_of_month.to_date, subject.current
subject = Semester.new(2017, 1)
assert_equal time_z(2016, 12, 1).to_date..time_z(2017, 5, 1).end_of_month.to_date, subject.current
assert_equal time_z(2016, 12, 1).to_date...time_z(2017, 5, 1).end_of_month.to_date, subject.current
end
test '#previous' do
travel_to time_z(2018, 8, 10)
subject = Semester.new
assert_equal time_z(2017, 12, 1).to_date..time_z(2018, 5, 1).end_of_month.to_date, subject.previous
assert_equal time_z(2017, 6, 1).to_date..time_z(2017, 11, 1).end_of_month.to_date, subject.previous(2)
assert_equal time_z(2016, 12, 1).to_date..time_z(2017, 5, 1).end_of_month.to_date, subject.previous(3)
assert_equal time_z(2017, 12, 1).to_date...time_z(2018, 5, 1).end_of_month.to_date, subject.previous
assert_equal time_z(2017, 6, 1).to_date...time_z(2017, 11, 1).end_of_month.to_date, subject.previous(2)
assert_equal time_z(2016, 12, 1).to_date...time_z(2017, 5, 1).end_of_month.to_date, subject.previous(3)
end
test '#next_semester' do
travel_to time_z(2018, 8, 10)
subject = Semester.new
assert_equal time_z(2018, 12, 1).to_date..time_z(2019, 5, 1).end_of_month.to_date, subject.next_semester
assert_equal time_z(2019, 6, 1).to_date..time_z(2019, 11, 1).end_of_month.to_date, subject.next_semester(2)
assert_equal time_z(2019, 12, 1).to_date..time_z(2020, 5, 1).end_of_month.to_date, subject.next_semester(3)
assert_equal time_z(2018, 12, 1).to_date...time_z(2019, 5, 1).end_of_month.to_date, subject.next_semester
assert_equal time_z(2019, 6, 1).to_date...time_z(2019, 11, 1).end_of_month.to_date, subject.next_semester(2)
assert_equal time_z(2019, 12, 1).to_date...time_z(2020, 5, 1).end_of_month.to_date, subject.next_semester(3)
end
test '#previous_s' do
......@@ -98,29 +98,29 @@ class SemesterServiceTest < ActionView::TestCase
subject = Semester.new
assert_equal [
time_z(2018, 6, 1).to_date..time_z(2018, 11, 1).end_of_month.to_date,
time_z(2017, 12, 1).to_date..time_z(2018, 5, 1).end_of_month.to_date,
time_z(2017, 6, 1).to_date..time_z(2017, 11, 1).end_of_month.to_date,
time_z(2016, 12, 1).to_date..time_z(2017, 5, 1).end_of_month.to_date
time_z(2018, 6, 1).to_date...time_z(2018, 11, 1).end_of_month.to_date,
time_z(2017, 12, 1).to_date...time_z(2018, 5, 1).end_of_month.to_date,
time_z(2017, 6, 1).to_date...time_z(2017, 11, 1).end_of_month.to_date,
time_z(2016, 12, 1).to_date...time_z(2017, 5, 1).end_of_month.to_date
], subject.list
assert_equal [
time_z(2018, 6, 1).to_date..time_z(2018, 11, 1).end_of_month.to_date,
time_z(2017, 12, 1).to_date..time_z(2018, 5, 1).end_of_month.to_date,
time_z(2017, 6, 1).to_date..time_z(2017, 11, 1).end_of_month.to_date
time_z(2018, 6, 1).to_date...time_z(2018, 11, 1).end_of_month.to_date,
time_z(2017, 12, 1).to_date...time_z(2018, 5, 1).end_of_month.to_date,
time_z(2017, 6, 1).to_date...time_z(2017, 11, 1).end_of_month.to_date
], subject.list(2)
assert_equal [
time_z(2017, 12, 1).to_date..time_z(2018, 5, 1).end_of_month.to_date,
time_z(2017, 6, 1).to_date..time_z(2017, 11, 1).end_of_month.to_date,
time_z(2016, 12, 1).to_date..time_z(2017, 5, 1).end_of_month.to_date
time_z(2017, 12, 1).to_date...time_z(2018, 5, 1).end_of_month.to_date,
time_z(2017, 6, 1).to_date...time_z(2017, 11, 1).end_of_month.to_date,
time_z(2016, 12, 1).to_date...time_z(2017, 5, 1).end_of_month.to_date
], subject.list(with_current: false)
assert_equal [
time_z(2018, 6, 1).to_date..time_z(2018, 11, 1).end_of_month.to_date,
time_z(2018, 12, 1).to_date..time_z(2019, 5, 1).end_of_month.to_date,
time_z(2019, 6, 1).to_date..time_z(2019, 11, 1).end_of_month.to_date,
time_z(2019, 12, 1).to_date..time_z(2020, 5, 1).end_of_month.to_date
time_z(2018, 6, 1).to_date...time_z(2018, 11, 1).end_of_month.to_date,
time_z(2018, 12, 1).to_date...time_z(2019, 5, 1).end_of_month.to_date,
time_z(2019, 6, 1).to_date...time_z(2019, 11, 1).end_of_month.to_date,
time_z(2019, 12, 1).to_date...time_z(2020, 5, 1).end_of_month.to_date
], subject.list(direction: :next_semester)
end
......
......@@ -28,6 +28,6 @@ class SemesterProcessVolunteersTest < ApplicationSystemTestCase
click_button "Semester: #{@current_semester.collection.second[1]}", match: :first
click_link @three_semesters_back.semester_t
click_on 'Neuen Semester Prozess erstellen', match: :first
assert page.has_select? 'Semester', selected: @current_semester.collection.last[0]
assert page.has_select? 'Semester', selected: @current_semester.unique_collection.last[0]
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment