Done with point archival
parent
5758d1d256
commit
a0f038e89d
|
@ -23,8 +23,11 @@ module Points
|
|||
end
|
||||
|
||||
def execute
|
||||
hard_delete ?
|
||||
points.destroy_all : points.update_all(discarded_at: Time.now)
|
||||
if hard_delete
|
||||
points.destroy_all
|
||||
else
|
||||
points.update_all(discarded_at: Time.now)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -14,7 +14,73 @@ describe Api::PointsController do
|
|||
Auth::CreateToken.run!(params)[:token].encoded
|
||||
end
|
||||
|
||||
it 'lists points' do
|
||||
it "shows only discarded points" do
|
||||
Point.destroy_all
|
||||
old = Plant.create!(x: 5,
|
||||
y: 5,
|
||||
z: 5,
|
||||
radius: 50,
|
||||
name: "old",
|
||||
device: user.device,
|
||||
openfarm_slug: "cabbage",
|
||||
pointer_type: "Plant",
|
||||
pointer_id: 0,
|
||||
discarded_at: Time.now)
|
||||
|
||||
Plant.create!(x: 5,
|
||||
y: 5,
|
||||
z: 5,
|
||||
radius: 50,
|
||||
name: "new",
|
||||
device: user.device,
|
||||
openfarm_slug: "cabbage",
|
||||
pointer_type: "Plant",
|
||||
pointer_id: 0,
|
||||
discarded_at: nil)
|
||||
SmarfDoc.note("If you want to see previously deleted points, " +
|
||||
"add `?filter=old` to the end of the URL.")
|
||||
sign_in user
|
||||
get :index, params: { filter: "old"}
|
||||
expect(response.status).to eq(200)
|
||||
expect(json.length).to eq(1)
|
||||
expect(json.first[:name]).to eq("old")
|
||||
end
|
||||
|
||||
it "shows `discarded` and `kept` points" do
|
||||
Point.destroy_all
|
||||
old = Plant.create!(x: 5,
|
||||
y: 5,
|
||||
z: 5,
|
||||
radius: 50,
|
||||
name: "old",
|
||||
device: user.device,
|
||||
openfarm_slug: "cabbage",
|
||||
pointer_type: "Plant",
|
||||
pointer_id: 0,
|
||||
discarded_at: Time.now)
|
||||
|
||||
Plant.create!(x: 5,
|
||||
y: 5,
|
||||
z: 5,
|
||||
radius: 50,
|
||||
name: "new",
|
||||
device: user.device,
|
||||
openfarm_slug: "cabbage",
|
||||
pointer_type: "Plant",
|
||||
pointer_id: 0,
|
||||
discarded_at: nil)
|
||||
SmarfDoc.note("If you want to see previously deleted points alongside" \
|
||||
" your active points, add `?filter=all` to the end of " \
|
||||
"the URL.")
|
||||
sign_in user
|
||||
get :index, params: { filter: "all"}
|
||||
expect(response.status).to eq(200)
|
||||
expect(json.length).to eq(2)
|
||||
expect(json.pluck(:name)).to include("old")
|
||||
expect(json.pluck(:name)).to include("new")
|
||||
end
|
||||
|
||||
it 'lists non-discarded (active) points' do
|
||||
sign_in user
|
||||
FactoryBot.create_list(:generic_pointer, 3, device: device)
|
||||
get :index
|
||||
|
|
|
@ -2,9 +2,9 @@ require 'spec_helper'
|
|||
require_relative "scenario"
|
||||
|
||||
describe Points::Destroy do
|
||||
let(:device) { FactoryBot.create(:device) }
|
||||
|
||||
it "prevents deletion of points that are in use" do
|
||||
# Create device
|
||||
device = FactoryBot.create(:device)
|
||||
# create many points
|
||||
points = FactoryBot.create_list(:generic_pointer, 3, device: device)
|
||||
# use one point in a sequence.
|
||||
|
@ -53,7 +53,6 @@ describe Points::Destroy do
|
|||
end
|
||||
|
||||
it "handles multiple sequence dep tracking issues at deletion time" do
|
||||
device = FactoryBot.create(:device)
|
||||
point = FactoryBot.create(:generic_pointer, device: device, x: 4, y: 5, z: 6)
|
||||
plant = FactoryBot.create(:plant, device: device, x: 0, y: 1, z: 0)
|
||||
empty_point = { kind: "coordinate", args: { x: 0, y: 0, z: 0 } }
|
||||
|
@ -98,4 +97,10 @@ describe Points::Destroy do
|
|||
.to eq("The sequence 'Sequence A' is still using the following points:"\
|
||||
" plant at (0.0, 1.0, 0.0)")
|
||||
end
|
||||
it "performs a hard (real) delete" do
|
||||
points = FactoryBot.create_list(:generic_pointer, 3, device: device)
|
||||
ids = points.pluck(:id)
|
||||
Points::Destroy.run!(point_ids: ids, device: device, hard_delete: true)
|
||||
expect(Point.where(id: ids).length).to eq(0)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue