Skip to content

Commit

Permalink
don't render profile urls in forwarding; ensure all reading keys pass…
Browse files Browse the repository at this point in the history
…ed to sidekiq are strings
  • Loading branch information
timcowlishaw committed Nov 13, 2024
1 parent dcfd1a4 commit 0b1ca63
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
6 changes: 1 addition & 5 deletions app/jobs/mqtt_forwarding_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def perform(device_id, data)
private

def payload_for(device, readings)
Presenters.present(device, device.owner, renderer, readings: readings)
Presenters.present(device, device.owner, nil, readings: readings)
end

def mqtt_client
Expand All @@ -26,10 +26,6 @@ def mqtt_client
})
end

def renderer
@renderer ||= ActionController::Base.new.view_context
end

def disconnect_mqtt!
@mqtt_client&.disconnect
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/message_forwarding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module MessageForwarding

def forward_readings(device, readings)
if device.forward_readings?
MQTTForwardingJob.perform_later(device.id, readings: readings)
MQTTForwardingJob.perform_later(device.id, readings: readings.map(&:stringify_keys))
end
end

Expand Down
7 changes: 1 addition & 6 deletions spec/jobs/mqtt_forwarding_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
double(:device_json)
}

let(:renderer) {
double(:renderer)
}

let(:forwarder) {
double(:forwarder).tap do |forwarder|
allow(forwarder).to receive(:forward_readings)
Expand All @@ -31,7 +27,6 @@
before do
allow(MQTTClientFactory).to receive(:create_client).and_return(mqtt_client)
allow(Presenters).to receive(:present).and_return(device_json)
allow_any_instance_of(ActionController::Base).to receive(:view_context).and_return(renderer)
allow(MQTTForwarder).to receive(:new).and_return(forwarder)
allow_any_instance_of(Device).to receive(:forwarding_token).and_return(forwarding_token)
end
Expand All @@ -51,7 +46,7 @@

it "renders the device json for the given device and reading, as the device owner" do
MQTTForwardingJob.perform_now(device.id, readings: readings)
expect(Presenters).to have_received(:present).with(device, device.owner, renderer, readings: readings)
expect(Presenters).to have_received(:present).with(device, device.owner, nil, readings: readings)
end

it "forwards using the device's id and forwarding token, with the rendered json payload" do
Expand Down
4 changes: 2 additions & 2 deletions spec/models/storer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@
double(:device_json)
}

it "forwards the message with the forwarding token and the device's id" do
it "forwards the readings for the device, ensuring reading keys are passed as strings" do
allow(device).to receive(:forward_readings?).and_return(true)
expect(MQTTForwardingJob).to receive(:perform_later).with(device.id, readings: [@sql_data])
expect(MQTTForwardingJob).to receive(:perform_later).with(device.id, readings: [@sql_data.stringify_keys])
storer.store(device, [@data])
end
end
Expand Down

0 comments on commit 0b1ca63

Please sign in to comment.