Skip to content

Commit

Permalink
Merge pull request #12 from Jas0nch/hyu22
Browse files Browse the repository at this point in the history
Hyu22
  • Loading branch information
Jas0nch committed Dec 7, 2019
2 parents acc6ded + 15de576 commit 71183aa
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 19 deletions.
6 changes: 4 additions & 2 deletions app/controllers/questionnaires_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ class QuestionnairesController < ApplicationController
def action_allowed?
if params[:action] == "edit"
@questionnaire = Questionnaire.find(params[:id])
if @questionnaire.type == "SupplementaryReviewQuestionnaire"
return ['Student'].include? current_role_name
unless @questionnaire.nil?
if @questionnaire.type == "SupplementaryReviewQuestionnaire"
return ['Student'].include? current_role_name
end
end
(['Super-Administrator',
'Administrator'].include? current_role_name) ||
Expand Down
4 changes: 3 additions & 1 deletion app/models/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ def construct_review_response code, self_id, show_tags = nil, current_user = nil
questionnaire = self.questionnaire_by_answer(answers.first)
questionnaire_max = questionnaire.max_question_score
questions = questionnaire.questions.sort_by(&:seq)
supplementary_review_questionnaire_id = Team.get_supplementary_review_questionnaire_id_of_team(self.map.contributor.id)
unless self.map.nil? || self.map.contributor.nil?
supplementary_review_questionnaire_id = Team.get_supplementary_review_questionnaire_id_of_team(self.map.contributor.id)
end
unless supplementary_review_questionnaire_id.nil?
supplementary_review_questionnaire = Questionnaire.find(supplementary_review_questionnaire_id)
supplementary_review_questions = supplementary_review_questionnaire.questions.sort_by(&:seq)
Expand Down
2 changes: 1 addition & 1 deletion app/views/submitted_content/_main.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<!-- If the instructor allows the team to create supplementary review questionnaire, the link is give below -->
<% if stage != "Finished" and controller.controller_name == 'submitted_content' and @can_submit %>
<% if @assignment.is_supplementary_review_enabled %>
<%= link_to "Create Supplementary Review Questionnaire", {:controller => "supplementary_review_questionnaires", :action => "create_supplementary_review_questionnaire", :id => participant.id } %>
<%= link_to "Create/Edit Supplementary Review Questionnaire", {:controller => "supplementary_review_questionnaires", :action => "create_supplementary_review_questionnaire", :id => participant.id } %>
<% end %>
<% end %>

1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@
get :view
post :add_new_questions
post :save_all_questions
post :create_supplmentary_review_questionnaire
end
end

Expand Down
15 changes: 3 additions & 12 deletions spec/controllers/questionnaires_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ def check_access username
let(:questionnaire) { build(:questionnaire, id: 1) }
let(:instructor) { build(:instructor, id: 1) }
let(:ta) { build(:teaching_assistant, id: 10, parent_id: 66) }
let(:student) {build(:student, id: 1)}
context 'when params action is edit or update and role current user is not student' do
context 'when params action is edit or update' do
before(:each) do
controller.params = {id: '1', action: 'edit'}
controller.request.session[:user] = instructor
end

context 'when the role name of current user is super admin or admin' do
it 'allows certain action' do
check_access(admin).to be true
Expand Down Expand Up @@ -71,14 +70,6 @@ def check_access username
end
end
end
context 'when params action is edit or update and role current user is student and questionnaire is Supplementary Review Questionnaire' do

it 'allows certain action' do
questionnaire = create(:questionnaire, type: "SupplementaryReviewQuestionnaire")
check_access(student).to be true
end

end
context 'when params action is not edit and update' do
before(:each) do
controller.params = {id: '1', action: 'new'}
Expand Down Expand Up @@ -207,7 +198,7 @@ def check_access username
describe '#edit' do
context 'when @questionnaire is not nil' do
it 'renders the questionnaires#edit page' do
allow(Questionnaire).to receive(:find).with('1').and_return(double('Questionnaire', instructor_id: 6))
allow(Questionnaire).to receive(:find).with('1').and_return(double('Questionnaire', instructor_id: 6, type: 'ReviewQuestionnaire'))
session = {user: instructor}
params = {id: 1}
get :edit, params, session
Expand Down
24 changes: 24 additions & 0 deletions spec/controllers/supplementary_review_questionnaires_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
describe SupplementaryReviewQuestionnairesController do
let(:team) { build(:assignment_team, id: 1, name: "team1", assignment: assignment) }
let(:student1) { build(:student, id: 1, name: "student1") }
let(:student2) { build(:student, id: 2, name: "student2") }
let(:participant) { build(:participant, id: 1, user: student1, assignment: assignment) }
let(:participant2) { build(:participant, id: 2, user: student2, assignment: assignment) }
let(:assignment) { build(:assignment, id: 1) }

# test the method of create_supplementary_review_questionnaire
describe '#create_supplementary_review_questionnaire' do
it 'redirects to questionnaires#edit page after create a new supplementary review questionnaire' do
session = {user: student1}
allow(AssignmentParticipant).to receive(:find).with('1').and_return(participant)
allow(participant).to receive(:team).and_return(team)
allow(Team).to receive(:find).with(1).and_return(team)
params = {id: 1}
get :create_supplementary_review_questionnaire, params, session
expect(response).to redirect_to("/supplementary_review_questionnaires/#{team.supplementary_review_questionnaire_id}/edit")
end
end



end
1 change: 1 addition & 0 deletions spec/factories/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
is_calibrated false
has_badge false
allow_selecting_additional_reviews_after_1st_round false
is_supplementary_review_enabled true
end

factory :assignment_team, class: AssignmentTeam do
Expand Down
84 changes: 84 additions & 0 deletions spec/features/supplementary_review_questionnaire_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
describe "Supplementary Review Questionnaire", js: true do
before(:each) do
create(:assignment, name: "TestAssignment", directory_path: "TestAssignment")
create_list(:participant, 3)
create(:topic, topic_name: "TestTopic")
create(:deadline_type, name: "submission")
create(:deadline_type, name: "review")
create(:deadline_type, name: "metareview")
create(:deadline_type, name: "drop_topic")
create(:deadline_type, name: "signup")
create(:deadline_type, name: "team_formation")
create(:deadline_right)
create(:deadline_right, name: 'Late')
create(:deadline_right, name: 'OK')
create(:assignment_due_date, deadline_type: DeadlineType.where(name: "submission").first, due_at: DateTime.now.in_time_zone + 1.day)
(1..3).each do |i|
create(:course, name: "Course #{i}")
end

(1..3).each do |i|
create(:questionnaire, name: "ReviewQuestionnaire#{i}")
create(:questionnaire, name: "AuthorFeedbackQuestionnaire#{i}", type: 'AuthorFeedbackQuestionnaire')
create(:questionnaire, name: "TeammateReviewQuestionnaire#{i}", type: 'TeammateReviewQuestionnaire')
end
end

def signup_topic
user = User.find_by(name: "student2064")
stub_current_user(user, user.role.name, user.role)
visit '/student_task/list'
visit '/sign_up_sheet/sign_up?id=1&topic_id=1' # signup topic
visit '/student_task/list'
click_link "TestAssignment"
expect(page).to have_content("Your work")
click_link "Your work"
end

it "can create assignment with supplementary review questoinnaire" do
# Instructor logs in and visits the page of assignment creation
login_as("instructor6")
visit '/assignments/new?private=1'

# Fill in the form under 'General'
fill_in 'assignment_form_assignment_name', with: 'test assignment'
select('Course 2', from: 'assignment_form_assignment_course_id')
fill_in 'assignment_form_assignment_directory_path', with: 'test directory'
check("team_assignment")

# Fill in the form under 'Rubrics'
click_link 'Rubrics'

within(:css, "tr#questionnaire_table_ReviewQuestionnaire") do
select "ReviewQuestionnaire2", from: 'assignment_form[assignment_questionnaire][][questionnaire_id]'
end


within(:css, "tr#questionnaire_table_AuthorFeedbackQuestionnaire") do
select "AuthorFeedbackQuestionnaire2", from: 'assignment_form[assignment_questionnaire][][questionnaire_id]'
end

within(:css, "tr#questionnaire_table_TeammateReviewQuestionnaire") do
select "TeammateReviewQuestionnaire2", from: 'assignment_form[assignment_questionnaire][][questionnaire_id]'
end

# Fill in the form under Review strategy
click_link 'Review strategy'
check 'assignment_form_assignment_is_supplementary_review_enabled'

# Click to create the assignment
click_button 'Create'

# check if the assignment is created successfully
assignment = Assignment.where(name: 'test assignment').first
expect(assignment).to have_attributes(
is_supplementary_review_enabled: true
)
end

it "can add supplementary review questions" do
signup_topic
click_link 'Create/Edit Supplementary Review Questionnaire'
expect(page).to have_content("Edit Review")
end
end
4 changes: 2 additions & 2 deletions spec/models/assignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
expect(assignment.scores(review1: [question]).inspect).to eq("{:participants=>{:\"1\"=>98}, :teams=>{:\"0\"=>{:team=>#<AssignmentTeam id: 1, "\
"name: \"no team\", parent_id: 1, type: \"AssignmentTeam\", comments_for_advertisement: nil, advertise_for_partner: nil, "\
"submitted_hyperlinks: \"---\\n- https://www.expertiza.ncsu.edu\", directory_num: 0, grade_for_submission: nil, "\
"comment_for_submission: nil>, :scores=>{:max=>95, :min=>88, :avg=>90.0}}}}")
"comment_for_submission: nil, supplementary_review_questionnaire_id: nil>, :scores=>{:max=>95, :min=>88, :avg=>90.0}}}}")
end
end

Expand All @@ -160,7 +160,7 @@
expect(assignment.scores(review: [question]).inspect).to eq("{:participants=>{:\"1\"=>98}, :teams=>{:\"0\"=>{:team=>#<AssignmentTeam id: 1, "\
"name: \"no team\", parent_id: 1, type: \"AssignmentTeam\", comments_for_advertisement: nil, advertise_for_partner: nil, "\
"submitted_hyperlinks: \"---\\n- https://www.expertiza.ncsu.edu\", directory_num: 0, grade_for_submission: nil, "\
"comment_for_submission: nil>, :scores=>{:max=>95, :min=>88, :avg=>90}}}}")
"comment_for_submission: nil, supplementary_review_questionnaire_id: nil>, :scores=>{:max=>95, :min=>88, :avg=>90}}}}")
end
end
end
Expand Down

0 comments on commit 71183aa

Please sign in to comment.