Add active_language controller and cookie storage

This commit is contained in:
maddiebaka
2023-10-27 15:24:48 -04:00
parent c2891a66f8
commit 3ba4a49a26
8 changed files with 89 additions and 1 deletions

View File

@@ -0,0 +1,20 @@
require 'rails_helper'
RSpec.describe "ActiveLanguages", type: :request do
describe "POST :set_active_language" do
it "should set the cookie" do
language = FactoryBot.create(:language)
post "/set_active_language/", params: { active_language_id: language.id }
expect(cookies[:active_language_id]).to_not be_nil
end
it "should not set the cookie if language does not exist" do
language = FactoryBot.create(:language)
id = language.id + 1
post "/set_active_language/", params: { active_language_id: id }
expect(response).to have_http_status(:unprocessable_entity)
end
end
end

View File

@@ -39,5 +39,12 @@ RSpec.describe "Root path", type: :request do
get root_path
expect(response.body).to include(user.username)
end
it "should have a language drop-down" do
user = FactoryBot.create(:user)
sign_in user
get root_path
expect(response.body).to have_field("active_language_id")
end
end
end