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

AO3-6856 Make default language no longer editable #4979

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions app/controllers/languages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def create
def edit
@language = Language.find_by(short: params[:id])
authorize @language
return unless @language == Language.default

flash[:error] = t("languages.cannot_edit_default")
redirect_to languages_path
end

def update
Expand Down
1 change: 1 addition & 0 deletions config/locales/controllers/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ en:
create:
success: Thank you for leaving kudos!
languages:
cannot_edit_default: Sorry, you can't edit the default language.
successfully_added: Language was successfully added.
successfully_updated: Language was successfully updated.
update:
Expand Down
11 changes: 9 additions & 2 deletions spec/controllers/languages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,21 @@
end

%w[translation superadmin support policy_and_abuse].each do |role|
Language.create(name: "Deutsch", short: "de")
context "when logged in as an admin with #{role} role" do
let(:admin) { create(:admin, roles: [role]) }

it "renders the edit template" do
it "renders the edit template for a non-default language" do
fake_login_admin(admin)
get :edit, params: { id: "en" }
get :edit, params: { id: "de" }
expect(response).to render_template("edit")
end

it "redirects for the default language" do
fake_login_admin(admin)
get :edit, params: { id: "en" }
it_redirects_to_with_error(languages_path, "Sorry, you can't edit the default language.")
end
end
end
end
Expand Down
Loading