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
|
|
|
|
params = {content:"good job",mission_id:123}
|
|
|
|
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
|
|
|
|
params = {content: nil,mission_id: 123}
|
|
|
|
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
|
|
|
|
params = {content:"good job", mission_id: nil}
|
|
|
|
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-26 10:19:56 +08:00
|
|
|
end
|