Skip to content

Commit

Permalink
Merge pull request #607 from rails/schneems/stable-ish-sort
Browse files Browse the repository at this point in the history
[close #573] Stable sort to get windows CI green
  • Loading branch information
schneems committed May 20, 2019
2 parents 179bed1 + f0207d7 commit 0aa0224
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
8 changes: 5 additions & 3 deletions lib/sprockets/http_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,16 @@ def find_q_matches(q_values, available, &matcher)
raise TypeError, "unknown q_values type: #{q_values.class}"
end

i = 0
q_values.each do |accepted, quality|
if match = available.find { |option| matcher.call(option, accepted) }
matches << [match, quality]
i += 1
matches << [-quality, i, match]
end
end

matches.sort_by! { |match, quality| -quality }
matches.map! { |match, quality| match }
matches.sort!
matches.map! { |_, _, match| match }
matches
end

Expand Down
1 change: 1 addition & 0 deletions sprockets.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Gem::Specification.new do |s|
unless RUBY_PLATFORM.include?('java')
s.add_development_dependency "jsminc", "~> 1.1"
end
s.add_development_dependency "timecop", "~> 0.9.1"
s.add_development_dependency "minitest", "~> 5.0"
s.add_development_dependency "nokogiri", "~> 1.3"
s.add_development_dependency "rack-test", "~> 0.6"
Expand Down
1 change: 1 addition & 0 deletions test/sprockets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "sprockets"
require "sprockets/environment"
require "fileutils"
require "timecop"

old_verbose, $VERBOSE = $VERBOSE, false
Encoding.default_external = 'UTF-8'
Expand Down
11 changes: 8 additions & 3 deletions test/test_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,24 +422,27 @@ def teardown
manifest.compile('application.js')
assert File.exist?("#{@dir}/#{digest_path}")

Timecop.travel(Time.now + 1)
File.open(filename, 'w') { |f| f.write "a;" }
mtime = Time.now + 1
mtime = Time.now
File.utime(mtime, mtime, filename)
new_digest_path1 = @env['application.js'].digest_path

manifest.compile('application.js')
assert File.exist?("#{@dir}/#{new_digest_path1}")

Timecop.travel(Time.now + 1)
File.open(filename, 'w') { |f| f.write "b;" }
mtime = Time.now + 2
mtime = Time.now
File.utime(mtime, mtime, filename)
new_digest_path2 = @env['application.js'].digest_path

manifest.compile('application.js')
assert File.exist?("#{@dir}/#{new_digest_path2}")

Timecop.travel(Time.now + 1)
File.open(filename, 'w') { |f| f.write "c;" }
mtime = Time.now + 3
mtime = Time.now
File.utime(mtime, mtime, filename)
new_digest_path3 = @env['application.js'].digest_path

Expand All @@ -460,6 +463,8 @@ def teardown
assert data['files'][new_digest_path3]
assert_equal new_digest_path3, data['assets']['application.js']
end
ensure
Timecop.return
end

test "test manifest does not exist" do
Expand Down

0 comments on commit 0aa0224

Please sign in to comment.