From 36e3e1554272dcfb51a2786f28461006ccc0311b Mon Sep 17 00:00:00 2001 From: Daniel Barber Date: Fri, 3 Jan 2020 19:54:36 -0500 Subject: [PATCH] Test github posting --- lib/micropub/post.rb | 4 +++ test/lib/micropub/github_test.rb | 48 ++++++++++++++++++++++++++++++++ test/lib/micropub/post_test.rb | 12 ++++++++ test/request_helper.rb | 2 -- 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 test/lib/micropub/github_test.rb diff --git a/lib/micropub/post.rb b/lib/micropub/post.rb index e141249..14bd781 100644 --- a/lib/micropub/post.rb +++ b/lib/micropub/post.rb @@ -58,6 +58,10 @@ module Micropub end end + def photo + params["photo"] + end + def content_from_hash if params["content"]["text"] params["content"]["text"] diff --git a/test/lib/micropub/github_test.rb b/test/lib/micropub/github_test.rb new file mode 100644 index 0000000..d3ec38b --- /dev/null +++ b/test/lib/micropub/github_test.rb @@ -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 diff --git a/test/lib/micropub/post_test.rb b/test/lib/micropub/post_test.rb index f77e67f..f610981 100644 --- a/test/lib/micropub/post_test.rb +++ b/test/lib/micropub/post_test.rb @@ -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( diff --git a/test/request_helper.rb b/test/request_helper.rb index 365a888..f9df925 100644 --- a/test/request_helper.rb +++ b/test/request_helper.rb @@ -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