ambition/spec/models/mission_spec.rb

74 lines
1.8 KiB
Ruby

require 'rails_helper'
RSpec.describe Mission , type: :model do
it 'has a valid mission' do
params = {name: "mission1",content: "mission content",deadline:"2016-10-17 10:00:00",priority:1,status:"进行中"}
mission = Mission.new(params)
mission.validate
expect(mission).to be_valid
end
it 'content should not be nil' do
expect(build(:no_content_mission)).to_not be_valid
end
it 'deadline should not be nil' do
expect(build(:no_deadline_mission)).to_not be_valid
end
it 'status should not be nil' do
expect(build(:no_status_mission)).to_not be_valid
end
it 'priority should not be nil' do
expect(build(:no_priority_mission)).to_not be_valid
end
it 'priority is not among valid values' do
mission = build(:priority_not_among_valid_values)
mission.validate
expect(mission.errors[:priority].size).to eq(1)
end
it 'status is not among valid values' do
mission = build(:status_not_among_valid_values)
mission.validate
expect(mission.errors[:status].size).to eq(1)
end
end
# require 'rails_helper'
# RSpec.describe Mission, type: :model do
# it 'has a valid mission' do
# expect(build(:project)).to be_valid
# end
# describe 'users test' do
# it 'has at least on user' do
# mission_with_no_user = build(:mission)
# mission_with_no_user.users = []
# mission_with_no_user.valid?
# expect(mission_with_no_user.errors[:users].size).to eq(1)
# end
# end
# describe 'name test' do
# it 'does not allow absence of name' do
# expect(build(:mission, name: nil)).to_not be_valid
# end
# it 'length of name in [1,20]' do
# expect(build(:mission_name_length_gt_20)).to_not be_valid
# end
# end
# end