Skip to content

Commit

Permalink
#164 make enrollment key optional (#194)
Browse files Browse the repository at this point in the history
* #164 make enrollment key optional

* fix rubocop errors
  • Loading branch information
mayer-maximilian authored and grittaweisheit committed Jan 16, 2020
1 parent 516337c commit d337d1d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/models/lecture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Lecture < ApplicationRecord
validates :end_time, presence: true

validates :name, presence: true, length: { in: 2..40 }
validates :enrollment_key, presence: true, length: { in: 3..20 }
validates :enrollment_key, length: { in: 3..20, if: :enrollment_key_present? }
scope :active, -> { where status: "running" }


Expand Down Expand Up @@ -61,4 +61,8 @@ def readonly?
end
false
end

def enrollment_key_present?
enrollment_key.present?
end
end
15 changes: 14 additions & 1 deletion spec/models/lecture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@
expect(@lecture).not_to be_valid
end

it "is not valid without a enrollment key" do
it "is valid without an enrollment key" do
@lecture.enrollment_key = ""
expect(@lecture).to be_valid
end

it "is valid with an enrollment key with 3 characters" do
@lecture.enrollment_key = "123"
expect(@lecture).to be_valid
end

it "is not valid with an enrollment key with 1 to 2 characters" do
@lecture.enrollment_key = "1"
expect(@lecture).not_to be_valid

@lecture.enrollment_key = "12"
expect(@lecture).not_to be_valid
end

Expand Down

0 comments on commit d337d1d

Please sign in to comment.