diff options
| author | Teddy Wing | 2017-08-07 16:51:19 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-08-07 16:51:19 +0200 |
| commit | 0b79907ea95a1f2fa9c8766474773f6555f49f37 (patch) | |
| tree | 4a784c303e752060e56d7bb9085469bc1f35d9ef | |
| parent | 1d490afb5b616f15837259d093d458357f17a439 (diff) | |
| download | chouette-core-0b79907ea95a1f2fa9c8766474773f6555f49f37.tar.bz2 | |
RoutesController: Add separate method for POST /duplicate
Send POST requests for duplication to a new controller method so we can
more easily handle them and separate setup and creation code.
Note that the test doesn't work. The `to change` part succeeds even
though it shouldn't. Still need to figure out what's going on there, but
committing this to hand off the feature to Robert.
Refs #4189
| -rw-r--r-- | app/controllers/routes_controller.rb | 4 | ||||
| -rw-r--r-- | config/routes.rb | 2 | ||||
| -rw-r--r-- | spec/controllers/routes_controller_spec.rb | 17 |
3 files changed, 22 insertions, 1 deletions
diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index 852477c5c..e20ae9d14 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -75,6 +75,10 @@ class RoutesController < ChouetteController build_breadcrumb(:edit) end + def post_duplicate + @route = Chouette::Route.find(params[:id]) + end + protected alias_method :route, :resource diff --git a/config/routes.rb b/config/routes.rb index b738c0943..e73a2a494 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -111,7 +111,7 @@ ChouetteIhm::Application.routes.draw do get 'edit_boarding_alighting' put 'save_boarding_alighting' get 'duplicate' - post 'duplicate' + post 'duplicate', to: 'routes#post_duplicate' end resource :journey_patterns_collection, :only => [:show, :update] resources :journey_patterns do diff --git a/spec/controllers/routes_controller_spec.rb b/spec/controllers/routes_controller_spec.rb index 5c17b78b8..3862d8173 100644 --- a/spec/controllers/routes_controller_spec.rb +++ b/spec/controllers/routes_controller_spec.rb @@ -85,4 +85,21 @@ RSpec.describe RoutesController, type: :controller do expect(response).to be_success end end + + describe "POST /duplicate" do + it "creates a new route" do + expect do + post :duplicate, + referential_id: route.line.line_referential_id, + line_id: route.line_id, + id: route.id, + params: { + name: '102 Route', + published_name: '102 route' + } + end.to change { Chouette::Route.count }.by(1) + + expect(Chouette::Route.last.name).to eq('102 Route') + end + end end |
