Skip to content

Commit

Permalink
Merge branch 'master' of github.com:water/mainline
Browse files Browse the repository at this point in the history
  • Loading branch information
jesjos committed May 8, 2012
2 parents 63ee155 + 69af254 commit b484745
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 15 deletions.
9 changes: 0 additions & 9 deletions app/controllers/lab_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 32 additions & 0 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions spec/controllers/registrations_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions spec/controllers/submissions_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b484745

Please sign in to comment.