Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1567, #1554, bug fix when approve invoice using batch action #1568

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app/admin/billing/invoices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ def scoped_collection
end

batch_action :approve, confirm: 'Are you sure?', if: proc { authorized?(:approve) } do |selection|
active_admin_config.resource_class.find(selection).each(&:approve)
redirect_to collection_path, notice: "#{active_admin_config.resource_label.pluralize} are approved!"
active_admin_config.resource_class.find(selection).each do |record|
BillingInvoice::Approve.call(invoice: record)
flash[:notice] = "#{active_admin_config.resource_label.pluralize} are approved!"
rescue BillingInvoice::Approve::Error => e
flash[:error] = "##{record.id}, #{e.message}"
break
end

redirect_to collection_path
end

member_action :approve, method: :post do
Expand Down
29 changes: 23 additions & 6 deletions spec/features/billing/invoices/approve_invoice_feature_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true

RSpec.describe 'Approve invoide feature', type: :feature do
subject { click_action_item 'Approve' }

RSpec.describe 'Approve invoice feature', type: :feature do
include_context :login_as_admin

let(:approved_state_id) { Billing::InvoiceState::APPROVED }
let!(:invoice) { FactoryBot.create(:invoice, :manual, :pending, :with_vendor_account) }

context 'when valid data' do
let!(:invoice) { FactoryBot.create(:invoice, :manual, :pending, :with_vendor_account) }
let(:approved_state_id) { Billing::InvoiceState::APPROVED }
subject { click_action_item 'Approve' }

before { visit invoice_path(invoice) }

Expand All @@ -19,8 +19,25 @@
end
end

context 'when approve from batch action' do
subject { click_button :OK }

before do
visit invoices_path
check class: 'toggle_all'
click_batch_action 'Approve Selected'
end

it 'should approve invoice', :js do
subject

expect(page).to have_flash_message 'Invoices are approved!', type: :notice
expect(invoice.reload).to have_attributes(state_id: approved_state_id)
end
end

context 'when invalid data', :js do
let!(:invoice) { FactoryBot.create(:invoice, :pending, :with_vendor_account) }
subject { click_action_item 'Approve' }

before do
allow(BillingInvoice::Approve).to receive(:call).and_raise(BillingInvoice::Approve::Error, 'error')
Expand Down
Loading