1
0
mirror of https://github.com/danbee/micropub.git synced 2025-03-04 08:59:13 +00:00

Test github posting

This commit is contained in:
Daniel Barber 2020-01-03 19:54:36 -05:00
parent 1f1afc99e8
commit 36e3e15542
4 changed files with 64 additions and 2 deletions

View File

@ -58,6 +58,10 @@ module Micropub
end
end
def photo
params["photo"]
end
def content_from_hash
if params["content"]["text"]
params["content"]["text"]

View File

@ -0,0 +1,48 @@
require "test_helper"
require "micropub/github"
describe Micropub::Github do
describe "#post!" do
it "sends the post to github" do
contents = mock("contents")
contents.expects(:create).with(
"danbee",
"danbarber.me.hugo",
"content/blog/2020-01-01-hello-world/index.md",
{
path: "content/blog/2020-01-01-hello-world/index.md",
message: "Posting: Hello, World!",
:content => <<~CONTENT,
---
date: '2020-01-01T00:00:00+00:00'
layout: micropost
categories:
- my-blog
---
Hello, World!
CONTENT
:branch => "master",
}).returns(true)
repos = mock("repos")
repos.stubs(:contents).returns(contents)
github_api = mock("Github")
github_api.stubs(:repos).returns(repos)
::Github.stubs(:new).returns(github_api)
github = Micropub::Github.new
post = Micropub::Post.new(params)
github.post!(post)
end
def params
{
"content" => "Hello, World!",
"category" => "my-blog",
"published" => DateTime.parse("2020-01-01").rfc3339,
}
end
end
end

View File

@ -184,6 +184,18 @@ describe Micropub::Post do
end
end
describe "#photo" do
it "returns the url of the photo" do
post = Micropub::Post.new(
"content" => "Hallo, Earth!",
"photo" => "http://www.example.com/example.png",
"published" => "2019-11-12",
)
_(post.photo).must_equal "http://www.example.com/example.png"
end
end
describe "#post_content" do
it "returns a post formatted for hugo" do
post = Micropub::Post.new(

View File

@ -1,8 +1,6 @@
require "test_helper"
require 'minitest/hooks'
include Rack::Test::Methods
MiniTest::Spec.register_spec_type(/something/, Minitest::HooksSpec)
def app
Micropub::Webserver