1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-13 23:48:55 +01:00
fab-manager/test/models/space_test.rb

74 lines
2.3 KiB
Ruby
Raw Normal View History

2023-02-24 17:26:55 +01:00
# frozen_string_literal: true
2017-02-13 14:38:28 +01:00
require 'test_helper'
class SpaceTest < ActiveSupport::TestCase
bio_lab = {
2018-12-12 13:49:14 +01:00
name: 'Bio-lab',
description: 'An biological laboratory to experiment bio-technologies',
default_places: 5
}
2017-02-13 14:38:28 +01:00
test 'create a space' do
space = Space.create!(bio_lab)
2017-02-13 14:38:28 +01:00
assert_not_nil space
subtype = StatisticSubType.find_by(key: space.slug)
assert_not_nil subtype
end
test 'update a space' do
new_name = 'Bio-tech lab'
space = Space.create!(bio_lab)
2023-02-24 17:26:55 +01:00
space.update(name: new_name)
2017-02-13 14:38:28 +01:00
subtype = StatisticSubType.find_by(key: space.slug)
assert_equal new_name, subtype.label
end
test 'delete a space' do
space = Space.create!(bio_lab)
2017-02-13 14:38:28 +01:00
slug = space.slug
space.destroy!
assert_nil Space.find_by(slug: slug)
assert_nil StatisticSubType.find_by(key: slug)
end
2023-07-28 16:16:44 +02:00
test "space can be associated with spaces in a tree-like structure" do
space_1 = Space.create!(name: "space 1", default_places: 2)
space_1_1 = Space.create!(name: "space 1_1", default_places: 2, parent: space_1)
space_1_2 = Space.create!(name: "space 1_2", default_places: 2, parent: space_1)
space_1_2_1 = Space.create!(name: "space 1_2_1", default_places: 2, parent: space_1_2)
space_other = Space.create!(name: "space other", default_places: 2)
assert_equal [space_1_1, space_1_2], space_1.children
assert_equal [], space_1_1.children
assert_equal [space_1_2_1], space_1_2.children
assert_equal [space_1, space_1_2], space_1_2_1.ancestors
assert_equal [space_1], space_1_2.ancestors
assert_equal [space_1], space_1_1.ancestors
assert_equal [], space_1.ancestors
assert_equal [space_1_1, space_1_2, space_1_2_1], space_1.descendants
assert_equal [], space_1_1.descendants
assert_equal [space_1_2_1], space_1_2.descendants
assert_equal [], space_1_2_1.descendants
assert_equal [], space_other.descendants
assert_equal [], space_other.ancestors
end
test "space can be associated with machines" do
space = spaces(:space_1)
machine_1 = machines(:machine_1)
machine_2 = machines(:machine_2)
space.machines << machine_1
space.machines << machine_2
assert_equal 2, space.machines.count
assert_equal space, machine_1.space
assert_equal space, machine_2.space
end
2017-02-13 14:38:28 +01:00
end