require 'rails_helper' RSpec.describe Missions_user , type: :model do it "mission should 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 params = {mission_id: 5,user_id: user.id} missions_user = Missions_user.new(params) missions_user.save expect(missions_user).to_not be_valid expect(missions_user.errors[:mission].size).to eq(1) expect(Missions_user.find_by(user_id: user.id)).to eq(nil) end it "user should 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 params = {mission_id: mission.id,user_id: 2} missions_user = Missions_user.new(params) missions_user.save #puts missions_user.inspect expect(missions_user).to_not be_valid expect(missions_user.errors[:user].size).to eq(1) expect(Missions_user.find_by(mission_id: mission.id)).to eq(nil) end end