Specs for enforcing pin 17/23 validations
parent
377d9f7331
commit
4591d7260f
|
@ -13,6 +13,7 @@ module PinBindings
|
|||
end
|
||||
|
||||
def validate
|
||||
validate_pin_num
|
||||
validate_sequence_id
|
||||
exactly_one_choice
|
||||
not_both_actions
|
||||
|
|
|
@ -3,6 +3,15 @@ module PinBindings
|
|||
BAD_SEQ_ID = "Sequence ID is not valid"
|
||||
MUTUAL_EXCLUSION = "Pin Bindings require exactly one sequence or special " \
|
||||
"action. Please pick one."
|
||||
OFF_LIMITS = [17, 23]
|
||||
BAD_PIN_NUM = "Pin numbers #{OFF_LIMITS.join(" and ")} cannot be used."
|
||||
|
||||
def validate_pin_num
|
||||
if pin_num && OFF_LIMITS.include?(pin_num)
|
||||
add_error :pin_num, :pin_num, BAD_PIN_NUM
|
||||
end
|
||||
end
|
||||
|
||||
def false_xor_sequence_id_special_actn
|
||||
add_error :sequence_id, :sequence_id, MUTUAL_EXCLUSION
|
||||
end
|
||||
|
|
|
@ -14,6 +14,7 @@ module PinBindings
|
|||
end
|
||||
|
||||
def validate
|
||||
validate_pin_num
|
||||
not_both_actions
|
||||
validate_sequence_id if sequence_id
|
||||
end
|
||||
|
|
|
@ -70,5 +70,26 @@ describe Api::PinBindingsController do
|
|||
expect(pin_binding[key]).to eq(input[key])
|
||||
end
|
||||
end
|
||||
|
||||
it 'disallows pin 17' do
|
||||
sign_in user
|
||||
s = FakeSequence.create( device: device)
|
||||
input = { pin_num: 17, sequence_id: s.id}
|
||||
b4 = PinBinding.count
|
||||
post :create, body: input.to_json, params: { format: :json}
|
||||
expect(response.status).to eq(422)
|
||||
expect(json[:pin_num]).to include("Pin numbers 17 and 23 cannot be used.")
|
||||
end
|
||||
|
||||
it 'disallows pin 23' do
|
||||
sign_in user
|
||||
s = FakeSequence.create( device: device)
|
||||
input = { pin_num: 23, sequence_id: s.id}
|
||||
put :update,
|
||||
body: input.to_json,
|
||||
params: { format: :json, id: pin_binding.id}
|
||||
expect(response.status).to eq(422)
|
||||
expect(json[:pin_num]).to include("Pin numbers 17 and 23 cannot be used.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -64,7 +64,7 @@ describe Api::SequencesController do
|
|||
sign_in user
|
||||
pb = PinBindings::Create.run!(device: user.device,
|
||||
sequence_id: sequence.id,
|
||||
pin_num: 23)
|
||||
pin_num: 24)
|
||||
delete :destroy, params: { id: sequence.id }
|
||||
expect(response.status).to eq(422)
|
||||
expect(json[:sequence]).to include("in use")
|
||||
|
|
|
@ -22,6 +22,7 @@ end
|
|||
|
||||
describe "Pin Binding updates" do
|
||||
it "enforces mutual exclusivity" do
|
||||
PinBinding.destroy_all
|
||||
Sequence.destroy_all
|
||||
Device.destroy_all
|
||||
device = FactoryBot.create(:device)
|
||||
|
|
Loading…
Reference in New Issue