-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathprogram_spec.rb
44 lines (35 loc) · 1.46 KB
/
program_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
require 'spec_helper'
describe Program, :type => :model do
it { is_expected.to have_many(:roles_users) }
it { is_expected.to have_many(:admins).through(:roles_users) }
it { is_expected.to have_many(:projects) }
it { is_expected.to have_many(:reviewers) }
it { is_expected.to have_many(:logs) }
it { is_expected.to belong_to(:creater) }
context '#valid?' do
context '#program_name' do
it { is_expected.to validate_presence_of(:program_name) }
it { is_expected.to validate_uniqueness_of(:program_name) }
it { is_expected.to ensure_length_of(:program_name).is_at_least(2) }
it { is_expected.to ensure_length_of(:program_name).is_at_most(20) }
it { is_expected.to allow_value('LETTERS_0123').for(:program_name) }
it 'leaves a blank name blank' do
p = Program.new
p.valid?
expect(p.program_name).to eq(nil)
end
it 'only allow alphanumeric characters, and replace spaces with underscores' do
p = Program.new(program_name: ' Whitespace, c0mma.')
p.valid?
expect(p.program_name).to eq('Whitespace_c0mma_')
end
end
context '#program_title' do
it { is_expected.to validate_presence_of(:program_title) }
it { is_expected.to ensure_length_of(:program_title).is_at_least(2) }
it { is_expected.to ensure_length_of(:program_title).is_at_most(80) }
end
it { is_expected.to validate_presence_of(:program_url) }
end
end