Skip to content

Commit

Permalink
Rename InProgressFormsPolicy, fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
pixiitech committed Dec 23, 2024
1 parent 17cac73 commit b5c2697
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ module V0
class InProgressFormsController < ApplicationController
def update
@form = find_form || build_form
authorize @form
authorize(@form, :update?, policy_class: AccreditedRepresentativePortal::InProgressFormPolicy)

@form.update!(
form_data: params[:form_data],
metadata: params[:metadata]
)

render json: InProgressFormSerializer.new(form)
render json: InProgressFormSerializer.new(@form)
end

def show
@form = find_form
authorize @form
authorize(@form, :show?, policy_class: AccreditedRepresentativePortal::InProgressFormPolicy)
render json: @form&.data_and_metadata || {}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def show
private

def in_progress_forms
policy_scope(InProgressForm).map do |form|
policy_scope(
InProgressForm, policy_scope_class: AccreditedRepresentativePortal::InProgressFormPolicy::Scope
).map do |form|
{
form: form.form_id,
metadata: form.metadata,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module AccreditedRepresentativePortal
class InProgressFormsPolicy < ApplicationPolicy
class InProgressFormPolicy < ApplicationPolicy
def update?
authorize
end
Expand Down Expand Up @@ -30,7 +30,7 @@ def resolve
private

def authorize
return false unless @current_user
return false unless user

true
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
AccreditedRepresentativePortal::Engine.routes.draw do
get 'arbitrary', to: 'arbitrary#arbitrary'
end
allow_any_instance_of(AccreditedRepresentativePortal::ApplicationController).to receive(:verify_pundit_authorization)
end

after do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
let(:representative_user) { create(:representative_user) }

before do
# TODO: Remove next line when Pundit authorization is added
allow_any_instance_of(::AccreditedRepresentativePortal::V0::Form21aController).to receive(:verify_pundit_authorization)
Flipper.enable(:accredited_representative_portal_pilot)
login_as(representative_user)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
let(:representative_user) { create(:representative_user) }
let(:form_id) { '21a' }
let(:headers) { { 'Content-Type' => 'application/json' } }
let!(:in_progress_form) { create(:in_progress_form) }

before do
Flipper.enable(:accredited_representative_portal_pilot)
Expand Down

0 comments on commit b5c2697

Please sign in to comment.