forked from mwlang/rails_wordpress
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelationship_spec.rb
38 lines (33 loc) · 908 Bytes
/
relationship_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'rails_helper'
module Wordpress
RSpec.describe Relationship, type: :model do
let(:post) { create(:post, :with_tags) }
let(:first_tag) { post.tags.first }
let(:second_tag) { post.tags[1] }
it "has tags" do
expect(post.tags.count).to eq 2
end
it "increments counts" do
expect(first_tag.count).to eq 1
expect(second_tag.count).to eq 1
end
it "decrements counts when removed from a post" do
first_tag
second_tag
post.tags.destroy_all
first_tag.reload
second_tag.reload
expect(first_tag.count).to eq 0
expect(second_tag.count).to eq 0
end
it "decrements count when post is deleted" do
first_tag
second_tag
post.destroy
first_tag.reload
second_tag.reload
expect(first_tag.count).to eq 0
expect(second_tag.count).to eq 0
end
end
end