From 4552685f6bd400666ec4058783eeabb11568e575 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Sun, 19 Feb 2023 23:24:14 -0500 Subject: Autofix Rubocop RSpec/LeadingSubject (#23670) --- spec/serializers/activitypub/note_spec.rb | 4 ++-- spec/serializers/activitypub/update_poll_spec.rb | 4 ++-- spec/serializers/rest/account_serializer_spec.rb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'spec/serializers') diff --git a/spec/serializers/activitypub/note_spec.rb b/spec/serializers/activitypub/note_spec.rb index 55bfbc16b..7ea47baef 100644 --- a/spec/serializers/activitypub/note_spec.rb +++ b/spec/serializers/activitypub/note_spec.rb @@ -3,6 +3,8 @@ require 'rails_helper' describe ActivityPub::NoteSerializer do + subject { JSON.parse(@serialization.to_json) } + let!(:account) { Fabricate(:account) } let!(:other) { Fabricate(:account) } let!(:parent) { Fabricate(:status, account: account, visibility: :public) } @@ -16,8 +18,6 @@ describe ActivityPub::NoteSerializer do @serialization = ActiveModelSerializers::SerializableResource.new(parent, serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter) end - subject { JSON.parse(@serialization.to_json) } - it 'has a Note type' do expect(subject['type']).to eql('Note') end diff --git a/spec/serializers/activitypub/update_poll_spec.rb b/spec/serializers/activitypub/update_poll_spec.rb index f9e035eab..4360808b5 100644 --- a/spec/serializers/activitypub/update_poll_spec.rb +++ b/spec/serializers/activitypub/update_poll_spec.rb @@ -3,6 +3,8 @@ require 'rails_helper' describe ActivityPub::UpdatePollSerializer do + subject { JSON.parse(@serialization.to_json) } + let(:account) { Fabricate(:account) } let(:poll) { Fabricate(:poll, account: account) } let!(:status) { Fabricate(:status, account: account, poll: poll) } @@ -11,8 +13,6 @@ describe ActivityPub::UpdatePollSerializer do @serialization = ActiveModelSerializers::SerializableResource.new(status, serializer: ActivityPub::UpdatePollSerializer, adapter: ActivityPub::Adapter) end - subject { JSON.parse(@serialization.to_json) } - it 'has a Update type' do expect(subject['type']).to eql('Update') end diff --git a/spec/serializers/rest/account_serializer_spec.rb b/spec/serializers/rest/account_serializer_spec.rb index 3bca06b73..528639943 100644 --- a/spec/serializers/rest/account_serializer_spec.rb +++ b/spec/serializers/rest/account_serializer_spec.rb @@ -3,12 +3,12 @@ require 'rails_helper' describe REST::AccountSerializer do + subject { JSON.parse(ActiveModelSerializers::SerializableResource.new(account, serializer: REST::AccountSerializer).to_json) } + let(:role) { Fabricate(:user_role, name: 'Role', highlighted: true) } let(:user) { Fabricate(:user, role: role) } let(:account) { user.account } - subject { JSON.parse(ActiveModelSerializers::SerializableResource.new(account, serializer: REST::AccountSerializer).to_json) } - context 'when the account is suspended' do before do account.suspend! -- cgit From 19614ba2477f3d12468f5ec251ce1cc5f8c6210c Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Thu, 23 Feb 2023 17:17:48 -0500 Subject: Rename ActivityPub Serializer Specs (#23844) --- .rubocop_todo.yml | 20 +++++----- .../activitypub/note_serializer_spec.rb | 44 ++++++++++++++++++++++ spec/serializers/activitypub/note_spec.rb | 44 ---------------------- .../activitypub/update_poll_serializer_spec.rb | 27 +++++++++++++ spec/serializers/activitypub/update_poll_spec.rb | 27 ------------- 5 files changed, 81 insertions(+), 81 deletions(-) create mode 100644 spec/serializers/activitypub/note_serializer_spec.rb delete mode 100644 spec/serializers/activitypub/note_spec.rb create mode 100644 spec/serializers/activitypub/update_poll_serializer_spec.rb delete mode 100644 spec/serializers/activitypub/update_poll_spec.rb (limited to 'spec/serializers') diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8d546ff42..6b2369fd4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -557,8 +557,8 @@ RSpec/DescribedClass: - 'spec/presenters/account_relationships_presenter_spec.rb' - 'spec/presenters/instance_presenter_spec.rb' - 'spec/presenters/status_relationships_presenter_spec.rb' - - 'spec/serializers/activitypub/note_spec.rb' - - 'spec/serializers/activitypub/update_poll_spec.rb' + - 'spec/serializers/activitypub/note_serializer_spec.rb' + - 'spec/serializers/activitypub/update_poll_serializer_spec.rb' - 'spec/serializers/rest/account_serializer_spec.rb' - 'spec/services/activitypub/fetch_remote_account_service_spec.rb' - 'spec/services/activitypub/fetch_remote_actor_service_spec.rb' @@ -698,8 +698,8 @@ RSpec/FilePath: - 'spec/lib/activitypub/tag_manager_spec.rb' - 'spec/lib/ostatus/tag_manager_spec.rb' - 'spec/lib/sanitize_config_spec.rb' - - 'spec/serializers/activitypub/note_spec.rb' - - 'spec/serializers/activitypub/update_poll_spec.rb' + - 'spec/serializers/activitypub/note_serializer_spec.rb' + - 'spec/serializers/activitypub/update_poll_serializer_spec.rb' - 'spec/services/activitypub/fetch_featured_collection_service_spec.rb' - 'spec/services/activitypub/fetch_featured_tags_collection_service_spec.rb' - 'spec/services/activitypub/fetch_remote_account_service_spec.rb' @@ -733,8 +733,8 @@ RSpec/HookArgument: - 'spec/helpers/instance_helper_spec.rb' - 'spec/models/user_spec.rb' - 'spec/rails_helper.rb' - - 'spec/serializers/activitypub/note_spec.rb' - - 'spec/serializers/activitypub/update_poll_spec.rb' + - 'spec/serializers/activitypub/note_serializer_spec.rb' + - 'spec/serializers/activitypub/update_poll_serializer_spec.rb' - 'spec/services/import_service_spec.rb' - 'spec/spec_helper.rb' @@ -755,8 +755,8 @@ RSpec/InstanceVariable: - 'spec/models/concerns/account_interactions_spec.rb' - 'spec/models/concerns/remotable_spec.rb' - 'spec/models/public_feed_spec.rb' - - 'spec/serializers/activitypub/note_spec.rb' - - 'spec/serializers/activitypub/update_poll_spec.rb' + - 'spec/serializers/activitypub/note_serializer_spec.rb' + - 'spec/serializers/activitypub/update_poll_serializer_spec.rb' - 'spec/services/remove_status_service_spec.rb' - 'spec/services/search_service_spec.rb' - 'spec/services/unblock_domain_service_spec.rb' @@ -1022,8 +1022,8 @@ RSpec/NamedSubject: - 'spec/policies/tag_policy_spec.rb' - 'spec/policies/user_policy_spec.rb' - 'spec/presenters/familiar_followers_presenter_spec.rb' - - 'spec/serializers/activitypub/note_spec.rb' - - 'spec/serializers/activitypub/update_poll_spec.rb' + - 'spec/serializers/activitypub/note_serializer_spec.rb' + - 'spec/serializers/activitypub/update_poll_serializer_spec.rb' - 'spec/serializers/rest/account_serializer_spec.rb' - 'spec/services/account_search_service_spec.rb' - 'spec/services/account_statuses_cleanup_service_spec.rb' diff --git a/spec/serializers/activitypub/note_serializer_spec.rb b/spec/serializers/activitypub/note_serializer_spec.rb new file mode 100644 index 000000000..7ea47baef --- /dev/null +++ b/spec/serializers/activitypub/note_serializer_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe ActivityPub::NoteSerializer do + subject { JSON.parse(@serialization.to_json) } + + let!(:account) { Fabricate(:account) } + let!(:other) { Fabricate(:account) } + let!(:parent) { Fabricate(:status, account: account, visibility: :public) } + let!(:reply1) { Fabricate(:status, account: account, thread: parent, visibility: :public) } + let!(:reply2) { Fabricate(:status, account: account, thread: parent, visibility: :public) } + let!(:reply3) { Fabricate(:status, account: other, thread: parent, visibility: :public) } + let!(:reply4) { Fabricate(:status, account: account, thread: parent, visibility: :public) } + let!(:reply5) { Fabricate(:status, account: account, thread: parent, visibility: :direct) } + + before(:each) do + @serialization = ActiveModelSerializers::SerializableResource.new(parent, serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter) + end + + it 'has a Note type' do + expect(subject['type']).to eql('Note') + end + + it 'has a replies collection' do + expect(subject['replies']['type']).to eql('Collection') + end + + it 'has a replies collection with a first Page' do + expect(subject['replies']['first']['type']).to eql('CollectionPage') + end + + it 'includes public self-replies in its replies collection' do + expect(subject['replies']['first']['items']).to include(reply1.uri, reply2.uri, reply4.uri) + end + + it 'does not include replies from others in its replies collection' do + expect(subject['replies']['first']['items']).to_not include(reply3.uri) + end + + it 'does not include replies with direct visibility in its replies collection' do + expect(subject['replies']['first']['items']).to_not include(reply5.uri) + end +end diff --git a/spec/serializers/activitypub/note_spec.rb b/spec/serializers/activitypub/note_spec.rb deleted file mode 100644 index 7ea47baef..000000000 --- a/spec/serializers/activitypub/note_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe ActivityPub::NoteSerializer do - subject { JSON.parse(@serialization.to_json) } - - let!(:account) { Fabricate(:account) } - let!(:other) { Fabricate(:account) } - let!(:parent) { Fabricate(:status, account: account, visibility: :public) } - let!(:reply1) { Fabricate(:status, account: account, thread: parent, visibility: :public) } - let!(:reply2) { Fabricate(:status, account: account, thread: parent, visibility: :public) } - let!(:reply3) { Fabricate(:status, account: other, thread: parent, visibility: :public) } - let!(:reply4) { Fabricate(:status, account: account, thread: parent, visibility: :public) } - let!(:reply5) { Fabricate(:status, account: account, thread: parent, visibility: :direct) } - - before(:each) do - @serialization = ActiveModelSerializers::SerializableResource.new(parent, serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter) - end - - it 'has a Note type' do - expect(subject['type']).to eql('Note') - end - - it 'has a replies collection' do - expect(subject['replies']['type']).to eql('Collection') - end - - it 'has a replies collection with a first Page' do - expect(subject['replies']['first']['type']).to eql('CollectionPage') - end - - it 'includes public self-replies in its replies collection' do - expect(subject['replies']['first']['items']).to include(reply1.uri, reply2.uri, reply4.uri) - end - - it 'does not include replies from others in its replies collection' do - expect(subject['replies']['first']['items']).to_not include(reply3.uri) - end - - it 'does not include replies with direct visibility in its replies collection' do - expect(subject['replies']['first']['items']).to_not include(reply5.uri) - end -end diff --git a/spec/serializers/activitypub/update_poll_serializer_spec.rb b/spec/serializers/activitypub/update_poll_serializer_spec.rb new file mode 100644 index 000000000..4360808b5 --- /dev/null +++ b/spec/serializers/activitypub/update_poll_serializer_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe ActivityPub::UpdatePollSerializer do + subject { JSON.parse(@serialization.to_json) } + + let(:account) { Fabricate(:account) } + let(:poll) { Fabricate(:poll, account: account) } + let!(:status) { Fabricate(:status, account: account, poll: poll) } + + before(:each) do + @serialization = ActiveModelSerializers::SerializableResource.new(status, serializer: ActivityPub::UpdatePollSerializer, adapter: ActivityPub::Adapter) + end + + it 'has a Update type' do + expect(subject['type']).to eql('Update') + end + + it 'has an object with Question type' do + expect(subject['object']['type']).to eql('Question') + end + + it 'has the correct actor URI set' do + expect(subject['actor']).to eql(ActivityPub::TagManager.instance.uri_for(account)) + end +end diff --git a/spec/serializers/activitypub/update_poll_spec.rb b/spec/serializers/activitypub/update_poll_spec.rb deleted file mode 100644 index 4360808b5..000000000 --- a/spec/serializers/activitypub/update_poll_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe ActivityPub::UpdatePollSerializer do - subject { JSON.parse(@serialization.to_json) } - - let(:account) { Fabricate(:account) } - let(:poll) { Fabricate(:poll, account: account) } - let!(:status) { Fabricate(:status, account: account, poll: poll) } - - before(:each) do - @serialization = ActiveModelSerializers::SerializableResource.new(status, serializer: ActivityPub::UpdatePollSerializer, adapter: ActivityPub::Adapter) - end - - it 'has a Update type' do - expect(subject['type']).to eql('Update') - end - - it 'has an object with Question type' do - expect(subject['object']['type']).to eql('Question') - end - - it 'has the correct actor URI set' do - expect(subject['actor']).to eql(ActivityPub::TagManager.instance.uri_for(account)) - end -end -- cgit