Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lecture edit page if active term is not set #683

Merged
merged 9 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions app/models/lecture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -830,12 +830,6 @@ def speakers
User.where(id: SpeakerTalkJoin.where(talk: talks).select(:speaker_id))
end

def older_than?(timespan)
return true unless term

term.begin_date <= Term.active.begin_date - timespan
end

def stale?
fosterfarrell9 marked this conversation as resolved.
Show resolved Hide resolved
older_than?(1.year)
end
Expand Down Expand Up @@ -947,4 +941,11 @@ def only_one_lecture

errors.add(:course, :already_present)
end

def older_than?(timespan)
return false unless Term.active
return true unless term

term.begin_date <= Term.active.begin_date - timespan
end
end
1 change: 1 addition & 0 deletions app/views/lectures/edit/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
id="lecture-nav-content" type="button" role="tab"
href="#content"
data-bs-toggle="pill" data-bs-target="#lecture-pane-content"
data-cy="content-tab-btn"
aria-controls="lecture-pane-content" aria-selected="true">
<%= t('content') %>
</button>
Expand Down
17 changes: 17 additions & 0 deletions spec/cypress/e2e/lecture_spec.cy.js
fosterfarrell9 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import FactoryBot from "../support/factorybot";

describe("Lecture edit page", () => {
it("shows content tab button", function () {
cy.createUserAndLogin("teacher").as("teacher");

cy.then(() => {
FactoryBot.create("lecture", "with_teacher_by_id",
{ teacher_id: this.teacher.id }).as("lecture");
});
fosterfarrell9 marked this conversation as resolved.
Show resolved Hide resolved

cy.then(() => {
cy.visit(`/lectures/${this.lecture.id}/edit`);
cy.getBySelector("content-tab-btn").should("be.visible");
fosterfarrell9 marked this conversation as resolved.
Show resolved Hide resolved
});
});
});
8 changes: 8 additions & 0 deletions spec/factories/terms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@
trait :summer do
season { "SS" }
end

trait :winter do
season { "WS" }
end

trait :active do
active { true }
end
end
end
46 changes: 46 additions & 0 deletions spec/models/lecture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,52 @@
end
end

describe "#stale?" do
let(:year) { 2024 }
fosterfarrell9 marked this conversation as resolved.
Show resolved Hide resolved

context "when there is no active term" do
it "returns false" do
lecture = FactoryBot.build(:lecture)
expect(lecture.stale?).to be(false)
end
end

context "when there is an active term" do
let(:year) { 2024 }

before(:each) do
FactoryBot.create(:term, :summer, :active, year: year)
end

context "and there is no term associated with the lecture" do
it "returns true" do
lecture = FactoryBot.build(:lecture, :term_independent)
expect(lecture.stale?).to be(true)
end
end

context "and the lecture term begin date is before the active term" \
"begin date minus 1 year" do
let(:lecture_term) { FactoryBot.build(:term, :summer, year: year - 1) }

it "returns true" do
lecture = FactoryBot.build(:lecture, term: lecture_term)
expect(lecture.stale?).to be(true)
end
end

context "when the lecture term begin date is not older than the" \
"active term begin date minus 1 year" do
let(:lecture_term) { FactoryBot.build(:term, :winter, year: year - 1) }

it "returns false" do
lecture = FactoryBot.build(:lecture, term: lecture_term)
expect(lecture.stale?).to be(false)
end
end
end
end

# Test methods -- NEEDS TO BE REFACTORED

# describe '#tags' do
Expand Down
Loading