diff --git a/lib/lolcommits/plugin/uploldz.rb b/lib/lolcommits/plugin/uploldz.rb index ebe643e..dbdc614 100644 --- a/lib/lolcommits/plugin/uploldz.rb +++ b/lib/lolcommits/plugin/uploldz.rb @@ -49,6 +49,7 @@ def valid_configuration? # def run_capture_ready debug "Posting capture to #{configuration[:endpoint]}" + RestClient.post( configuration[:endpoint], { diff --git a/test/images/lolcommit.jpg b/test/images/lolcommit.jpg new file mode 100644 index 0000000..e61a939 Binary files /dev/null and b/test/images/lolcommit.jpg differ diff --git a/test/lolcommits/plugin/uploldz_test.rb b/test/lolcommits/plugin/uploldz_test.rb index ae679de..02e9261 100644 --- a/test/lolcommits/plugin/uploldz_test.rb +++ b/test/lolcommits/plugin/uploldz_test.rb @@ -4,118 +4,114 @@ require 'webmock/minitest' describe Lolcommits::Plugin::Uploldz do - include Lolcommits::TestHelpers::GitRepo include Lolcommits::TestHelpers::FakeIO - describe "with a runner" do - def runner - # a simple lolcommits runner with an empty configuration Hash - @runner ||= Lolcommits::Runner.new( - lolcommit_path: Tempfile.new('lolcommit.jpg').path - ) - end + def valid_enabled_config + { + enabled: true, + endpoint: "https://uploldz.com/uplol", + optional_http_auth_username: 'joe', + optional_http_auth_password: '1234' + } + end - def plugin - @plugin ||= Lolcommits::Plugin::Uploldz.new(runner: runner) + describe "initalizing" do + it "assigns runner and all plugin options" do + _(plugin.runner).wont_be_nil + _(plugin.options).must_equal [ + :enabled, + :endpoint, + :optional_key, + :optional_http_auth_username, + :optional_http_auth_password + ] end + end - def valid_enabled_config - { - enabled: true, - endpoint: "https://uploldz.com/uplol", - optional_http_auth_username: 'joe', - optional_http_auth_password: '1234' - } + describe "#enabled?" do + it "is false by default" do + _(plugin.enabled?).must_equal false end - describe "initalizing" do - it "assigns runner and all plugin options" do - _(plugin.runner).must_equal runner - _(plugin.options).must_equal [ - :enabled, - :endpoint, - :optional_key, - :optional_http_auth_username, - :optional_http_auth_password - ] - end + it "is true when configured" do + plugin.configuration = valid_enabled_config + _(plugin.enabled?).must_equal true end + end - describe "#enabled?" do - it "is false by default" do - _(plugin.enabled?).must_equal false - end + describe "run_capture_ready" do + before { commit_repo_with_message("first commit!") } + after { teardown_repo } - it "is true when configured" do - plugin.configuration = valid_enabled_config - _(plugin.enabled?).must_equal true - end - end + it "syncs lolcommits" do + captured_img_path = File.expand_path("./test/images/lolcommit.jpg") - describe "run_capture_ready" do - before { commit_repo_with_message("first commit!") } - after { teardown_repo } - - it "syncs lolcommits" do - in_repo do - plugin.configuration = valid_enabled_config - - stub_request(:post, "https://uploldz.com/uplol").to_return(status: 200) - - plugin.run_capture_ready - - assert_requested :post, "https://uploldz.com/uplol", times: 1, - headers: {'Content-Type' => /multipart\/form-data/ } do |req| - _(req.body).must_match(/Content-Disposition: form-data;.+name="file"; filename="lolcommit.jpg.+"/) - _(req.body).must_match 'name="repo"' - _(req.body).must_match 'name="author_name"' - _(req.body).must_match 'name="author_email"' - _(req.body).must_match 'name="sha"' - _(req.body).must_match 'name="key"' - _(req.body).must_match "plugin-test-repo" - _(req.body).must_match "first commit!" - end + in_repo do + plugin.configuration = valid_enabled_config + plugin.runner.lolcommit_path = captured_img_path + + stub_request(:post, "https://uploldz.com/uplol").to_return(status: 200) + + plugin.run_capture_ready + + assert_requested :post, "https://uploldz.com/uplol", times: 1, + headers: {'Content-Type' => /multipart\/form-data/ } do |req| + _(req.body).must_match(/Content-Disposition: form-data;.+name="file"; filename="lolcommit.jpg"/) + _(req.body).must_match 'name="repo"' + _(req.body).must_match 'name="author_name"' + _(req.body).must_match 'name="author_email"' + _(req.body).must_match 'name="sha"' + _(req.body).must_match 'name="key"' + _(req.body).must_match "plugin-test-repo" + _(req.body).must_match "first commit!" end end end + end - describe "configuration" do - it "allows plugin options to be configured" do - # enabled, endpoint, key, user, password - inputs = %w( - true - https://my-server.com/uplol - key-123 - joe - 1337pass - ) - configured_plugin_options = {} - - fake_io_capture(inputs: inputs) do - configured_plugin_options = plugin.configure_options! - end + describe "configuration" do + it "allows plugin options to be configured" do + # enabled, endpoint, key, user, password + inputs = %w( + true + https://my-server.com/uplol + key-123 + joe + 1337pass + ) + configured_plugin_options = {} - _(configured_plugin_options).must_equal({ - enabled: true, - endpoint: "https://my-server.com/uplol", - optional_key: "key-123", - optional_http_auth_username: "joe", - optional_http_auth_password: "1337pass" - }) + fake_io_capture(inputs: inputs) do + configured_plugin_options = plugin.configure_options! end - describe "#valid_configuration?" do - it "returns false for an invalid configuration" do - plugin.configuration = { endpoint: "gibberish" } - _(plugin.valid_configuration?).must_equal false - end + _(configured_plugin_options).must_equal({ + enabled: true, + endpoint: "https://my-server.com/uplol", + optional_key: "key-123", + optional_http_auth_username: "joe", + optional_http_auth_password: "1337pass" + }) + end - it "returns true with a valid configuration" do - plugin.configuration = valid_enabled_config - _(plugin.valid_configuration?).must_equal true - end + describe "#valid_configuration?" do + it "returns false for an invalid configuration" do + plugin.configuration = { endpoint: "gibberish" } + _(plugin.valid_configuration?).must_equal false + end + + it "returns true with a valid configuration" do + plugin.configuration = valid_enabled_config + _(plugin.valid_configuration?).must_equal true end end end + + private + def plugin + @plugin ||= Lolcommits::Plugin::Uploldz.new( + runner: Lolcommits::Runner.new + ) + end end