mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06: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:
@@ -204,8 +204,7 @@ RSpec.describe ApplicationController do
|
||||
end
|
||||
|
||||
it 'supports subfolder with permalinks' do
|
||||
GlobalSetting.stubs(:relative_url_root).returns('/forum')
|
||||
Discourse.stubs(:base_uri).returns("/forum")
|
||||
set_subfolder "/forum"
|
||||
|
||||
trashed_topic = create_post.topic
|
||||
trashed_topic.trash!
|
||||
|
||||
@@ -21,8 +21,7 @@ describe CategoriesController do
|
||||
end
|
||||
|
||||
it 'web crawler view has correct urls for subfolder install' do
|
||||
GlobalSetting.stubs(:relative_url_root).returns('/forum')
|
||||
Discourse.stubs(:base_uri).returns("/forum")
|
||||
set_subfolder "/forum"
|
||||
get '/categories', headers: { 'HTTP_USER_AGENT' => 'Googlebot' }
|
||||
html = Nokogiri::HTML(response.body)
|
||||
expect(html.css('body.crawler')).to be_present
|
||||
|
||||
@@ -339,8 +339,7 @@ RSpec.describe ListController do
|
||||
end
|
||||
|
||||
it 'renders links correctly with subfolder' do
|
||||
GlobalSetting.stubs(:relative_url_root).returns('/forum')
|
||||
Discourse.stubs(:base_uri).returns("/forum")
|
||||
set_subfolder "/forum"
|
||||
post = Fabricate(:post, topic: topic, user: user)
|
||||
get "/latest.rss"
|
||||
expect(response.status).to eq(200)
|
||||
@@ -458,8 +457,7 @@ RSpec.describe ListController do
|
||||
end
|
||||
|
||||
it "renders RSS in subfolder correctly" do
|
||||
GlobalSetting.stubs(:relative_url_root).returns('/forum')
|
||||
Discourse.stubs(:base_uri).returns("/forum")
|
||||
set_subfolder "/forum"
|
||||
get "/c/#{category.slug}.rss"
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.body).to_not include("/forum/forum")
|
||||
|
||||
@@ -18,8 +18,7 @@ describe PermalinksController do
|
||||
|
||||
it "should work for subfolder installs too" do
|
||||
permalink.update!(topic_id: topic.id)
|
||||
GlobalSetting.stubs(:relative_url_root).returns('/forum')
|
||||
Discourse.stubs(:base_uri).returns("/forum")
|
||||
set_subfolder "/forum"
|
||||
|
||||
get "/#{permalink.url}"
|
||||
|
||||
|
||||
@@ -49,7 +49,8 @@ RSpec.describe RobotsTxtController do
|
||||
|
||||
context 'subfolder' do
|
||||
it 'prefixes the rules with the directory' do
|
||||
Discourse.stubs(:base_uri).returns('/forum')
|
||||
set_subfolder "/forum"
|
||||
|
||||
get '/robots.txt'
|
||||
expect(response.body).to include("\nDisallow: /forum/admin")
|
||||
end
|
||||
|
||||
@@ -1861,7 +1861,8 @@ RSpec.describe TopicsController do
|
||||
|
||||
describe 'clear_notifications' do
|
||||
it 'correctly clears notifications if specified via cookie' do
|
||||
Discourse.stubs(:base_uri).returns("/eviltrout")
|
||||
set_subfolder "/eviltrout"
|
||||
|
||||
notification = Fabricate(:notification)
|
||||
sign_in(notification.user)
|
||||
|
||||
@@ -2146,8 +2147,7 @@ RSpec.describe TopicsController do
|
||||
end
|
||||
|
||||
it 'renders rss of the topic correctly with subfolder' do
|
||||
GlobalSetting.stubs(:relative_url_root).returns('/forum')
|
||||
Discourse.stubs(:base_uri).returns("/forum")
|
||||
set_subfolder "/forum"
|
||||
get "/t/foo/#{topic.id}.rss"
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.body).to_not include("/forum/forum")
|
||||
|
||||
@@ -192,16 +192,9 @@ describe UserBadgesController do
|
||||
end
|
||||
|
||||
describe 'with relative_url_root' do
|
||||
before do
|
||||
@orig_relative_url_root = ActionController::Base.config.relative_url_root
|
||||
ActionController::Base.config.relative_url_root = "/discuss"
|
||||
end
|
||||
|
||||
after do
|
||||
ActionController::Base.config.relative_url_root = @orig_relative_url_root
|
||||
end
|
||||
|
||||
it 'grants badge when valid post/topic link is given in reason' do
|
||||
set_subfolder "/discuss"
|
||||
|
||||
admin = Fabricate(:admin)
|
||||
post = create_post
|
||||
|
||||
|
||||
Reference in New Issue
Block a user