Skip to content

Commit

Permalink
Merge cd29989 into ef449f6
Browse files Browse the repository at this point in the history
  • Loading branch information
neelshah26 committed Apr 22, 2024
2 parents ef449f6 + cd29989 commit 9ad767b
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 17 deletions.
26 changes: 21 additions & 5 deletions app/controllers/assignments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ def create
assignment_form_params[:assignment_questionnaire] = ques_array
assignment_form_params[:due_date] = due_array
@assignment_form.update(assignment_form_params, current_user)
aid = Assignment.find(@assignment_form.assignment.id).id
# renamed the variable from ambiguous aid to assignment_id
assignment_id = Assignment.find(@assignment_form.assignment.id).id
ExpertizaLogger.info "Assignment created: #{@assignment_form.as_json}"
redirect_to edit_assignment_path aid
# added assignment id to session
session[:assignment_id] = assignment_id
redirect_to edit_assignment_path assignment_id
undo_link("Assignment \"#{@assignment_form.assignment.name}\" has been created successfully. ")
return
else
Expand All @@ -71,6 +74,8 @@ def create

# edits an assignment's deadlines and assigned rubrics
def edit
# setting the assignment_id in session to nil when editing
session[:assignment_id] = nil
user_timezone_specified
edit_params_setting
assignment_staggered_deadline?
Expand All @@ -85,6 +90,9 @@ def edit
@badges = Badge.all
@use_bookmark = @assignment.use_bookmark
@duties = Duty.where(assignment_id: @assignment_form.assignment.id)
# extracting the assignment id from parameters and updating it to sessions list
@assignment = Assignment.find(params[:id])
session[:assignment_id] = @assignment.id
end

# updates an assignment via an assignment form
Expand All @@ -107,9 +115,16 @@ def update
end
end

# displays an assignment via ID
# displays an assignment via ID and stores it in the session list
def show
# initial approach to fix "back" link to show list of assignments
if params[:id] == 'edit'
redirect_to student_task_path
return
end
session[:assignment_id] = nil
@assignment = Assignment.find(params[:id])
session[:assignment_id] = @assignment.id
end

# gets an assignment's path/url
Expand Down Expand Up @@ -301,9 +316,10 @@ def assignment_form_save_handler
assignment_form_params[:assignment][:id] = exist_assignment.id.to_s
fix_assignment_missing_path
update_assignment_form(exist_assignment)
aid = Assignment.find_by(name: @assignment_form.assignment.name).id
# renaming the variable from aid to assignment_id
assignment_id = Assignment.find_by(name: @assignment_form.assignment.name)
ExpertizaLogger.info "Assignment created: #{@assignment_form.as_json}"
redirect_to edit_assignment_path aid
redirect_to edit_assignment_path assignment_id
undo_link("Assignment \"#{@assignment_form.assignment.name}\" has been created successfully. ")
end

Expand Down
17 changes: 8 additions & 9 deletions app/models/assignment_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def update(attributes, user, _vary_by_topic_desired = false)
# Code to update values of assignment
def update_assignment(attributes)
unless @assignment.update_attributes(attributes)
@errors = @assignment.errors.to_s
# calling the full_messages method instead of to_s method
@errors = @assignment.errors.full_messages
@has_errors = true
end
@assignment.num_review_of_reviews = @assignment.num_metareviews_allowed
Expand All @@ -93,29 +94,27 @@ def update_assignment_questionnaires(attributes)

if attributes[0].key?(:questionnaire_weight)
validate_assignment_questionnaires_weights(attributes)
@errors = @assignment.errors.to_s
# calling the full_messages method instead of to_s method
@errors = @assignment.errors.full_messages
topic_id = nil
end
unless @has_errors
# Update AQ if found, otherwise create new entry
attributes.each do |attr|
next if attr[:questionnaire_id].blank?

questionnaire_type = Questionnaire.find(attr[:questionnaire_id]).type
topic_id = attr[:topic_id] if attr.key?(:topic_id)
duty_id = attr[:duty_id] if attr.key?(:duty_id) # if duty_id is present in the attributes, save it.
aq = assignment_questionnaire(questionnaire_type, attr[:used_in_round], topic_id, duty_id)
if aq.id.nil?
unless aq.save
@errors = @assignment.errors.to_s
# calling the full_messages method instead of to_s method
@errors = @assignment.errors.full_messages
@has_errors = true
next
end
end
unless aq.update_attributes(attr)
@errors = @assignment.errors.to_s
@has_errors = true
end
next unless aq.update_attributes(attr)
end
end
end
Expand Down Expand Up @@ -152,7 +151,7 @@ def update_tag_prompt_deployments(attributes)
end
end
end

def create_or_update_tag_prompt_deployments(questionnaire_id, value)
(0..value['tag_prompt'].count - 1).each do |i|
tag_dep = nil
Expand Down
7 changes: 7 additions & 0 deletions app/views/assignments/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@
$('#go_to_tabs2').click(function(){
$('#Rubrics').click();
});
<!-- Below javascript will redirect to the due date page -->
jQuery(document).ready(function() {
var referrer = document.referrer;
if(referrer.includes("late_policies")){
$('#DueDates').click();
}
});
</script>
<% end %>

Expand Down
3 changes: 2 additions & 1 deletion app/views/late_policies/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ end
<br />

<%= link_to 'New late policy', :action => 'new'%><br />
<%= link_to 'Back', :controller=> 'assignments', :action => 'edit', :id=>session[:assignment]%>
<!-- We have save the assignment id in the controller and using that when we click on back, we redirect to that assignment -->
<%= link_to 'Back', :controller=> 'assignments', :action => 'edit', :id=>session[:assignment_id]%>
3 changes: 2 additions & 1 deletion app/views/late_policies/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@

<br>
<br>
<%= link_to 'Back', :controller=> 'assignments', :action => 'edit', :id=>session[:assignment]%>
<!-- We have save the assignment id in the controller and using that when we click on back, we redirect to that assignment -->
<%= link_to 'Back', :controller=> 'assignments', :action => 'edit', :id=>session[:assignment_id]%>
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@
t.float "Hamer", limit: 24, default: 1.0
t.float "Lauw", limit: 24, default: 0.0
t.integer "duty_id"
t.boolean "can_mentor"
t.boolean "can_mentor", default: false
t.index ["duty_id"], name: "index_participants_on_duty_id"
t.index ["user_id"], name: "fk_participant_users"
end
Expand Down
50 changes: 50 additions & 0 deletions spec/features/late_policy_features_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require_relative './helpers/assignment_creation_helper'

describe 'Assignment creation topics tab' do
include AssignmentCreationHelper
# This block runs before each test to set up the environment
before(:each) do
create_deadline_types
(1..3).each { |i| create(:course, name: "Course #{i}") }
@assignment = create(:assignment, name: 'assignment for late policy test')
login_as('instructor6')
visit "/assignments/#{@assignment.id}/edit"
check('assignment_form_assignment_calculate_penalty', allow_label_click: true)
click_link 'Due dates'
end

# Test to ensure no flash error message is displayed on the New Late Policy Page
it 'does not displays flash error message on New Late Policy Page' do
create(:topic, assignment_id: @assignment.id)
visit "/assignments/#{@assignment.id}/edit"
click_link 'Due dates'
click_link 'New late policy'
expected_error_message = "Failed to save the assignment: #{@assignment.id}"
expect(page).not_to have_content(expected_error_message)
end

# Test to check navigation back to the assignment edit page via the "Back" button
it 'navigates back to assignment edit page on Back button click' do
create(:topic, assignment_id: @assignment.id)
visit "/assignments/#{@assignment.id}/edit"
click_link 'Due dates'
click_link 'New late policy'
click_link 'Back'
expect(page).to have_current_path("/assignments/#{@assignment.id}/edit")
end

# Test to check navigation back to the assignment edit page while creating a late policy
it 'navigates back to assignment edit page while creating on Back button click' do
create(:topic, assignment_id: @assignment.id)
visit "/assignments/#{@assignment.id}/edit"
click_link 'Due dates'
click_link 'New late policy'
fill_in 'late_policy_policy_name', with: 'Test Late Policy'
fill_in 'late_policy_penalty_per_unit', with: '15'
fill_in 'late_policy_max_penalty', with: '20'
click_button 'Create'
visit '/late_policies'
click_link 'Back'
expect(page).to have_current_path("/assignments/#{@assignment.id}/edit")
end
end
25 changes: 25 additions & 0 deletions spec/features/late_policy_navigations_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require_relative './helpers/assignment_creation_helper'

describe 'Navigation scenarios for Late Policies' do
include AssignmentCreationHelper

# This block runs before each test to set up the necessary context
before(:each) do
@course = create(:course, name: 'Test Course')
login_as('instructor6')
end

# Test case for navigating back from "New Late Policy" to the Assignments tab when accessed directly
it 'navigates to Assignments tab on the home screen from New Late Policy' do
visit '/late_policies/new'
click_link 'Back'
expect(page).to have_current_path('/student_task/list')
end

# Test case for navigating back from "All Late Policies" to the Assignments tab when accessed directly
it 'navigates to Assignments tab on the home screen from All Late Policies' do
visit '/late_policies'
click_link 'Back'
expect(page).to have_current_path('/student_task/list')
end
end

0 comments on commit 9ad767b

Please sign in to comment.