Skip to content

Commit e322536

Browse files
Copilotccutrer
andauthored
Add tests for module ID inference fallback and on_load attachment
Agent-Logs-Url: https://github.com/openhab/openhab-jruby/sessions/d9c9a5cd-d6e9-4819-8e5a-38415ebe7788 Co-authored-by: ccutrer <191320+ccutrer@users.noreply.github.com>
1 parent 08dbabb commit e322536

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

spec/openhab/dsl/rules/builder_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,25 @@ def triggered?
134134
end
135135
expect(my_rule.triggers.map(&:id)).to eq %w[my_test_rule:1 my_test_rule:2]
136136
end
137+
138+
it "uses a uuid as fallback trigger id when no rule uid is available" do
139+
items.build { switch_item "MySwitch" }
140+
rule_triggers = OpenHAB::DSL::Rules::RuleTriggers.new
141+
trigger = rule_triggers.append_trigger(
142+
type: "core.ItemStateChangeTrigger",
143+
config: { "itemName" => "MySwitch" }
144+
)
145+
expect(trigger.id).to match(/\A[0-9a-f-]{36}\z/)
146+
end
147+
148+
it "infers on_load module id from the rule uid" do
149+
attachment = nil
150+
rule id: "my_load_rule" do
151+
on_load attach: :test_attach
152+
run { |event| attachment = event.attachment }
153+
end
154+
expect(attachment).to eq :test_attach
155+
end
137156
end
138157

139158
describe "#on_start" do

0 commit comments

Comments
 (0)