about summary refs log tree commit diff
path: root/spec/models
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/account_warning_preset_spec.rb5
-rw-r--r--spec/models/account_warning_spec.rb5
-rw-r--r--spec/models/admin/account_action_spec.rb4
-rw-r--r--spec/models/custom_emoji_filter_spec.rb70
4 files changed, 84 insertions, 0 deletions
diff --git a/spec/models/account_warning_preset_spec.rb b/spec/models/account_warning_preset_spec.rb
new file mode 100644
index 000000000..a859a305f
--- /dev/null
+++ b/spec/models/account_warning_preset_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe AccountWarningPreset, type: :model do
+  pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/spec/models/account_warning_spec.rb b/spec/models/account_warning_spec.rb
new file mode 100644
index 000000000..5286f9177
--- /dev/null
+++ b/spec/models/account_warning_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe AccountWarning, type: :model do
+  pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/spec/models/admin/account_action_spec.rb b/spec/models/admin/account_action_spec.rb
new file mode 100644
index 000000000..8c55cf4dd
--- /dev/null
+++ b/spec/models/admin/account_action_spec.rb
@@ -0,0 +1,4 @@
+require 'rails_helper'
+
+RSpec.describe Admin::AccountAction, type: :model do
+end
diff --git a/spec/models/custom_emoji_filter_spec.rb b/spec/models/custom_emoji_filter_spec.rb
new file mode 100644
index 000000000..d859f5c5f
--- /dev/null
+++ b/spec/models/custom_emoji_filter_spec.rb
@@ -0,0 +1,70 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe CustomEmojiFilter do
+  describe '#results' do
+    let!(:custom_emoji_0) { Fabricate(:custom_emoji, domain: 'a') }
+    let!(:custom_emoji_1) { Fabricate(:custom_emoji, domain: 'b') }
+    let!(:custom_emoji_2) { Fabricate(:custom_emoji, domain: nil, shortcode: 'hoge') }
+
+    subject { described_class.new(params).results }
+
+    context 'params have values' do
+      context 'local' do
+        let(:params) { { local: true } }
+
+        it 'returns ActiveRecord::Relation' do
+          expect(subject).to be_kind_of(ActiveRecord::Relation)
+          expect(subject).to match_array([custom_emoji_2])
+        end
+      end
+
+      context 'remote' do
+        let(:params) { { remote: true } }
+
+        it 'returns ActiveRecord::Relation' do
+          expect(subject).to be_kind_of(ActiveRecord::Relation)
+          expect(subject).to match_array([custom_emoji_0, custom_emoji_1])
+        end
+      end
+
+      context 'by_domain' do
+        let(:params) { { by_domain: 'a' } }
+
+        it 'returns ActiveRecord::Relation' do
+          expect(subject).to be_kind_of(ActiveRecord::Relation)
+          expect(subject).to match_array([custom_emoji_0])
+        end
+      end
+
+      context 'shortcode' do
+        let(:params) { { shortcode: 'hoge' } }
+
+        it 'returns ActiveRecord::Relation' do
+          expect(subject).to be_kind_of(ActiveRecord::Relation)
+          expect(subject).to match_array([custom_emoji_2])
+        end
+      end
+
+      context 'else' do
+        let(:params) { { else: 'else' } }
+
+        it 'raises RuntimeError' do
+          expect do
+            subject
+          end.to raise_error(RuntimeError, /Unknown filter: else/)
+        end
+      end
+    end
+
+    context 'params without value' do
+      let(:params) { { hoge: nil } }
+
+      it 'returns ActiveRecord::Relation' do
+        expect(subject).to be_kind_of(ActiveRecord::Relation)
+        expect(subject).to match_array([custom_emoji_0, custom_emoji_1, custom_emoji_2])
+      end
+    end
+  end
+end