docbrown/spec/models/admin_menu_spec.rb
Jeremy Friesen e1f7a6548c
Adding docs and specs to AdminMenu.nested_menu_items (#16888)
* Adding docs and specs to AdminMenu.nested_menu_items

This relates to PR forem/forem#16847 which addresses issue
forem/forem#16842.

The goal of this PR is to help me develop an understanding of the
AdminMenu so I can further extend it and better understand it.

There's also a bit of knowledge sharing that I'm looking for, and the
comments and tests are there to help "confirm" that knowledge.  There
might be more that I'd consider regarding a refactor, but I want to make
sure I'm on the right path before I go further.

tl;dr - this is the smallest commit I can make to begin to tease out an
understanding of the method I put under test.

* Update app/models/admin_menu.rb

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>

* Adding more documentation

* Update app/models/admin_menu.rb

Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com>

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com>
2022-03-18 08:30:41 -04:00

28 lines
841 B
Ruby

require "rails_helper"
RSpec.describe AdminMenu do
describe ".nested_menu_items_from_request" do
subject(:method_call) { described_class.nested_menu_items_from_request(request) }
let(:request) { instance_double("ActionDispatch::Request", path: path) }
let(:path) { "/admin" }
context "when path is /admin/moderation/feedback_messages" do
let(:path) { "/admin/moderation/feedback_messages" }
it { is_expected.not_to be_present }
end
context "when path is /admin/content_manager/badge_achievements" do
let(:path) { "/admin/content_manager/badge_achievements" }
let(:badges_node) do
described_class::ITEMS[:content_manager]
.fetch(:children)
.detect { |ch| ch.fetch(:name) == "badges" }
end
it { is_expected.to eq(badges_node) }
end
end
end