Skip to content

Commit

Permalink
fix: Fix Raw::Register#commit_changes(message)
Browse files Browse the repository at this point in the history
  • Loading branch information
ribose-jeffreylau committed Nov 20, 2024
1 parent 4c5d5c1 commit a83bee6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/paneron/register/writeable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand Down
4 changes: 2 additions & 2 deletions spec/raw_register_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a83bee6

Please sign in to comment.