Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate priority from MIME types of same family #132

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/mime/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def <=>(other)
# before unregistered or obsolete content types.
def priority_compare(other)
pc = simplified <=> other.simplified
if pc.zero?
if pc.zero? || !(extensions & other.extensions).empty?
pc = if (reg = registered?) != other.registered?
reg ? -1 : 1 # registered < unregistered
elsif (comp = complete?) != other.complete?
Expand Down
17 changes: 14 additions & 3 deletions test/test_mime_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,21 +330,32 @@ def assert_priority(left, middle, right)
assert_priority text_1, text_1p, text_2
end

it 'sorts (2) based on the registration state' do
it 'sorts (2) based on extensions' do
text_1.extensions = ["foo", "bar"]
text_2.extensions = ["foo"]

assert_priority_same text_1, text_2

text_2.registered = true

assert_priority_more text_1, text_2
end

it 'sorts (3) based on the registration state' do
text_1.registered = text_1p.registered = true
text_1b = mime_type(text_1) { |t| t.registered = false }

assert_priority text_1, text_1p, text_1b
end

it 'sorts (3) based on the completeness' do
it 'sorts (4) based on the completeness' do
text_1.extensions = text_1p.extensions = '1'
text_1b = mime_type(text_1) { |t| t.extensions = nil }

assert_priority text_1, text_1p, text_1b
end

it 'sorts (4) based on obsolete status' do
it 'sorts (5) based on obsolete status' do
text_1.obsolete = text_1p.obsolete = false
text_1b = mime_type(text_1) { |t| t.obsolete = true }

Expand Down