CSC/ECE 517 Spring 2022 - E2205: Testing for participants controller, versions controller

From Expertiza_Wiki
Jump to navigation Jump to search

About Expertiza

Expertiza is the software benefits for both instructors and students by supporting various types of submissions and providing reusable objects for peer review. It is an open-source project based on Ruby on Rails framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.

Description about project

This page is a description of Expertiza OSS project E2205 which is testing for participants_controller and versions_controller

Files Involved

  • participants_controller_spec.rb
  • versions_controller_spec.rb

Running Tests

rspec ./spec/controllers/participants_controller_spec.rb
rspec ./spec/controllers/versions_controller_spec.rb 

Requirement

In participants controller had some methods not tested, also some edge cases not included in the previous test work. And There were no tests for the versions controller. Our aim is to test all the methods in these two controllers and try to cover more edge cases when testing.

Analysis

Test for Participants Controller

Test for Versions Controller

1. action_allowed?

  describe '#action_allowed?' do
    context 'when user does not have right privilege, it denies action' do
      it 'for no user' do
        expect(controller.send(:action_allowed?)).to be false
      end
      it 'for student' do
        allow(controller).to receive(:current_user).and_return(build(:student))
        expect(controller.send(:action_allowed?)).to be false
      end
      it 'for instructor' do
        stub_current_user(instructor, instructor.role.name, instructor.role)
        expect(controller.send(:action_allowed?)).to be false
      end
    end
    context 'when user has right privilege, it allows action' do
      it 'for admin' do
        stub_current_user(admin, admin.role.name, admin.role)
        expect(controller.send(:action_allowed?)).to be true
      end
      it 'for super_admin' do
        stub_current_user(super_admin, super_admin.role.name, super_admin.role)
        expect(controller.send(:action_allowed?)).to be true
      end
    end
  end

2. index

  describe 'GET /index' do
    it 'returns http success' do
      stub_current_user(admin, admin.role.name, admin.role)
      get 'index'
      expect(response).to redirect_to('/versions/search')
    end
  end

Conclusion

Links

The pull request [1]

The forked git repository [2]