diff options
| author | Robert | 2017-09-11 09:41:03 +0200 | 
|---|---|---|
| committer | Robert | 2017-09-11 17:15:49 +0200 | 
| commit | f7bc874de79ff9a68aa03523cf653407663e7c55 (patch) | |
| tree | 1716586822ad9b9912e44f658193e5c1aea04e88 /spec | |
| parent | 003c4689248673fbc8922a107475caa9e059bcab (diff) | |
| download | chouette-core-f7bc874de79ff9a68aa03523cf653407663e7c55.tar.bz2 | |
Fixes #4189@4h Route Duplication
* Duplication of Route is triggered by link and UI forwarded to edit of duplicatee
     - Changing route, only POST duplicate_referential_line_route --> RoutesController#duplicate
     - Removing route       GET  duplicate_referential_line_route --> RoutesController#duplicate
     - Removing controller action RoutesController#post_duplicate
* Link in Route Decorator depends on new policy RoutePolicy#decorate?
* Adapting specs
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/controllers/routes_controller_spec.rb | 27 | ||||
| -rw-r--r-- | spec/models/chouette/route/route_duplication_spec.rb | 13 | ||||
| -rw-r--r-- | spec/policies/route_policy_spec.rb | 4 | ||||
| -rw-r--r-- | spec/routing/routes_routing_spec.rb | 8 | 
4 files changed, 14 insertions, 38 deletions
| diff --git a/spec/controllers/routes_controller_spec.rb b/spec/controllers/routes_controller_spec.rb index 3862d8173..336f20945 100644 --- a/spec/controllers/routes_controller_spec.rb +++ b/spec/controllers/routes_controller_spec.rb @@ -1,3 +1,5 @@ +Route = Chouette::Route +  RSpec.describe RoutesController, type: :controller do    login_user @@ -75,31 +77,20 @@ RSpec.describe RoutesController, type: :controller do      end    end -  describe "GET /duplicate" do -    it "returns success" do -      get :duplicate, -        referential_id: route.line.line_referential_id, -        line_id: route.line_id, -        id: route.id - -      expect(response).to be_success -    end -  end    describe "POST /duplicate" do +    let!( :route_prime ){ route } +      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') +          id: route.id +      end.to change { Route.count }.by(1) + +      expect(Route.last.name).to eq(route.name) +      expect(Route.last.published_name).to eq(route.published_name)      end    end  end diff --git a/spec/models/chouette/route/route_duplication_spec.rb b/spec/models/chouette/route/route_duplication_spec.rb index 74e944181..6645b909f 100644 --- a/spec/models/chouette/route/route_duplication_spec.rb +++ b/spec/models/chouette/route/route_duplication_spec.rb @@ -13,19 +13,6 @@ RSpec.describe Route do          route.duplicate          expect( values_for_create(Route.last, except: %w{objectid}) ).to eq( values_for_create( route, except: %w{objectid} ) )        end -      it 'but some can be redefined optionally', :wip do -        excluded_attributes = %w{objectid checksum checksum_source} -        expected_attributes = values_for_create( -          route, -          name: 'new name', -          published_name: 'new published name', -          except: excluded_attributes )  - -        route.duplicate name: 'new name', published_name: 'new published name' -        expect( -          values_for_create(Route.last, except: excluded_attributes) -        ).to eq( expected_attributes ) -      end        it 'and others cannot' do          expect{ route.duplicate name: 'YAN', line_id: 42  }.to raise_error(ArgumentError)        end diff --git a/spec/policies/route_policy_spec.rb b/spec/policies/route_policy_spec.rb index 243d85acb..d7edceaef 100644 --- a/spec/policies/route_policy_spec.rb +++ b/spec/policies/route_policy_spec.rb @@ -6,6 +6,10 @@ RSpec.describe RoutePolicy, type: :policy do      it_behaves_like 'permitted policy and same organisation', 'routes.create', archived: true    end +  permissions :duplicate? do +    it_behaves_like 'permitted policy and same organisation', 'routes.create', archived: true +  end +    permissions :destroy? do      it_behaves_like 'permitted policy and same organisation', 'routes.destroy', archived: true    end diff --git a/spec/routing/routes_routing_spec.rb b/spec/routing/routes_routing_spec.rb index 4635603d4..311de9f39 100644 --- a/spec/routing/routes_routing_spec.rb +++ b/spec/routing/routes_routing_spec.rb @@ -3,16 +3,10 @@ RSpec.describe "routes for Routes", type: :routing do      let( :controller ){ {controller: 'routes', referential_id: ':referential_id', line_id: ':line_id', id: ':id'}  } -    it 'with method get to #duplicate' do -      expect( -        get: '/referentials/:referential_id/lines/:line_id/routes/:id/duplicate' -      ).to route_to controller.merge(action: 'duplicate') -    end -      it 'with method post to #post_duplicate' do        expect(          post: '/referentials/:referential_id/lines/:line_id/routes/:id/duplicate' -      ).to route_to controller.merge(action: 'post_duplicate') +      ).to route_to controller.merge(action: 'duplicate')      end    end  end | 
