Skip to content

Commit

Permalink
Hanami::Action::Config#root to match Hanami.app.root
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Sep 20, 2023
1 parent 2eb8390 commit 8768ec7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/hanami/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ def self.gem_loader
cookie_options.to_h.compact
}
setting :root_directory, constructor: -> (dir) {
Pathname(File.expand_path(dir || Dir.pwd)).realpath
if Hanami.respond_to?(:app) && Hanami.app
Hanami.app.root
else
Pathname(File.expand_path(dir || Dir.pwd)).realpath
end
}
setting :public_directory, default: Config::DEFAULT_PUBLIC_DIRECTORY
setting :before_callbacks, default: Utils::Callbacks::Chain.new, mutable: true
Expand Down
16 changes: 16 additions & 0 deletions spec/unit/hanami/action/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@
config.root_directory = "/non-existent"
}.to raise_error(StandardError)
end

context "within a Hanami app" do
before do
app = double("Hanami.app", root: root_directory)

allow(Hanami).to receive(:respond_to?).with(:app, true).and_return(true)
allow(Hanami).to receive(:respond_to?).with(:app).and_return(true)
allow(Hanami).to receive(:app).and_return(app)
end

let(:root_directory) { Pathname.new(__dir__).join("spec") }

it "returns the Hanami app root" do
expect(config.root_directory).to eq(root_directory)
end
end
end

describe "public_directory" do
Expand Down

0 comments on commit 8768ec7

Please sign in to comment.