Skip to content

Commit

Permalink
fix: Fix errors when modifying register attributes when unsaved
Browse files Browse the repository at this point in the history
  • Loading branch information
ribose-jeffreylau committed Nov 20, 2024
1 parent a83bee6 commit 9ccca6a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
12 changes: 8 additions & 4 deletions lib/paneron/register/raw/register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,14 @@ def data_set_path(data_set_name)
end

def metadata
@metadata ||= YAML.safe_load_file(
register_yaml_path,
permitted_classes: [Time, Date, DateTime],
)
@metadata ||= begin
YAML.safe_load_file(
register_yaml_path,
permitted_classes: [Time, Date, DateTime],
)
rescue Errno::ENOENT
self.class.metadata_template
end
end

def metadata=(metadata)
Expand Down
32 changes: 22 additions & 10 deletions spec/raw_register_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -471,18 +471,30 @@
end

describe "#title=" do
it "updates the metadata title" do
expect do
raw_register.title = "new title"
end.to change { raw_register.metadata["title"] }.from("register").to("new title")
shared_examples_for "changes title" do |old_title|
it "updates the metadata title" do
expect do
raw_register.title = "new title"
end.to change { raw_register.metadata["title"] }.from(old_title).to("new title")

expect do
raw_register.title = "new title"
end.to_not(change { raw_register.metadata["title"] })
expect do
raw_register.title = "new title"
end.to_not(change { raw_register.metadata["title"] })

expect do
raw_register.title = "new title 2"
end.to change { raw_register.title }.from("new title").to("new title 2")
expect do
raw_register.title = "new title 2"
end.to change { raw_register.title }.from("new title").to("new title 2")
end
end

it_behaves_like "changes title", "register"

describe "for an unsaved register" do
let(:raw_register) do
described_class.new("./another/new/register")
end

it_behaves_like "changes title", ""
end
end
end

0 comments on commit 9ccca6a

Please sign in to comment.