This instance will be upgraded to Heptapod 0.23.2 on 2021-08-05 at 11:00 UTC+2 (a few minutes of down time)

Commit d555165d authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

HgGitRepository: RSpec tests for HGRC management methods

Probably not comprehensive enough, but writing new ones
will be easy from now

--HG--
branch : heptapod-stable
parent 604f866cbf2c
......@@ -16,12 +16,16 @@
let(:user) { build(:user) }
let(:admin_user) { create(:admin) }
let(:project) { create(:hg_git_project, :hg_repository) }
let(:non_empty_repository) do
let(:empty_repository) do
repo = mutable_repository
status = repo.create_repository(namespace_fs_path: "group",
in_subgroup: false)
expect(status).to be(true)
repo
end
let(:non_empty_repository) do
repo = empty_repository
repo.multi_action(user,
branch_name: 'branch/default',
......@@ -68,6 +72,68 @@
end
end
describe "#set_hgrc" do
subject { empty_repository }
let(:hgrc_main) { Pathname(mutable_repository_path).join('.hg', 'hgrc') }
let(:hgrc_managed) { Pathname(mutable_repository_path).join('.hg', 'hgrc.managed') }
after do
subject.remove
end
it "writes with inherit=true a value correctly" do
subject.set_hgrc(user, true, "group",
{ heptapod: { allow_bookmarks: "yes" } })
expect(strip_hgrc_lines(hgrc_main.readlines))
.to eq(["%include ../../group/hgrc", "%include hgrc.managed"])
expect(strip_hgrc_lines(hgrc_managed.readlines))
.to eq(["[heptapod]", "allow_bookmarks = yes"])
expect(subject.get_hgrc).to eq({ 'inherit' => true,
'content' => hgrc_managed.read })
end
it "writes with inherit=false a value correctly" do
subject.set_hgrc(user, false, "group",
{ heptapod: { allow_bookmarks: "yes" } })
expect(strip_hgrc_lines(hgrc_main.readlines))
.to eq(["%include hgrc.managed"])
expect(strip_hgrc_lines(hgrc_managed.readlines))
.to eq(["[heptapod]", "allow_bookmarks = yes"])
expect(subject.get_hgrc).to eq({ 'inherit' => false,
'content' => hgrc_managed.read })
end
it "respects inheritance with inherit=nil yet enforces inclusion of managed file" do
subject
hgrc_main.write("%include ../../group/hgrc\n")
subject.set_hgrc(user, nil, "group", nil)
expect(strip_hgrc_lines(hgrc_main.readlines))
.to eq(["%include ../../group/hgrc", "%include hgrc.managed"])
end
end
describe "#check_fix_hgrc_inheritance" do
subject { empty_repository }
let(:hgrc_main) { Pathname(mutable_repository_path).join('.hg', 'hgrc') }
let(:hgrc_managed) { Pathname(mutable_repository_path).join('.hg', 'hgrc.managed') }
after do
subject.remove
end
it "fixes the inheritance relative path for a simple change" do
subject
hgrc_main.write("%include ../../group/hgrc\nsome other line\n")
subject.check_fix_hgrc_inheritance("new_group")
expect(strip_hgrc_lines(hgrc_main.readlines))
.to eq(["%include ../../new_group/hgrc", "some other line"])
# we would need the repo farther from repos roots from the
# beginning to test deep paths.
end
end
describe "#rebase" do
subject { non_empty_repository }
......@@ -327,4 +393,10 @@
end
end
end
# Remove hash comments (# example), lead/trailing whitespace
# and remove empty lines
def strip_hgrc_lines(lines)
lines.map { |l| l.split("#", 2).first.strip }.select{ |l| !l.empty? }
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment