Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport 'Fix version pages showing a HTTP 500 error when the version does not exist' to v0.27 #9810

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
module Accountability
describe VersionsController, versioning: true, type: :controller do
routes { Decidim::Accountability::Engine.routes }

let(:resource) { create(:result) }

it_behaves_like "versions controller"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ module ResourceVersionsConcern
helper Decidim::TraceabilityHelper
helper_method :current_version, :versioned_resource

def show
raise ActionController::RoutingError, "Not found" unless current_version
end

private

# Overwrite this method in your controller to define how to find the
Expand Down
1 change: 1 addition & 0 deletions decidim-core/lib/decidim/core/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@
require "decidim/core/test/shared_examples/translated_event_examples"
require "decidim/core/test/shared_examples/conversations_examples"
require "decidim/core/test/shared_examples/resource_endorsed_event_examples"
require "decidim/core/test/shared_examples/versions_controller_examples"
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

require "spec_helper"

shared_examples "versions controller" do
let(:base_params) do
if resource.is_a?(Decidim::Participable)
{ "#{resource.model_name.singular_route_key}_slug".to_sym => resource.slug }
else
{ "#{resource.model_name.singular_route_key}_id".to_sym => resource.id }
end
end

before do
request.env["decidim.current_organization"] = resource.organization

if resource.is_a?(Decidim::HasComponent)
request.env["decidim.current_participatory_space"] = resource.participatory_space
request.env["decidim.current_component"] = resource.component
end
end

describe "GET show" do
context "with an existing version" do
it "returns a HTTP 200" do
get :show, params: base_params.merge(id: 1)

expect(response).to have_http_status(:ok)
end
end

context "when the resource does not exist" do
it "raises a routing error" do
expect do
get :show, params: base_params.merge(id: 999_999_999)
end.to raise_error(ActionController::RoutingError)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
module Debates
describe VersionsController, versioning: true, type: :controller do
routes { Decidim::Debates::Engine.routes }

let(:resource) { create(:debate) }

it_behaves_like "versions controller"
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
module Initiatives
describe VersionsController, versioning: true, type: :controller do
routes { Decidim::Initiatives::Engine.routes }

let(:resource) { create(:initiative) }

it_behaves_like "versions controller"
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
module Meetings
describe VersionsController, versioning: true, type: :controller do
routes { Decidim::Meetings::Engine.routes }

let(:resource) { create(:meeting) }

it_behaves_like "versions controller"
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
module Proposals
describe VersionsController, versioning: true, type: :controller do
routes { Decidim::Proposals::Engine.routes }

let(:resource) { create(:proposal) }

it_behaves_like "versions controller"
end
end
end