mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 19:39:30 +08:00
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:
@ -558,14 +558,12 @@ describe CookedPostProcessor do
|
||||
end
|
||||
|
||||
let(:cpp) { CookedPostProcessor.new(post, disable_loading_image: true) }
|
||||
let(:base_url) { "http://test.localhost/subfolder" }
|
||||
let(:base_uri) { "/subfolder" }
|
||||
|
||||
before do
|
||||
set_subfolder "/subfolder"
|
||||
|
||||
SiteSetting.max_image_height = 2000
|
||||
SiteSetting.create_thumbnails = true
|
||||
Discourse.stubs(:base_url).returns(base_url)
|
||||
Discourse.stubs(:base_uri).returns(base_uri)
|
||||
FastImage.expects(:size).returns([1750, 2000])
|
||||
OptimizedImage.expects(:resize).returns(true)
|
||||
|
||||
|
@ -114,11 +114,6 @@ describe FileStore::LocalStore do
|
||||
|
||||
end
|
||||
|
||||
def stub_for_subfolder
|
||||
GlobalSetting.stubs(:relative_url_root).returns('/forum')
|
||||
Discourse.stubs(:base_uri).returns("/forum")
|
||||
end
|
||||
|
||||
describe "#absolute_base_url" do
|
||||
|
||||
it "is present" do
|
||||
@ -126,7 +121,7 @@ describe FileStore::LocalStore do
|
||||
end
|
||||
|
||||
it "supports subfolder" do
|
||||
stub_for_subfolder
|
||||
set_subfolder "/forum"
|
||||
expect(store.absolute_base_url).to eq("http://test.localhost/forum/uploads/default")
|
||||
end
|
||||
|
||||
@ -139,7 +134,7 @@ describe FileStore::LocalStore do
|
||||
end
|
||||
|
||||
it "supports subfolder" do
|
||||
stub_for_subfolder
|
||||
set_subfolder "/forum"
|
||||
expect(store.relative_base_url).to eq("/forum/uploads/default")
|
||||
end
|
||||
|
||||
|
@ -386,8 +386,7 @@ describe FileStore::S3Store do
|
||||
|
||||
# none of this should matter at all
|
||||
# subfolder should not leak into uploads
|
||||
global_setting :relative_url_root, '/community'
|
||||
Discourse.stubs(:base_uri).returns("/community")
|
||||
set_subfolder "/community"
|
||||
|
||||
url = "//s3-upload-bucket.s3.dualstack.us-east-1.amazonaws.com/livechat/original/gif.png"
|
||||
|
||||
|
@ -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])
|
||||
|
||||
|
@ -214,12 +214,8 @@ describe TopicView do
|
||||
end
|
||||
|
||||
context 'subfolder' do
|
||||
before do
|
||||
GlobalSetting.stubs(:relative_url_root).returns('/forum')
|
||||
Discourse.stubs(:base_uri).returns("/forum")
|
||||
end
|
||||
|
||||
it "provides the correct absolute url" do
|
||||
set_subfolder "/forum"
|
||||
expect(topic_view.absolute_url).to eq("http://test.localhost/forum/t/#{topic.slug}/#{topic.id}")
|
||||
end
|
||||
end
|
||||
|
@ -33,7 +33,8 @@ describe UrlHelper do
|
||||
store = stub
|
||||
store.expects(:has_been_uploaded?).returns(false)
|
||||
Discourse.stubs(:store).returns(store)
|
||||
Discourse.stubs(:base_uri).returns("/subpath")
|
||||
|
||||
set_subfolder "/subpath"
|
||||
expect(UrlHelper.is_local("/subpath/assets/javascripts/all.js")).to eq(true)
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user