Commit 2d34dd4c authored by Samir Noir's avatar Samir Noir 🧀
Browse files

Rename media_type helper to api_media_type helper.

From from rails 6.0, there is a new method name media_type in
Action::Dispatch class, so it breaked controllers using our helper.
parent 5f3d4c30
......@@ -29,12 +29,12 @@ class ClustersController < ResourcesController
{
"rel" => "self",
"href" => uri_to(status_site_cluster_path(params[:site_id],params[:id])),
"type" => media_type(:g5kitemjson)
"type" => api_media_type(:g5kitemjson)
},
{
"rel" => "parent",
"href" => uri_to(site_cluster_path(params[:site_id],params[:id])),
"type" => media_type(:g5kitemjson)
"type" => api_media_type(:g5kitemjson)
}
]
}
......@@ -61,7 +61,7 @@ class ClustersController < ResourcesController
links.push({
"rel" => "status",
"type" => media_type(:g5kitemjson),
"type" => api_media_type(:g5kitemjson),
"href" => uri_to(File.join(resource_path(item["uid"]), "status"))
})
links
......
......@@ -198,12 +198,12 @@ class DeploymentsController < ApplicationController
{
"rel" => "self",
"href" => uri_to(resource_path(item['uid'])),
"type" => media_type(:g5kitemjson)
"type" => api_media_type(:g5kitemjson)
},
{
"rel" => "parent",
"href" => uri_to(parent_path),
"type" => media_type(:g5kitemjson)
"type" => api_media_type(:g5kitemjson)
}
]
end
......@@ -213,12 +213,12 @@ class DeploymentsController < ApplicationController
{
"rel" => "self",
"href" => uri_to(collection_path),
"type" => media_type(:g5kcollectionjson)
"type" => api_media_type(:g5kcollectionjson)
},
{
"rel" => "parent",
"href" => uri_to(parent_path),
"type" => media_type(:g5kitemjson)
"type" => api_media_type(:g5kitemjson)
}
]
end
......
......@@ -80,7 +80,7 @@ class JobsController < ApplicationController
:head => {
'X-Remote-Ident' => @credentials[:cn],
'X-Api-User-Cn' => @credentials[:cn],
'Accept' => media_type(:json)
'Accept' => api_media_type(:json)
}
)
......@@ -127,8 +127,8 @@ class JobsController < ApplicationController
:head => {
'X-Remote-Ident' => @credentials[:cn],
'X-Api-User-Cn' => @credentials[:cn],
'Content-Type' => media_type(:json),
'Accept' => media_type(:json)
'Content-Type' => api_media_type(:json),
'Accept' => api_media_type(:json)
} )
continue_if!(http, :is => [201,202])
......@@ -178,12 +178,12 @@ class JobsController < ApplicationController
{
"rel" => "self",
"href" => uri_to(resource_path(item.uid)),
"type" => media_type(:g5kitemjson)
"type" => api_media_type(:g5kitemjson)
},
{
"rel" => "parent",
"href" => uri_to(parent_path),
"type" => media_type(:g5kitemjson)
"type" => api_media_type(:g5kitemjson)
}
]
end
......@@ -193,12 +193,12 @@ class JobsController < ApplicationController
{
"rel" => "self",
"href" => uri_to(collection_path),
"type" => media_type(:g5kcollectionjson)
"type" => api_media_type(:g5kcollectionjson)
},
{
"rel" => "parent",
"href" => uri_to(parent_path),
"type" => media_type(:g5kitemjson)
"type" => api_media_type(:g5kitemjson)
}
]
end
......
......@@ -156,28 +156,28 @@ class ResourcesController < ApplicationController
links.push({
"rel" => subresource.name,
"href" => href,
"type" => media_type(:g5kcollectionjson)
"type" => api_media_type(:g5kcollectionjson)
})
end
links.push({
"rel" => "self",
"type" => media_type(:g5kitemjson),
"type" => api_media_type(:g5kitemjson),
"href" => uri_to(resource_path(item["uid"]))
})
links.push({
"rel" => "parent",
"type" => media_type(:g5kitemjson),
"type" => api_media_type(:g5kitemjson),
"href" => uri_to(parent_path)
})
links.push({
"rel" => "version",
"type" => media_type(:g5kitemjson),
"type" => api_media_type(:g5kitemjson),
"href" => uri_to(File.join(resource_path(item["uid"]), "versions", item["version"]))
})
links.push({
"rel" => "versions",
"type" => media_type(:g5kcollectionjson),
"type" => api_media_type(:g5kcollectionjson),
"href" => uri_to(File.join(resource_path(item["uid"]), "versions"))
})
links
......@@ -188,12 +188,12 @@ class ResourcesController < ApplicationController
links = []
links.push({
"rel" => "self",
"type" => media_type(:g5kcollectionjson),
"type" => api_media_type(:g5kcollectionjson),
"href" => uri_to(collection_path)
})
links.push({
"rel" => "parent",
"type" => media_type(:g5kitemjson),
"type" => api_media_type(:g5kitemjson),
"href" => uri_to(parent_path)
}) unless parent_path.blank?
links
......
......@@ -66,7 +66,7 @@ class RootController < ResourcesController
%w{users notifications}.each do |rel|
links.push({
"rel" => rel,
"type" => media_type(:g5kcollectionjson),
"type" => api_media_type(:g5kcollectionjson),
"href" => uri_to(File.join(resource_path(item["uid"]), rel))
})
end
......
......@@ -39,12 +39,12 @@ class SitesController < ResourcesController
{
"rel" => "self",
"href" => uri_to(status_site_path(params[:id])),
"type" => media_type(:g5kitemjson)
"type" => api_media_type(:g5kitemjson)
},
{
"rel" => "parent",
"href" => uri_to(site_path(params[:id])),
"type" => media_type(:g5kitemjson)
"type" => api_media_type(:g5kitemjson)
}
]
}
......@@ -70,13 +70,13 @@ class SitesController < ResourcesController
%w{jobs deployments vlans metrics}.each do |rel|
links.push({
"rel" => rel,
"type" => media_type(:g5kcollectionjson),
"type" => api_media_type(:g5kcollectionjson),
"href" => uri_to(File.join(resource_path(item["uid"]), rel))
})
end
links.push({
"rel" => "status",
"type" => media_type(:g5kitemjson),
"type" => api_media_type(:g5kitemjson),
"href" => uri_to(File.join(resource_path(item["uid"]), "status"))
})
links
......
......@@ -34,12 +34,12 @@ class VersionsController < ApplicationController
{
"rel" => "self",
"href" => uri_to("#{resource_path}/versions"),
"type" => media_type(:g5kcollectionjson)
"type" => api_media_type(:g5kcollectionjson)
},
{
"rel" => "parent",
"href" => uri_to("#{resource_path.split("/")[0..-2].join("/")}"),
"type" => media_type(:g5kitemjson)
"type" => api_media_type(:g5kitemjson)
}
]
......@@ -92,12 +92,12 @@ class VersionsController < ApplicationController
{
"rel" => "self",
"href" => uri_to("#{resource_path}/versions/#{commit.id}"),
"type" => media_type(:g5kitemjson)
"type" => api_media_type(:g5kitemjson)
},
{
"rel" => "parent",
"href" => uri_to(resource_path),
"type" => media_type(:g5kitemjson)
"type" => api_media_type(:g5kitemjson)
}
]
}
......
......@@ -41,7 +41,7 @@ module ApplicationHelper
)
end
def media_type(type)
def api_media_type(type)
t = Mime::Type.lookup_by_extension(type)
if t
t.to_s
......
......@@ -115,7 +115,7 @@ describe ClustersController do
expected_url = "http://api-out.local:80/sites/nancy/clusters/mbi?branch=master&pretty=yes"
stub_request(:get, expected_url).
with(
:headers => {'Accept' => media_type(:json)}
:headers => {'Accept' => api_media_type(:json)}
).
to_return(:body => fixture("reference-repository/data/grid5000/sites/nancy/clusters/mbi/mbi.json"))
get :show, params: { :branch => 'master', :site_id => "nancy", :id => "mbi", :format => :json }
......@@ -129,7 +129,7 @@ describe ClustersController do
expected_url = "http://api-out.local:80/sites/nancy/clusters/talc?branch=master&pretty=yes"
stub_request(:get, expected_url).
with(
:headers => {'Accept' => media_type(:json)}
:headers => {'Accept' => api_media_type(:json)}
).
to_return(:body => fixture("reference-repository/data/grid5000/sites/nancy/clusters/talc/talc.json"))
get :show, params: { :branch => 'master', :site_id => "nancy", :id => "talc", :format => :json }
......@@ -143,7 +143,7 @@ describe ClustersController do
expected_url = "http://api-out.local:80/sites/nancy/clusters/graphique?branch=master&pretty=yes"
stub_request(:get, expected_url).
with(
:headers => {'Accept' => media_type(:json)}
:headers => {'Accept' => api_media_type(:json)}
).
to_return(:body => fixture("reference-repository/data/grid5000/sites/nancy/clusters/graphique/graphique.json"))
get :show, params: { :branch => 'master', :site_id => "nancy", :id => "graphique", :format => :json }
......@@ -157,7 +157,7 @@ describe ClustersController do
expected_url = "http://api-out.local:80/sites/nancy/clusters/mbi?branch=master&queues=production&pretty=yes"
stub_request(:get, expected_url).
with(
:headers => {'Accept' => media_type(:json)}
:headers => {'Accept' => api_media_type(:json)}
).
to_return(:body => fixture("reference-repository/data/grid5000/sites/nancy/clusters/mbi/mbi.json"))
get :show, params: { :branch => 'master', :site_id => "nancy", :id => "mbi", :queues => "production", :format => :json }
......@@ -172,7 +172,7 @@ describe ClustersController do
expected_url = "http://api-out.local:80/sites/nancy/clusters/talc?branch=master&queues=default&pretty=yes"
stub_request(:get, expected_url).
with(
:headers => {'Accept' => media_type(:json)}
:headers => {'Accept' => api_media_type(:json)}
).
to_return(:body => fixture("reference-repository/data/grid5000/sites/nancy/clusters/talc/talc.json"))
get :show, params: { :branch => 'master', :site_id => "nancy", :id => "talc", :queues => "default", :format => :json }
......@@ -186,7 +186,7 @@ describe ClustersController do
expected_url = "http://api-out.local:80/sites/nancy/clusters/talc?branch=master&queues=production&pretty=yes"
stub_request(:get, expected_url).
with(
:headers => {'Accept' => media_type(:json)}
:headers => {'Accept' => api_media_type(:json)}
).
to_return(:body => fixture("reference-repository/data/grid5000/sites/nancy/clusters/talc/talc.json"))
get :show, params: { :branch => 'master', :site_id => "nancy", :id => "talc", :queues => "production", :format => :json }
......@@ -226,7 +226,7 @@ describe ClustersController do
expected_url = "http://api-out.local:80/sites/nancy/clusters?branch=master&queues=production&pretty=yes"
stub_request(:get, expected_url).
with(
:headers => {'Accept' => media_type(:json)}
:headers => {'Accept' => api_media_type(:json)}
).
to_return(:body => fixture("reference-repository/data/grid5000/sites/nancy/clusters/mbi/mbi.json"))
get :index, params: { :branch => 'master', :site_id => "nancy", :queues => "production", :format => :json }
......@@ -243,7 +243,7 @@ describe ClustersController do
expected_url = "http://api-out.local:80/sites/nancy/clusters?branch=master&queues=default&pretty=yes"
stub_request(:get, expected_url).
with(
:headers => {'Accept' => media_type(:json)}
:headers => {'Accept' => api_media_type(:json)}
).
to_return(:body => fixture("reference-repository/data/grid5000/sites/nancy/clusters/talc/talc.json"))
get :index, params: { :branch => 'master', :site_id => "nancy", :queues => "default", :format => :json }
......
......@@ -42,24 +42,24 @@ describe DeploymentsController do
{
"rel"=> "self",
"href"=> "/sites/rennes/deployments/uid9",
"type"=> media_type(:g5kitemjson)
"type"=> api_media_type(:g5kitemjson)
},
{
"rel"=> "parent",
"href"=> "/sites/rennes",
"type"=> media_type(:g5kitemjson)
"type"=> api_media_type(:g5kitemjson)
}
])
expect(json['links']).to eq([
{
"rel"=>"self",
"href"=>"/sites/rennes/deployments",
"type"=>media_type(:g5kcollectionjson)
"type"=> api_media_type(:g5kcollectionjson)
},
{
"rel"=>"parent",
"href"=>"/sites/rennes",
"type"=>media_type(:g5kitemjson)
"type"=> api_media_type(:g5kitemjson)
}
])
end
......
......@@ -33,24 +33,24 @@ describe JobsController do
{
"rel"=> "self",
"href"=> "/sites/rennes/jobs/374210",
"type"=> media_type(:g5kitemjson)
"type"=> api_media_type(:g5kitemjson)
},
{
"rel"=> "parent",
"href"=> "/sites/rennes",
"type"=> media_type(:g5kitemjson)
"type"=> api_media_type(:g5kitemjson)
}
])
expect(json['links']).to eq ([
{
"rel"=>"self",
"href"=>"/sites/rennes/jobs",
"type"=>media_type(:g5kcollectionjson)
"type"=> api_media_type(:g5kcollectionjson)
},
{
"rel"=>"parent",
"href"=>"/sites/rennes",
"type"=>media_type(:g5kitemjson)
"type"=> api_media_type(:g5kitemjson)
}
])
end
......@@ -120,8 +120,8 @@ describe JobsController do
stub_request(:post, expected_url).
with(
:headers => {
'Accept' => media_type(:json),
'Content-Type' => media_type(:json),
'Accept' => api_media_type(:json),
'Content-Type' => api_media_type(:json),
'X-Remote-Ident' => "crohr",
'X-Api-User-Cn' => "crohr"
},
......@@ -145,8 +145,8 @@ describe JobsController do
stub_request(:post, expected_url).
with(
:headers => {
'Accept' => media_type(:json),
'Content-Type' => media_type(:json),
'Accept' => api_media_type(:json),
'Content-Type' => api_media_type(:json),
'X-Remote-Ident' => "crohr",
'X-Api-User-Cn' => "crohr"
},
......@@ -171,8 +171,8 @@ describe JobsController do
stub_request(:post, expected_url).
with(
:headers => {
'Accept' => media_type(:json),
'Content-Type' => media_type(:json),
'Accept' => api_media_type(:json),
'Content-Type' => api_media_type(:json),
'X-Remote-Ident' => "xyz",
'X-Api-User-Cn' => "xyz"
},
......@@ -196,8 +196,8 @@ describe JobsController do
stub_request(:post, expected_url).
with(
:headers => {
'Accept' => media_type(:json),
'Content-Type' => media_type(:json),
'Accept' => api_media_type(:json),
'Content-Type' => api_media_type(:json),
'X-Remote-Ident' => "crohr",
'X-Api-User-Cn' => "crohr"
},
......@@ -227,7 +227,7 @@ describe JobsController do
@job = OAR::Job.first
@expected_url = "http://api-out.local/sites/rennes/internal/oarapi/jobs/#{@job.uid}.json"
@expected_headers = {
'Accept' => media_type(:json),
'Accept' => api_media_type(:json),
'X-Remote-Ident' => @job.user,
'X-Api-User-Cn' => @job.user
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment