DEV: improve usability of subfolder specs

Previously people were not consistent about mocking which left internals in
a fragile state when running subfolder specs.

This introduces a simple helper `set_subfolder` which you can use to set
the subfolder for the spec. It takes care of proper configuration of subfolder
and teardown.

```
# usage
set_subfolder "/my_amazing_subfolder"
```

You should no longer stub base_uri or global_settings
This commit is contained in:
Sam Saffron
2019-11-15 16:48:24 +11:00
parent 40d14ba166
commit e7cf4579a8
18 changed files with 38 additions and 68 deletions

View File

@ -269,12 +269,8 @@ describe PrettyText do
fab!(:user) { Fabricate(:user) }
context "subfolder" do
before do
GlobalSetting.stubs(:relative_url_root).returns("/forum")
Discourse.stubs(:base_uri).returns("/forum")
end
it "should have correct avatar url" do
set_subfolder "/forum"
md = <<~MD
[quote="#{user.username}, post:123, topic:456, full:true"]
ddd
@ -331,12 +327,9 @@ describe PrettyText do
end
context 'subfolder' do
before do
GlobalSetting.stubs(:relative_url_root).returns('/forum')
Discourse.stubs(:base_uri).returns("/forum")
end
it "handles user and group mentions correctly" do
set_subfolder "/forum"
Fabricate(:user, username: 'user1')
Fabricate(:group, name: 'groupA', mentionable_level: Group::ALIAS_LEVELS[:everyone])