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

semesters to planner #615

Merged
merged 13 commits into from
Feb 18, 2025
1 change: 1 addition & 0 deletions app/models/subject_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ class SubjectPlan < ApplicationRecord
belongs_to :subject

validates :subject_id, uniqueness: { scope: :user_id }
validates :semester, numericality: { only_integer: true, greater_than: 0 }
end
18 changes: 18 additions & 0 deletions spec/models/subject_plan_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'rails_helper'

RSpec.describe SubjectPlan, type: :model do
describe 'associations' do
it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:subject) }
end

describe 'validations' do
subject { create :subject_plan }

it {
is_expected.to validate_uniqueness_of(:subject_id)
.scoped_to(:user_id)
}
it { is_expected.to validate_numericality_of(:semester).only_integer.is_greater_than(0) }
end
end
7 changes: 7 additions & 0 deletions test/factories/subject_plans.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryBot.define do
factory :subject_plan do
user
subject
semester { 1 }
end
end