DEV: Replace const munging in specs with stub_const helper

This commit is contained in:
Martin Brennan 2021-06-21 11:50:52 +10:00 committed by Alan Guo Xiang Tan
parent 06fa1efd3d
commit 53dab8cf1e
2 changed files with 2 additions and 16 deletions

View File

@ -802,19 +802,12 @@ describe TopicView do
describe 'for mega topics' do describe 'for mega topics' do
it 'should return the right columns' do it 'should return the right columns' do
begin stub_const(TopicView, "MEGA_TOPIC_POSTS_COUNT", 2) do
original_const = TopicView::MEGA_TOPIC_POSTS_COUNT
TopicView.send(:remove_const, "MEGA_TOPIC_POSTS_COUNT")
TopicView.const_set("MEGA_TOPIC_POSTS_COUNT", 2)
expect(topic_view.filtered_post_stream).to eq([ expect(topic_view.filtered_post_stream).to eq([
post.id, post.id,
post2.id, post2.id,
post3.id post3.id
]) ])
ensure
TopicView.send(:remove_const, "MEGA_TOPIC_POSTS_COUNT")
TopicView.const_set("MEGA_TOPIC_POSTS_COUNT", original_const)
end end
end end
end end

View File

@ -1309,11 +1309,7 @@ describe GroupsController do
end end
it 'display error when try to add to many users at once' do it 'display error when try to add to many users at once' do
begin stub_const(GroupsController, "ADD_MEMBERS_LIMIT", 1) do
old_constant = GroupsController.const_get("ADD_MEMBERS_LIMIT")
GroupsController.send(:remove_const, "ADD_MEMBERS_LIMIT")
GroupsController.const_set("ADD_MEMBERS_LIMIT", 1)
expect do expect do
put "/groups/#{group.id}/members.json", put "/groups/#{group.id}/members.json",
params: { user_emails: [user1.email, user2.email].join(",") } params: { user_emails: [user1.email, user2.email].join(",") }
@ -1325,9 +1321,6 @@ describe GroupsController do
"groups.errors.adding_too_many_users", "groups.errors.adding_too_many_users",
count: 1 count: 1
)) ))
ensure
GroupsController.send(:remove_const, "ADD_MEMBERS_LIMIT")
GroupsController.const_set("ADD_MEMBERS_LIMIT", old_constant)
end end
end end
end end