Stricter validations for ToolSLot (avoid double slotting at DB layer, too)

pull/1163/head
Rick Carlino 2019-04-18 17:33:10 -07:00
parent 12806e849f
commit b0dc438bca
4 changed files with 26 additions and 3 deletions

View File

@ -0,0 +1,7 @@
class StricterValidationForToolId < ActiveRecord::Migration[5.2]
def change
safety_assured do
add_index :points, [:device_id, :tool_id], unique: true
end
end
end

View File

@ -2405,6 +2405,13 @@ CREATE INDEX index_plant_templates_on_saved_garden_id ON public.plant_templates
CREATE INDEX index_points_on_device_id ON public.points USING btree (device_id);
--
-- Name: index_points_on_device_id_and_tool_id; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX index_points_on_device_id_and_tool_id ON public.points USING btree (device_id, tool_id);
--
-- Name: index_points_on_discarded_at; Type: INDEX; Schema: public; Owner: -
--
@ -2895,6 +2902,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20190411171401'),
('20190411222900'),
('20190416035406'),
('20190417165636');
('20190417165636'),
('20190419001321');

View File

@ -1,2 +0,0 @@
describe Point do
end

View File

@ -0,0 +1,10 @@
describe ToolSlot do
it "does not allow double slotting of tools" do
slot1 = FactoryBot.create(:tool_slot)
device = slot1.device
tool = slot1.tool
expect do
FactoryBot.create(:tool_slot, device: device, tool: tool)
end.to raise_error(ActiveRecord::RecordInvalid)
end
end