From c54b1122fbbba48af07f24c320e0744e9ebbc39c Mon Sep 17 00:00:00 2001 From: Delaney Dow Date: Sat, 22 Mar 2025 18:44:07 -0400 Subject: [PATCH 01/18] initial commit with testing framework --- .../submission_records_controller.rb | 22 +++++++++ app/models/submission_record.rb | 7 +++ .../submission_records_controller_spec.rb | 47 +++++++++++++++++++ spec/models/submission_record_spec.rb | 40 ++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 app/controllers/submission_records_controller.rb create mode 100644 app/models/submission_record.rb create mode 100644 spec/controllers/submission_records_controller_spec.rb create mode 100644 spec/models/submission_record_spec.rb diff --git a/app/controllers/submission_records_controller.rb b/app/controllers/submission_records_controller.rb new file mode 100644 index 000000000..b37ec675c --- /dev/null +++ b/app/controllers/submission_records_controller.rb @@ -0,0 +1,22 @@ +class SubmissionRecordsController < ApplicationController + include AuthorizationHelper + + before_action :set_submission_record, only: %i[show edit update destroy] + + def action_allowed? + # currently we only have a index method which shows all the submission records given a team_id + assignment_team = AssignmentTeam.find(params[:team_id]) + assignment = Assignment.find(assignment_team.parent_id) + return true if current_user_has_admin_privileges? + return true if current_user_has_instructor_privileges? && current_user_instructs_assignment?(assignment) + return true if current_user_has_ta_privileges? && current_user_has_ta_mapping_for_assignment?(assignment) + + false + end + + # Show submission records. + # expects to get team_id from params + def index + @submission_records = SubmissionRecord.where(team_id: params[:team_id]) + end +end \ No newline at end of file diff --git a/app/models/submission_record.rb b/app/models/submission_record.rb new file mode 100644 index 000000000..4a1b80694 --- /dev/null +++ b/app/models/submission_record.rb @@ -0,0 +1,7 @@ +class SubmissionRecord < ApplicationRecord + validates :content, presence: true + validates :operation, presence: true + validates :team_id, presence: true + validates :user, presence: true + validates :assignment_id, presence: true +end \ No newline at end of file diff --git a/spec/controllers/submission_records_controller_spec.rb b/spec/controllers/submission_records_controller_spec.rb new file mode 100644 index 000000000..7795d0063 --- /dev/null +++ b/spec/controllers/submission_records_controller_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true +require 'rails_helper' + +RSpec.describe SubmissionRecordsController, type: :controller do + let(:student_user) { create(:student) } + let(:assignment) { create(:assignment) } + let(:assignment_team) { create(:assignment_team, parent_id: assignment.id) } + let(:submission_record) { create(:submission_record, team_id: assignment_team.id) } + + before do + assignment_team.users << student_user + end + + describe 'GET #index' do + + context 'when user is student' do + before { sign_in student_user } + + it 'assigns all submission records to @submission_records' do + get :index, params: { team_id: assignment_team.id } + expect(assigns(:submission_records)).to eq([submission_record]) + end + + it 'renders the index template' do + get :index, params: { team_id: assignment_team.id } + expect(response).to render_template('index') + end + end + + context 'when user is a student but not in the team' do + let(:other_student) { create(:student) } + before { sign_in other_student } + + it 'denies access' do + get :index, params: { team_id: assignment_team.id } + expect(response).to have_http_status(:forbidden) + end + end + + context 'when user is not logged in' do + it 'denies access' do + get :index, params: { team_id: assignment_team.id } + expect(response).to have_http_status(:forbidden) + end + end + end +end \ No newline at end of file diff --git a/spec/models/submission_record_spec.rb b/spec/models/submission_record_spec.rb new file mode 100644 index 000000000..4c1f87a11 --- /dev/null +++ b/spec/models/submission_record_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true +require 'rails_helper' + +##just needs to validate that submission is valid, if anything + +RSpec.describe SubmissionRecord, type: :model do + describe "validations" do + it "is valid with valid attributes" do + submission = build(:submission_record) + expect(submission).to be_valid + end + + it "is invalid without a user" do + submission = build(:submission_record, user: nil) + expect(submission).not_to be_valid + end + + it "is invalid without an assignment" do + submission = build(:submission_record, assignment: nil) + expect(submission).not_to be_valid + end + end + + describe "associations" do + it { should belong_to(:user) } + it { should belong_to(:assignment) } + end + + describe "scopes and methods" do + let(:user) { create(:user) } + let(:assignment) { create(:assignment) } + let!(:old_submission) { create(:submission_record, user: user, assignment: assignment, created_at: 1.week.ago) } + let!(:new_submission) { create(:submission_record, user: user, assignment: assignment, created_at: 1.day.ago) } + + it "returns submissions in descending order" do + expect(SubmissionRecord.ordered_by_date).to eq([new_submission, old_submission]) + end + end +end + From 30d358dc45c09956831f5a126ab08167c91481af Mon Sep 17 00:00:00 2001 From: Delaney Dow Date: Sat, 22 Mar 2025 19:03:18 -0400 Subject: [PATCH 02/18] Adding list.html.erb in student task view Still need to modify the file to add task link to view submission records once that has been committed --- app/views/student_task/list.html.erb.html | 149 ++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 app/views/student_task/list.html.erb.html diff --git a/app/views/student_task/list.html.erb.html b/app/views/student_task/list.html.erb.html new file mode 100644 index 000000000..52a42842b --- /dev/null +++ b/app/views/student_task/list.html.erb.html @@ -0,0 +1,149 @@ +

<%=t ".assignments" %>

+ + +
+
+    <%= @tasknotstarted.size.to_s %>  <%=t ".tasks_not_started" %>

+ + <% @tasknotstarted.each do |student_task| + participant = student_task.participant + stage = student_task.current_stage + controller = "" + action = "" + if stage == "submission" || stage == 'signup' + controller = "submitted_content" + action = "edit" + + # check if the assignment has a sign-up sheet + if Assignment.find(participant.assignment.id).topics? + selected_topics = nil + + #ACS Get the topics selected by all teams + #removed code that handles team and individual assignments differently + # get the user's team and check if they have signed up for a topic yet + users_team = Team.find_team_users(participant.assignment.id,participant.user.id) + if users_team.size > 0 + selected_topics = SignedUpTeam.find_user_signup_topics(participant.assignment.id,users_team[0].t_id) + end + + if selected_topics.nil? || selected_topics.length == 0 + # there is a signup sheet and user/team hasn't signed up yet, produce a link to do so + controller = "sign_up_sheet" + action = "list" + end + end + elsif stage == "review" or stage == "metareview" + assignment = Assignment.find(participant.assignment.id) + if assignment.bidding_for_reviews_enabled == 'Bidding' and assignment.can_choose_topic_to_review? + controller = "review_bids" + action = "show" + elsif assignment.bidding_for_reviews_enabled == 'Bidding' + controller = "review_bids" + action = "index" + else + controller = "student_review" + action = "list" + end + end + %> + +   » + <%= link_to student_task.assignment.name + " " + student_task.current_stage, :controller => controller, :action => action, :id => participant.id %> + (<%= student_task.relative_deadline %> <%=t ".left" %>) +
+ <% end %> + +
   <%= @taskrevisions.size.to_s %>  <%=t ".revisions" %>

+ <% @taskrevisions.each do |student_task| + participant = student_task.participant + stage = student_task.current_stage + topic_id = SignedUpTeam.topic_id(participant.parent_id, participant.user_id) + duedate = participant.assignment.stage_deadline(topic_id) + controller = "" + action = "" + if stage == "submission" + controller = "submitted_content" + action = "edit" + elsif stage == "review" or stage == "metareview" + controller = "student_review" + action = "list" + end + %> + +   » <%= link_to participant.assignment.name + " " + + stage, :controller => controller, :action => action, :id => participant.id %> +(<%= time_ago_in_words(duedate) %> left)
+ <% end %> +
+ + <%=t ".student_team" %>

+ + <% @students_teamed_with.keys.each do |course_id| %> +    <%= @students_teamed_with[course_id].size.to_s %>  + <%if course_id.nil?%> + <%=t ".not_associated" %> + <%else%> + <%= Course.find(course_id).name %> + <%end%> +

+ <% if @students_teamed_with[course_id].size %> + <% @students_teamed_with[course_id].each do |student|%> +   » <%= student %>
+ <% end %> + <% end %> + <% end %> +
+
+ + + + + + + + + + + + <% @student_tasks.each do |student_task| %> + <% participant = student_task.participant %> + <% if student_task.assignment %> + + + + + + + <% topic_id = SignedUpTeam.topic_id(participant.parent_id, participant.user_id) %> + <% if SignUpTopic.exists?(topic_id) %> + + <% else %> + + <% end %> + + + + + + + + + + + + + + + <% end %> + <% end %> +
<%=t ".assignment_name" %><%=t ".course" %><%=t ".topic" %><%=t ".current_stage" %><%=t ".review_grade" %><%=t ".badges" %><%=t ".stage_deadline" %><%=t ".publishing_rights" %>
<%= link_to student_task.assignment.name, :action => 'view', :id => participant %><%= student_task.course.try :name %><%= SignUpTopic.find(topic_id).try :topic_name %>- + <% if participant.assignment.link_for_current_stage(topic_id)!= nil && participant.assignment.link_for_current_stage(topic_id).length!=0%> + <%= link_to participant.assignment.current_stage_name(topic_id), participant.assignment.link_for_current_stage(topic_id) %> + <% else %> + <%= participant.assignment.current_stage_name(topic_id) %> + <% end %> + <%= get_review_grade_info(participant) %><%= get_awarded_badges(participant) %><%= student_task.stage_deadline.in_time_zone(session[:user].timezonepref) %> + checked<%end%>> +
+
+
\ No newline at end of file From a6e2270df650b415cebb35147b6e47e83e898e9b Mon Sep 17 00:00:00 2001 From: Delaney Dow Date: Sat, 22 Mar 2025 20:22:27 -0400 Subject: [PATCH 03/18] Updating RSpec framework - ensuring that framework only tests functionality that we are adding to the OSS rather than testing existing functionality --- .../submission_records_controller_spec.rb | 48 ++++++++++--------- spec/models/submission_record_spec.rb | 2 +- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/spec/controllers/submission_records_controller_spec.rb b/spec/controllers/submission_records_controller_spec.rb index 7795d0063..d44e7b1fb 100644 --- a/spec/controllers/submission_records_controller_spec.rb +++ b/spec/controllers/submission_records_controller_spec.rb @@ -2,46 +2,50 @@ require 'rails_helper' RSpec.describe SubmissionRecordsController, type: :controller do - let(:student_user) { create(:student) } - let(:assignment) { create(:assignment) } - let(:assignment_team) { create(:assignment_team, parent_id: assignment.id) } - let(:submission_record) { create(:submission_record, team_id: assignment_team.id) } - - before do - assignment_team.users << student_user - end + # pulling assumptions from factorybots. + # A mock student and assignment have already been created to generate a submission record. + let(:student_user) { create(:student) } # TODO check this is set up correctly + let(:assignment) { create(:assignment) } # TODO check this is set up correctly + let(:submission_record) { create(:submission_record) } # TODO check this is set up correctly describe 'GET #index' do - context 'when user is student' do - before { sign_in student_user } - - it 'assigns all submission records to @submission_records' do - get :index, params: { team_id: assignment_team.id } - expect(assigns(:submission_records)).to eq([submission_record]) + # only testing for when user is a student, assume existing functionality already works + # expected output: when user is a student the submission records should be accessed successfully + context "user is student" do + before do + sign_in student_user + get :index end - it 'renders the index template' do - get :index, params: { team_id: assignment_team.id } - expect(response).to render_template('index') + it "renders student view" do + expect(response).to render_template("student_task/list") end end + # it 'renders the index template' do + # get :index, params: { team_id: assignment_team.id } + # expect(response).to render_template('index') + # end + + # goal: ensure that other students cannot view another submission record context 'when user is a student but not in the team' do - let(:other_student) { create(:student) } + let(:other_student) { create(:student) } # create other student that is not in the team before { sign_in other_student } it 'denies access' do - get :index, params: { team_id: assignment_team.id } expect(response).to have_http_status(:forbidden) end end - + # goal: denies access if user is not logged in context 'when user is not logged in' do + before {get :index } it 'denies access' do - get :index, params: { team_id: assignment_team.id } expect(response).to have_http_status(:forbidden) end end end -end \ No newline at end of file +end + + + diff --git a/spec/models/submission_record_spec.rb b/spec/models/submission_record_spec.rb index 4c1f87a11..4a5cba5ab 100644 --- a/spec/models/submission_record_spec.rb +++ b/spec/models/submission_record_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'rails_helper' -##just needs to validate that submission is valid, if anything +#just needs to validate that submission is valid, if anything RSpec.describe SubmissionRecord, type: :model do describe "validations" do From 98cb12fd91112c1dcf19003c4ad4cc742e6e5e4c Mon Sep 17 00:00:00 2001 From: priya gandhi Date: Sat, 22 Mar 2025 20:38:19 -0400 Subject: [PATCH 04/18] added column for checking submission history --- app/views/student_task/list.html.erb.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/views/student_task/list.html.erb.html b/app/views/student_task/list.html.erb.html index 52a42842b..53106cd3a 100644 --- a/app/views/student_task/list.html.erb.html +++ b/app/views/student_task/list.html.erb.html @@ -103,6 +103,7 @@

<%=t ".assignments" %>

<%=t ".review_grade" %> <%=t ".badges" %> <%=t ".stage_deadline" %> + <%=t ".submission_history" %> <%=t ".publishing_rights" %> <% @student_tasks.each do |student_task| %> @@ -136,7 +137,11 @@

<%=t ".assignments" %>

<%= student_task.stage_deadline.in_time_zone(session[:user].timezonepref) %> - + + <%= link_to "Submission History", submission_records_path(team_id: participant.team.id) %> + + + checked<%end%>> From 20d4957370d9dfdc52b720389b633c9281775bb1 Mon Sep 17 00:00:00 2001 From: priya gandhi Date: Sat, 22 Mar 2025 20:44:46 -0400 Subject: [PATCH 05/18] Added route for student to view their submission record --- config/routes.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index 33df803e7..5d52b541f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -23,6 +23,9 @@ get 'role/:name', action: :role_users end end + + resources :submission_records, only: [:index] + resources :assignments do collection do post '/:assignment_id/add_participant/:user_id',action: :add_participant From 26e34b9ba6ae03b440bd4c41b7b66a2074f78225 Mon Sep 17 00:00:00 2001 From: priya gandhi Date: Sat, 22 Mar 2025 20:51:07 -0400 Subject: [PATCH 06/18] Added view for student to see their submission history --- app/views/submission_records/index.html.erb | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 app/views/submission_records/index.html.erb diff --git a/app/views/submission_records/index.html.erb b/app/views/submission_records/index.html.erb new file mode 100644 index 000000000..4df6230d3 --- /dev/null +++ b/app/views/submission_records/index.html.erb @@ -0,0 +1,36 @@ +

Submission History

+ +<% if @submission_records.any? %> + + + + + + + + + + + + <% @submission_records.each do |record| %> + + + + + + + + <% end %> + +
Submission IDSubmitted BySubmission TimeFileComments
<%= record.id %><%= record.submitter.try(:name) || "Unknown" %><%= record.created_at.strftime("%Y-%m-%d %H:%M:%S") %> + <% if record.file_url.present? %> + <%= link_to "View File", record.file_url, target: "_blank" %> + <% else %> + No file uploaded + <% end %> + <%= record.comments.presence || "No comments" %>
+<% else %> +

No submission records found for this team.

+<% end %> + +<%= link_to "Back to Assignments", assignments_path, class: "btn btn-primary" %> From a677be95409365fbb41a4a6578d811b1c4572c30 Mon Sep 17 00:00:00 2001 From: stallap Date: Sun, 23 Mar 2025 10:22:33 -0400 Subject: [PATCH 07/18] Modified the Submission record controller file to let the students view their history of submissions, Modified submission_records_controller.rb to allow students to view their team's submission history --- 2 | 0 .../submission_records_controller.rb | 44 +++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 2 diff --git a/2 b/2 new file mode 100644 index 000000000..e69de29bb diff --git a/app/controllers/submission_records_controller.rb b/app/controllers/submission_records_controller.rb index b37ec675c..4cd23f88e 100644 --- a/app/controllers/submission_records_controller.rb +++ b/app/controllers/submission_records_controller.rb @@ -1,22 +1,50 @@ class SubmissionRecordsController < ApplicationController include AuthorizationHelper + # Set up before_action callbacks before_action :set_submission_record, only: %i[show edit update destroy] + before_action :set_assignment_team, only: [:index] + # Determines if the current user has permission to access submission records + # Returns true for: + # - Administrators + # - Instructors teaching the assignment + # - TAs assigned to the assignment + # - Students who are members of the team def action_allowed? - # currently we only have a index method which shows all the submission records given a team_id - assignment_team = AssignmentTeam.find(params[:team_id]) - assignment = Assignment.find(assignment_team.parent_id) + # Allow access to instructors, TAs, and admins return true if current_user_has_admin_privileges? - return true if current_user_has_instructor_privileges? && current_user_instructs_assignment?(assignment) - return true if current_user_has_ta_privileges? && current_user_has_ta_mapping_for_assignment?(assignment) + return true if current_user_has_instructor_privileges? && current_user_instructs_assignment?(@assignment) + return true if current_user_has_ta_privileges? && current_user_has_ta_mapping_for_assignment?(@assignment) + + # Allow students to view their own team's submission records + if current_user_has_student_privileges? + return true if @assignment_team.user_id == current_user.id || @assignment_team.users.include?(current_user) + end false end - # Show submission records. - # expects to get team_id from params + # Displays submission records for a specific assignment team + # - Fetches all records for the team + # - Orders them by most recent first + # - Makes them available to the view as @submission_records def index - @submission_records = SubmissionRecord.where(team_id: params[:team_id]) + @submission_records = SubmissionRecord.where(team_id: @assignment_team.id) + .order(created_at: :desc) # Order by most recent first + end + + private + + # Sets up the assignment team and assignment for the current request + # Used by the index action to ensure proper context for viewing records + def set_assignment_team + @assignment_team = AssignmentTeam.find(params[:team_id]) + @assignment = @assignment_team.parent + end + + # Sets up a single submission record for show/edit/update/destroy actions + def set_submission_record + @submission_record = SubmissionRecord.find(params[:id]) end end \ No newline at end of file From 9cb62555ff59f91eb0306741cc9804579bf20032 Mon Sep 17 00:00:00 2001 From: stallap Date: Sun, 23 Mar 2025 11:00:42 -0400 Subject: [PATCH 08/18] Added associations and scopes to SubmissionRecord model - Added belongs_to associations for user, team, and assignment - Added scopes for recent, for_team, and for_assignment queries --- app/models/submission_record.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/models/submission_record.rb b/app/models/submission_record.rb index 4a1b80694..6ab3a7d2e 100644 --- a/app/models/submission_record.rb +++ b/app/models/submission_record.rb @@ -1,7 +1,20 @@ +# Represents a record of a submission made by a student team +# This model tracks all submission activities class SubmissionRecord < ApplicationRecord + # Associations + belongs_to :user + belongs_to :team, class_name: 'AssignmentTeam' + belongs_to :assignment + + # Validations validates :content, presence: true validates :operation, presence: true validates :team_id, presence: true validates :user, presence: true validates :assignment_id, presence: true + + # Scopes for common queries + scope :recent, -> { order(created_at: :desc) } + scope :for_team, ->(team_id) { where(team_id: team_id) } + scope :for_assignment, ->(assignment_id) { where(assignment_id: assignment_id) } end \ No newline at end of file From 5eaef15ce35e0ad31f947c5320428f3864906de2 Mon Sep 17 00:00:00 2001 From: stallap Date: Sun, 23 Mar 2025 11:04:58 -0400 Subject: [PATCH 09/18] Updated submission records view for student access - Updated index view to display submission history in table format - Removed the Files and Comment fields to match up with the model. - Added proper error handling for empty records - Removed incorrect navigation link --- app/views/submission_records/index.html.erb | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/app/views/submission_records/index.html.erb b/app/views/submission_records/index.html.erb index 4df6230d3..26993f35e 100644 --- a/app/views/submission_records/index.html.erb +++ b/app/views/submission_records/index.html.erb @@ -7,24 +7,16 @@ Submission ID Submitted By Submission Time - File - Comments + Content <% @submission_records.each do |record| %> <%= record.id %> - <%= record.submitter.try(:name) || "Unknown" %> + <%= record.user.try(:name) || "Unknown" %> <%= record.created_at.strftime("%Y-%m-%d %H:%M:%S") %> - - <% if record.file_url.present? %> - <%= link_to "View File", record.file_url, target: "_blank" %> - <% else %> - No file uploaded - <% end %> - - <%= record.comments.presence || "No comments" %> + <%= truncate(record.content, length: 50) %> <% end %> @@ -32,5 +24,3 @@ <% else %>

No submission records found for this team.

<% end %> - -<%= link_to "Back to Assignments", assignments_path, class: "btn btn-primary" %> From 8ed1d82e76433b780f3f47d93de58de67f4dbd79 Mon Sep 17 00:00:00 2001 From: stallap Date: Mon, 24 Mar 2025 09:17:47 -0400 Subject: [PATCH 10/18] Updated the controller file for response handling Added necessary response code handling such as 200,400 for proper testing functionality --- .../submission_records_controller.rb | 52 +++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/app/controllers/submission_records_controller.rb b/app/controllers/submission_records_controller.rb index 4cd23f88e..9b6352920 100644 --- a/app/controllers/submission_records_controller.rb +++ b/app/controllers/submission_records_controller.rb @@ -4,6 +4,7 @@ class SubmissionRecordsController < ApplicationController # Set up before_action callbacks before_action :set_submission_record, only: %i[show edit update destroy] before_action :set_assignment_team, only: [:index] + rescue_from ActiveRecord::RecordNotFound, with: :not_found # Determines if the current user has permission to access submission records # Returns true for: @@ -18,8 +19,8 @@ def action_allowed? return true if current_user_has_ta_privileges? && current_user_has_ta_mapping_for_assignment?(@assignment) # Allow students to view their own team's submission records - if current_user_has_student_privileges? - return true if @assignment_team.user_id == current_user.id || @assignment_team.users.include?(current_user) + if current_user_has_student_privileges? && (@assignment_team.user_id == current_user.id || @assignment_team.users.include?(current_user)) + return true end false @@ -31,7 +32,40 @@ def action_allowed? # - Makes them available to the view as @submission_records def index @submission_records = SubmissionRecord.where(team_id: @assignment_team.id) - .order(created_at: :desc) # Order by most recent first + .order(created_at: :desc) # Order by most recent first + render json: @submission_records, status: :ok + rescue StandardError => e + render json: { error: e.message }, status: :unprocessable_entity + end + + # GET /submission_records/:id + def show + render json: @submission_record, status: :ok + end + + # POST /submission_records + def create + @submission_record = SubmissionRecord.new(submission_record_params) + if @submission_record.save + render json: @submission_record, status: :created + else + render json: @submission_record.errors, status: :unprocessable_entity + end + end + + # PATCH/PUT /submission_records/:id + def update + if @submission_record.update(submission_record_params) + render json: @submission_record, status: :ok + else + render json: @submission_record.errors, status: :unprocessable_entity + end + end + + # DELETE /submission_records/:id + def destroy + @submission_record.destroy + render json: { message: 'Submission record deleted successfully' }, status: :no_content end private @@ -41,10 +75,20 @@ def index def set_assignment_team @assignment_team = AssignmentTeam.find(params[:team_id]) @assignment = @assignment_team.parent + rescue ActiveRecord::RecordNotFound + render json: { error: 'Assignment team not found' }, status: :not_found end # Sets up a single submission record for show/edit/update/destroy actions def set_submission_record @submission_record = SubmissionRecord.find(params[:id]) end -end \ No newline at end of file + + def submission_record_params + params.require(:submission_record).permit(:team_id, :operation, :user, :content, :created_at) + end + + def not_found + render json: { error: 'Submission record not found' }, status: :not_found + end +end From bbabe0a31d5c2448cf901396228a24e2c2806cc4 Mon Sep 17 00:00:00 2001 From: stallap Date: Mon, 24 Mar 2025 09:18:18 -0400 Subject: [PATCH 11/18] Updated the Rspec controller for testing Updated the file to handle the proper response handling during the testing. --- .../submission_records_controller_spec.rb | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/spec/controllers/submission_records_controller_spec.rb b/spec/controllers/submission_records_controller_spec.rb index d44e7b1fb..715022568 100644 --- a/spec/controllers/submission_records_controller_spec.rb +++ b/spec/controllers/submission_records_controller_spec.rb @@ -1,51 +1,41 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe SubmissionRecordsController, type: :controller do - # pulling assumptions from factorybots. - # A mock student and assignment have already been created to generate a submission record. - let(:student_user) { create(:student) } # TODO check this is set up correctly - let(:assignment) { create(:assignment) } # TODO check this is set up correctly - let(:submission_record) { create(:submission_record) } # TODO check this is set up correctly + let(:student_user) { create(:student) } + let(:assignment) { create(:assignment) } + let(:submission_record) { create(:submission_record) } describe 'GET #index' do - - # only testing for when user is a student, assume existing functionality already works - # expected output: when user is a student the submission records should be accessed successfully - context "user is student" do + context 'user is student' do before do sign_in student_user get :index end - it "renders student view" do - expect(response).to render_template("student_task/list") + it 'renders student view' do + expect(response).to render_template('student_task/list') + expect(response).to have_http_status(:ok) end end - # it 'renders the index template' do - # get :index, params: { team_id: assignment_team.id } - # expect(response).to render_template('index') - # end - - # goal: ensure that other students cannot view another submission record context 'when user is a student but not in the team' do - let(:other_student) { create(:student) } # create other student that is not in the team + let(:other_student) { create(:student) } before { sign_in other_student } it 'denies access' do + get :index expect(response).to have_http_status(:forbidden) end end - # goal: denies access if user is not logged in + context 'when user is not logged in' do - before {get :index } + before { get :index } + it 'denies access' do expect(response).to have_http_status(:forbidden) end end end end - - - From 39fec62f4b0e1e3aab74297224be36db16e9413e Mon Sep 17 00:00:00 2001 From: Delaney Dow Date: Mon, 24 Mar 2025 10:58:01 -0400 Subject: [PATCH 12/18] Updated RSpec file locations, added HTTP code handling Ensuring that updated controllers past test cases, RSpec files are compatible with API handling, Swagger, etc. according to project specifications --- .../submission_records_controller_spec.rb | 41 ----- spec/models/submission_record_spec.rb | 40 ----- .../requests/api/v1/submission_record_spec.rb | 163 ++++++++++++++++++ .../v1/submission_records_controller_spec.rb | 129 ++++++++++++++ 4 files changed, 292 insertions(+), 81 deletions(-) delete mode 100644 spec/controllers/submission_records_controller_spec.rb delete mode 100644 spec/models/submission_record_spec.rb create mode 100644 spec/requests/api/v1/submission_record_spec.rb create mode 100644 spec/requests/api/v1/submission_records_controller_spec.rb diff --git a/spec/controllers/submission_records_controller_spec.rb b/spec/controllers/submission_records_controller_spec.rb deleted file mode 100644 index 715022568..000000000 --- a/spec/controllers/submission_records_controller_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe SubmissionRecordsController, type: :controller do - let(:student_user) { create(:student) } - let(:assignment) { create(:assignment) } - let(:submission_record) { create(:submission_record) } - - describe 'GET #index' do - context 'user is student' do - before do - sign_in student_user - get :index - end - - it 'renders student view' do - expect(response).to render_template('student_task/list') - expect(response).to have_http_status(:ok) - end - end - - context 'when user is a student but not in the team' do - let(:other_student) { create(:student) } - before { sign_in other_student } - - it 'denies access' do - get :index - expect(response).to have_http_status(:forbidden) - end - end - - context 'when user is not logged in' do - before { get :index } - - it 'denies access' do - expect(response).to have_http_status(:forbidden) - end - end - end -end diff --git a/spec/models/submission_record_spec.rb b/spec/models/submission_record_spec.rb deleted file mode 100644 index 4a5cba5ab..000000000 --- a/spec/models/submission_record_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true -require 'rails_helper' - -#just needs to validate that submission is valid, if anything - -RSpec.describe SubmissionRecord, type: :model do - describe "validations" do - it "is valid with valid attributes" do - submission = build(:submission_record) - expect(submission).to be_valid - end - - it "is invalid without a user" do - submission = build(:submission_record, user: nil) - expect(submission).not_to be_valid - end - - it "is invalid without an assignment" do - submission = build(:submission_record, assignment: nil) - expect(submission).not_to be_valid - end - end - - describe "associations" do - it { should belong_to(:user) } - it { should belong_to(:assignment) } - end - - describe "scopes and methods" do - let(:user) { create(:user) } - let(:assignment) { create(:assignment) } - let!(:old_submission) { create(:submission_record, user: user, assignment: assignment, created_at: 1.week.ago) } - let!(:new_submission) { create(:submission_record, user: user, assignment: assignment, created_at: 1.day.ago) } - - it "returns submissions in descending order" do - expect(SubmissionRecord.ordered_by_date).to eq([new_submission, old_submission]) - end - end -end - diff --git a/spec/requests/api/v1/submission_record_spec.rb b/spec/requests/api/v1/submission_record_spec.rb new file mode 100644 index 000000000..be2b6c096 --- /dev/null +++ b/spec/requests/api/v1/submission_record_spec.rb @@ -0,0 +1,163 @@ +# frozen_string_literal: true +require 'rails_helper' +require 'swagger_helper' + +RSpec.describe 'Submission Records API', type: :request do + let(:valid_headers) { { "Authorization" => "Bearer valid_token" } } + let(:invalid_headers) { { "Authorization" => "Bearer invalid_token" } } + + before(:all) do + @roles = create_roles_hierarchy + end + + let(:student) do + User.create!( + name: 'StudentA', + password_digest: "password", + role_id: @roles[:student].id, + full_name: "Student A", + email: "studenta@example.com", + ) + end + + let(:instructor) do + User.create!( + name: "Instructor", + password_digest: "password", + role_id: @roles[:instructor].id, + full_name: "Instructor Name", + email: "instructor@example.com" + ) + end + + let!(:assignment) do + Assignment.create!( + name: 'Test Assignment', + instructor_id: instructor.id + ) + end + + let!(:team) do + Team.create!( + name: 'Team A', + assignment: assignment, + users: [student], + parent_id: 1 + ) + end + + let!(:submission_record) do + SubmissionRecord.create!( + team_id: team.id, + assignment_id: assignment.id, + user: student, + operation: "submit", + content: "Test submission" + ) + end + + let(:token) { JsonWebToken.encode({ id: student.id }) } + let(:Authorization) { "Bearer #{token}" } + + path '/submission_records/{id}' do + get 'Retrieve a Submission Record' do + tags 'Submission Records' + produces 'application/json' + parameter name: :id, in: :path, type: :integer, required: true, description: 'Submission Record ID' + parameter name: :Authorization, in: :header, type: :string, required: true, description: 'Bearer Token' + + response '200', 'submission record found' do + let(:id) { submission_record.id } + run_test! + end + + response '404', 'submission record not found' do + let(:id) { 9999999 } + run_test! + end + + response '500', 'internal server error' do + before do + allow(SubmissionRecord).to receive(:find).and_raise(StandardError) + end + let(:id) { submission_record.id } + run_test! + end + end + end + + path '/submission_records' do + post 'Create a Submission Record' do + tags 'Submission Records' + consumes 'application/json' + produces 'application/json' + parameter name: :submission_record, in: :body, schema: { + type: :object, + properties: { + team_id: { type: :integer }, + assignment_id: { type: :integer }, + user_id: { type: :integer }, + operation: { type: :string }, + content: { type: :string } + } + } + parameter name: :Authorization, in: :header, type: :string, required: true, description: 'Bearer Token' + + response '201', 'submission record created' do + let(:submission_record) do + { + team_id: team.id, + assignment_id: assignment.id, + user_id: student.id, + operation: "submit", + content: "New submission" + } + end + run_test! + end + + response '400', 'bad request - missing parameters' do + let(:submission_record) { { operation: "submit" } } # Missing required fields + run_test! + end + end + end + + path '/submission_records/{id}' do + delete 'Delete a Submission Record' do + tags 'Submission Records' + parameter name: :id, in: :path, type: :integer, required: true, description: 'Submission Record ID' + parameter name: :Authorization, in: :header, type: :string, required: true, description: 'Bearer Token' + + response '204', 'submission record deleted' do + let(:id) { submission_record.id } + run_test! + end + + response '404', 'submission record not found' do + let(:id) { 9999999 } + run_test! + end + + response '403', 'forbidden - student cannot delete' do + let(:Authorization) { "Bearer #{JsonWebToken.encode({ id: other_student.id })}" } + let(:id) { submission_record.id } + run_test! + end + + response '401', 'unauthorized - invalid token' do + let(:Authorization) { "Bearer invalid_token" } + let(:id) { submission_record.id } + run_test! + end + + response '503', 'catch all' do + before do + allow(SubmissionRecord).to receive(:find).and_raise(ActiveRecord::ConnectionNotEstablished) + end + let(:id) { submission_record.id } + run_test! + end + end + end +end diff --git a/spec/requests/api/v1/submission_records_controller_spec.rb b/spec/requests/api/v1/submission_records_controller_spec.rb new file mode 100644 index 000000000..8b1f8ee3d --- /dev/null +++ b/spec/requests/api/v1/submission_records_controller_spec.rb @@ -0,0 +1,129 @@ +# frozen_string_literal: true +require 'rails_helper' +require 'swagger_helper' +require 'json_web_token' + +# spec/requests/api/v1/submission_records_spec.rb + +#INITIALIZE TESTING OBJECTS +RSpec.describe 'Submission Records API', type: :request do + let(:valid_headers) { { "Authorization" => "Bearer #{JsonWebToken.encode({ id: studenta.id })}" } } + let(:invalid_headers) { { "Authorization" => "Bearer invalid_token" } } + let(:unauthorized_headers) { { "Authorization" => "Bearer #{JsonWebToken.encode({ id: studentb.id })}" } } + #call roles hierarchy to create sample roles + before(:all) do + @roles = create_roles_hierarchy + end + + #OBJECTIVE: Create appropriate structures for student functionality testing. + # Two different students will be created and one assignment associated with one of those students + # The assignment will have a designated team and associated submission record + + let(:studenta) do + User.create!( + name: 'StudentA', + password_digest: "password", + role_id: @roles[:student].id, + full_name: "Student A", + email: "studenta@example.com", + ) + end + + let(:studentb) do + User.create!( + name: 'StudentB', + password_digest: "password", + role_id: @roles[:student].id, + full_name: "Student B", + email: "studentb@example.com", + ) + end + + #instructor is created as an associate of the assignment + let!(:instructor) do + User.create!( + name: "Instructor", + password_digest: "password", + role_id: @roles[:instructor].id, + full_name: "Instructor Name", + email: "instructor@example.com" + ) + end + let!(:assignment1) do + Assignment.create!( + name: 'Test Assignment', + instructor_id: instructor.id + ) + end + let!(:team) do + Team.create!( + name: 'Team A', + assignment: assignment1, + users: [studenta], #only student a is on the team to test if student b can access + parent_id: 1 + ) + end + let(:submission_record) do + SubmissionRecord.create!( + id: 1, + team_id: team.id, + assignment_id: assignment1.id, + ) + end + + #SET UP WEB TOKENS SO THAT WE CAN TEST HTTP RESPONSE REQUESTS + let(:token) { JsonWebToken.encode({id: studenta.id}) } + let(:Authorization) { "Bearer #{token}" } + + #INDEX TESTING + # GET /api/v1/student_task (Get student tasks) + + describe 'GET /submission_records/:id' do + context 'when the student is part of the team' do + it 'allows access and returns a 200 status' do + get "/submission_records/#{submission_record.id}", headers: valid_headers + expect(response).to have_http_status(:ok) + end + end + + context 'when the student is NOT part of the team' do + it 'denies access and returns a 403 status' do + get "/submission_records/#{submission_record.id}", headers: unauthorized_headers + expect(response).to have_http_status(:forbidden) + end + end + + context 'when an invalid token is provided' do + it 'returns a 401 status' do + get "/submission_records/#{submission_record.id}", headers: invalid_headers + expect(response).to have_http_status(:unauthorized) + end + end + end + + describe 'GET /submission_records' do + context 'when the student belongs to a team' do + it 'retrieves submission records and returns a 200 status' do + get "/submission_records", params: { team_id: team.id }, headers: valid_headers + expect(response).to have_http_status(:ok) + expect(JSON.parse(response.body).length).to be > 0 + end + end + + context 'when the student does NOT belong to a team' do + it 'denies access and returns a 403 status' do + get "/submission_records", params: { team_id: team.id }, headers: unauthorized_headers + expect(response).to have_http_status(:forbidden) + end + end + end + + describe 'Edge Cases' do + context 'when requesting a non-existent submission record' do + it 'returns a 404 status' do + get "/submission_records/99999", headers: valid_headers + expect(response).to have_http_status(:not_found) + end + end + end +end \ No newline at end of file From 260387c417d97643a890ef58bd2d605a58c643b9 Mon Sep 17 00:00:00 2001 From: Delaney Dow Date: Mon, 24 Mar 2025 15:20:30 -0400 Subject: [PATCH 13/18] Changing location of controller to /api/v1 to match project specs --- app/controllers/{ => api/v1}/submission_records_controller.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/controllers/{ => api/v1}/submission_records_controller.rb (100%) diff --git a/app/controllers/submission_records_controller.rb b/app/controllers/api/v1/submission_records_controller.rb similarity index 100% rename from app/controllers/submission_records_controller.rb rename to app/controllers/api/v1/submission_records_controller.rb From 00e54f39f14ed131e3bcecf51a0864f1da17650e Mon Sep 17 00:00:00 2001 From: PriyaGandhi Date: Mon, 24 Mar 2025 18:17:46 -0400 Subject: [PATCH 14/18] Added route for fetching submission records --- config/routes.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 5d52b541f..cde01d214 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,7 +24,15 @@ end end - resources :submission_records, only: [:index] + resources :submission_records, only: [:create, :update, :destroy] do + collection do + # This will allow access to submission records based on team_id + get 'index/:team_id', to: 'submission_records#index', as: 'team_submission_records' + end + end + + # Define individual routes for show, create, update, destroy actions + resources :submission_records, only: [:show] resources :assignments do collection do @@ -125,4 +133,4 @@ end end end -end \ No newline at end of file +end From 5d8bd2d7120f8170a728e05b3643eb26740f01ad Mon Sep 17 00:00:00 2001 From: stallap Date: Mon, 24 Mar 2025 18:44:57 -0400 Subject: [PATCH 15/18] Updating routes.rb for swagger UI documentation --- config/routes.rb | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index cde01d214..8f7165fda 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,4 @@ Rails.application.routes.draw do - mount Rswag::Api::Engine => 'api-docs' mount Rswag::Ui::Engine => 'api-docs' # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html @@ -24,34 +23,31 @@ end end - resources :submission_records, only: [:create, :update, :destroy] do - collection do - # This will allow access to submission records based on team_id - get 'index/:team_id', to: 'submission_records#index', as: 'team_submission_records' - end - end + resources :submission_records, only: %i[create update destroy] do + collection do + get 'index/:team_id', to: 'submission_records#index', as: 'team_submission_records' + end + end - # Define individual routes for show, create, update, destroy actions - resources :submission_records, only: [:show] - + resources :submission_records, only: [:show] resources :assignments do collection do - post '/:assignment_id/add_participant/:user_id',action: :add_participant - delete '/:assignment_id/remove_participant/:user_id',action: :remove_participant - patch '/:assignment_id/remove_assignment_from_course',action: :remove_assignment_from_course - patch '/:assignment_id/assign_course/:course_id',action: :assign_course + post '/:assignment_id/add_participant/:user_id', action: :add_participant + delete '/:assignment_id/remove_participant/:user_id', action: :remove_participant + patch '/:assignment_id/remove_assignment_from_course', action: :remove_assignment_from_course + patch '/:assignment_id/assign_course/:course_id', action: :assign_course post '/:assignment_id/copy_assignment', action: :copy_assignment - get '/:assignment_id/has_topics',action: :has_topics - get '/:assignment_id/show_assignment_details',action: :show_assignment_details + get '/:assignment_id/has_topics', action: :has_topics + get '/:assignment_id/show_assignment_details', action: :show_assignment_details get '/:assignment_id/team_assignment', action: :team_assignment get '/:assignment_id/has_teams', action: :has_teams get '/:assignment_id/valid_num_review/:review_type', action: :valid_num_review get '/:assignment_id/varying_rubrics_by_round', action: :varying_rubrics_by_round? - post '/:assignment_id/create_node',action: :create_node + post '/:assignment_id/create_node', action: :create_node end end - resources :bookmarks, except: [:new, :edit] do + resources :bookmarks, except: %i[new edit] do member do get 'bookmarkratings', to: 'bookmarks#get_bookmark_rating_score' post 'bookmarkratings', to: 'bookmarks#save_bookmark_rating_score' @@ -83,8 +79,8 @@ resources :questions do collection do get :types - get 'show_all/questionnaire/:id', to:'questions#show_all#questionnaire', as: 'show_all' - delete 'delete_all/questionnaire/:id', to:'questions#delete_all#questionnaire', as: 'delete_all' + get 'show_all/questionnaire/:id', to: 'questions#show_all#questionnaire', as: 'show_all' + delete 'delete_all/questionnaire/:id', to: 'questions#delete_all#questionnaire', as: 'delete_all' end end @@ -97,12 +93,10 @@ resources :join_team_requests do collection do - post 'decline/:id', to:'join_team_requests#decline' + post 'decline/:id', to: 'join_team_requests#decline' end end - - resources :sign_up_topics do collection do get :filter From 9869013b244f029e595569b2e5a26122f58c5f1b Mon Sep 17 00:00:00 2001 From: PriyaGandhi Date: Mon, 24 Mar 2025 23:36:10 -0400 Subject: [PATCH 16/18] Update database.yml with correct credentials --- config/database.yml | 47 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/config/database.yml b/config/database.yml index b9f5aa055..092986fc7 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,18 +1,55 @@ +# MySQL. Versions 5.5.8 and up are supported. +# +# Install the MySQL driver +# gem install mysql2 +# +# Ensure the MySQL gem is defined in your Gemfile +# gem "mysql2" +# +# And be sure to use new-style password hashing: +# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html +# default: &default adapter: mysql2 encoding: utf8mb4 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - port: 3306 - socket: /var/run/mysqld/mysqld.sock + username: root + password: expertiza + development: <<: *default - url: <%= ENV['DATABASE_URL'].gsub('?', '_development?') %> + database: reimplementation_development +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. test: <<: *default - url: <%= ENV['DATABASE_URL'].gsub('?', '_test?') %> + database: reimplementation_test +# As with config/credentials.yml, you never want to store sensitive information, +# like your database password, in your source code. If your source code is +# ever seen by anyone, they now have access to your database. +# +# Instead, provide the password or a full connection URL as an environment +# variable when you boot the app. For example: +# +# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" +# +# If the connection URL is provided in the special DATABASE_URL environment +# variable, Rails will automatically merge its configuration values on top of +# the values provided in this file. Alternatively, you can specify a connection +# URL environment variable explicitly: +# +# production: +# url: <%= ENV["MY_APP_DATABASE_URL"] %> +# +# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database +# for a full overview on how database connection configuration can be specified. +# production: <<: *default - url: <%= ENV['DATABASE_URL'].gsub('?', '_production?') %> \ No newline at end of file + database: reimplementation_production + username: reimplementation + password: <%= ENV["REIMPLEMENTATION_DATABASE_PASSWORD"] %> From ea0a792793231653f7d2d4b851d865d2dda77bb0 Mon Sep 17 00:00:00 2001 From: priya gandhi Date: Tue, 25 Mar 2025 20:17:14 -0400 Subject: [PATCH 17/18] Added Rspec for view --- spec/factories/submissions.rb | 7 +++ spec/factories/users.rb | 5 +++ spec/views/submissions/index.html.erb_spec.rb | 45 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 spec/factories/submissions.rb create mode 100644 spec/factories/users.rb create mode 100644 spec/views/submissions/index.html.erb_spec.rb diff --git a/spec/factories/submissions.rb b/spec/factories/submissions.rb new file mode 100644 index 000000000..339b0c821 --- /dev/null +++ b/spec/factories/submissions.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :submission do + user + content { "Sample content for the submission." } + created_at { Time.now } + end + end \ No newline at end of file diff --git a/spec/factories/users.rb b/spec/factories/users.rb new file mode 100644 index 000000000..0ab6b2433 --- /dev/null +++ b/spec/factories/users.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :user do + name { "Test User" } + end + end \ No newline at end of file diff --git a/spec/views/submissions/index.html.erb_spec.rb b/spec/views/submissions/index.html.erb_spec.rb new file mode 100644 index 000000000..5668fe08b --- /dev/null +++ b/spec/views/submissions/index.html.erb_spec.rb @@ -0,0 +1,45 @@ +require 'rails_helper' + +RSpec.describe "submissions/index.html.erb", type: :view do + before do + # Create mock data for the tests + @user = create(:user, name: "Test User") # Replace with your actual User model factory + end + + context "when there are submission records" do + before do + # Creating some submission records + @submission_records = create_list(:submission, 3, user: @user) + assign(:submission_records, @submission_records) + + render # Renders the view + end + + it "displays the submission history table" do + expect(rendered).to have_selector('table.table-striped') # Check for the table + end + + it "displays the submission details correctly" do + @submission_records.each do |record| + expect(rendered).to include(record.id.to_s) + expect(rendered).to include(record.user.name) + expect(rendered).to include(record.created_at.strftime("%Y-%m-%d %H:%M:%S")) + expect(rendered).to include(truncate(record.content, length: 50)) + end + end + end + + context "when there are no submission records" do + before do + # No submission records + @submission_records = [] + assign(:submission_records, @submission_records) + + render + end + + it "displays a message saying no records found" do + expect(rendered).to include("No submission records found for this team.") + end + end +end From 5c3214b6f72fa444297b9d9fb5d13a1c8bd4b80b Mon Sep 17 00:00:00 2001 From: priya gandhi Date: Tue, 25 Mar 2025 20:33:32 -0400 Subject: [PATCH 18/18] Revert "Added Rspec for view" This reverts commit ea0a792793231653f7d2d4b851d865d2dda77bb0. --- spec/factories/submissions.rb | 7 --- spec/factories/users.rb | 5 --- spec/views/submissions/index.html.erb_spec.rb | 45 ------------------- 3 files changed, 57 deletions(-) delete mode 100644 spec/factories/submissions.rb delete mode 100644 spec/factories/users.rb delete mode 100644 spec/views/submissions/index.html.erb_spec.rb diff --git a/spec/factories/submissions.rb b/spec/factories/submissions.rb deleted file mode 100644 index 339b0c821..000000000 --- a/spec/factories/submissions.rb +++ /dev/null @@ -1,7 +0,0 @@ -FactoryBot.define do - factory :submission do - user - content { "Sample content for the submission." } - created_at { Time.now } - end - end \ No newline at end of file diff --git a/spec/factories/users.rb b/spec/factories/users.rb deleted file mode 100644 index 0ab6b2433..000000000 --- a/spec/factories/users.rb +++ /dev/null @@ -1,5 +0,0 @@ -FactoryBot.define do - factory :user do - name { "Test User" } - end - end \ No newline at end of file diff --git a/spec/views/submissions/index.html.erb_spec.rb b/spec/views/submissions/index.html.erb_spec.rb deleted file mode 100644 index 5668fe08b..000000000 --- a/spec/views/submissions/index.html.erb_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'rails_helper' - -RSpec.describe "submissions/index.html.erb", type: :view do - before do - # Create mock data for the tests - @user = create(:user, name: "Test User") # Replace with your actual User model factory - end - - context "when there are submission records" do - before do - # Creating some submission records - @submission_records = create_list(:submission, 3, user: @user) - assign(:submission_records, @submission_records) - - render # Renders the view - end - - it "displays the submission history table" do - expect(rendered).to have_selector('table.table-striped') # Check for the table - end - - it "displays the submission details correctly" do - @submission_records.each do |record| - expect(rendered).to include(record.id.to_s) - expect(rendered).to include(record.user.name) - expect(rendered).to include(record.created_at.strftime("%Y-%m-%d %H:%M:%S")) - expect(rendered).to include(truncate(record.content, length: 50)) - end - end - end - - context "when there are no submission records" do - before do - # No submission records - @submission_records = [] - assign(:submission_records, @submission_records) - - render - end - - it "displays a message saying no records found" do - expect(rendered).to include("No submission records found for this team.") - end - end -end