Tests for the in_use flag

pull/742/head
Rick Carlino 2018-03-23 09:49:44 -05:00
parent 305cacb0f4
commit a1b19d579d
2 changed files with 34 additions and 2 deletions

View File

@ -1,8 +1,8 @@
FactoryBot.define do
factory :farm_event do
start_time { Date.yesterday - [*(1..5)].sample.days }
end_time { Date.today + 1.minute + ([*(1..5)].sample).days }
time_unit { FarmEvent::UNITS_OF_TIME.sample }
end_time { Date.today + 1.minute + ([*(1..5)].sample).days }
time_unit { FarmEvent::UNITS_OF_TIME.sample }
repeat { [*(1..5)].sample }
# device
after(:build) do |s|

View File

@ -5,6 +5,38 @@ describe CeleryScript::FetchCelery do
let(:user) { FactoryBot.create(:user) }
let(:device) { user.device }
it "marks in_use as false when not in use" do
in_use = \
CeleryScript::FetchCelery.run!(sequence: FakeSequence.create())[:in_use]
expect(in_use).to be(false)
end
it "marks a sequence as in_use by Regimen" do
sequence = FakeSequence.create()
ri = RegimenItem.new(time_offset: 100, sequence_id: sequence.id)
regimen = FactoryBot.create(:regimen, regimen_items: [ri])
results = CeleryScript::FetchCelery.run!(sequence: sequence)
expect(results[:in_use]).to be(true)
end
it "marks a sequence as in_use by FarmEvent" do
fe = FactoryBot.create(:farm_event)
sequence = fe.executable
results = CeleryScript::FetchCelery.run!(sequence: sequence)
expect(results[:in_use]).to be(true)
end
it "marks a sequence as in_use by Sequence" do
sequence = FakeSequence.create()
user = FakeSequence.create(body: [
{ kind: "execute", args: { sequence_id: sequence.id } }
])
results = CeleryScript::FetchCelery.run!(sequence: sequence)
expect(results[:in_use]).to be(true)
end
__NOTHING______ = "nothing"
it "Makes JSON that is identical to the legacy implementation - part 1" do