CSC/ECE 517 Fall 2019 - E1960. Create new late policy successfully and fixing "Back" link: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(42 intermediate revisions by 3 users not shown)
Line 3: Line 3:
Expertiza is an open-source project based on Ruby on Rails framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages
Expertiza is an open-source project based on Ruby on Rails framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages


== Peer Review Information ==
==Project Description==


For users intending to view the deployed Expertiza associated with this assignment, the credentials are below:
===='''Problem Statement'''====
Instructor Login: username -> instructor6, password -> password
E1960. Create new late policy successfully and fixing "Back" link
 
'''Navigation to test via UI''':
 
1. Login to expertiza using the above credentials.
 
2. Click on Assignments under Manage Notifications.
 
3. Click on Edit icon under any of the Assignments.


4. Navigate to Due Dates Tab.
===='''Background'''====


5. Scroll Down and click on "New Late Policy".
An instructor can create late policies for any assignment, wherein the instructor can specify the points per unit and the maximum penalty that can be applied for any assignment submission.  
 
6. Create/test new Late Policy !
 
== Problem Statement ==
'''E1960. Create new late policy successfully and fixing "Back" link'''
 
'''Background''': An instructor can create late policies for any assignment, wherein the instructor can specify the points per unit and the maximum penalty that can be applied for any assignment submission.  
'''
'''


'''Issue 1:'''
===='''Issue 1'''====
If an instructor while creating a policy, clicks on “Create” (Step 5), following error message is displayed on the top of the page “The following error occurred while saving the penalty policy:” and the policy is not created and added to the list of policies.
If an instructor while creating a policy, clicks on “Create” (Step 5), following error message is displayed on the top of the page “The following error occurred while saving the penalty policy:” and the policy is not created and added to the list of policies.


'''Issue 2:'''
===='''Issue 2'''====
If an instructor, while creating a policy, clicks on "Back" link (Step 6) and wants to go back to the previous page, (s)he is directed to the list of policies instead of “Due Date” tab of assignment edit page (Step 2 above).
If an instructor, while creating a policy, clicks on "Back" link (Step 6) and wants to go back to the previous page, (s)he is directed to the list of policies instead of “Due Date” tab of assignment edit page (Step 2 above).


== Problems in Current Implementation ==
== Problems in Current Implementation ==
'''Problem 1: Failure to create a new policy'''
====Problem 1: Failure to create a new policy====
The create button on the new page of late_policy is not working.  
The create button on the new page of late_policy is not working.  
Whenever the data for the form is filled and submitted by clicking on the Create button, an error message is shown saying “The following error occurred while saving the penalty policy:” and the policy is not created and added to the list of policies.
Whenever the data for the form is filled and submitted by clicking on the Create button, an error message is shown saying “The following error occurred while saving the penalty policy:” and the policy is not created and added to the list of policies.


 
====Problem 2: Back link redirects to the wrong page====
'''Problem 2: Back link redirects to the wrong page'''
An instructor can choose to go back to the previous page from the create new policy page.
An instructor can choose to go back to the previous page from the create new policy page.
When the Back button on the create new late policy is clicked, it should be redirected to the Due Date tab of the assignment it came from but it is redirected to the index page of late policies.
When the Back button on the create new late policy is clicked, it should be redirected to the Due Date tab of the assignment it came from but it is redirected to the index page of late policies.


== Solutions to Problems in Current Implementation ==
====Problem 1: Failure to create a new policy====
'''Solution'''


== Solutions to Problems in Current Implementation ==
There was no provision to handle the validations of the form in the new late_policy page.
A new late policy would not be created if any of the validations fail and the user would be notified of the errors by a flash error message.


'''Problem 1: Failure to create a new policy'''
'''Updated File:''' app/views/late_policies/new.html.erb
    Solution:
    There was no provision to handle the validations of the form in the new late_policy page.


<pre>
<pre>
<% if @late_policy.errors.any? %>
<% if @late_policy.errors.any? %>
   <div id="error_explanation">
   <div id="error_explanation">
    <h2>
  <% flash[:error] = @late_policy.errors.full_messages.join("<br/>").html_safe %>
      <%= pluralize(@late_policy.errors.count, "error") %>
      prohibited this post from being saved:
    </h2>
 
    <ul>
    <% @late_policy.errors.full_messages.each do |msg| %>
      <li><%= msg %></li>
    <% end %>
    </ul>
   </div>
   </div>
<% end %>
<% end %>
</pre>
</pre>


'''Problem 2: Back link redirects to the wrong page'''
A new Rspec File has been written to carry out the automatic testing. All the test cases have been mentioned in the Test Plan subsection. A new late policy must not be created if any of these validations fail.
 
'''File created:''' spec/models/late_policy_spec.rb
 
<pre>
describe LatePolicy do
let(:policy) do
LatePolicy.new penalty_per_unit: 10.0, max_penalty: 30, penalty_unit: "Day", times_used: 0, instructor_id: 6, policy_name: 'rspectest'
end
#validaes penalty per unit field
describe 'validate penalty_per_unit' do
it 'returns the penalty_per_unit' do
expect(policy.penalty_per_unit).to eq(10.0)
end
 
it 'Validate presence of penalty_per_unit which cannot be blank' do
      policy.penalty_per_unit = nil
      expect(policy).not_to be_valid
    end
it 'Validate if penalty_per_unit is less than max_penalty' do
      policy.max_penalty = 20
policy.penalty_per_unit = 30
      expect(policy).not_to be_valid
    end
end
#validates max_penalty field
describe 'validate max_penalty' do
it 'returns the max_penalty' do
expect(policy.max_penalty).to eq(30)
end
it 'Validate presence of max_penalty which cannot be blank' do
      policy.max_penalty = nil
      expect(policy).not_to be_valid
    end
it 'Validate if max_penalty is less tha 50' do
      policy.max_penalty = 60
      expect(policy).not_to be_valid
    end
end
#validates penalty unit field
describe 'validate penalty_unit' do
it 'returns the penalty_unit' do
expect(policy.penalty_unit).to eq('Day')
end
it 'Validate presence of penalty_unit which cannot be blank' do
      policy.penalty_unit = nil
      expect(policy).not_to be_valid
    end
end
 
describe 'validate times_used backgorund field' do
it 'returns times_used' do
expect(policy.times_used).to eq(0)
end
end
#validates policy_name field
describe 'validate policy_name' do
it 'returns the policy name' do
expect(policy.policy_name).to eq('rspectest')
end
it 'Validate presence of policy name which cannot be blank' do
      policy.policy_name = nil
      expect(policy).not_to be_valid
    end
end
end
 
</pre>
 
====Problem 2: Back link redirects to the wrong page====
An instructor can choose to go back to the previous page from the create new policy page.
An instructor can choose to go back to the previous page from the create new policy page.
When Back button on the create new late policy is clicked, it should be redirected to the Due Date tab of the assignment it came from but it is redirected to the list of late policies page
When Back button on the create new late policy is clicked, it should be redirected to the Due Date tab of the assignment it came from but it is redirected to the list of late policies page


    Solution:
'''Solution'''
    We tried to store the assignment id of the page from where the create new policy was clicked. This way when we have to redirect after the back button,  
 
    we can send it to this particular assignment with the help of assignment id.
We tried to store the assignment id of the page from where the create new policy was clicked. This way when we have to redirect after the back button,  
we can send it to this particular assignment with the help of assignment id. This session variable gets overwritten every time whenever an edit page for the new assignment is opened. So the bug in the back link is fixed.
 
 
''' update method at app/controllers/assignments_controller.rb '''   
<pre> session[:assignment_id] = @assignment_form.assignment.id  </pre>
 


   
'''app/views/late_policies/new.html.erb'''
'''app/views/late_policies/new.html.erb'''
    <%= f.hidden_field :assign_id, value: params[:id] %>
<pre>
     <%= link_to 'Back', :controller => 'assignments', :action => 'edit', :id => params[:id], :anchor => "tabs-5" %>
     <%= link_to 'Back', :controller => 'assignments', :action => 'edit', :id => session[:assignment_id] , :anchor => "tabs-5" %>
</pre>




'''app/controllers/late_policies_controller.rb'''
    redirect_to action: 'index', id: params[:late_policy][:assign_id]


''' app/views/late_policies/index.html.erb'''
==Test Plan==
    <%= link_to 'New late policy', :action => 'new', :id => params[:id]%>


For users intending to view the deployed Expertiza associated with this assignment, the credentials are below:
Instructor Login: username -> instructor6, password -> password


'''Back Case - 1'''
    Step 1: Click Back on Create New Policy page
[[File:Back-1.1.png|500px]]
    Step 2: Redirected to the Due Dates tab of the assignment page it came from
[[File:Back-1.2.png|500px]]




'''Back Case - 2'''
====    Click on Create button without entering any details    ====
    Step 1: On Index Page of Late Policies. Click Create New Policy
[[File:Case-1.png|600px|center]]
[[File:Back-2.1.png|500px]]


    Step 2: Click Back
[[File:Back-2.2d.png|500px]]


    Step 3: Redirected to the due dates tab of assignment page it came from
====    Enter the policy name which already exists. You can find it out on list of policies page.    ====
[[File:Back-2.3.png|500px]]
[[File:Create_policy_case-2.png|600px|center]]
 
 
====    Enter alphabet or string in penalty per unit field    ====
[[File:Create_policy_case-3.png|600px|center]]
 
 
====    Max Penalty cannot be greater than or equal to 50. Try entering a larger number ====
[[File:Create_policy_case-4.png|600px|center]]
 
 
====  Enter valid data in all fields. ====
[[File:Create_policy_case-5.png|680px|center]]
 
====Manual Testing via UI====
 
1. Login to expertiza using the above credentials.
 
2. Click on Assignments under Manage Notifications.
 
3. Click on Edit icon under any of the Assignments.
 
4. Navigate to Due Dates Tab.
 
5. Scroll Down and click on "New Late Policy".
 
6. Create/test new Late Policy!
 
====Automated Test Cases for new late policy validations====
 
A new late policy must not be created if any of these validations fail.
 
<ol>
  <li> Late Policy Name
    <ol>
      <li>Late Policy Name must not be blank</li>
      <li>Late Policy must be unique</li>
    </ol>
  </li>
  <li>Penalty Points per unit
    <ol>
      <li>Penalty points must not be blank</li>
      <li>Penalty points must be a number</li>
      <li>penalty points must be less than total penalty points</li>
    </ol>
  </li>
  <li>Maximum Penalty
    <ol>
      <li>Maximum Penalty must not be blank</li>
      <li>Maximum Penalty must be less than 50</li>
    </ol>
  </li>
</ol>
 
All these test cases have been automatically tested by writing a new RSpec file: spec/models/late_policy_spec.rb
 
====Test Case log after running rspec file====
[[File:Testrspec.PNG]]
 
==== Test Cases for back link ====
There are three different cases covered under the back link testing on the new late policy page.
 
===== Test Case 1: Back Link directly from new late policy page =====
Flow: Assignments -> Edit Button -> Due Dates Tab -> New Late Policy -> Back.
 
It is redirected to the due dates tab of that assignment.
 
 
===== Test Case 2: Back Link after error on validation =====
Flow: Assignments -> Edit Button -> Due Dates Tab -> New Late Policy -> Click on create without Entering values -> Back.
 
An error message is shown regarding the validations when the create button is clicked. When the Back button is clicked at this stage,  it is
redirected to the due dates tab of that assignment.
 
 
 
===== Test Case 3: Back Link after visiting the index page =====
Flow: Assignments -> Edit Button -> Due Dates Tab -> New Late Policy -> Submit a policy -> Create New policy -> Back
 
Once a policy is created we are redirected to the index page of the policies which lists all the policies available. Now if we try to create a new policy from here and click on the Back button after that, we are redirected to the due dates tab of that assignment.


==Test Plan==
abs


==Tasks Accomplished:==
==Tasks Accomplished==
Following tasks were accomplished in this project:
Following tasks were accomplished in this project:


Line 118: Line 242:
3. Added RSPEC test cases for testing changes done in late_policies Controller.
3. Added RSPEC test cases for testing changes done in late_policies Controller.


== Team Information: ==
==Code Coverage==
27.125%
 
== Team Information ==


Devarsh Shah
Devarsh Shah

Latest revision as of 03:31, 7 November 2019

About Expertiza

Expertiza is an open-source project based on Ruby on Rails framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages

Project Description

Problem Statement

E1960. Create new late policy successfully and fixing "Back" link

Background

An instructor can create late policies for any assignment, wherein the instructor can specify the points per unit and the maximum penalty that can be applied for any assignment submission.

Issue 1

If an instructor while creating a policy, clicks on “Create” (Step 5), following error message is displayed on the top of the page “The following error occurred while saving the penalty policy:” and the policy is not created and added to the list of policies.

Issue 2

If an instructor, while creating a policy, clicks on "Back" link (Step 6) and wants to go back to the previous page, (s)he is directed to the list of policies instead of “Due Date” tab of assignment edit page (Step 2 above).

Problems in Current Implementation

Problem 1: Failure to create a new policy

The create button on the new page of late_policy is not working. Whenever the data for the form is filled and submitted by clicking on the Create button, an error message is shown saying “The following error occurred while saving the penalty policy:” and the policy is not created and added to the list of policies.

Problem 2: Back link redirects to the wrong page

An instructor can choose to go back to the previous page from the create new policy page. When the Back button on the create new late policy is clicked, it should be redirected to the Due Date tab of the assignment it came from but it is redirected to the index page of late policies.

Solutions to Problems in Current Implementation

Problem 1: Failure to create a new policy

Solution

There was no provision to handle the validations of the form in the new late_policy page. A new late policy would not be created if any of the validations fail and the user would be notified of the errors by a flash error message.

Updated File: app/views/late_policies/new.html.erb

<% if @late_policy.errors.any? %>
  <div id="error_explanation">
  <% flash[:error] = @late_policy.errors.full_messages.join("<br/>").html_safe %>
  </div>
<% end %>

A new Rspec File has been written to carry out the automatic testing. All the test cases have been mentioned in the Test Plan subsection. A new late policy must not be created if any of these validations fail.

File created: spec/models/late_policy_spec.rb

describe LatePolicy do
	let(:policy) do
		LatePolicy.new penalty_per_unit: 10.0, max_penalty: 30, penalty_unit: "Day", times_used: 0, instructor_id: 6, policy_name: 'rspectest'
	end
	#validaes penalty per unit field
	describe 'validate penalty_per_unit' do
		it 'returns the penalty_per_unit' do
			expect(policy.penalty_per_unit).to eq(10.0)
		end

		it 'Validate presence of penalty_per_unit which cannot be blank' do
      			policy.penalty_per_unit = nil
      			expect(policy).not_to be_valid
    		end
		it 'Validate if penalty_per_unit is less than max_penalty' do
      			policy.max_penalty = 20
			policy.penalty_per_unit = 30
      			expect(policy).not_to be_valid
    		end
	end
	
	#validates max_penalty field
	describe 'validate max_penalty' do
		it 'returns the max_penalty' do
			expect(policy.max_penalty).to eq(30)
		end
		it 'Validate presence of max_penalty which cannot be blank' do
      			policy.max_penalty = nil
      			expect(policy).not_to be_valid
    		end
		it 'Validate if max_penalty is less tha 50' do
      			policy.max_penalty = 60
      			expect(policy).not_to be_valid
    		end
	end
	
	#validates penalty unit field
	describe 'validate penalty_unit' do
		it 'returns the penalty_unit' do
			expect(policy.penalty_unit).to eq('Day')
		end
		it 'Validate presence of penalty_unit which cannot be blank' do
      			policy.penalty_unit = nil
      			expect(policy).not_to be_valid
    		end
	end

	describe 'validate times_used backgorund field' do
		it 'returns times_used' do
			expect(policy.times_used).to eq(0)
		end
	end
	
	#validates policy_name field
	describe 'validate policy_name' do
		it 'returns the policy name' do
			expect(policy.policy_name).to eq('rspectest')
		end
		it 'Validate presence of policy name which cannot be blank' do
      			policy.policy_name = nil
      			expect(policy).not_to be_valid
    		end
	end
end

Problem 2: Back link redirects to the wrong page

An instructor can choose to go back to the previous page from the create new policy page. When Back button on the create new late policy is clicked, it should be redirected to the Due Date tab of the assignment it came from but it is redirected to the list of late policies page

Solution

We tried to store the assignment id of the page from where the create new policy was clicked. This way when we have to redirect after the back button, we can send it to this particular assignment with the help of assignment id. This session variable gets overwritten every time whenever an edit page for the new assignment is opened. So the bug in the back link is fixed.


update method at app/controllers/assignments_controller.rb

 session[:assignment_id] = @assignment_form.assignment.id  


app/views/late_policies/new.html.erb

    <%= link_to 'Back', :controller => 'assignments', :action => 'edit', :id => session[:assignment_id] , :anchor => "tabs-5" %>


Test Plan

For users intending to view the deployed Expertiza associated with this assignment, the credentials are below: Instructor Login: username -> instructor6, password -> password


Click on Create button without entering any details


Enter the policy name which already exists. You can find it out on list of policies page.


Enter alphabet or string in penalty per unit field


Max Penalty cannot be greater than or equal to 50. Try entering a larger number


Enter valid data in all fields.

Manual Testing via UI

1. Login to expertiza using the above credentials.

2. Click on Assignments under Manage Notifications.

3. Click on Edit icon under any of the Assignments.

4. Navigate to Due Dates Tab.

5. Scroll Down and click on "New Late Policy".

6. Create/test new Late Policy!

Automated Test Cases for new late policy validations

A new late policy must not be created if any of these validations fail.

  1. Late Policy Name
    1. Late Policy Name must not be blank
    2. Late Policy must be unique
  2. Penalty Points per unit
    1. Penalty points must not be blank
    2. Penalty points must be a number
    3. penalty points must be less than total penalty points
  3. Maximum Penalty
    1. Maximum Penalty must not be blank
    2. Maximum Penalty must be less than 50

All these test cases have been automatically tested by writing a new RSpec file: spec/models/late_policy_spec.rb

Test Case log after running rspec file

Test Cases for back link

There are three different cases covered under the back link testing on the new late policy page.

Test Case 1: Back Link directly from new late policy page

Flow: Assignments -> Edit Button -> Due Dates Tab -> New Late Policy -> Back.

It is redirected to the due dates tab of that assignment.


Test Case 2: Back Link after error on validation

Flow: Assignments -> Edit Button -> Due Dates Tab -> New Late Policy -> Click on create without Entering values -> Back.

An error message is shown regarding the validations when the create button is clicked. When the Back button is clicked at this stage, it is redirected to the due dates tab of that assignment.


Test Case 3: Back Link after visiting the index page

Flow: Assignments -> Edit Button -> Due Dates Tab -> New Late Policy -> Submit a policy -> Create New policy -> Back

Once a policy is created we are redirected to the index page of the policies which lists all the policies available. Now if we try to create a new policy from here and click on the Back button after that, we are redirected to the due dates tab of that assignment.


Tasks Accomplished

Following tasks were accomplished in this project:

1. Corrected the code for the late_policies controller and new late_policy page.

2. Improved the code for the Back button inside the new late_policy page.

3. Added RSPEC test cases for testing changes done in late_policies Controller.

Code Coverage

27.125%

Team Information

Devarsh Shah

Jay Jagtap

Ritesh Ghorse

Mentor: Yashad Trivedi (ytrived@ncsu.edu)

References

1.Expertiza on GitHub

2.GitHub Project Repository Fork

3.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