base version

This commit is contained in:
HuJiaxuan 2016-12-26 02:19:56 +00:00
parent 1e860fa797
commit 9c09939939
9 changed files with 83 additions and 10 deletions

View File

@ -1,3 +0,0 @@
class Comment < ActiveRecord::Base
belongs_to :mission
end

View File

@ -1,4 +0,0 @@
class Mission < ActiveRecord::Base
has_and_belongs_to_many :users
has_many :comments
end

View File

@ -1,3 +0,0 @@
class Note < ActiveRecord::Base
belongs_to :user
end

View File

@ -0,0 +1,19 @@
require 'faker'
FactoryGirl.define do
factory :comment do
sequence(:content){ |n| "This is comment content#{n}"}
factory :comment_content_null do
content ""
end
factory :comment_conten_allspace do
content " "
end
end
end

View File

@ -0,0 +1,17 @@
require 'faker'
FactoryGirl.define do
factory :mission do
name { Faker::Name.title }
deadline "2016-10-17 10:00:00"
priority {Faker::Number.between(1, 3)}
status "已完成"
after(:build) do |mission|
3.times { mission.users << FactoryGirl.create(:user_with_sequence_number) }
end
factory :mission_name_length_gt_20 do
name { Faker::Internet.password(51, 51) }
end
end
end

View File

@ -0,0 +1,15 @@
require 'rails_helper'
RSpec.describe Comment , type: model do
it 'has a valid factory' do
expect(build(:comment)).to be_valid
end
describe "comment content test" do
it 'the content should not be empty' do
expect(build(:comment, content: nil)).not_to be_valid
end
end
end

View File

@ -0,0 +1,32 @@
require 'rails_helper'
RSpec.describe Mission, type: :model do
it 'has a valid factory' 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
# it 'does not allow duplicate name' do
# create(:mission, name: 'mission1')
# expect(build(:mission, name: 'mission1')).to_not be_valid
# end
end
end