ambition/spec/models/note_spec.rb

90 lines
2.9 KiB
Ruby
Raw Normal View History

2016-12-29 17:33:25 +08:00
require 'rails_helper'
RSpec.describe Note , type: :model do
it "has a valid note" do
params = {name: "jaxon",email: "370403444@qq.com",password_digest: "123456",phone: "15652336366"}
user = User.new(params)
user.save
2016-12-29 19:20:27 +08:00
params = {name: "project_1",content: "project content"}
project = Project.new(params)
project.users << user
project.save
expect(project).to be_valid
params = {content: "note content",user_id: user.id,project_id: project.id,category: 1}
2016-12-29 17:33:25 +08:00
note = Note.new(params)
note.save
expect(note).to be_valid
end
it "notes content should at least has one character" do
params = {name: "jaxon",email: "370403444@qq.com",password_digest: "123456",phone: "15652336366"}
user = User.new(params)
user.save
params = {content: " ",user_id: user.id,category: 1}
note = Note.new(params)
note.save
expect(note.errors[:content].size).to eq(2)
end
it "category should be among valid values" do
params = {name: "jaxon",email: "370403444@qq.com",password_digest: "123456",phone: "15652336366"}
user = User.new(params)
user.save
params = {content: " ",user_id: user.id,category: 4}
note = Note.new(params)
note.save
expect(note.errors[:category].size).to eq(1)
expect(note).to_not be_valid
end
2016-12-29 19:20:27 +08:00
it "notes user should be exist" do
params = {name: "jaxon",email: "370403444@qq.com",password_digest: "123456",phone: "15652336366"}
user = User.new(params)
user.save
params = {name: "project_1",content: "project content"}
project = Project.new(params)
project.users << user
project.save
expect(project).to be_valid
params = {content: "note content",user_id: user.id,project_id: 5,category: 1}
note = Note.new(params)
note.save
expect(note).to_not be_valid
expect(note.errors[:project].size).to eq(1)
expect(Note.find_by(project_id: 5)).to eq(nil)
end
it "notes project should be exist" do
params = {name: "jaxon",email: "370403444@qq.com",password_digest: "123456",phone: "15652336366"}
user = User.new(params)
user.save
params = {name: "project_1",content: "project content"}
project = Project.new(params)
project.users << user
project.save
expect(project).to be_valid
params = {content: "note content",user_id: 5,project_id: project.id,category: 1}
note = Note.new(params)
note.save
expect(note).to_not be_valid
expect(note.errors[:user].size).to eq(1)
expect(Note.find_by(user_id: 5)).to eq(nil)
end
2016-12-29 17:33:25 +08:00
end