User talk:Zli36: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 147: Line 147:


===Automated Testing using RSPEC===
===Automated Testing using RSPEC===
The current version of expertiza did not have any test for VersionsController. Using the test driven development(TDD) approach, we have added an exhaustive set of RSPEC tests for VersionsController, to test all the modifications we have done to the code of the controller class. The tests use double and stub features of rspec-rails gem, to fake the log in by different users - Administrator, Instructor, Student etc. The tests can be executed "rpec spec" command as shown below.
<pre>
user-expertiza $rspec spec
.
.
.
Finished in 5.39 seconds (files took 25.33 seconds to load)
66 examples, 0 failures


Randomized with seed 19254
 
.
.
</pre>


===Testing from UI===
===Testing from UI===
Following are a few testcases with respectto our code changes that can be tried from UI:
1. To go to versions index page, type in the following url after logging in:
  http://152.46.16.81:3000/versions
2. After logging in as student/instructor or admin : Try accessing the  new, create, edit, update actions. These actions are not allowed to any of the users.
  http://152.46.16.81:3000/versions/new
  This calls the new action. In the current production version of expertiza, it is unhandled and application gives a default 404 page.
3. Another feature that can be tested from UI is Pagination. Try searching for a user's versions and see if the results are paginated or not. Search here:
  http://152.46.16.81:3000/versions/search


4. Visit the same URL as step 3, you should see only the students under that instructor in the users dropdown.


===References===
===References===


#[https://github.com/expertiza/expertiza Expertiza on GitHub]
#[https://github.com/expertiza/expertiza Expertiza on GitHub]
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]
#[https://github.com/rsndates/expertiza GitHub Project Repository Fork]
#[http://expertiza.ncsu.edu/ The live Expertiza website]
#[http://expertiza.ncsu.edu/ The live Expertiza website]
#[http://bit.ly/myexpertiza  Demo link]  
#[http://bit.ly/myexpertiza  Demo link]  

Revision as of 20:40, 28 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 Passed

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

Testing from UI

References

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