Browse Source

Delete not started logs (#1656)

pull/1666/head
Jack 2 years ago committed by GitHub
parent
commit
f4982f9d93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/policies/lettings_log_policy.rb
  2. 3
      app/policies/sales_log_policy.rb
  3. 16
      spec/policies/lettings_log_policy_spec.rb
  4. 12
      spec/policies/sales_log_policy_spec.rb

3
app/policies/lettings_log_policy.rb

@ -12,9 +12,6 @@ class LettingsLogPolicy
# Can only delete editable logs # Can only delete editable logs
return false unless log.collection_period_open? return false unless log.collection_period_open?
# Only delete logs with answered questions
return false unless log.in_progress? || log.completed?
# Support users can delete any log # Support users can delete any log
return true if user.support? return true if user.support?

3
app/policies/sales_log_policy.rb

@ -12,9 +12,6 @@ class SalesLogPolicy
# Can only delete editable logs # Can only delete editable logs
return false unless log.collection_period_open? return false unless log.collection_period_open?
# Only delete logs with answered questions
return false unless log.in_progress? || log.completed?
# Support users can delete any log # Support users can delete any log
return true if user.support? return true if user.support?

16
spec/policies/lettings_log_policy_spec.rb

@ -44,16 +44,8 @@ RSpec.describe LettingsLogPolicy do
end end
context "when not started" do context "when not started" do
before do it "allows deletion of log" do
allow(log).to receive(:in_progress?).and_return(false) expect(policy).to permit(build(:user, :support), create(:lettings_log))
allow(log).to receive(:completed?).and_return(false)
end
it "does not allow deletion of log" do
expect(log).to receive(:in_progress?)
expect(log).to receive(:collection_period_open?)
expect(policy).not_to permit(build(:user, :support), log)
end end
end end
@ -83,9 +75,7 @@ RSpec.describe LettingsLogPolicy do
context "when user is support" do context "when user is support" do
let(:user) { create(:user, :support) } let(:user) { create(:user, :support) }
it "does allow deletion of log" do it "allows deletion of log" do
expect(log).to receive(:collection_period_open?)
expect(policy).to permit(user, log) expect(policy).to permit(user, log)
end end
end end

12
spec/policies/sales_log_policy_spec.rb

@ -44,16 +44,8 @@ RSpec.describe SalesLogPolicy do
end end
context "when not started" do context "when not started" do
before do it "allows deletion of log" do
allow(log).to receive(:in_progress?).and_return(false) expect(policy).to permit(build(:user, :support), create(:sales_log))
allow(log).to receive(:completed?).and_return(false)
end
it "does not allow deletion of log" do
expect(log).to receive(:in_progress?)
expect(log).to receive(:collection_period_open?)
expect(policy).not_to permit(build(:user, :support), log)
end end
end end

Loading…
Cancel
Save