Skip to content

Commit

Permalink
Support version 1.0.0 of Hashdiff
Browse files Browse the repository at this point in the history
In version 1.0.0, the `hashdiff` gem changed its module name from
`HashDiff` to `Hashdiff` to prevent name collision with the `hash_diff`
gem (more information:
liufengyun/hashdiff#45).

The API did not change.

This commit updates fixture_builder to allow using the new version of
hashdiff, while maintaining support for the old versions.

It also adds a test for the code path that calls Hashdiff.
  • Loading branch information
gabebw committed Aug 9, 2019
1 parent 0d54e60 commit 0927a8b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/fixture_builder/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
require 'hashdiff'

module FixtureBuilder
if Object.const_defined?(:Hashdiff)
# hashdiff version >= 1.0.0
Differ = Hashdiff
else
Differ = HashDiff
end

class Configuration
include Delegations::Namer

Expand Down Expand Up @@ -135,7 +142,7 @@ def rebuild_fixtures?
return true
elsif file_hashes_from_disk != file_hashes_from_config
puts '=> rebuilding fixtures because one or more of the following files have changed (see http://www.rubydoc.info/gems/hashdiff for diff syntax):'
HashDiff.diff(file_hashes_from_disk, file_hashes_from_config).map {|diff| print ' '; p diff}
Differ.diff(file_hashes_from_disk, file_hashes_from_config).map {|diff| print ' '; p diff}
return true
end
false
Expand Down
16 changes: 15 additions & 1 deletion test/fixture_builder_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))


class Model
def self.table_name
'models'
Expand Down Expand Up @@ -83,4 +82,19 @@ def test_absolute_rails_fixtures_path
def test_fixtures_dir
assert_match /test\/fixtures$/, FixtureBuilder.configuration.send(:fixtures_dir).to_s
end

def test_rebuilding_due_to_differing_file_hashes
create_and_blow_away_old_db
force_fixture_generation_due_to_differing_file_hashes

FixtureBuilder.configure do |fbuilder|
fbuilder.files_to_check += Dir[test_path("*.rb")]
fbuilder.factory do
@enty = MagicalCreature.create(:name => 'Enty', :species => 'ent',
:powers => %w{shading rooting seeding})
end
end
generated_fixture = YAML.load(File.open(test_path("fixtures/magical_creatures.yml")))
assert_equal "---\n- shading\n- rooting\n- seeding\n", generated_fixture['enty']['powers']
end
end
8 changes: 8 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,11 @@ def force_fixture_generation
rescue
end
end

def force_fixture_generation_due_to_differing_file_hashes
begin
path = File.expand_path("../../tmp/fixture_builder.yml", __FILE__)
File.write(path, "blah blah blah")
rescue
end
end

0 comments on commit 0927a8b

Please sign in to comment.