TODO: Add support for custom CS Node validation (ability to pass block to node defn, not just arg defn)
parent
e5d0dfb016
commit
fbdc6469bc
|
@ -26,10 +26,11 @@ module CeleryScript
|
|||
n ? n : raise(TypeCheckError, BAD_NODE_NAME + name.to_s)
|
||||
end
|
||||
|
||||
def node(kind, allowed_args, allowed_body_nodes = [])
|
||||
def node(kind, allowed_args, allowed_body_nodes = [], &blk = nil)
|
||||
@node_def_list[kind.to_sym] = NodeSpecification.new(kind,
|
||||
allowed_args,
|
||||
allowed_body_nodes)
|
||||
allowed_body_nodes,
|
||||
blk)
|
||||
self
|
||||
end
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ module CeleryScriptSettingsBag
|
|||
.arg(:x, [Integer])
|
||||
.arg(:y, [Integer])
|
||||
.arg(:z, [Integer])
|
||||
.arg(:pin_id, [Integer]) { raise "TODO" }
|
||||
.arg(:pin_id, [Integer])
|
||||
.arg(:pin_type, [String]) do |node|
|
||||
within(ALLOWED_PIN_TYPES, node) do |val|
|
||||
BAD_PIN_TYPE % [val.to_s, ALLOWED_PIN_TYPES.inspect]
|
||||
|
@ -165,7 +165,9 @@ module CeleryScriptSettingsBag
|
|||
node.invalidate!(BAD_PERIPH_ID % node.value) if no_periph
|
||||
end
|
||||
end
|
||||
.node(:named_pin, [:pin_type, :pin_id])
|
||||
.node(:named_pin, [:pin_type, :pin_id]) do |node|
|
||||
binding.pry
|
||||
end
|
||||
.node(:read_peripheral, [:peripheral_id, :pin_mode])
|
||||
.node(:nothing, [])
|
||||
.node(:tool, [:tool_id])
|
||||
|
|
|
@ -114,4 +114,24 @@ describe CeleryScript::Checker do
|
|||
expect(chk.valid?).to be false
|
||||
expect(chk.error.message).to include("not a type of pin")
|
||||
end
|
||||
|
||||
it "Catches bad `pin_type`s in `read_pin`" do
|
||||
p = FactoryBot.create(:peripheral)
|
||||
hash[:body] = [
|
||||
{
|
||||
kind: "read_pin",
|
||||
args: {
|
||||
pin_mode: 0,
|
||||
label: "pin",
|
||||
pin_number: {
|
||||
kind: "named_pin",
|
||||
args: { pin_type: p.class.name, pin_id: p.id }
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
chk = CeleryScript::Checker.new(tree, corpus)
|
||||
expect(chk.valid?).to be false
|
||||
expect(chk.error.message).to include("not a type of pin")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,3 @@
|
|||
ENV['MQTT_HOST'] = "blooper.io"
|
||||
ENV['OS_UPDATE_SERVER'] = "http://non_legacy_update_url.com"
|
||||
ENV['RAILS_ENV'] ||= 'test'
|
||||
require File.expand_path('../../config/environment', __FILE__)
|
||||
require_relative './stuff'
|
||||
require_relative './topic_stub'
|
||||
require_relative './nice_response'
|
||||
|
||||
ENV['MQTT_HOST'] = "blooper.io"
|
||||
ENV['OS_UPDATE_SERVER'] = "http://non_legacy_update_url.com"
|
||||
require 'simplecov'
|
||||
|
@ -26,6 +18,7 @@ ENV['RAILS_ENV'] ||= 'test'
|
|||
require File.expand_path('../../config/environment', __FILE__)
|
||||
require 'rspec/rails'
|
||||
require_relative './stuff'
|
||||
require_relative './topic_stub'
|
||||
|
||||
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
||||
|
||||
|
@ -72,3 +65,51 @@ def const_reassign(target, const, value)
|
|||
target.send(:remove_const, const)
|
||||
target.const_set(const, value)
|
||||
end
|
||||
|
||||
class NiceResponse
|
||||
attr_reader :r, :body
|
||||
|
||||
def initialize(r)
|
||||
@r = r
|
||||
@body = r.body.read
|
||||
end
|
||||
|
||||
def path
|
||||
r.path
|
||||
end
|
||||
|
||||
def pretty_url
|
||||
r.method + " " + r.path.first(45) + query
|
||||
end
|
||||
|
||||
def has_params?
|
||||
r.params
|
||||
.except(:controller, :action, :format, :id)
|
||||
.keys
|
||||
.length > 0
|
||||
end
|
||||
|
||||
def has_body?
|
||||
r.body.size > 4
|
||||
end
|
||||
|
||||
def display_body
|
||||
begin
|
||||
JSON
|
||||
.pretty_generate(JSON.parse(body))
|
||||
.first(500)
|
||||
rescue
|
||||
JSON.pretty_generate(r
|
||||
.params
|
||||
.except(:controller, :action, :format, :id, :user_id, :device_id)).first(500)
|
||||
end
|
||||
end
|
||||
|
||||
def query
|
||||
if r.query_string.present?
|
||||
"?" + r.query_string.first(45)
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue