DEV: amend test for anonymous handling to use real data

DEV: amend test for anonymous handling to use real data

Previously we relied on fabrication on anonymous, we can not get the transaction commit pipeline to work as it does in production, cleanly

This amends it so our anonymous user is created using the core APIs

Signed-off-by: Sam Saffron

diff --git a/plugins/discourse-narrative-bot/spec/user_spec.rb b/plugins/discourse-narrative-bot/spec/user_spec.rb
index 8ddf472..f73c291 100644
--- a/plugins/discourse-narrative-bot/spec/user_spec.rb
+++ b/plugins/discourse-narrative-bot/spec/user_spec.rb
@@ -109,12 +109,17 @@ describe User do
     context 'when user is anonymous?' do
-      let(:anonymous_user) { Fabricate(:anonymous) }
-      it 'should not initiate the bot' do
+      before do
         SiteSetting.allow_anonymous_posting = true
+      end
+      it 'should initiate bot for real user only' do
+        user = Fabricate(:user, trust_level: 1)
+        shadow = AnonymousShadowCreator.get(user)
-        expect { anonymous_user }.to_not change { Post.count }
+        expect(TopicAllowedUser.where(user_id: eq(0)
+        expect(TopicAllowedUser.where(user_id: eq(1)

GitHub sha: 1efed6e5

1 Like

I dislike this pattern:

    let(:obj) { ... }

    it ... do
       expect { obj }.to change ...

It relies on it being the first call to obj which I think is fragile. Iā€™m glad to see another instance of it gone.