From 04411abe6872e48829366ac7a21ac7fb86f412d3 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Fri, 23 Jan 2009 15:34:33 -0800 Subject: [PATCH] Added a conversation test for the Billing plugin. #1922 --- lib/rate_conversion.rb | 2 ++ lib/tasks/data.rake | 75 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/lib/rate_conversion.rb b/lib/rate_conversion.rb index 24ff003..83f9274 100644 --- a/lib/rate_conversion.rb +++ b/lib/rate_conversion.rb @@ -1,6 +1,8 @@ class RateConversion MemberRateDataFile = "#{RAILS_ROOT}/tmp/budget_member_rate_data.yml" DeliverableDataFile = "#{RAILS_ROOT}/tmp/budget_deliverable_data.yml" + VendorInvoiceDataFile = "#{RAILS_ROOT}/tmp/billing_vendor_invoice_data.yml" + def self.compare_values(pre, post, message) puts "ERROR: #{message} (pre: #{pre}, post: #{post})" unless pre == post diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index 980d310..d62b05f 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -77,8 +77,81 @@ namespace :rate_plugin do if counter > 0 puts "#{counter} errors found." else - puts "No conversation errors found, congrats." + puts "No Budget conversation errors found, congrats." end end end + + namespace :billing do + desc "Export the values of the Billing plugin to a file before installing the rate plugin" + task :pre_install_export => :environment do + + unless Redmine::Plugin.registered_plugins[:redmine_billing].version == "0.0.1" + puts "ERROR: This task is only needed when upgrading from version 0.0.1 to version 0.3.0" + return false + end + + invoices = '' + + FixedVendorInvoice.find(:all).each do |invoice| + invoices << { + :id => invoice.id, + :number => invoice.number, + :amount => invoice.amount, + :project_id => invoice.project_id, + :type => 'FixedVendorInvoice' + }.to_yaml + end + + HourlyVendorInvoice.find(:all).each do |invoice| + invoices << { + :id => invoice.id, + :number => invoice.number, + :amount => invoice.amount_for_user, + :project_id => invoice.project_id, + :type => 'HourlyVendorInvoice' + }.to_yaml + end + + File.open(RateConversion::VendorInvoiceDataFile, 'w') do |file| + file.puts invoices + end + end + + desc "Check the values of the export" + task :post_install_check => :environment do + + unless Redmine::Plugin.registered_plugins[:redmine_billing].version == "0.3.0" + puts "ERROR: Please upgrade the billing_plugin to 0.3.0 now" + return false + end + + counter = 0 + + File.open(RateConversion::VendorInvoiceDataFile) do |file| + YAML::load_documents(file) { |invoice_export| + invoice = VendorInvoice.find_by_id(invoice_export[:id]) + + if invoice.nil? + puts "ERROR: No VendorInvoice found with the ID of #{invoice_export[:id]}" + counter += 1 + else + if invoice.type.to_s == "FixedVendorInvoice" + counter += 1 unless RateConversion.compare_values(invoice_export[:amount], invoice.amount, "VendorInvoice #{invoice.id}'s amount is off") + else + counter += 1 unless RateConversion.compare_values(invoice_export[:amount], invoice.amount_for_user, "VendorInvoice #{invoice.id}'s amount is off") + end + + end + } + end + + if counter > 0 + puts "#{counter} errors found." + else + puts "No Billing conversation errors found, congrats." + end + end + end + end