From 53dab8cf1ecf08979c0f4c17fdd8f2181b77b5ba Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Mon, 21 Jun 2021 11:50:52 +1000 Subject: [PATCH] DEV: Replace const munging in specs with stub_const helper --- spec/components/topic_view_spec.rb | 9 +-------- spec/requests/groups_controller_spec.rb | 9 +-------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rb index d934128688e..cfda8b6ef46 100644 --- a/spec/components/topic_view_spec.rb +++ b/spec/components/topic_view_spec.rb @@ -802,19 +802,12 @@ describe TopicView do describe 'for mega topics' do it 'should return the right columns' do - begin - original_const = TopicView::MEGA_TOPIC_POSTS_COUNT - TopicView.send(:remove_const, "MEGA_TOPIC_POSTS_COUNT") - TopicView.const_set("MEGA_TOPIC_POSTS_COUNT", 2) - + stub_const(TopicView, "MEGA_TOPIC_POSTS_COUNT", 2) do expect(topic_view.filtered_post_stream).to eq([ post.id, post2.id, post3.id ]) - ensure - TopicView.send(:remove_const, "MEGA_TOPIC_POSTS_COUNT") - TopicView.const_set("MEGA_TOPIC_POSTS_COUNT", original_const) end end end diff --git a/spec/requests/groups_controller_spec.rb b/spec/requests/groups_controller_spec.rb index 1ef1174942d..340376607af 100644 --- a/spec/requests/groups_controller_spec.rb +++ b/spec/requests/groups_controller_spec.rb @@ -1309,11 +1309,7 @@ describe GroupsController do end it 'display error when try to add to many users at once' do - begin - old_constant = GroupsController.const_get("ADD_MEMBERS_LIMIT") - GroupsController.send(:remove_const, "ADD_MEMBERS_LIMIT") - GroupsController.const_set("ADD_MEMBERS_LIMIT", 1) - + stub_const(GroupsController, "ADD_MEMBERS_LIMIT", 1) do expect do put "/groups/#{group.id}/members.json", params: { user_emails: [user1.email, user2.email].join(",") } @@ -1325,9 +1321,6 @@ describe GroupsController do "groups.errors.adding_too_many_users", count: 1 )) - ensure - GroupsController.send(:remove_const, "ADD_MEMBERS_LIMIT") - GroupsController.const_set("ADD_MEMBERS_LIMIT", old_constant) end end end