Skip to content

Commit

Permalink
Fix MIME type for JavaScript in test (#2295)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaymaeBZ authored Oct 7, 2024
1 parent fc41610 commit eaccd57
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions padrino-core/test/test_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
assert ok?
assert_equal 'application/xml;charset=utf-8', response.headers['Content-Type']

get '/foo', {}, { 'HTTP_ACCEPT' => 'application/javascript' }
get '/foo', {}, { 'HTTP_ACCEPT' => 'text/javascript' }
assert ok?
assert_equal 'application/javascript', body
assert_equal 'application/javascript;charset=utf-8', response.headers['Content-Type']
assert_equal 'text/javascript', body
assert_equal 'text/javascript;charset=utf-8', response.headers['Content-Type']

get '/foo.js'
assert ok?
assert_equal 'application/javascript;charset=utf-8', response.headers['Content-Type']
assert_equal 'text/javascript;charset=utf-8', response.headers['Content-Type']

get '/foo', {}, { "HTTP_ACCEPT" => 'text/html' }
assert_equal 406, status
Expand Down
26 changes: 13 additions & 13 deletions padrino-core/test/test_routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ class Test < Padrino::Application
get("/foo", :provides => [:html, :js, :xml]) { content_type.to_s }
end

get '/foo', {}, { 'HTTP_ACCEPT' => 'application/javascript, */*;q=0.5' }
get '/foo', {}, { 'HTTP_ACCEPT' => 'text/javascript, */*;q=0.5' }
assert_equal 'js', body
end

Expand All @@ -556,7 +556,7 @@ class Test < Padrino::Application
end

get "/a", {}, {}
assert_equal "application/javascript;charset=utf-8", content_type
assert_equal "text/javascript;charset=utf-8", content_type
end

it 'should not match routes if url_format and http_accept is provided but not included' do
Expand Down Expand Up @@ -794,7 +794,7 @@ class Test < Padrino::Application
end
get "/a.js"
assert_equal "js", body
assert_equal 'application/javascript;charset=utf-8', response["Content-Type"]
assert_equal 'text/javascript;charset=utf-8', response["Content-Type"]
get "/a.json"
assert_equal "json", body
assert_equal 'application/json', response["Content-Type"]
Expand Down Expand Up @@ -1324,9 +1324,9 @@ class Test < Padrino::Application
end
end

get '/foo', {}, { 'CONTENT_TYPE' => 'application/javascript' }
get '/foo', {}, { 'CONTENT_TYPE' => 'text/javascript' }
assert ok?
assert_equal 'application/javascript', body
assert_equal 'text/javascript', body
end

it 'should filters by accept header' do
Expand All @@ -1345,14 +1345,14 @@ class Test < Padrino::Application
assert ok?
assert_equal 'application/xml;charset=utf-8', response.headers['Content-Type']

get '/foo', {}, { 'HTTP_ACCEPT' => 'application/javascript' }
get '/foo', {}, { 'HTTP_ACCEPT' => 'text/javascript' }
assert ok?
assert_equal 'application/javascript', body
assert_equal 'application/javascript;charset=utf-8', response.headers['Content-Type']
assert_equal 'text/javascript', body
assert_equal 'text/javascript;charset=utf-8', response.headers['Content-Type']

get '/foo.js'
assert ok?
assert_equal 'application/javascript;charset=utf-8', response.headers['Content-Type']
assert_equal 'text/javascript;charset=utf-8', response.headers['Content-Type']

get '/foo', {}, { "HTTP_ACCEPT" => 'text/html' }
assert_equal 406, status
Expand Down Expand Up @@ -1433,11 +1433,11 @@ class Test < Padrino::Application
assert_equal 'html', body
end

it 'should set content_type to :js if Accept includes both application/javascript and */*;q=0.5' do
it 'should set content_type to :js if Accept includes both text/javascript and */*;q=0.5' do
mock_app do
get("/foo", :provides => [:html, :js]) { content_type.to_s }
end
get '/foo', {}, { 'HTTP_ACCEPT' => 'application/javascript, */*;q=0.5' }
get '/foo', {}, { 'HTTP_ACCEPT' => 'text/javascript, */*;q=0.5' }
assert_equal 'js', body
end

Expand All @@ -1450,12 +1450,12 @@ class Test < Padrino::Application
assert_equal 'html', body
end

it 'should set content_type to :js if Accept includes both application/javascript, */*;q=0.5 and provides of :any' do
it 'should set content_type to :js if Accept includes both text/javascript, */*;q=0.5 and provides of :any' do
mock_app do
get("/foo", :provides => :any) { content_type.to_s }
end

get '/foo', {}, { 'HTTP_ACCEPT' => 'application/javascript, */*;q=0.5' }
get '/foo', {}, { 'HTTP_ACCEPT' => 'text/javascript, */*;q=0.5' }
assert_equal 'js', body
end

Expand Down

0 comments on commit eaccd57

Please sign in to comment.