Skip to content

Commit

Permalink
frozen options bug (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpep authored Mar 9, 2024
1 parent 77a9ac5 commit 6b640ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/smarter_csv/options_processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ class << self
def process_options(given_options = {})
puts "User provided options:\n#{pp(given_options)}\n" if given_options[:verbose]

@options = DEFAULT_OPTIONS.dup.merge!(given_options)

# fix invalid input
given_options[:invalid_byte_sequence] = '' if given_options[:invalid_byte_sequence].nil?
@options[:invalid_byte_sequence] ||= ''

@options = DEFAULT_OPTIONS.dup.merge!(given_options)
puts "Computed options:\n#{pp(@options)}\n" if given_options[:verbose]
puts "Computed options:\n#{pp(@options)}\n" if @options[:verbose]

validate_options!(@options)
@options
Expand Down
6 changes: 6 additions & 0 deletions spec/smarter_csv/options_processing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
generated_options = SmarterCSV.process_options(invalid_byte_sequence: nil)
expect(generated_options[:invalid_byte_sequence]).to eq ''
end

it 'works with frozen options hash' do
options = {chunk_size: 1}.freeze
generated_options = SmarterCSV.process_options(options)
expect(generated_options[:chunk_size]).to eq 1
end
end

describe '#validate_options!' do
Expand Down

0 comments on commit 6b640ac

Please sign in to comment.