Commit 7428990c0f3fc431a32340ee999b41e7e4806833
1 parent
abdd2edc
Exists in
colab
and in
4 other branches
Better HTTP method semantics for repository state
Showing
4 changed files
with
8 additions
and
7 deletions
Show diff stats
app/assets/javascripts/repository/state.js.coffee
@@ -2,7 +2,7 @@ class Repository.State | @@ -2,7 +2,7 @@ class Repository.State | ||
2 | constructor: (@repository_id) -> | 2 | constructor: (@repository_id) -> |
3 | 3 | ||
4 | poll_state: (last_state) -> | 4 | poll_state: (last_state) -> |
5 | - $.post('/repositories/' + @repository_id + '/state', | 5 | + $.get('/repositories/' + @repository_id + '/state', |
6 | last_state: last_state) | 6 | last_state: last_state) |
7 | 7 | ||
8 | schedule_poll_state: (last_state) -> | 8 | schedule_poll_state: (last_state) -> |
app/views/repositories/show.html.erb
@@ -39,7 +39,7 @@ | @@ -39,7 +39,7 @@ | ||
39 | 39 | ||
40 | <p><strong> <%= t('repository.show.date_processing') %>: </strong></p> | 40 | <p><strong> <%= t('repository.show.date_processing') %>: </strong></p> |
41 | 41 | ||
42 | -<%= form_tag(repository_state_with_date_path(@repository.id), method: "post", remote: true) do %> | 42 | +<%= form_tag(repository_state_with_date_path(@repository.id), method: "get", remote: true) do %> |
43 | <p> | 43 | <p> |
44 | <%= label_tag :day, t("day") %>: | 44 | <%= label_tag :day, t("day") %>: |
45 | <%= select_tag(:day, options_for_select(day_options), :style => "width:55px; margin-top:5px") %> | 45 | <%= select_tag(:day, options_for_select(day_options), :style => "width:55px; margin-top:5px") %> |
config/routes.rb
@@ -9,9 +9,10 @@ Rails.application.routes.draw do | @@ -9,9 +9,10 @@ Rails.application.routes.draw do | ||
9 | 9 | ||
10 | resources :repositories, except: [:update, :index] | 10 | resources :repositories, except: [:update, :index] |
11 | get '/repositories/:id/modules/:module_result_id' => 'repositories#show', as: :repository_module | 11 | get '/repositories/:id/modules/:module_result_id' => 'repositories#show', as: :repository_module |
12 | - post '/repositories/:id/state' => 'repositories#state', as: :repository_state | ||
13 | - post '/repositories/:id/state_with_date' => 'repositories#state_with_date', as: :repository_state_with_date | 12 | + get '/repositories/:id/state' => 'repositories#state', as: :repository_state |
13 | + get '/repositories/:id/state_with_date' => 'repositories#state_with_date', as: :repository_state_with_date | ||
14 | put '/repositories/:id' => 'repositories#update', as: :repository_update | 14 | put '/repositories/:id' => 'repositories#update', as: :repository_update |
15 | + # This route should be a POST to be semantically correct. But, RepositoriesController#create relies on a redirect to it which is not possible with a POST | ||
15 | get '/repositories/:id/process' => 'repositories#process_repository', as: :repository_process | 16 | get '/repositories/:id/process' => 'repositories#process_repository', as: :repository_process |
16 | 17 | ||
17 | get '/repository_branches' => 'repositories#branches', as: :repository_branches | 18 | get '/repository_branches' => 'repositories#branches', as: :repository_branches |
@@ -35,7 +36,7 @@ Rails.application.routes.draw do | @@ -35,7 +36,7 @@ Rails.application.routes.draw do | ||
35 | put '/readings/:id' => 'readings#update', as: :reading_update | 36 | put '/readings/:id' => 'readings#update', as: :reading_update |
36 | end | 37 | end |
37 | 38 | ||
38 | - #resources :modules | 39 | + # Modules |
39 | post '/modules/:id/metric_history' => 'modules#metric_history' | 40 | post '/modules/:id/metric_history' => 'modules#metric_history' |
40 | post '/modules/:id/tree' => 'modules#load_module_tree' | 41 | post '/modules/:id/tree' => 'modules#load_module_tree' |
41 | 42 |
spec/routing/repositories_routing_spec.rb
@@ -18,9 +18,9 @@ describe RepositoriesController, :type => :routing do | @@ -18,9 +18,9 @@ describe RepositoriesController, :type => :routing do | ||
18 | to(controller: :repositories, action: :update, id: 1) } | 18 | to(controller: :repositories, action: :update, id: 1) } |
19 | it { is_expected.not_to route(:get, '/repositories'). | 19 | it { is_expected.not_to route(:get, '/repositories'). |
20 | to(controller: :repositories, action: :index) } | 20 | to(controller: :repositories, action: :index) } |
21 | - it { is_expected.to route(:post, '/repositories/1/state'). | 21 | + it { is_expected.to route(:get, '/repositories/1/state'). |
22 | to(controller: :repositories, action: :state, id: 1) } | 22 | to(controller: :repositories, action: :state, id: 1) } |
23 | - it { is_expected.to route(:post, '/repositories/1/state_with_date'). | 23 | + it { is_expected.to route(:get, '/repositories/1/state_with_date'). |
24 | to(controller: :repositories, action: :state_with_date, id: 1) } | 24 | to(controller: :repositories, action: :state_with_date, id: 1) } |
25 | it { is_expected.to route(:get, '/repositories/1/process'). | 25 | it { is_expected.to route(:get, '/repositories/1/process'). |
26 | to(controller: :repositories, action: :process_repository, id: 1) } | 26 | to(controller: :repositories, action: :process_repository, id: 1) } |