Skip to content

Commit a55c04d

Browse files
authored
Manual entry of a hiring fee collected out of band (joemasilotti#636)
* Manual entry of a hiring fee collected out of band * Standardize * Add test for manual entry
1 parent a2db67d commit a55c04d

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

app/models/open_startup/reporting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def create_or_update_transaction(t)
4444
def normalize_revenue
4545
log "Normalizing revenue..."
4646
Revenue.transaction do
47-
Revenue.delete_all
47+
Revenue.automated.delete_all
4848

4949
monthly_charges = StripeTransaction.charge
5050
.group_by_month(:created).group(:description)

app/models/open_startup/revenue.rb

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module OpenStartup
22
class Revenue < ApplicationRecord
33
self.table_name = "open_startup_revenue"
44

5+
scope :automated, -> { where(manual: false) }
6+
57
validates :occurred_on, presence: true
68
validates :description, presence: true
79
validates :amount, numericality: {greater_than_or_equal_to: 0}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddManualFlagToOpenStartupRevenues < ActiveRecord::Migration[7.0]
2+
def change
3+
add_column :open_startup_revenue, :manual, :boolean, null: false, default: false
4+
end
5+
end

db/schema.rb

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/models/open_startup/reporting_test.rb

+16-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
class OpenStartup::ReportingTest < ActiveSupport::TestCase
44
include StripeHelper
55

6-
test "refreshes Revenue records (grouped by month and description)" do
6+
test "refreshes Revenue records (grouped by month and description and keeping manual entries)" do
7+
create_existing_revenue_record(manual: false, amount: 500)
8+
create_existing_revenue_record(manual: true, amount: 1000)
9+
710
@balance_transactions = [
811
charge(amount: 1000, created: january, description: "New subscription"),
912
charge(amount: 2000, created: january, description: "New subscription"),
@@ -15,10 +18,12 @@ class OpenStartup::ReportingTest < ActiveSupport::TestCase
1518
refresh_metrics
1619

1720
revenue = OpenStartup::Revenue.pluck(:occurred_on, :description, :amount)
18-
assert_equal 4, revenue.count
21+
assert_equal 5, revenue.count
1922
assert_includes revenue, [Date.new(2022, 1, 1), "New subscriptions", 30]
2023
assert_includes revenue, [Date.new(2022, 2, 1), "New subscriptions", 40]
2124
assert_includes revenue, [Date.new(2022, 2, 1), "Hiring fees", 99]
25+
refute_includes revenue, [Date.new(2022, 2, 1), "Hiring fees", 500]
26+
assert_includes revenue, [Date.new(2022, 2, 1), "Hiring fees", 1000]
2227
assert_includes revenue, [Date.new(2022, 2, 1), "Update subscriptions", 50]
2328
end
2429

@@ -106,6 +111,15 @@ def refresh_metrics
106111
end
107112
end
108113

114+
def create_existing_revenue_record(manual:, amount:)
115+
OpenStartup::Revenue.create!(
116+
occurred_on: today,
117+
amount:,
118+
description: "Hiring fees",
119+
manual:
120+
)
121+
end
122+
109123
def balance_transactions
110124
@balance_transactions || []
111125
end

0 commit comments

Comments
 (0)