OSS E1852.rb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 60: Line 60:
===Tested Methods===
===Tested Methods===


*'''team''': returns the team associated with a participant.
*'''team''' : Returns the team associated with a participant.
<pre>
<pre>
</pre>
</pre>
* response : This method returns the response associated with the perticular participant. we use mock method to simulate return of the response from the participant response_map
* response : This method returns the response associated with the particular participant. we use mock method to simulate return of the response from the participant response_map
<pre>
<pre>
describe '#response' do
describe '#response' do
Line 73: Line 73:
</pre>
</pre>


*name: Returns the name of the participant  
*'''name''' : Returns the name of a participant.
<pre>
<pre>
describe "#name" do
describe "#name" do
Line 82: Line 82:
</pre>
</pre>


*fullname : Returns the full name of the participant  
*'''fullname''' : Returns the full name of a participant.
<pre>
<pre>
describe "#fullname" do
describe "#fullname" do
Line 91: Line 91:
</pre>
</pre>


*handle : Returns handle of the participant
*'''handle''' : Returns the handle of a participant.
<pre>
<pre>
describe '#handle' do
describe '#handle' do
Line 99: Line 99:
</pre>
</pre>


* delete: It deletes the participant if the participant doesn't have any association adn value of "force" is nil else it will raise an exception
*'''delete''' : Deletes a participant according to the participant's current associations and the value passed to the variable 'force'.
<pre>
<pre>
describe '#delete' do
describe '#delete' do
Line 117: Line 117:
       expect( participant.delete( true ) ).to eq( participant )
       expect( participant.delete( true ) ).to eq( participant )
     end
     end
     it 'raises execption when trying to delect participant where associations exists and force is nil' do
     it 'raises exception when trying to delete participant where associations exists and force is nil' do
       allow( participant ).to receive( :team ).and_return( team )
       allow( participant ).to receive( :team ).and_return( team )
       expect{ participant.delete( nil ) }.to raise_error.with_message("Associations exist for this participant.")
       expect{ participant.delete( nil ) }.to raise_error.with_message("Associations exist for this participant.")
Line 123: Line 123:
   end
   end
</pre>
</pre>
*force_delete: This method is called inside the delete method . coverage for this is handled in delete method. hence there is not explicit cases are written.
*'''force_delete''' : Method called inside #delete to remove the participant and all necessary associations. Testing of this method is covered through the testing of #delete. Therefore, there are not explicit test cases written.
*topic_name: Retunrs the topic name associated with the participant
*'''topic_name''' : Returns the topic name associated with a participant.
<pre>
<pre>
describe '#topic_name' do
describe '#topic_name' do
Line 136: Line 136:
   end
   end
</pre>
</pre>
*able_to_review: check the review rights of the participant  
*'''able_to_review''' : Checks and returns the review rights of a participant.
<pre>
<pre>
describe '#able_to_review' do
describe '#able_to_review' do
Line 150: Line 150:
   end
   end
</pre>
</pre>
*email: sends an email to participant
*'''email''' : Sends an email to a participant verifying an assignment registration.
<pre>
<pre>
describe '#email' do
describe '#email' do
Line 162: Line 162:
<pre>
<pre>
</pre>
</pre>
*get_permissions:Returns the permission of various users such as participant , reader, reviewer, submitter
*'''get_permissions''' : Returns the permissions association with a participant based on participant type (i.e. participant, reader, reviewer, submitter)
<pre>
<pre>
describe '#get_permissions' do
describe '#get_permissions' do
Line 183: Line 183:
   end
   end
</pre>
</pre>
*get_authorization: Returns the authorization role based on the access rights (can_submit,can_review,can_take_quiz).
*'''get_authorization''' : Returns the authorization role based on a participant's access rights (can_submit,can_review,can_take_quiz).
<pre>
<pre>
describe '#get_authorization' do
describe '#get_authorization' do
Line 200: Line 200:
   end
   end
</pre>
</pre>
*sort_by_name: Returns the sorted participants name.
*'''sort_by_name''' : Returns the sorted array of participants by name.
<pre>
<pre>
describe '#sort_by_name' do
describe '#sort_by_name' do

Revision as of 16:32, 29 October 2018

This wiki page is for the description of changes made under E1852 OSS assignment for Fall 2018, CSC/ECE 517

Background

Expertiza is an open source web-based peer review system developed and maintained by students and faculty members at North Carolina State University. Features of Expertiza enable students to work collaboratively in teams on course projects and assignments.

Problem

There are not enough unit tests for the Participant model of Expertiza. Current path coverage of participant.rb is only 36.08%.

Work to be done

  • Write unit test using Rspec
  • Achieve path coverage more than 90%
  • Achieve as high branch coverage

Modified Files

  • spec/models/particpant_spec.rb

Unit Test Description

Unit Tests are implemented to ensure proper independence and desired functionality of methods in a model. Unit Testing is an essential component for the following strategies:

  • Test Driven Development(TDD), where unit tests are used to drive the development of a product.
  • Behavior Driven Development(BDD), which augments test driven development through the application of principles such as "Five Why's" and "Outside In" to identify and implement behaviors that are directly beneficial to the outcome of the product.

In this project, we are using RSpec testing models to achieve behavior driven development.

Participant Unit Test

Factories

The following factories were generated to assist in the testing of the Participant model.

let(:user) { 
	build( :student, id: 1, name: 'no name', fullname: 'no one') }
  let(:team) {	
	build( :assignment_team, id: 1, name: 'myTeam' ) }
  let(:team_user) { 
	build( :team_user, id: 1, user: user, team: team) }

  let(:topic){ build( :topic ) }

  let(:participant) {
	build(:participant,
	user: build( :student, name: "Jane", fullname: "Doe, Jane", id: 1 ) ) }
  let(:participant2) { 
	build(:participant, 
	user: build( :student, name: "John", fullname: "Doe, John", id: 2 ) ) }
  let(:participant3) { 
	build(:participant, can_review: false, 
	user: build(:student, name: "King", fullname: "Titan, King", id: 3 ) ) }

  let(:assignment) { build(:assignment, id: 1, name: 'no assgt') }

Tested Methods

  • team : Returns the team associated with a participant.

  • response : This method returns the response associated with the particular participant. we use mock method to simulate return of the response from the participant response_map
describe '#response' do
    it 'Returns the responses that are associated with this participant' do
      allow( participant ).to receive( :responses ).and_return( response )
      expect( participant.responses ).to eq( response )
    end
  end
  • name : Returns the name of a participant.
describe "#name" do
    it "returns the name of the user" do
      expect( participant.name ).to eq( "Jane" )
    end
  end
  • fullname : Returns the full name of a participant.
describe "#fullname" do
    it "returns the full name of the user" do
      expect( participant.fullname ).to eq( "Doe, Jane" )
    end
  end
  • handle : Returns the handle of a participant.
describe '#handle' do
    it 'returns the handle of the participant' do
      expect( participant.handle( nil ) ).to eq( "handle" )
    end
  • delete : Deletes a participant according to the participant's current associations and the value passed to the variable 'force'.
describe '#delete' do
    it 'deletes a participant if no associations exist and force is nil' do
      expect( participant.delete( nil ) ).to eq( participant )
    end
    it 'deletes a participant if no associations exist and force is true' do
      expect( participant.delete( true ) ).to eq( participant )
    end
    it 'deletes a participant if associations exist and force is true' do
      allow( participant ).to receive( :team ).and_return( team )
      expect( participant.delete( true ) ).to eq( participant )
    end
    it 'deletes a participant if associations exist and force is true' do
      allow( participant ).to receive( :team ).and_return( team )
      allow( team ).to receive( :teams_users ).and_return( length: 1 )
      expect( participant.delete( true ) ).to eq( participant )
    end
    it 'raises exception when trying to delete participant where associations exists and force is nil' do
      allow( participant ).to receive( :team ).and_return( team )
      expect{ participant.delete( nil ) }.to raise_error.with_message("Associations exist for this participant.")
    end
  end
  • force_delete : Method called inside #delete to remove the participant and all necessary associations. Testing of this method is covered through the testing of #delete. Therefore, there are not explicit test cases written.
  • topic_name : Returns the topic name associated with a participant.
describe '#topic_name' do
    it 'returns the topic name associated with the participant topic name is nil' do
      expect( participant.topic_name ).to eq( '<center>—</center>' )
    end
    it 'returns the topic name associated with the participant topic name has value' do
      allow( participant ).to receive( :topic ).and_return( topic )
      expect( participant.topic_name ).to eq( "Hello world!" )   
    end
  end
  • able_to_review : Checks and returns the review rights of a participant.
describe '#able_to_review' do
    it '#able_to_review when can_review is true' do
      expect(participant.able_to_review).to eq(true)
    end
  end

  describe '#able_to_review' do
    it '#able_to_review when can_review is false' do
      expect(participant3.able_to_review).to eq(false)
    end
  end
  • email : Sends an email to a participant verifying an assignment registration.
describe '#email' do
    it 'sends an email to the participant' do
      expect { participant.email("Missing 'pw'", "Missing 'home_page'") }.to change {
		ActionMailer::Base.deliveries.count }.by(1)
    end
  end
  • score

  • get_permissions : Returns the permissions association with a participant based on participant type (i.e. participant, reader, reviewer, submitter)
describe '#get_permissions' do
    it 'returns the permissions of participant' do
      expect( Participant.get_permissions( 'participant' ) ).to contain_exactly(
		[ :can_submit, true ], [ :can_review, true ], [ :can_take_quiz, true ] )
    end
    it 'returns the permissions of reader' do
      expect( Participant.get_permissions( 'reader' ) ).to contain_exactly(
		[ :can_submit, false ], [ :can_review, true ], [ :can_take_quiz, true ] )
    end
    it 'returns the permissions of reviewer' do
      expect( Participant.get_permissions( 'reviewer' ) ).to contain_exactly(
		[ :can_submit, false ], [ :can_review, true ], [ :can_take_quiz, false ] )
    end
    it 'returns the permissions of submitter' do
      expect(Participant.get_permissions('submitter')).to contain_exactly(
		[:can_submit, true], [:can_review, false], [:can_take_quiz, false] )
    end
  end
  • get_authorization : Returns the authorization role based on a participant's access rights (can_submit,can_review,can_take_quiz).
describe '#get_authorization' do
    it 'returns participant when no arguments are pasted' do
      expect( Participant.get_authorization( nil, nil, nil ) ).to eq( 'participant' )
    end
    it 'returns reader when no arguments are pasted' do
      expect( Participant.get_authorization( false, true, true ) ).to eq( 'reader' )
    end
    it 'returns submitter when no arguments are pasted' do
      expect( Participant.get_authorization( true, false, false ) ).to eq( 'submitter' )
    end
    it 'returns reviewer when no arguments are pasted' do
      expect( Participant.get_authorization( false, true, false ) ).to eq( 'reviewer' )
    end
  end
  • sort_by_name : Returns the sorted array of participants by name.
describe '#sort_by_name' do
    it 'returns a sorted list of participants alphabetical by name' do
      unsorted = [ participant3, participant, participant2 ]
      sorted = [ participant, participant2, participant3  ]
      expect( Participant.sort_by_name( unsorted ) ).to eq( sorted )
    end
  end

Running the Tests

To run the test run below command in terminal

 rspec spec/models/participant_spec.rb

External links

External links

References