51 lines
1.6 KiB
Ruby
51 lines
1.6 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe Projects_user , type: :model do
|
|
|
|
it "project 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 = {project_id: 3,user_id: user.id}
|
|
projects_user = Projects_user.new(params)
|
|
projects_user.save
|
|
expect(projects_user).to_not be_valid
|
|
expect(projects_user.errors[:project].size).to eq(1)
|
|
expect(Projects_user.find_by(project_id: 3)).to eq(nil)
|
|
|
|
|
|
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 = {project_id: project.id,user_id: 5}
|
|
projects_user = Projects_user.new(params)
|
|
projects_user.save
|
|
expect(projects_user).to_not be_valid
|
|
expect(projects_user.errors[:user].size).to eq(1)
|
|
expect(Projects_user.find_by(user_id: 5)).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
end |