In the management section, `current_user` is the user impersonated by the manager. We were deciding whether to show the admin menu depending on the privileges of the current user, but this menu should be shown according to the privileges of the manager who is impersonating the user. We're doing a similar (very subtle) change in the login items. We were rendering the `login_items` partial passing `current_user: user`. However, inside this method, we were using `user_signed_in`, which ignored the `current_user` we were passing. The result was always the same expect in tests where we manually sign in users, but we're changing it anyway in order to reduce confusion.
37 lines
1.1 KiB
Ruby
37 lines
1.1 KiB
Ruby
require "rails_helper"
|
|
|
|
describe Layout::AdminHeaderComponent do
|
|
let(:user) { create(:user) }
|
|
before { Setting["org_name"] = "CONSUL" }
|
|
|
|
around do |example|
|
|
with_request_url("/") { example.run }
|
|
end
|
|
|
|
context "management section", controller: Management::BaseController do
|
|
it "shows the menu for administrators" do
|
|
create(:administrator, user: user)
|
|
|
|
render_inline Layout::AdminHeaderComponent.new(user)
|
|
|
|
expect(page).to have_link "Go back to CONSUL"
|
|
expect(page).to have_link "You don't have new notifications"
|
|
expect(page).to have_link "My content"
|
|
expect(page).to have_link "My account"
|
|
expect(page).to have_link "Sign out"
|
|
end
|
|
|
|
it "does not show the menu managers" do
|
|
create(:manager, user: user)
|
|
|
|
render_inline Layout::AdminHeaderComponent.new(user)
|
|
|
|
expect(page).to have_link "Go back to CONSUL"
|
|
expect(page).not_to have_content "You don't have new notifications"
|
|
expect(page).not_to have_content "My content"
|
|
expect(page).not_to have_content "My account"
|
|
expect(page).not_to have_content "Sign out"
|
|
end
|
|
end
|
|
end
|