Skip to content

Commit

Permalink
Edit courses relation on academic group
Browse files Browse the repository at this point in the history
  • Loading branch information
mpugach committed Mar 12, 2023
1 parent 42c5c12 commit 9acbd8d
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/select_2_initializers.js.coffee
Expand Up @@ -69,4 +69,5 @@ $ ->
simpleSelect($('select#class_schedule_academic_group_ids'), 'academic_groups')
simpleSelect($('select#class_schedule_classroom_id'), 'classrooms')
simpleSelect($('select#class_schedule_course_id'), 'courses')
simpleSelect($('select#academic_group_course_ids'), 'courses')
simpleSelect($('select#program_questionnaire_ids'), 'questionnaires')
3 changes: 2 additions & 1 deletion app/controllers/academic_groups_controller.rb
Expand Up @@ -81,7 +81,8 @@ def self.filter(params)
:administrator_id,
:praepostor_id,
:curator_id,
:establ_date
:establ_date,
course_ids: []
)
end
end
Expand Down
9 changes: 8 additions & 1 deletion app/policies/course_policy.rb
@@ -1,5 +1,12 @@
class CoursePolicy < BasePolicy
def ui_index?
user.can_act?(%w[class_schedule:edit class_schedule:new])
user.can_act?(
%w[
academic_group:edit
academic_group:new
class_schedule:edit
class_schedule:new
]
)
end
end
5 changes: 5 additions & 0 deletions app/views/academic_groups/_form.html.haml
Expand Up @@ -31,6 +31,11 @@
'ajax--url': ui_group_praepostors_path(group_id: f.object.id) },
disabled: is_group_not_persisted }

= f.association :courses, label_method: :label_for_select, collection: f.object.courses,
hint: t('.courses_hint'),
input_html: { data: { placeholder: t('.courses_placeholder'),
'ajax--url': ui_courses_path } }

~ f.input :message_ru, input_html: { rows: 5 }, hint: t('.message_hint')
~ f.input :message_uk, input_html: { rows: 5 }, hint: t('.message_hint')

Expand Down
1 change: 1 addition & 0 deletions config/locales/active_record.ru.yml
Expand Up @@ -3,6 +3,7 @@ ru:
attributes:
academic_group:
administrator: 'Координатор'
courses: 'Предметы'
curator: 'Куратор'
establ_date: 'Дата создания'
graduated_at: 'Дата окончания'
Expand Down
1 change: 1 addition & 0 deletions config/locales/active_record.uk.yml
Expand Up @@ -3,6 +3,7 @@ uk:
attributes:
academic_group:
administrator: 'Координатор'
courses: 'Предмети'
curator: 'Куратор'
establ_date: 'Дата створення'
graduated_at: 'Дата закінчення'
Expand Down
2 changes: 2 additions & 0 deletions config/locales/general.ru.yml
Expand Up @@ -283,6 +283,8 @@ ru:
praepostor_placeholder: 'Выберите старосту'
message_hint: 'Отображается на странице группы'
disabled_praepostor_hint: 'Старосту можно выбрать, когда в группе появятся студенты'
courses_hint: 'Зачетные работы по этим предметам будут присутствовать на странице отмечания успеваемости группы'
courses_placeholder: 'Выберите связные предметы'
edit:
title: 'Редактирование группы'
submit: 'Сохранить'
Expand Down
2 changes: 2 additions & 0 deletions config/locales/general.uk.yml
Expand Up @@ -283,6 +283,8 @@ uk:
praepostor_placeholder: 'Оберіть старосту'
message_hint: 'Показується на сторінці групи'
disabled_praepostor_hint: "Старосту можна обрати коли у групі з'являться студенти"
courses_hint: 'Залікові роботи з цих предметів будуть присутні на сторінці відмічання успішності групи'
courses_placeholder: "Оберіть пов'язні предмети"
edit:
title: 'Редагування групи'
submit: 'Зберегти'
Expand Down
28 changes: 20 additions & 8 deletions spec/features/academic_groups/edit_academic_group_spec.rb
Expand Up @@ -2,8 +2,18 @@

describe 'Edit academic group:' do
Given(:academic_group) { create :academic_group }
Given(:model_name_locale) { I18n.t('activerecord.models.academic_group') }
Given(:click_save) { click_button I18n.t('academic_groups.edit.submit') }

Given(:expect_to_flash_success) do
expect(find('body')).to(
have_selector(
'.alert-success',
text: I18n.t('flash.academic_groups.update.success', resource_name: model_name_locale)
)
)
end

When { login_as_admin }
When { visit edit_academic_group_path(academic_group) }

Expand Down Expand Up @@ -82,14 +92,6 @@
end

describe 'When values are valid:' do
Given(:model_name_locale) { I18n.t('activerecord.models.academic_group') }

Given(:expect_to_flash_success) do
expect(find('body')).to have_selector('.alert-success',
text: I18n.t('flash.academic_groups.update.success',
resource_name: model_name_locale))
end

[
{
field: I18n.t('activerecord.attributes.academic_group.title'),
Expand Down Expand Up @@ -124,4 +126,14 @@
And { expect_to_flash_success }
end
end

describe 'add courses', :js do
Given(:course) { create :course }

When { select2_multi('academic_group_courses', course.title) }
When { click_save }

Then { expect_to_flash_success }
And { expect(academic_group.reload.course_ids).to eq([course.id]) }
end
end
9 changes: 8 additions & 1 deletion spec/support/shared_examples.rb
Expand Up @@ -403,7 +403,14 @@ def underscore_humanize(str)
end

context 'not permit with all other' do
Given(:permitted_activities) { %w[class_schedule:edit class_schedule:new] }
Given(:permitted_activities) do
%w[
class_schedule:edit
class_schedule:new
academic_group:edit
academic_group:new
]
end

Given { user.roles << [create(:role, activities: all_activities - permitted_activities)] }

Expand Down

0 comments on commit 9acbd8d

Please sign in to comment.