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

From Expertiza_Wiki
Jump to navigation Jump to search
Line 67: Line 67:
<pre>
<pre>
   describe 'GET /index' do
   describe 'GET /index' do
     it 'returns http success' do
     it 'redirect to search' do
       stub_current_user(admin, admin.role.name, admin.role)
       stub_current_user(admin, admin.role.name, admin.role)
       get 'index'
       get 'index'

Revision as of 01:06, 22 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 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

1. controller_locale - This is to test the function 'controller_locale' which is to search the courses' locale of current user.

describe '#controller_locale' do
    it 'should return I18n.default_locale' do
      user = student
      stub_current_user(user, user.role.name, user.role)
      expect(controller.send(:controller_locale)).to eq(I18n.default_locale)
    end
  end

Test for Versions Controller

1. action_allowed? - This is the first method that would be called when a user is accessing the version controller. This method ensures that only the users with admin privileges can assess the features.

  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 - This method is to display the versions with given id with 25 records each page

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

3. show

  describe 'GET /show' do
    it 'render show' do
      stub_current_user(admin, admin.role.name, admin.role)
      allow(Version).to receive(:find).with('1').and_return(version)
      get 'show', id: 1
      expect(response).to render_template('show')
    end
  end

4. search - This method is called to search the versions records of given user id

  describe 'GET /search' do
    it 'returns http success' do
      stub_current_user(admin, admin.role.name, admin.role)
      params = { id: 3 }
      get 'search', params
      expect(response).to be_success
    end
    it 'should render search template' do
      stub_current_user(admin, admin.role.name, admin.role)
      get 'search'
      expect(response).to render_template('search')
    end
  end

Conclusion

Links

The pull request [1]

The forked git repository [2]