frontend/spec/features/students/course_enrollments_spec.rb in gaku-0.1.1 vs frontend/spec/features/students/course_enrollments_spec.rb in gaku-0.2.0

- old
+ new

@@ -1,39 +1,62 @@ require 'spec_helper' -describe 'Student Course Enrollments' do +describe 'Student course enrollment' do + before(:all) { set_resource 'student-course-enrollment' } before { as :admin } - let(:student) { create(:student) } - let(:course) { create(:course, code: 'fall2050') } + let(:student) { create(:student, name: 'John', surname: 'Doe') } + let(:course) { create(:course) } + let(:course_enrollment) { create(:course_enrollment, student: student, enrollmentable: course) } - before(:all) { set_resource 'student-course-enrollment' } + context 'new', js: true do - context 'new' do before do - @course = course + course visit gaku.edit_student_path(student) - click '#student-academic-tab-link' - @data = student - @select = 'course_enrollment_course_id' - click tab_link + click '#student-courses-menu a' + click new_link end - it_behaves_like 'enroll to course' - end + it 'creates' do + expect do + expect do + select course.code, from: 'enrollment_enrollmentable_id' + click submit + within(table) { has_content? course.code } + end.to change(Gaku::Enrollment, :count).by(1) + end.to change(student.course_enrollments, :count).by(1) - context 'remove' do + within(table) { has_content? course.code } + within('.courses-count') { expect(page.has_content?('1')).to eq true } + count? 'Courses list(1)' + end + + it { has_validations? } + end + + context 'existing', js: true do before do - student.courses << course + course + course_enrollment visit gaku.edit_student_path(student) - click '#student-academic-tab-link' - @data = student - - click tab_link + click '#student-courses-menu a' end - it_behaves_like 'remove enrollment' - end + it 'deletes' do + has_content? course.code + count? 'Courses list(1)' + expect do + ensure_delete_is_working + within(table) { has_no_content? course.code } + end.to change(Gaku::Enrollment, :count).by(-1) + + count? 'Courses list' + within('.courses-count') { expect(page.has_content?('0')).to eq true } + + + end + end end