about summary refs log tree commit diff
path: root/spec/support
diff options
context:
space:
mode:
authorStarfall <us@starfall.systems>2023-04-14 19:22:47 -0500
committerStarfall <us@starfall.systems>2023-04-14 19:22:47 -0500
commit4fe1689de43f4404eb9530fcfbcbfb26d6c1c13a (patch)
tree6811b845bb7f4966b10dcefa3dea404246f161c7 /spec/support
parent65c1e53a32cabcdbb7bca57002bb0f6acdebe07e (diff)
parentbed63f6dae0879ac840066b031229e0d139089cd (diff)
Merge remote-tracking branch 'glitch/main' HEAD main
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/examples/lib/admin/checks.rb21
-rw-r--r--spec/support/examples/lib/settings/scoped_settings.rb32
-rw-r--r--spec/support/matchers/json/match_json_schema.rb2
-rw-r--r--spec/support/matchers/model/model_have_error_on_field.rb8
-rw-r--r--spec/support/stories/profile_stories.rb4
5 files changed, 45 insertions, 22 deletions
diff --git a/spec/support/examples/lib/admin/checks.rb b/spec/support/examples/lib/admin/checks.rb
new file mode 100644
index 000000000..b50faa77b
--- /dev/null
+++ b/spec/support/examples/lib/admin/checks.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+shared_examples 'a check available to devops users' do
+  describe 'skip?' do
+    context 'when user can view devops' do
+      before { allow(user).to receive(:can?).with(:view_devops).and_return(true) }
+
+      it 'returns false' do
+        expect(check.skip?).to be false
+      end
+    end
+
+    context 'when user cannot view devops' do
+      before { allow(user).to receive(:can?).with(:view_devops).and_return(false) }
+
+      it 'returns true' do
+        expect(check.skip?).to be true
+      end
+    end
+  end
+end
diff --git a/spec/support/examples/lib/settings/scoped_settings.rb b/spec/support/examples/lib/settings/scoped_settings.rb
index 2457dcfbf..106adb4fa 100644
--- a/spec/support/examples/lib/settings/scoped_settings.rb
+++ b/spec/support/examples/lib/settings/scoped_settings.rb
@@ -3,13 +3,13 @@
 shared_examples 'ScopedSettings' do
   describe '[]' do
     it 'inherits default settings' do
-      expect(Setting.boost_modal).to eq false
-      expect(Setting.interactions['must_be_follower']).to eq false
+      expect(Setting.boost_modal).to be false
+      expect(Setting.interactions['must_be_follower']).to be false
 
       settings = create!
 
-      expect(settings['boost_modal']).to eq false
-      expect(settings['interactions']['must_be_follower']).to eq false
+      expect(settings['boost_modal']).to be false
+      expect(settings['interactions']['must_be_follower']).to be false
     end
   end
 
@@ -17,16 +17,16 @@ shared_examples 'ScopedSettings' do
     # expecting [] and []= works
 
     it 'returns records merged with default values except hashes' do
-      expect(Setting.boost_modal).to eq false
-      expect(Setting.delete_modal).to eq true
+      expect(Setting.boost_modal).to be false
+      expect(Setting.delete_modal).to be true
 
       settings = create!
       settings['boost_modal'] = true
 
       records = settings.all_as_records
 
-      expect(records['boost_modal'].value).to eq true
-      expect(records['delete_modal'].value).to eq true
+      expect(records['boost_modal'].value).to be true
+      expect(records['delete_modal'].value).to be true
     end
   end
 
@@ -34,15 +34,15 @@ shared_examples 'ScopedSettings' do
     # expecting [] and []= works.
 
     it 'reads settings' do
-      expect(Setting.boost_modal).to eq false
+      expect(Setting.boost_modal).to be false
       settings = create!
-      expect(settings.boost_modal).to eq false
+      expect(settings.boost_modal).to be false
     end
 
     it 'updates settings' do
       settings = fabricate
       settings.boost_modal = true
-      expect(settings['boost_modal']).to eq true
+      expect(settings['boost_modal']).to be true
     end
   end
 
@@ -54,13 +54,13 @@ shared_examples 'ScopedSettings' do
 
     Setting.save!
 
-    expect(settings['boost_modal']).to eq true
-    expect(settings['interactions']['must_be_follower']).to eq true
+    expect(settings['boost_modal']).to be true
+    expect(settings['interactions']['must_be_follower']).to be true
 
     Rails.cache.clear
 
-    expect(settings['boost_modal']).to eq true
-    expect(settings['interactions']['must_be_follower']).to eq true
+    expect(settings['boost_modal']).to be true
+    expect(settings['interactions']['must_be_follower']).to be true
   end
 
   xit 'does not mutate defaults via the cache' do
@@ -69,6 +69,6 @@ shared_examples 'ScopedSettings' do
     # This mutates the global settings default such that future
     # instances will inherit the incorrect starting values
 
-    expect(fabricate.settings['interactions']['must_be_follower']).to eq false
+    expect(fabricate.settings['interactions']['must_be_follower']).to be false
   end
 end
diff --git a/spec/support/matchers/json/match_json_schema.rb b/spec/support/matchers/json/match_json_schema.rb
index 5d9c9a618..3a275199e 100644
--- a/spec/support/matchers/json/match_json_schema.rb
+++ b/spec/support/matchers/json/match_json_schema.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 RSpec::Matchers.define :match_json_schema do |schema|
   match do |input_json|
     schema_path = Rails.root.join('spec', 'support', 'schema', "#{schema}.json").to_s
diff --git a/spec/support/matchers/model/model_have_error_on_field.rb b/spec/support/matchers/model/model_have_error_on_field.rb
index 85bdd8215..0f9c81a47 100644
--- a/spec/support/matchers/model/model_have_error_on_field.rb
+++ b/spec/support/matchers/model/model_have_error_on_field.rb
@@ -1,10 +1,10 @@
+# frozen_string_literal: true
+
 RSpec::Matchers.define :model_have_error_on_field do |expected|
   match do |record|
-    if record.errors.empty?
-      record.valid?
-    end
+    record.valid? if record.errors.empty?
 
-    record.errors.has_key?(expected)
+    record.errors.key?(expected)
   end
 
   failure_message do |record|
diff --git a/spec/support/stories/profile_stories.rb b/spec/support/stories/profile_stories.rb
index 0c4a14d1c..de7ae17e6 100644
--- a/spec/support/stories/profile_stories.rb
+++ b/spec/support/stories/profile_stories.rb
@@ -20,8 +20,8 @@ module ProfileStories
   end
 
   def with_alice_as_local_user
-    @alice_bio = '@alice and @bob are fictional characters commonly used as'\
-                 'placeholder names in #cryptology, as well as #science and'\
+    @alice_bio = '@alice and @bob are fictional characters commonly used as' \
+                 'placeholder names in #cryptology, as well as #science and' \
                  'engineering 📖 literature. Not affiliated with @pepe.'
 
     @alice = Fabricate(