|
4 | 4 | require "publify_core/testing_support/dns_mock"
|
5 | 5 |
|
6 | 6 | describe Trackback, type: :model do
|
7 |
| - let(:article) { create(:article) } |
| 7 | + describe "validations" do |
| 8 | + let(:blog) { build_stubbed :blog } |
| 9 | + let(:trackback) { described_class.new } |
8 | 10 |
|
9 |
| - before do |
10 |
| - @blog = create(:blog) |
11 |
| - @blog.sp_global = true |
12 |
| - @blog.default_moderate_comments = false |
13 |
| - @blog.save! |
14 |
| - end |
| 11 | + it "allows an article with open trackback window" do |
| 12 | + article = Article.new(blog: blog, allow_pings: true, state: "published", |
| 13 | + published_at: 1.day.ago) |
15 | 14 |
|
16 |
| - it "Incomplete trackbacks should not be accepted" do |
17 |
| - tb = described_class.new(blog_name: "Blog name", |
18 |
| - title: "Title", |
19 |
| - excerpt: "Excerpt", |
20 |
| - article_id: create(:article).id) |
21 |
| - expect(tb).not_to be_valid |
22 |
| - expect(tb.errors["url"]).to be_any |
23 |
| - end |
| 15 | + expect(trackback).to allow_value(article).for(:article) |
| 16 | + end |
24 | 17 |
|
25 |
| - it "A valid trackback should be accepted" do |
26 |
| - tb = described_class.new(blog_name: "Blog name", |
27 |
| - title: "Title", |
28 |
| - url: "http://foo.com", |
29 |
| - excerpt: "Excerpt", |
30 |
| - article_id: create(:article).id) |
31 |
| - expect(tb).to be_valid |
32 |
| - tb.save |
33 |
| - expect(tb.guid.size).to be > 15 |
34 |
| - expect(tb).not_to be_spam |
35 |
| - end |
| 18 | + it "requires article trackback window to be open" do |
| 19 | + article = Article.new(blog: blog, allow_pings: true) |
36 | 20 |
|
37 |
| - it "Trackbacks with a spammy link in the excerpt should be rejected" do |
38 |
| - tb = article.trackbacks. |
39 |
| - build(ham_params.merge(excerpt: '<a href="http://chinaaircatering.com">spam</a>')) |
40 |
| - tb.classify_content |
41 |
| - expect(tb).to be_spammy |
42 |
| - end |
| 21 | + expect(trackback).not_to allow_value(article).for(:article). |
| 22 | + with_message("Trackbacks are closed") |
| 23 | + end |
43 | 24 |
|
44 |
| - it "Trackbacks with a spammy source url should be rejected" do |
45 |
| - tb = article.trackbacks.build(ham_params.merge(url: "http://www.chinaircatering.com")) |
46 |
| - tb.classify_content |
47 |
| - expect(tb).to be_spammy |
48 |
| - end |
| 25 | + it "requires article to be open to trackback" do |
| 26 | + article = Article.new(blog: blog, allow_pings: false) |
49 | 27 |
|
50 |
| - it "Trackbacks from a spammy ip address should be rejected" do |
51 |
| - tb = article.trackbacks.build(ham_params.merge(ip: "212.42.230.207")) |
52 |
| - tb.classify_content |
53 |
| - expect(tb).to be_spammy |
| 28 | + expect(trackback).not_to allow_value(article).for(:article). |
| 29 | + with_message("Article is not open for trackbacks") |
| 30 | + end |
54 | 31 | end
|
55 | 32 |
|
56 |
| - def ham_params |
57 |
| - { blog_name: "Blog", title: "trackback", excerpt: "bland", |
58 |
| - url: "http://notaspammer.com", ip: "212.42.230.206" } |
| 33 | + describe "spam detection" do |
| 34 | + let(:article) { create(:article) } |
| 35 | + |
| 36 | + before do |
| 37 | + @blog = create(:blog) |
| 38 | + @blog.sp_global = true |
| 39 | + @blog.default_moderate_comments = false |
| 40 | + @blog.save! |
| 41 | + end |
| 42 | + |
| 43 | + it "Incomplete trackbacks should not be accepted" do |
| 44 | + tb = described_class.new(blog_name: "Blog name", |
| 45 | + title: "Title", |
| 46 | + excerpt: "Excerpt", |
| 47 | + article_id: create(:article).id) |
| 48 | + expect(tb).not_to be_valid |
| 49 | + expect(tb.errors["url"]).to be_any |
| 50 | + end |
| 51 | + |
| 52 | + it "A valid trackback should be accepted" do |
| 53 | + tb = described_class.new(blog_name: "Blog name", |
| 54 | + title: "Title", |
| 55 | + url: "http://foo.com", |
| 56 | + excerpt: "Excerpt", |
| 57 | + article_id: create(:article).id) |
| 58 | + expect(tb).to be_valid |
| 59 | + tb.save |
| 60 | + expect(tb.guid.size).to be > 15 |
| 61 | + expect(tb).not_to be_spam |
| 62 | + end |
| 63 | + |
| 64 | + it "Trackbacks with a spammy link in the excerpt should be rejected" do |
| 65 | + tb = article.trackbacks. |
| 66 | + build(ham_params.merge(excerpt: '<a href="http://chinaaircatering.com">spam</a>')) |
| 67 | + tb.classify_content |
| 68 | + expect(tb).to be_spammy |
| 69 | + end |
| 70 | + |
| 71 | + it "Trackbacks with a spammy source url should be rejected" do |
| 72 | + tb = article.trackbacks.build(ham_params.merge(url: "http://www.chinaircatering.com")) |
| 73 | + tb.classify_content |
| 74 | + expect(tb).to be_spammy |
| 75 | + end |
| 76 | + |
| 77 | + it "Trackbacks from a spammy ip address should be rejected" do |
| 78 | + tb = article.trackbacks.build(ham_params.merge(ip: "212.42.230.207")) |
| 79 | + tb.classify_content |
| 80 | + expect(tb).to be_spammy |
| 81 | + end |
| 82 | + |
| 83 | + def ham_params |
| 84 | + { blog_name: "Blog", title: "trackback", excerpt: "bland", |
| 85 | + url: "http://notaspammer.com", ip: "212.42.230.206" } |
| 86 | + end |
59 | 87 | end
|
60 | 88 | end
|
0 commit comments