Guest User

Untitled

a guest
Mar 21st, 2019
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. require 'rails_helper'
  2.  
  3. RSpec.describe Comment, type: :model do
  4.  
  5. before(:each) do
  6. @comment = FactoryBot.build(:comment)
  7. end
  8.  
  9. it "has a valid factory" do
  10. expect(build(:comment)).to be_valid
  11. end
  12.  
  13. context "validation" do
  14. it "is valid with valid attributes" do
  15. expect(@comment).to be_a(Comment)
  16. end
  17.  
  18. describe "#content" do
  19. it {expect(@comment).to validate_presence_of(:content)}
  20. it {is_expected.to allow_value("This is some quality content. ").for(:content)}
  21. it {is_expected.to allow_value("a" * 1000).for(:content)}
  22. it {is_expected.to_not allow_value("N").for(:content)}
  23. it {is_expected.to_not allow_value("b" * 1001).for(:content)}
  24. end
  25. end
  26.  
  27. context "public instance methods" do
  28.  
  29. describe "readable_date" do
  30. it { expect(@comment).to respond_to(:readable_date) }
  31.  
  32. it "should a readable date" do
  33. comment = FactoryBot.create(:comment)
  34. expect(comment.readable_date).to eq(comment.created_at.strftime("%d/%m/%y à %H:%M"))
  35. end
  36. end
  37. end
  38.  
  39. context "associations" do
  40. it { expect(@comment).to have_many(:likes) }
  41. it { expect(@comment).to have_many(:comments) }
  42. it { expect(@comment).to belong_to(:user) }
  43. it { expect(@comment).to belong_to(:commenteable) }
  44. end
  45. end
Add Comment
Please, Sign In to add comment