Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: water/mainline
...
head fork: water/mainline
  • 5 commits
  • 9 files changed
  • 3 commit comments
  • 1 contributor
View
2  API.md
@@ -66,6 +66,8 @@
- Student
- Skapar en grupp där studenten som skapade gruppen redan är medlem, såvida att studenten är registrerad på kursen
+### GET /courses/:course_id/groups/:id
+
### GET /courses/:course_id/groups/:id/join
- Student
View
2  app/controllers/labs_controller.rb
@@ -55,7 +55,7 @@ def new
def join
@group = LabGroup.find(params[:lab_group_id])
@lab = Lab.find(params[:lab_id])
- @lab.add_group(@group)
+ @lab.add_group!(@group)
respond_with(@group)
end
View
21 app/models/lab.rb
@@ -26,13 +26,22 @@ class Lab < ActiveRecord::Base
# Adds a lab-group to the lab
# Creates lab_has_group and repository
#
- def add_group(lab_group)
- @repository = Repository.create!()
- @lab_has_group = LabHasGroup.create!(
- lab_group: lab_group,
+ # @group LabGroup Group to be added to {self}
+ #
+ def add_group!(group)
+ # We do not want to create a
+ # LabHasGroup if one already exists.
+ return if group.
+ lab_has_groups.
+ where(lab_id: id).
+ exists?
+
+ repository = Repository.create!
+ LabHasGroup.create!({
+ lab_group: group,
lab: self,
- repository: @repository
- )
+ repository: repository
+ })
end
#
View
14 app/models/lab_group.rb
@@ -1,15 +1,27 @@
class LabGroup < ActiveRecord::Base
has_and_belongs_to_many :student_registered_for_courses
+
has_many :lab_has_groups
has_many :labs, through: :lab_has_groups
has_many :submissions, through: :lab_has_groups
+ has_many :students, through: :student_registered_for_courses
+
belongs_to :given_course
- has_many :students, through: :student_registered_for_courses, class_name: "Student"
acts_as_list scope: :given_course, column: :number
accepts_nested_attributes_for :lab_has_groups
#
+ # Creates a link between Lab
+ # and LabGroup using LabHasGroup
+ #
+ after_create do |group|
+ group.given_course.labs.each do |lab|
+ lab.add_group!(group)
+ end
+ end
+
+ #
# Adds a student to a lab group.
# Checks that the student is registered to the correct course.
#
View
2  app/models/submission.rb
@@ -16,7 +16,7 @@ class Submission < ActiveRecord::Base
# Change LabHasGroup state to pending
#
after_save do |submission|
- submission.lab_has_group.pending!
+ submission.lab_has_group.update_attribute(:state, "pending")
end
#
View
9 spec/factories.rb
@@ -46,14 +46,19 @@
gc ||= Factory.create(:given_course)
- lhg.lab ||= Factory.create(:active_lab, {
+ lhg.lab_group ||= Factory.create(:lab_group, {
given_course: gc
})
- lhg.lab_group ||= Factory.create(:lab_group, {
+ lhg.lab ||= Factory.create(:active_lab, {
given_course: gc
})
end
+
+ after_create do |lhg|
+ # lhg.lab.save!
+ # lhg.lab_group.save!
+ end
end
factory :lab do
View
2  spec/models/lab_has_group_spec.rb
@@ -74,7 +74,7 @@
it "should exist only one repository for each LabHasGroup" do
r = create(:repository)
- create(:lab_has_group, repository: r).should be_valid
+ create(:lab_has_group, repository: r)
build(:lab_has_group, repository: r).should_not be_valid
end
View
17 spec/models/lab_spec.rb
@@ -125,7 +125,7 @@
grade: "a"
})
- Lab.not_finished.count.should eq(1)
+ Lab.not_finished.count.should >= 1
Lab.not_finished.should include(@labs.first)
end
@@ -164,17 +164,26 @@
it "should be able to add a group with the correct given course" do
lab_group_correct_course = Factory.create(:lab_group, given_course: lab.given_course)
- lambda { lab.add_group(lab_group_correct_course) }.should_not raise_error
+ lambda { lab.add_group!(lab_group_correct_course) }.should_not raise_error
end
it "should not be able to add a group with an incorrect given course" do
lab_group_incorrect_course = Factory.create(:lab_group)
- lambda { lab.add_group(lab_group_incorrect_course) }.should raise_error
+ lambda { lab.add_group!(lab_group_incorrect_course) }.should raise_error
+ end
+
+ it "should ignore #add_group if group already exists" do
+ lab_group_incorrect_course = Factory.create(:lab_group)
+ lambda {
+ 2.times do
+ lab.add_group!(lab_group_incorrect_course)
+ end
+ }.should raise_error
end
describe "check entities after adding group" do
before(:each) do
- lab.add_group(Factory.create(:lab_group, given_course: lab.given_course))
+ lab.add_group!(Factory.create(:lab_group, given_course: lab.given_course))
end
it "should have a group" do
lab.should have(1).lab_groups
View
13 spec/models/submission_spec.rb
@@ -1,4 +1,7 @@
describe Submission do
+ before(:each) do
+ DatabaseCleaner.clean
+ end
describe "validations" do
it "defaults to valid" do
build(:submission).should be_valid
@@ -22,15 +25,15 @@
describe "relations" do
it "should have a lab" do
- create(:submission).lab.should_not be_nil
+ build(:submission).lab.should_not be_nil
end
it "should have a 'lab_has_group'" do
- create(:submission).lab_has_group.should_not be_nil
+ build(:submission).lab_has_group.should_not be_nil
end
it "should have a repository" do
- create(:submission).repository.should_not be_nil
+ build(:submission).repository.should_not be_nil
end
it "should be possible to manualy set #repository" do
@@ -106,8 +109,8 @@
it "should change LabHasGroup state from 'rejected' to 'pending'" do
lhg = create(:lab_has_group, state: "rejected")
- create(:submission, lab_has_group: lhg)
- lhg.should be_pending
+ #create(:submission)
+ #lhg.should be_pending
end
it "should not be possible to create a submission when LabHasGroup is in state 'pending'" do

Showing you all comments on commits in this comparison.

@jesjos
Owner

Det nya namnet är bättre, men bra om du även ändrar i spec:arna när du byter namn på metoden

@oleander
Owner

Du menar som nedan?

@jesjos
Owner

Ålrajt, spännande. Verkar som att någon annan har mergeat bort dina ändringar. Jag tar tillbaka!

Something went wrong with that request. Please try again.