require 'rails_helper' RSpec.describe Comment , type: :model do it 'has a valid comment' do params = {name: "jaxon",email: "370403444@qq.com",password_digest: "123456",phone: "15652336366"} user = User.new(params) user.save params = {content:"good job",mission_id:123,user_id: user.id} expect(Comment.new(params)).to be_valid end it "content should not be empty" do params = {name: "jaxon",email: "370403444@qq.com",password_digest: "123456",phone: "15652336366"} user = User.new(params) user.save params = {content: nil,mission_id: 123,user_id: user.id} expect(Comment.new(params)).to_not be_valid end it "mission_id should not be empty" do params = {name: "jaxon",email: "370403444@qq.com",password_digest: "123456",phone: "15652336366"} user = User.new(params) user.save params = {content:"good job", mission_id: nil,user_id: user.id} expect(Comment.new(params)).to_not be_valid end it "content should has at least one word " do comment_with_allspace = build(:comment_content_allspace) comment_with_allspace.validate expect(comment_with_allspace.errors[:content].size).to eq(1) end it "user should be exist" do params = {name: "jaxon",email: "370403444@qq.com",password_digest: "123456",phone: "15652336366"} user = User.new(params) user.save expect(user).to be_valid params = {name: "project_1",content: "project content"} project = Project.new(params) project.users << user project.save expect(project).to be_valid params = {name: "mission",deadline: "2016-10-17 10:00:00",priority: 1,status: 2,content: "mission content",project_id: project.id} mission = Mission.new(params) mission.save expect(mission).to be_valid expect(mission.errors[:project_id].size).to eq(0) params = {content: "comment", mission_id: mission.id, user_id: user.id} comment = Comment.new(params) expect(comment).to be_valid end end