Minor changes (fixes `tag` related 500)
parent
5e46edc1fb
commit
f57ac121c3
|
@ -76,8 +76,7 @@ class NervesHub
|
|||
# ["application:prod", "channel:stable"]
|
||||
# Becomes: {"application"=>"prod", "channel"=>"stable"}
|
||||
# NEVER DUPLICATE TAG PREFIXES (thing before ":"). Must be unique!
|
||||
tag_map = \
|
||||
dev.fetch("tags").map { |x| x.split(":") }.to_h
|
||||
tag_map = dev.fetch(:tags).map { |x| x.split(":") }.to_h
|
||||
tag_map[CHANNEL] = channel
|
||||
next_tags = tag_map.to_a.map { |x| x.join(":") }
|
||||
update(serial_number, next_tags)
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
class DeviceSerialNumber < ApplicationRecord
|
||||
belongs_to :device
|
||||
before_save :dont_save
|
||||
|
||||
def dont_save
|
||||
raise "This table is deprecated. Stop using it."
|
||||
end
|
||||
# DO NOT USE THIS TABLE. IT IS DEPRECATED. DESTROY FEB 2019.
|
||||
end
|
||||
|
|
|
@ -2,5 +2,6 @@ FactoryBot.define do
|
|||
factory :device do
|
||||
name { Faker::Food.vegetables }
|
||||
timezone { Device::TIMEZONES.sample }
|
||||
serial_number { SecureRandom.hex(16)}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,14 +1,6 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe NervesHub do
|
||||
class StubResp
|
||||
attr_accessor :code, :body
|
||||
|
||||
def initialize(code, body)
|
||||
@code, @body = code, body
|
||||
end
|
||||
end
|
||||
|
||||
def stub_connection
|
||||
double(SecureRandom.hex.first(6), :ca_file= => nil,
|
||||
:cert_store => nil,
|
||||
|
|
|
@ -5,13 +5,26 @@ describe FbosConfig do
|
|||
let(:config) { FbosConfig.create!(device: device) }
|
||||
|
||||
it 'triggers callbacks' do
|
||||
pending "Probably can be removed."
|
||||
serial_number = SecureRandom.hex.first(8)
|
||||
conn = double("Create a cert", :ca_file= => nil,
|
||||
:cert_store => nil,
|
||||
:cert_store= => nil,
|
||||
:use_ssl => nil,
|
||||
:use_ssl= => nil,
|
||||
:cert= => nil,
|
||||
:key= => nil)
|
||||
NervesHub.set_conn(conn)
|
||||
# url = "/orgs/farmbot/devices/#{device.serial_number}"
|
||||
# resp = StubResp.new("200", { "data" => { "tags": [] } }.to_json)
|
||||
# resp2 = StubResp.new("201", { "data" => { "tags": [] } }.to_json)
|
||||
# params = [ url,
|
||||
# {"tags": ["channel:beta"]}.to_json,
|
||||
# {"Content-Type"=>"application/json"} ]
|
||||
# expect(NervesHub.conn).to(receive(:get).with(url).and_return(resp))
|
||||
# expect(NervesHub.conn).to(receive(:put).with(*params).and_return(resp2))
|
||||
|
||||
channel = "beta"
|
||||
msg = :push_changes_to_nerves_hub
|
||||
|
||||
DeviceSerialNumber.create!(device: device, serial_number: serial_number)
|
||||
expect(config).to receive(msg).with(serial_number, channel)
|
||||
expect(config).to receive(msg).with(device.serial_number, channel)
|
||||
run_jobs_now do
|
||||
config.update_attributes!(update_channel: channel)
|
||||
end
|
||||
|
|
|
@ -119,6 +119,14 @@ def const_reassign(target, const, value)
|
|||
target.const_set(const, value)
|
||||
end
|
||||
|
||||
class StubResp
|
||||
attr_accessor :code, :body
|
||||
|
||||
def initialize(code, body)
|
||||
@code, @body = code, body
|
||||
end
|
||||
end
|
||||
|
||||
class NiceResponse
|
||||
attr_reader :r, :body
|
||||
|
||||
|
|
Loading…
Reference in New Issue