model and policy specs

This commit is contained in:
Karol
2019-12-07 13:11:48 +01:00
parent 5625fa63b0
commit c89ee6c102
9 changed files with 109 additions and 13 deletions

View File

@ -0,0 +1,16 @@
require 'rails_helper'
describe CodeharborLink do
it { is_expected.to validate_presence_of(:check_uuid_url) }
it { is_expected.to validate_presence_of(:push_url) }
it { is_expected.to validate_presence_of(:api_key) }
it { is_expected.to belong_to(:user) }
describe '#to_s' do
subject { codeharbor_link.to_s }
let(:codeharbor_link) { FactoryBot.create(:codeharbor_link) }
it { is_expected.to eql codeharbor_link.id.to_s }
end
end

View File

@ -22,10 +22,6 @@ describe Exercise do
expect(exercise.errors[:description]).to be_present
end
it 'validates the presence of an execution environment' do
expect(exercise.errors[:execution_environment_id]).to be_present
end
it 'validates the presence of the public flag' do
expect(exercise.errors[:public]).to be_present
exercise.update(public: false)
@ -45,6 +41,30 @@ describe Exercise do
expect(exercise.errors[:user_type]).to be_present
end
context 'when exercise is unpublished' do
subject { FactoryBot.build(:dummy, unpublished: true) }
it { is_expected.not_to validate_presence_of(:execution_environment) }
end
context 'when exercise is not unpublished' do
subject { FactoryBot.build(:dummy, unpublished: false) }
it { is_expected.to validate_presence_of(:execution_environment) }
end
context 'with uuid' do
subject { FactoryBot.build(:dummy, uuid: SecureRandom.uuid) }
it { is_expected.to validate_uniqueness_of(:uuid).case_insensitive }
end
context 'without uuid' do
subject { FactoryBot.build(:dummy, uuid: nil) }
it { is_expected.not_to validate_uniqueness_of(:uuid) }
end
describe '#average_percentage' do
let(:exercise) { FactoryBot.create(:fibonacci) }