Skip to content

Commit

Permalink
Add some tests for track_blank_changes option
Browse files Browse the repository at this point in the history
This is mostly a "get my feet wet" commit, but it adds some tests for the
track_blank_changes option being present and having the right default. As I
haven't added track_blank_changes as an option yet, these tests fail as
expected.

I did a rake with out-of-the-box code and saved the results in
testresults/0-baseline.txt, after running them through this script:

  #!/usr/bin/env ruby

  until (line = gets).nil?
    line.gsub!(/_id: [[:xdigit:]]{24}/, '_id: <id>/')
    line.gsub!(/BSON::ObjectId\('[[:xdigit:]]{24}'\)/, '<id>')

    line.gsub!(/[\d.]+/, 'n') if line.start_with?('Finished in ')

    puts line
  end

to get rid of _ids and the total run time, both of which change every run. I
then ran rake after the changes in this commit and saved the output to
testresults/1-track_blank_changes-default-tests.txt. I won't include the
entire 197 line diff here, but the important part is:

  $ diff -u testresults/0-baseline.txt testresults/1-track_blank_changes-default-tests.txt | head
  --- testresults/0-baseline.txt	2024-08-05 11:17:55.000000000 -0700
  +++ testresults/1-track_blank_changes-default-tests.txt	2024-08-05 11:21:01.000000000 -0700
  [...]
  -432 examples, 0 failures, 2 pending
  +432 examples, 6 failures, 2 pending
  [...]

Those 6 failures are all to be expected given that the
track_blank_changes_option doesn't exist yet. There were no rubocop
complaints.
  • Loading branch information
BrianLMatthews committed Aug 5, 2024
1 parent f01173b commit 52cc180
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spec/unit/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class EmbFour
track_create: true,
track_update: true,
track_destroy: true,
track_blank_changes: false,
format: nil
}
end
Expand Down Expand Up @@ -173,6 +174,7 @@ class EmbFour
track_create: true,
track_update: true,
track_destroy: true,
track_blank_changes: false,
fields: %w[foo b],
dynamic: [],
relations: { embeds_one: {}, embeds_many: {} },
Expand Down
1 change: 1 addition & 0 deletions spec/unit/trackable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class MyModelWithNoModifier
track_create: true,
track_update: true,
track_destroy: true,
track_blank_changes: false,
fields: %w[foo],
relations: { embeds_one: {}, embeds_many: {} },
dynamic: [],
Expand Down

0 comments on commit 52cc180

Please sign in to comment.