diff --git a/app/controllers/lab_groups_controller.rb b/app/controllers/lab_groups_controller.rb index 6cdd35bd..43da1010 100644 --- a/app/controllers/lab_groups_controller.rb +++ b/app/controllers/lab_groups_controller.rb @@ -68,13 +68,4 @@ def join redirect_to new_course_lab_group_path("student", params[:course_id]) end end - - def register - @repository = Repository.create!() - lhg = LabHasGroup.new(lab_group_id: params[:id], lab_id: params[:lab_id], repository_id: @repository.id) - if lhg.save - redirect_to root_url, notice: "Ok"; return - end - redirect_back alert: "Oops, something went wrong" - end end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb new file mode 100644 index 00000000..2bcdd10e --- /dev/null +++ b/app/controllers/registrations_controller.rb @@ -0,0 +1,32 @@ +# encoding: utf-8 +class RegistrationsController < ApplicationController + + def new + end + + def create + end + + def register + ActiveRecord::Base.transaction do + @lab_group = LabGroup.create!( + given_course_id: params[:course_id], + students: [current_user] + ) + + repository = Repository.create!() + + LabHasGroup.create!( + repository: repository, + lab_id: params[:lab_id], + lab_group_id: @lab_group + ) + end + if LabGroup.exists?(@lab_group) + redirect_back notice: "You have joined a lab and lab group" + else + redirect_back notice: "Something went wrong" + end + end + +end diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 8e3c995f..3aac6b8c 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -21,6 +21,20 @@ def update # TODO end + def initial_comment + submission = Submission.find(params[:id]) + comment = Comment.new( + user_id: current_user, + type: "submission", body: params[:input], + parent_id: nil + ) + if comment.save! + submission.update_column(:comment_id, comment.id) + redirect_back notice: "Comment created"; return + end + redirect_back notice: "Something went wrong" + end + def create lhg = LabHasGroup.where({ lab_id: params[:lab_id], diff --git a/config/routes.rb b/config/routes.rb index bd3c35b3..25d6b177 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,9 @@ resources :lab_deadlines, :study_periods, :course_codes scope ":role", constraints: { role: /examiner|student|administrator|assistant|/ } do + resources :registration, only: [:new, :create, :destroy] do + post "/courses/:course_id/labs/:lab_id/register" => "registrations#register" + end resources :labs resources :dashboards, only: [:index] resources :courses do @@ -14,7 +17,6 @@ collection do post "join" => "lab_groups#join" post "create" => "lab_groups#create" - put ":lab_id/register" => "lab_groups#register" end resources :labs, only: [:index, :show] do resources :submissions, only: [:create, :new, :show, :edit, :update] do diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb new file mode 100644 index 00000000..aa2347e0 --- /dev/null +++ b/spec/controllers/registrations_controller_spec.rb @@ -0,0 +1,12 @@ +describe RegistrationsController do + + describe "register" do + it "should be possible to use method register" do + given_course = FactoryGirl.create(:given_course) + lab = FactoryGirl.create(:lab, active: true, given_course_id: given_course.id) + post :register, lab_id: lab.id, course_id: given_course.id + + LabHasGroup.find_by_lab_id(lab.id).lab_id.should eq(lab.id) + end + end +end \ No newline at end of file diff --git a/spec/controllers/submissions_controller_spec.rb b/spec/controllers/submissions_controller_spec.rb index 31475f72..1605bd78 100644 --- a/spec/controllers/submissions_controller_spec.rb +++ b/spec/controllers/submissions_controller_spec.rb @@ -1,11 +1,11 @@ describe SubmissionsController do describe "PUT notes" do it "should be possible for an assistant to set notes" do - assistant = Factory.create(:assistant) - login_as(assistant) - subm = Factory.create(:submission) - post :notes, id: subm.id, notes: "hej" - subm.notes.should eq("hej") + assistant = FactoryGirl.create(:assistant) + subm = FactoryGirl.create(:submission) + post :initial_comment, id: subm.id, input: "hej" + subm = Submission.find(subm.id) + Comment.find(subm.comment_id).body.should eq("hej") end end end \ No newline at end of file