Merge pull request #742 from RickCarlino/in_use_stats

Add `in_use` flag to Sequences on API
pull/743/head^2
Rick Carlino 2018-03-23 10:04:07 -05:00 committed by GitHub
commit c2451bbc87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 2 deletions

View File

@ -110,6 +110,10 @@ module CeleryScript
def execute
canonical_form = misc_fields.merge!(recurse_into_node(entry_node))
canonical_form[:in_use] = \
EdgeNode.where(kind: "sequence_id", value: sequence.id).exists? ||
RegimenItem.where(sequence_id: sequence.id).exists? ||
FarmEvent.where(executable: sequence).exists?
return HashWithIndifferentAccess.new(canonical_form)
end
end

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

View File

@ -57,6 +57,7 @@ export interface Sequence extends CeleryScriptSequence {
id?: number;
color: Color;
name: string;
in_use?: boolean;
}
export interface SequenceReducerState {