ambition/spec/models/share_spec.rb

90 lines
2.9 KiB
Ruby
Raw Permalink Normal View History

2016-12-29 17:33:25 +08:00
require 'rails_helper'
RSpec.describe Share, type: :model do
it "its a valid share" do
params = {name: "jaxon",email: "370403488@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 = {content: "share content",project_id: project.id,user_id: user.id}
share = Share.new(params)
share.save
expect(share).to be_valid
expect(Share.find_by(id: share.id)).to_not eq(nil)
end
it "share content should have at least one character" 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 = {content: " ",project_id: project.id,user_id: user.id}
share = Share.new(params)
share.save
expect(share).to_not be_valid
expect(share.errors[:content].size).to eq(2)
expect(Share.find_by(id: share.id)).to eq(nil)
end
it "share's 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 = {content: "share content",project_id: 5,user_id: user.id}
share = Share.new(params)
share.save
expect(share).to_not be_valid
expect(share.errors[:project].size).to eq(1)
expect(Share.find_by(id: share.id)).to eq(nil)
end
it "share's 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 = {content: "share content",project_id: project.id,user_id: 10}
share = Share.new(params)
share.save
expect(share).to_not be_valid
expect(share.errors[:user].size).to eq(1)
expect(Share.find_by(id: share.id)).to eq(nil)
end
end