CSC/ECE 517 Spring 2022 - E2203: Adding tests for courses controller, eula controller: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 50: Line 50:
Code snippet:
Code snippet:
<pre>
<pre>
describe '#action_allowed?' do
  describe '#action_allowed?' do


     context 'when current user is student' do
     context 'when current user is student' do
Line 79: Line 79:
       end
       end
     end
     end
end
  end
</pre>
</pre>


2. display - this action can be called to displays the current page.
2. display - this action can be called to displays the current page.
<pre>
  describe '#display' do
    # check it displays current page
    it 'displays current page' do
      expect(response.status).to eq(200)
    end
  end
</pre>
3. display - this action can be called to displays the current page.
<pre>
<pre>
   describe '#display' do
   describe '#display' do

Revision as of 01:08, 17 March 2022

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 E2203 which is adding unit tests for courses_controller.rb, eula_controller.rb.

Files Involved

courses_controller.rb courses_controller_spec.rb eula_controller.rb eula_controller_spec.rb

Running Tests

  rspec ./spec/controllers/courses_controller_spec.rb
  rspec ./spec/controllers/eula_controller_spec.rb

Test Plan

At the beginning of the project, we first ran the original test cases but it only cover part of the methods in controllers. Therefore, in total, we wrote tests to cover all 4 methods in the eula_controller and added 5 tests to cover all 12 methods in the courses_controller. We created unit test cases with the help of mocked objects (factory objects and stub objects).

Eula Controller Methods

The code of the controller can be found here. The methods are:

  • action_allowed?
  • display
  • accept
  • decline

Courses Controller Methods

The code of the controller can be found here. The methods which miss test cases are:

  • copy
  • view_teaching_assistants
  • add_ta
  • remove_ta
  • set_course_fields

Test Frame for eula controller

In the case of controllers, unit testing is about testing the functional logic.

1. action_allowed? - This is the first action that takes place when the user tries to access the eula. This checks whether the current user is authorized to view the page. It is only available for those with student privileges, and also to make sure students cannot do all actions.

Code snippet:

  describe '#action_allowed?' do

    context 'when current user is student' do
      # first test to make sure student cannot do all actions
      it 'allows all actions' do
        expect(controller.send(:action_allowed?)).to be false
      end
      # then test to make sure student can do accept and decline actions
      it 'allows accept action' do
        controller.params = {action: 'accept'}
        user = student
        stub_current_user(user, user.role.name, user.role)
        expect(controller.send(:action_allowed?)).to be true
      end
      it 'allows decline action' do
        controller.params = {action: 'decline'}
        user = student
        stub_current_user(user, user.role.name, user.role)
        expect(controller.send(:action_allowed?)).to be true
      end
    end
    # make sure action_allowed is only available for those with student privileges
    context 'when current user is anything besides student' do
      it 'allows all actions' do
        user = instructor
        stub_current_user(user, user.role.name, user.role)
        expect(controller.send(:action_allowed?)).to be true
      end
    end
  end

2. display - this action can be called to displays the current page.

  describe '#display' do

    # check it displays current page
    it 'displays current page' do
      expect(response.status).to eq(200)
    end
  end

3. display - this action can be called to displays the current page.

  describe '#display' do

    # check it displays current page
    it 'displays current page' do
      expect(response.status).to eq(200)
    end
  end

Test Frame for courses controller