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

Raise exception in UserTimelineController if no user with the nickname provided #11465

Merged
merged 2 commits into from
Aug 9, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class UserTimelineController < Decidim::ApplicationController
helper_method :activities, :resource_types, :user

def index
raise ActionController::RoutingError, "Not Found" if current_user != user
raise ActionController::RoutingError, "Not Found" unless user && current_user == user
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,54 @@

module Decidim
describe UserTimelineController, type: :controller do
subject { get :index, params: { nickname: nickname } }

routes { Decidim::Core::Engine.routes }

let(:organization) { create(:organization) }
let!(:user) { create(:user, :confirmed, nickname: "Nick", organization: organization) }
let(:nickname) { "foobar" }

before do
request.env["decidim.current_organization"] = organization
sign_in user
end

shared_examples_for "a not found page" do
it "raises an ActionController::RoutingError" do
expect { subject }.to raise_error(ActionController::RoutingError, "Not Found")
end
end

describe "#index" do
context "with a different user than me" do
it "raises an ActionController::RoutingError" do
expect do
get :index, params: { nickname: "foobar" }
end.to raise_error(ActionController::RoutingError, "Not Found")
context "with the user logged in" do
before do
sign_in user
end

context "with a different user than me" do
it_behaves_like "a not found page"
end

context "with my user with uppercase" do
let(:nickname) { user.nickname.upcase }

it "returns the lowercased user" do
subject

expect(response).to render_template(:index)
end
end
end

context "with my user with uppercase" do
it "returns the lowercased user" do
get :index, params: { nickname: "NICK" }
expect(response).to render_template(:index)
context "without the user logged in" do
context "with a non existing user" do
it_behaves_like "a not found page"
end

context "with my user with uppercase" do
let(:nickname) { user.nickname.upcase }

it_behaves_like "a not found page"
end
end
end
Expand Down