diff --git a/app/jobs/mqtt_forwarding_job.rb b/app/jobs/mqtt_forwarding_job.rb index 8c5e2e76..e155a91f 100644 --- a/app/jobs/mqtt_forwarding_job.rb +++ b/app/jobs/mqtt_forwarding_job.rb @@ -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 @@ -26,10 +26,6 @@ def mqtt_client }) end - def renderer - @renderer ||= ActionController::Base.new.view_context - end - def disconnect_mqtt! @mqtt_client&.disconnect end diff --git a/app/models/concerns/message_forwarding.rb b/app/models/concerns/message_forwarding.rb index a1a02b71..f32224c3 100644 --- a/app/models/concerns/message_forwarding.rb +++ b/app/models/concerns/message_forwarding.rb @@ -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 diff --git a/spec/jobs/mqtt_forwarding_job_spec.rb b/spec/jobs/mqtt_forwarding_job_spec.rb index ab8041d8..81c8960e 100644 --- a/spec/jobs/mqtt_forwarding_job_spec.rb +++ b/spec/jobs/mqtt_forwarding_job_spec.rb @@ -18,10 +18,6 @@ double(:device_json) } - let(:renderer) { - double(:renderer) - } - let(:forwarder) { double(:forwarder).tap do |forwarder| allow(forwarder).to receive(:forward_readings) @@ -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 @@ -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 diff --git a/spec/models/storer_spec.rb b/spec/models/storer_spec.rb index 54d689b8..5de1fb04 100644 --- a/spec/models/storer_spec.rb +++ b/spec/models/storer_spec.rb @@ -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