ambition/spec/models/comment_spec.rb

56 lines
2.1 KiB
Ruby
Raw Normal View History

2016-12-26 10:19:56 +08:00
require 'rails_helper'
2016-12-27 20:15:05 +08:00
RSpec.describe Comment , type: :model do
2016-12-26 10:19:56 +08:00
2016-12-27 20:15:05 +08:00
it 'has a valid comment' do
2016-12-29 17:33:25 +08:00
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}
2016-12-27 20:15:05 +08:00
expect(Comment.new(params)).to be_valid
2016-12-26 10:19:56 +08:00
end
2016-12-27 20:15:05 +08:00
it "content should not be empty" do
2016-12-29 17:33:25 +08:00
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}
2016-12-27 20:15:05 +08:00
expect(Comment.new(params)).to_not be_valid
2016-12-26 10:19:56 +08:00
end
2016-12-27 20:15:05 +08:00
it "mission_id should not be empty" do
2016-12-29 17:33:25 +08:00
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}
2016-12-27 20:15:05 +08:00
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
2016-12-29 17:33:25 +08:00
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
2016-12-27 20:15:05 +08:00
2016-12-26 10:19:56 +08:00
end