about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api/v1/accounts_controller_spec.rb38
-rw-r--r--spec/controllers/api/v1/mutes_controller_spec.rb19
-rw-r--r--spec/fabricators/mute_fabricator.rb3
-rw-r--r--spec/mailers/previews/notification_mailer_preview.rb17
-rw-r--r--spec/models/account_spec.rb9
-rw-r--r--spec/models/mute_spec.rb5
-rw-r--r--spec/models/tag_spec.rb10
-rw-r--r--spec/services/mute_service_spec.rb5
-rw-r--r--spec/services/unmute_service_spec.rb5
9 files changed, 105 insertions, 6 deletions
diff --git a/spec/controllers/api/v1/accounts_controller_spec.rb b/spec/controllers/api/v1/accounts_controller_spec.rb
index 98b284f7a..5d36b0159 100644
--- a/spec/controllers/api/v1/accounts_controller_spec.rb
+++ b/spec/controllers/api/v1/accounts_controller_spec.rb
@@ -116,6 +116,44 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
     end
   end
 
+  describe 'POST #mute' do
+    let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
+
+    before do
+      user.account.follow!(other_account)
+      post :mute, params: {id: other_account.id }
+    end
+
+    it 'returns http success' do
+      expect(response).to have_http_status(:success)
+    end
+
+    it 'does not remove the following relation between user and target user' do
+      expect(user.account.following?(other_account)).to be true
+    end
+
+    it 'creates a muting relation' do
+      expect(user.account.muting?(other_account)).to be true
+    end
+  end
+
+  describe 'POST #unmute' do
+    let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
+
+    before do
+      user.account.mute!(other_account)
+      post :unmute, params: { id: other_account.id }
+    end
+
+    it 'returns http success' do
+      expect(response).to have_http_status(:success)
+    end
+
+    it 'removes the muting relation between user and target user' do
+      expect(user.account.muting?(other_account)).to be false
+    end
+  end
+
   describe 'GET #relationships' do
     let(:simon) { Fabricate(:user, email: 'simon@example.com', account: Fabricate(:account, username: 'simon')).account }
     let(:lewis) { Fabricate(:user, email: 'lewis@example.com', account: Fabricate(:account, username: 'lewis')).account }
diff --git a/spec/controllers/api/v1/mutes_controller_spec.rb b/spec/controllers/api/v1/mutes_controller_spec.rb
new file mode 100644
index 000000000..be8a5e7dd
--- /dev/null
+++ b/spec/controllers/api/v1/mutes_controller_spec.rb
@@ -0,0 +1,19 @@
+require 'rails_helper'
+
+RSpec.describe Api::V1::MutesController, type: :controller do
+  render_views
+
+  let(:user)  { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
+  let(:token) { double acceptable?: true, resource_owner_id: user.id }
+
+  before do
+    allow(controller).to receive(:doorkeeper_token) { token }
+  end
+
+  describe 'GET #index' do
+    it 'returns http success' do
+      get :index
+      expect(response).to have_http_status(:success)
+    end
+  end
+end
diff --git a/spec/fabricators/mute_fabricator.rb b/spec/fabricators/mute_fabricator.rb
new file mode 100644
index 000000000..fc150c1d6
--- /dev/null
+++ b/spec/fabricators/mute_fabricator.rb
@@ -0,0 +1,3 @@
+Fabricator(:mute) do
+
+end
diff --git a/spec/mailers/previews/notification_mailer_preview.rb b/spec/mailers/previews/notification_mailer_preview.rb
index 8fc8d0d34..a08a80d17 100644
--- a/spec/mailers/previews/notification_mailer_preview.rb
+++ b/spec/mailers/previews/notification_mailer_preview.rb
@@ -1,24 +1,31 @@
 # Preview all emails at http://localhost:3000/rails/mailers/notification_mailer
 class NotificationMailerPreview < ActionMailer::Preview
-
   # Preview this email at http://localhost:3000/rails/mailers/notification_mailer/mention
   def mention
-    # NotificationMailer.mention
+    m = Mention.last
+    NotificationMailer.mention(m.account, Notification.find_by(activity: m))
   end
 
   # Preview this email at http://localhost:3000/rails/mailers/notification_mailer/follow
   def follow
-    # NotificationMailer.follow
+    f = Follow.last
+    NotificationMailer.follow(f.target_account, Notification.find_by(activity: f))
   end
 
   # Preview this email at http://localhost:3000/rails/mailers/notification_mailer/favourite
   def favourite
-    # NotificationMailer.favourite
+    f = Favourite.last
+    NotificationMailer.favourite(f.status.account, Notification.find_by(activity: f))
   end
 
   # Preview this email at http://localhost:3000/rails/mailers/notification_mailer/reblog
   def reblog
-    # NotificationMailer.reblog
+    r = Status.where.not(reblog_of_id: nil).first
+    NotificationMailer.reblog(r.reblog.account, Notification.find_by(activity: r))
   end
 
+  # Preview this email at http://localhost:3000/rails/mailers/notification_mailer/digest
+  def digest
+    NotificationMailer.digest(Account.first, since: 90.days.ago)
+  end
 end
diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb
index 287f389ac..91c8d75cf 100644
--- a/spec/models/account_spec.rb
+++ b/spec/models/account_spec.rb
@@ -178,7 +178,6 @@ RSpec.describe Account, type: :model do
     end
   end
 
-
   describe 'MENTION_RE' do
     subject { Account::MENTION_RE }
 
@@ -190,6 +189,14 @@ RSpec.describe Account, type: :model do
       expect(subject.match('@alice Hey how are you?')[1]).to eq 'alice'
     end
 
+    it 'matches full usernames' do
+      expect(subject.match('@alice@example.com')[1]).to eq 'alice@example.com'
+    end
+
+    it 'matches full usernames with a dot at the end' do
+      expect(subject.match('Hello @alice@example.com.')[1]).to eq 'alice@example.com'
+    end
+
     it 'matches dot-prepended usernames' do
       expect(subject.match('.@alice I want everybody to see this')[1]).to eq 'alice'
     end
diff --git a/spec/models/mute_spec.rb b/spec/models/mute_spec.rb
new file mode 100644
index 000000000..83ba793b2
--- /dev/null
+++ b/spec/models/mute_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe Mute, type: :model do
+
+end
diff --git a/spec/models/tag_spec.rb b/spec/models/tag_spec.rb
index 9a7f481e4..360bbc16d 100644
--- a/spec/models/tag_spec.rb
+++ b/spec/models/tag_spec.rb
@@ -1,5 +1,15 @@
 require 'rails_helper'
 
 RSpec.describe Tag, type: :model do
+  describe 'HASHTAG_RE' do
+    subject { Tag::HASHTAG_RE }
 
+    it 'does not match URLs with anchors with non-hashtag characters' do
+      expect(subject.match('Check this out https://medium.com/@alice/some-article#.abcdef123')).to be_nil
+    end
+
+    it 'does not match URLs with hashtag-like anchors' do
+      expect(subject.match('https://en.wikipedia.org/wiki/Ghostbusters_(song)#Lawsuit')).to be_nil
+    end
+  end
 end
diff --git a/spec/services/mute_service_spec.rb b/spec/services/mute_service_spec.rb
new file mode 100644
index 000000000..397368416
--- /dev/null
+++ b/spec/services/mute_service_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe MuteService do
+  subject { MuteService.new }
+end
diff --git a/spec/services/unmute_service_spec.rb b/spec/services/unmute_service_spec.rb
new file mode 100644
index 000000000..5dc971fb1
--- /dev/null
+++ b/spec/services/unmute_service_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe UnmuteService do
+  subject { UnmuteService.new }
+end