Skip to content

Commit

Permalink
Use options hash for to_csv
Browse files Browse the repository at this point in the history
  • Loading branch information
orien committed Feb 9, 2024
1 parent b1defbb commit d79a21d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions app/presenters/user_csv_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ class UserCsvPresenter
## - user_id - defaults to nil, reports on only one user (will set inherited to true)
## - datetime - defaults to now, Timestamp for when the report is kicked off and generated

def self.to_csv(
inherited: false, deleted: false, project_id: nil, user_id: nil, datetime: (Time.now.strftime "%Y%m%d_%H%M")
)
def self.to_csv(options = {})
inherited = options.fetch(:inherited, false)
deleted = options.fetch(:deleted, false)
project_id = options.fetch(:project_id, nil)
user_id = options.fetch(:user_id, nil)
datetime = options.fetch(:datetime, Time.now.strftime("%Y%m%d_%H%M"))

inherited = true if project_id || user_id
users = (deleted || user_id ? User.unscoped : User)
users = users.order(:id)
Expand Down
6 changes: 3 additions & 3 deletions test/presenters/user_csv_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@

def csv_completeness_test(options = {}, expected = {})
meta_rows = 3
UserCsvPresenter.to_csv(options).split("\n").size.must_equal expected + meta_rows
UserCsvPresenter.to_csv(options).split("\n")[-2].split(",")[-1].to_i.must_equal expected
UserCsvPresenter.to_csv(**options).split("\n").size.must_equal expected + meta_rows
UserCsvPresenter.to_csv(**options).split("\n")[-2].split(",")[-1].to_i.must_equal expected
end

# on updating #csv_line this test helper may need to be updated
# This tests the optimized logic against the non-optimized logic.
def csv_accuracy_test(options = {})
actual = CSV.parse(UserCsvPresenter.to_csv(options))
actual = CSV.parse(UserCsvPresenter.to_csv(**options))
actual.shift
actual.pop(2)
actual.each do |csv_row|
Expand Down

0 comments on commit d79a21d

Please sign in to comment.