~edwardloveall/scribe

ref: 91687bb68908fd8376503a8bb04fb344bd839c9d scribe/spec/requests/articles/show_spec.cr -rw-r--r-- 1.8 KiB
91687bb6Edward Loveall Add automatic redirect instructions to homepage 7 months ago
                                                                                
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require "../../spec_helper"

class TestClient < MediumClient
  class_property last_post_id : String = ""

  def self.post_data(post_id : String) : PostResponse::Root
    self.last_post_id = post_id
    PostResponse::Root.from_json <<-JSON
      {
        "data": {
          "post": {
            "title": "a title",
            "createdAt": 0,
            "creator": { "id": "0", "name": "username" },
            "content": { "bodyModel": { "paragraphs": [] } }
          }
        }
      }
    JSON
  end
end

class Articles::Show
  def client_class
    TestClient
  end
end

describe Articles::Show do
  it "parses the post id for urls like /@user/:post_slug" do
    HttpClient.get("/@user/my-post-111111abcdef")

    TestClient.last_post_id.should eq("111111abcdef")
  end

  it "parses the post id for urls like /user/:post_slug" do
    HttpClient.get("/user/my-post-222222abcdef")

    TestClient.last_post_id.should eq("222222abcdef")
  end

  it "parses the post id for urls like /p/:post_slug" do
    HttpClient.get("/p/my-post-333333abcdef")

    TestClient.last_post_id.should eq("333333abcdef")
  end

  it "parses the post id for urls like /posts/:post_slug" do
    HttpClient.get("/posts/my-post-444444abcdef")

    TestClient.last_post_id.should eq("444444abcdef")
  end

  it "parses the post id for urls like /p/:post_id" do
    HttpClient.get("/p/555555abcdef")

    TestClient.last_post_id.should eq("555555abcdef")
  end

  it "parses the post id for urls like /:post_slug" do
    HttpClient.get("/my-post-666666abcdef")

    TestClient.last_post_id.should eq("666666abcdef")
  end

  it "parses the post id for urls like /https:/medium.com/@user/:post_slug" do
    HttpClient.get("/https:/medium.com/@user/777777abcdef")

    TestClient.last_post_id.should eq("777777abcdef")
  end
end