Skip to content
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: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
get "/appearance", to: "private#appearance"
end

mount Lookbook::Engine, at: "/lookbook" if defined?(Lookbook)
if Avo.configuration.mount_lookbook
mount Lookbook::Engine, at: "/lookbook" if defined?(Lookbook)
end
end
end
2 changes: 2 additions & 0 deletions lib/avo/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Configuration
attr_writer :body_classes
attr_accessor :sidebar_toggle_visible
attr_accessor :tailwindcss_integration_enabled
attr_accessor :mount_lookbook

unless defined?(CONTAINER_WIDTH_DEFAULTS)
CONTAINER_WIDTH_DEFAULTS = {
Expand Down Expand Up @@ -201,6 +202,7 @@ def initialize
@sidebar_toggle_visible = true
@body_classes = []
@tailwindcss_integration_enabled = true
@mount_lookbook = false
end

unless defined?(RESOURCE_ROW_CONTROLS_CONFIG_DEFAULTS)
Expand Down
4 changes: 3 additions & 1 deletion lib/avo/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ class Engine < ::Rails::Engine
# Add the mount_avo method to Rails
# rubocop:disable Style/ArgumentsForwarding
ActionDispatch::Routing::Mapper.include(Module.new {
def mount_avo(at: Avo.configuration.root_path, **options, &block)
def mount_avo(at: Avo.configuration.root_path, mount_lookbook: false, **options, &block)
Avo.configuration.mount_lookbook = mount_lookbook

mount Avo::Engine, at:, **options

scope at do
Expand Down
2 changes: 1 addition & 1 deletion spec/components/avo/index/table_row_component_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

# Component-layer integration coverage. The full merge contract is exercised
# in `spec/lib/avo/table_row_options_spec.rb`; this file covers the parts that
# in `spec/features/avo/lib/table_row_options_spec.rb`; this file covers the parts that
# only the component owns: `view` derivation and the wiring of the merger
# call.
RSpec.describe Avo::Index::TableRowComponent, type: :component do
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
resources :posts

authenticate :user, ->(user) { user.is_admin? } do
mount_avo do
mount_avo mount_lookbook: true do
scope :resources do
get "courses/cities", to: "courses#cities"
get "users/get_users", to: "users#get_users"
Expand Down
42 changes: 42 additions & 0 deletions spec/features/avo/lib/mount_avo_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require "rails_helper"

RSpec.describe "mount_avo" do
around do |example|
original = Avo.configuration.mount_lookbook
example.run
ensure
Avo.configuration.mount_lookbook = original
end

def draw_mount_avo(**options)
Comment thread
Paul-Bob marked this conversation as resolved.
routes = ActionDispatch::Routing::RouteSet.new
routes.draw { mount_avo(**options) }
Comment thread
Paul-Bob marked this conversation as resolved.
routes
end

it "defaults mount_lookbook to false" do
draw_mount_avo

expect(Avo.configuration.mount_lookbook).to be false
end

it "sets mount_lookbook when mount_lookbook: true is passed" do
draw_mount_avo mount_lookbook: true

expect(Avo.configuration.mount_lookbook).to be true
end

it "sets mount_lookbook to false when mount_lookbook: false is passed" do
Avo.configuration.mount_lookbook = true

draw_mount_avo mount_lookbook: false

expect(Avo.configuration.mount_lookbook).to be false
end
end

RSpec.describe Avo::Configuration, "#mount_lookbook" do
it "defaults to false" do
expect(described_class.new.mount_lookbook).to be false
end
end
Loading