-
-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix exceptions there isn't an organization with a host (#12861)
* Fix exception in time zone when there isn't an organization * Fix exception in force authentication when there isn't an organization * Fix rubocop offenses
- Loading branch information
1 parent
981b087
commit 928efaa
Showing
4 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
decidim-core/spec/controllers/concerns/force_authentication_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
module Decidim | ||
describe "ForceAuthentication" do | ||
let(:organization) { create(:organization, force_users_to_authenticate_before_access_organization:) } | ||
|
||
controller do | ||
include Decidim::ForceAuthentication | ||
|
||
def current_organization | ||
request.env["decidim.current_organization"] | ||
end | ||
|
||
def show | ||
render plain: "Hello world" | ||
end | ||
|
||
def locale | ||
render plain: "Locale changed" | ||
end | ||
end | ||
|
||
before do | ||
request.env["decidim.current_organization"] = organization | ||
routes.draw do | ||
get "show" => "anonymous#show" | ||
get "locale" => "anonymous#locale" | ||
end | ||
end | ||
|
||
context "when the organization is configured to force user authentication" do | ||
let(:force_users_to_authenticate_before_access_organization) { true } | ||
|
||
it "forces authentication" do | ||
get :show | ||
expect(response.location).to eq("http://test.host/users/sign_in") | ||
expect(response.body).to have_text("You are being redirected") | ||
expect(response).to have_http_status(:found) | ||
end | ||
|
||
it "allows accessing the locale page" do | ||
get :locale | ||
expect(request.path).to eq("/locale") | ||
expect(response.body).to have_text("Locale changed") | ||
expect(response).to have_http_status(:ok) | ||
end | ||
end | ||
|
||
context "when the organization is configured to not force user authentication" do | ||
let(:force_users_to_authenticate_before_access_organization) { false } | ||
|
||
it "shows the page" do | ||
get :show | ||
expect(request.path).to eq("/show") | ||
expect(response.body).to have_text("Hello world") | ||
expect(response).to have_http_status(:ok) | ||
end | ||
end | ||
|
||
context "when there is no organization" do | ||
let(:organization) { nil } | ||
|
||
it "shows the page" do | ||
get :show | ||
expect(request.path).to eq("/show") | ||
expect(response.body).to have_text("Hello world") | ||
expect(response).to have_http_status(:ok) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters