Skip to content

Add build_csv_enumerator to the EnumeratorBuilder#183

Merged
basicBrogrammer merged 3 commits into
mainfrom
jw/add-build-csv-to-enumerator-builder
Feb 10, 2022
Merged

Add build_csv_enumerator to the EnumeratorBuilder#183
basicBrogrammer merged 3 commits into
mainfrom
jw/add-build-csv-to-enumerator-builder

Conversation

@basicBrogrammer

@basicBrogrammer basicBrogrammer commented Feb 8, 2022

Copy link
Copy Markdown
Contributor

The Billing team is working towards adding the job-iteration gem and removing the legacy BackgroundQueue::Iteration. To achieve feature parity, we can add build_csv_enumerator to the EnumeratorBuilder. The build_throttle_enumerator and others gives us precedence to add this method as well.

@basicBrogrammer basicBrogrammer force-pushed the jw/add-build-csv-to-enumerator-builder branch from 2965ecd to c02247d Compare February 8, 2022 16:32
@basicBrogrammer basicBrogrammer force-pushed the jw/add-build-csv-to-enumerator-builder branch from c02247d to f594bb3 Compare February 8, 2022 16:35
Comment thread test/unit/enumerator_builder_test.rb Outdated

test_builder_method(:build_csv_enumerator) do
enum = enumerator_builder(wraps: 0).build_csv_enumerator(CSV.new("test"), cursor: nil)
assert_instance_of(Enumerator::Lazy, enum)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this assertion really belong here, with the way this test file is set up?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to validate that JobIteration::CsvEnumerator is being used was being used. Do you think I should add it as a separate test?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably. This test_builder_method method should return the enumerator itself, as it generates a test through meta-programming. If you want to test something in addition, adding a separate test seems better.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EnumeratorBuilder methods are straightforward enough that you may not need a specific assertion. I'm not sure what this one really brings us for example, a Lazy Enumerator could be anything really. In any case if you really care about asserting this, another test would be preferable, those are really about the wrapping feature.

test_builder_method method should return the enumerator itself

Technically since it sets up a mocha expectation that is just expected to be triggered during the block, we don't really care about the return value, it does check that this enumerator isn't wrapped.

@rporrasluc rporrasluc left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once @Mangara's comment is addressed this looks great!

Comment on lines +65 to +79
test "#build_csv_enumerator uses the CsvEnumerator class" do
csv = CSV.new('test')
expected_cursor = 42
enumerator = JobIteration::CsvEnumerator.new(csv)
builder = EnumeratorBuilder.new(mock, wrapper: mock)

JobIteration::CsvEnumerator.expects(:new).with(csv).returns(enumerator)
enumerator.expects(:rows).with(cursor: expected_cursor)
builder.build_csv_enumerator(csv, cursor: expected_cursor)
end

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mangara & @etiennebarrie How about this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually I don't like those tests as they just duplicate the code in mocks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etiennebarrie How about the new test? It's kind of copy pasta of a csv enum test but if we don't want to use the mock this is the only way I can think of to verify the output of #build_csv_enumerator

@basicBrogrammer basicBrogrammer force-pushed the jw/add-build-csv-to-enumerator-builder branch from bd9a295 to dc76741 Compare February 9, 2022 14:44
Comment thread lib/job-iteration/csv_enumerator.rb Outdated
@basicBrogrammer basicBrogrammer force-pushed the jw/add-build-csv-to-enumerator-builder branch from dc76741 to 83b32b2 Compare February 9, 2022 16:10
@basicBrogrammer basicBrogrammer merged commit 2c79c0c into main Feb 10, 2022
@basicBrogrammer basicBrogrammer deleted the jw/add-build-csv-to-enumerator-builder branch February 10, 2022 13:47
@shopify-shipit shopify-shipit Bot temporarily deployed to rubygems February 10, 2022 13:49 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants