Files
openfoodnetwork/spec/lib/tasks/enterprises_rake_spec.rb
Maikel Linke f532c4712e Load rake tasks only once for code coverage
Apparently, Rake's way of reloading the task code confuses the code
coverage report. Code tested by rake task specs was not recognised as
covered even though it was.
2025-08-05 12:44:13 +10:00

42 lines
1.2 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'enterprises.rake' do
include_context "rake"
describe ':remove_enterprise' do
context 'when the enterprises exists' do
it 'removes the enterprise' do
enterprise = create(:enterprise)
expect {
invoke_task "ofn:remove_enterprise[#{enterprise.id}]"
}.to change { Enterprise.count }.by(-1)
end
end
end
describe ':enterprises' do
describe ':activate_connected_app_type' do
it 'updates only disconnected enterprises' do
# enterprise with affiliate sales data
enterprise_asd = create(:enterprise)
enterprise_asd.connected_apps.create type: 'ConnectedApps::AffiliateSalesData'
# enterprise with different type
enterprise_diff = create(:enterprise)
enterprise_diff.connected_apps.create
expect {
invoke_task(
"ofn:enterprises:activate_connected_app_type[affiliate_sales_data]"
)
}.to change { ConnectedApps::AffiliateSalesData.count }.by(1)
expect(enterprise_asd.connected_apps.affiliate_sales_data.count).to eq 1
expect(enterprise_diff.connected_apps.affiliate_sales_data.count).to eq 1
end
end
end
end