diff --git a/app/services/status_message_creation_service.rb b/app/services/status_message_creation_service.rb index a0601d07b..c35a7176d 100644 --- a/app/services/status_message_creation_service.rb +++ b/app/services/status_message_creation_service.rb @@ -72,4 +72,7 @@ class StatusMessageCreationService url: short_post_url(status_message.guid, host: AppConfig.environment.url), service_types: receiving_services) end + + class BadAspectsIDs < RuntimeError + end end diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index c954ce4c6..d38c12289 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -132,6 +132,12 @@ describe StatusMessagesController, :type => :controller do status_message = StatusMessage.find_by_text(text) expect(status_message.aspect_visibilities.map(&:aspect)).to match_array([@aspect1, @aspect2]) end + + it "responses 422 when aspect_ids don't contain any applicable aspect identifiers" do + bad_ids = [Aspect.ids.max.next, bob.aspects.first.id] + post :create, params: status_message_hash.merge(aspect_ids: bad_ids.to_s), format: :json + expect(response.status).to eq(422) + end end it "dispatches the post to the specified services" do diff --git a/spec/services/status_message_creation_service_spec.rb b/spec/services/status_message_creation_service_spec.rb index a7b9f05c3..aaca06da3 100644 --- a/spec/services/status_message_creation_service_spec.rb +++ b/spec/services/status_message_creation_service_spec.rb @@ -29,6 +29,13 @@ describe StatusMessageCreationService do status_message = StatusMessageCreationService.new(alice).create(params.merge(public: true)) expect(status_message.aspect_visibilities).to be_empty end + + it "raises exception if aspects_ids don't contain any applicable aspect identifiers" do + bad_ids = [Aspect.ids.max.next, bob.aspects.first.id].map(&:to_s) + expect { + StatusMessageCreationService.new(alice).create(params.merge(aspect_ids: bad_ids)) + }.to remain(StatusMessage, :count).and raise_error(StatusMessageCreationService::BadAspectsIDs) + end end context "with public" do diff --git a/spec/shared_behaviors/account_deletion.rb b/spec/shared_behaviors/account_deletion.rb index d4019937a..25ce9a6d9 100644 --- a/spec/shared_behaviors/account_deletion.rb +++ b/spec/shared_behaviors/account_deletion.rb @@ -44,8 +44,6 @@ shared_examples_for "it removes the person associations" do end shared_examples_for "it keeps the person conversations" do - RSpec::Matchers.define_negated_matcher :remain, :change - it "remains the person conversations" do expect { account_removal_method diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8cb7fa13b..cb810e975 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,6 +24,8 @@ Dir["#{File.dirname(__FILE__)}/shared_behaviors/**/*.rb"].each do |f| require f end +RSpec::Matchers.define_negated_matcher :remain, :change + ProcessedImage.enable_processing = false UnprocessedImage.enable_processing = false