diff --git a/lib/paneron/register/writeable.rb b/lib/paneron/register/writeable.rb index e8dfbd9..f687a89 100644 --- a/lib/paneron/register/writeable.rb +++ b/lib/paneron/register/writeable.rb @@ -58,8 +58,8 @@ def has_unsynced_changes? git_client.gcommit("head").sha end - def commit_changes(message: nil) - git_client.commit(message.nil? ? "Sync from ruby-paneron-register" : message) + def commit_changes(message = nil) + git_client.commit(message.nil? || message.empty? ? "Sync from ruby-paneron-register" : message) end def push_commits_to_remote @@ -79,7 +79,7 @@ def sync(update: false, message: nil) add_changes_to_staging if has_uncommited_changes? - commit_changes(message: message) + commit_changes(message) end if has_unsynced_changes? diff --git a/spec/raw_register_spec.rb b/spec/raw_register_spec.rb index e866169..8fe7862 100644 --- a/spec/raw_register_spec.rb +++ b/spec/raw_register_spec.rb @@ -134,7 +134,7 @@ allow(raw_register).to receive(:remote?).and_return(true) allow(raw_register).to receive(:pull_from_remote) allow(raw_register).to receive(:add_changes_to_staging) - allow(raw_register).to receive(:commit_changes) + allow(raw_register).to receive(:commit_changes).with(optional(String)) allow(raw_register).to receive(:has_unsynced_changes?) allow(raw_register).to receive(:has_uncommited_changes?) allow(raw_register).to receive(:push_commits_to_remote) @@ -157,7 +157,7 @@ end it "calls commit_changes" do - expect(raw_register).to receive(:commit_changes) + expect(raw_register).to receive(:commit_changes).with(optional(String)) raw_register.sync(update: true) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fc98c95..6a69ffd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -27,6 +27,10 @@ # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| + def optional(type) + satisfy { |value| value.nil? || value.is_a?(type) } + end + # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest # assertions if you prefer.