CSC/ECE 517 Fall 2016/E1675. Timestamp for student file & hyperlink submissions: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 147: Line 147:


===Automated Testing using RSPEC===
===Automated Testing using RSPEC===
The testing for this project has been done using several advanced ruby features. Below are a few of the features which were used :
* RSpec
* Factory Girl ruby gem
* FFaker ruby gem


Using these techniques, the project was thoroughly tested.


Models were tested for their validation. We had to verify each of the parameters which we received in our model. This was done by developing a Ruby Factory which had sample data. This sample data was fed into the models. Using RSpec, we then checked for validity for each of the parameters received in the models. This validity check is important since this information is prerequisite for having a perfectly working controller and view.
Below is a code snippet which describes the testing methodology.
require 'rails_helper'
describe SubmissionRecord do
  it 'is invalid without a team id' do
    expect(build(:submission_record, team_id: nil)).to_not be_valid
  end
  it 'is invalid without an operation' do
    expect(build(:submission_record, operation: nil)).to_not be_valid
  end
  it 'is invalid without a user' do
    expect(build(:submission_record, user: nil)).to_not be_valid
  end
  it 'is invalid without an assingment id' do
    expect(build(:submission_record, assignment_id: nil)).to_not be_valid
  end
  it 'is invalid without an operation' do
    expect(build(:submission_record, operation: nil)).to_not be_valid
  end
end


===Testing from UI===
===Testing from UI===

Revision as of 22:25, 29 October 2016

E1675.Timestamp for student file & hyperlink submissions

This page provides a description of the Expertiza based OSS project.



About Expertiza

Expertiza is an open source project based on Ruby on Rails framework. Expertiza project is software to create reusable learning objects through peer review. It also supports team projects, and the submission of almost any document type, including URLs and wiki pages.

Problem Statement

In Expertiza we accept hyperlinks as well as files submitted by students, which makes it harder to track the updates for students' submission. In this project you are required to keep track of timestamp records for students' submissions and updates of artifacts (submitted files or hyperlinks). Authors can delete or re-submit files and hyperlinks too, you should also have those activities recorded.


Task Goals

What needs to be done:

  • Record the timestamps for file/hyperlink submissions.
  • Add code to keep all those time stamps tracked and updated.
  • Change the view of 0.0.0.0:3000/assignments/list_submissions view (by clicking the “View submissions icon”) to display the submition histories of each team.
  • Make the available submissions clickable (some submitted items maight be deleted, so they are displayed but not clickable).
  • After this project, the ResubmissionTime model (and related code) will not be used anymore. Please remove related code and db table.
  • Create tests to make sure the test coverage increase.


Program Design

We created a set of new controller, model and views to finish the function for timestamps. We added a model named SubmissionRecord that contains the following attributes.

  • Hyperlink - hyperlink that could be uploaded - String.
  • Upload File - file that could be uploaded - File.
  • Team id - id that links the model to the team that created it. - Integer.
  • Created at - timestamp for time of creation.
  • Operation - Description of what occured, create, update and delete.
  • User - User who change the status of current table Get this from current user id.
  • Content - String, the file name or the hyperlink.


Implementation

Action_allowed
  • In present code, the application has right control to decide which kind of user could have access to the specific page. In order to let instructor see the submission_record, we need to add action_allowed method in submission_record_controller. Codes are here.
def action_allowed?
    if params[:action] == 'edit' || params[:action] == 'update'
      assignment = Assignment.find(params[:id])
      return true if ['Super-Administrator', 'Administrator'].include? current_role_name
      return true if assignment.instructor_id == current_user.id
      return true if TaMapping.exists?(ta_id: current_user.id, course_id: assignment.course_id) &&
      (TaMapping.where(course_id: assignment.course_id).include?TaMapping.where(ta_id: current_user.id, course_id: assignment.course_id).first)
      return true if assignment.course_id && Course.find(assignment.course_id).instructor_id == current_user.id
      return false
    else
      ['Super-Administrator',
       'Administrator',
       'Instructor',
       'Teaching Assistant'].include? current_role_name
    end
  end
Submit Hyperlink & File
  • After we created the table, there isn't a specific page for us to fill in the submission_record database table. So we find the previous page for students to submitted their hyperlinks and files which are in submitted_content. And we add codes to fill in submission_record table once a hyperlink or file is submitted.
 def submit_hyperlink

    @participant = AssignmentParticipant.find(params[:id])
    return unless current_user_id?(@participant.user_id)

    team = @participant.team
    team_hyperlinks = team.hyperlinks
    if team_hyperlinks.include?(params['submission'])
      flash[:error] = "You or your teammate(s) have already submitted the same hyperlink."
    else
      begin
        team.submit_hyperlink(params['submission'])
        @participant.update_resubmit_times

        #create a submission record
        @submission_record = SubmissionRecord.new(team_id: team, user: @participant.name, assignment_id: params[:id], operation: "Submit Hyperlink")
        @submission_record.save
      rescue
        flash[:error] = "The URL or URI is not valid. Reason: #{$ERROR_INFO}"
      end
      undo_link("The link has been successfully submitted.")
    end
    redirect_to action: 'edit', id: @participant.id
  end
#create a submission record
    assignment = Assignment.find(participant.parent_id)
    team = participant.team
    @submission_record = SubmissionRecord.new(team_id: team.id, user: participant.name , assignment_id: assignment.id, operation: "Submit File")
    @submission_record.save


Remove Hyperlink or File
  • When students want to delete their hyperlinks or files submitted before, the data in submission_record table should not disappear. What we want are all operations made by the team. As a result, we add specific code in the original delete function to reserve the data in submission_record table.
#create a submission record
    @submission_record = SubmissionRecord.new(team_id: team.id, user:@participant.name , assignment_id: assignment.id, operation: "Remove Hyperlink")
    @submission_record.save
def delete_selected_files
    #create a submission record
    assignment = Assignment.find(participant.parent_id)
    team = participant.team
    @submission_record = SubmissionRecord.new(team_id: team.id, user: participant.name , assignment_id: assignment.id, operation: "Remove File")
    @submission_record.save
    filename = params[:directories][params[:chk_files]] + "/" + params[:filenames][params[:chk_files]]
    FileUtils.rm_r(filename)
  end
View Submission Record
  • In order to make the exist hyperlinks clickable, we will choose whose operation is Submit Hyperlink in database.
<% if record.operation == "Submit Hyperlink" %>
        <td><a href="<%= record.content %>" target="_blank"><%= record.content %></a><br/></td>

        <% else %>
            <td><%= record.content %></td>
         <% end %>
        <td><%= record.created_at %></td>

Parameter Passing

We utilize the params hash from the previous view called List_submissions. We then use a where query that matches the team_id from the submissions record table.


    <%= link_to "Show Submission Records", submission_records_path(team_id: team.id) %>(View:list_submission)
     @submission_records = SubmissionRecord.where(team_id: params[:team_id])(submission_record_controller)

Automated Testing using RSPEC

The testing for this project has been done using several advanced ruby features. Below are a few of the features which were used :

  • RSpec
  • Factory Girl ruby gem
  • FFaker ruby gem

Using these techniques, the project was thoroughly tested.

Models were tested for their validation. We had to verify each of the parameters which we received in our model. This was done by developing a Ruby Factory which had sample data. This sample data was fed into the models. Using RSpec, we then checked for validity for each of the parameters received in the models. This validity check is important since this information is prerequisite for having a perfectly working controller and view.

Below is a code snippet which describes the testing methodology.

require 'rails_helper' describe SubmissionRecord do

 it 'is invalid without a team id' do
   expect(build(:submission_record, team_id: nil)).to_not be_valid
 end
 it 'is invalid without an operation' do
   expect(build(:submission_record, operation: nil)).to_not be_valid
 end
 it 'is invalid without a user' do
   expect(build(:submission_record, user: nil)).to_not be_valid
 end
 it 'is invalid without an assingment id' do
   expect(build(:submission_record, assignment_id: nil)).to_not be_valid
 end
 it 'is invalid without an operation' do
   expect(build(:submission_record, operation: nil)).to_not be_valid
 end

end

Testing from UI

  1. Demo link

References

  1. Expertiza on GitHub
  2. GitHub Project Repository Fork
  3. The live Expertiza website
  4. Expertiza project documentation wiki
  5. Rspec Documentation
  6. Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin