Skip to content

Commit

Permalink
Fix sitemap builder proxy (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimtng authored Jan 6, 2024
1 parent ae3cb4a commit 31e3e6e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/openhab/dsl/sitemaps/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,14 @@ def initialize(type,
if @builder_proxy
old_obj = @builder_proxy.__getobj__
@builder_proxy.__setobj__(self)
yield @builder_proxy
begin
yield @builder_proxy
ensure
@builder_proxy.__setobj__(old_obj)
end
else
instance_eval_with_dummy_items(&block)
end
ensure
@builder_proxy&.__setobj__(old_obj)
end

# Adds one or more new rules for setting the label color
Expand Down
4 changes: 4 additions & 0 deletions spec/openhab/dsl/sitemaps/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
expect(b.__getobj__).to be_a(OpenHAB::DSL::Sitemaps::SitemapBuilder)
expect(self).not_to respond_to(:text)
b.text item: "Switch1"
expect(self).to be example
expect(b.__getobj__).to be_a(OpenHAB::DSL::Sitemaps::SitemapBuilder)
expect(self).not_to respond_to(:text)
expect { b.text }.not_to raise_error # Call a second time to ensure that builder proxy got reset correctly
end
end
end
Expand Down

0 comments on commit 31e3e6e

Please sign in to comment.