Browse Source

Fix irreversible and whole_word parameters handling in /api/v1/filters (#21988)

Fixes #21965
closed-social-glitch-2
Claire 1 year ago
committed by GitHub
parent
commit
69137f4a90
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 7 deletions
  1. +3
    -3
      app/controllers/api/v1/filters_controller.rb
  2. +1
    -1
      app/models/custom_filter.rb
  3. +23
    -3
      spec/controllers/api/v1/filters_controller_spec.rb

+ 3
- 3
app/controllers/api/v1/filters_controller.rb View File

@ -13,7 +13,7 @@ class Api::V1::FiltersController < Api::BaseController
def create
ApplicationRecord.transaction do
filter_category = current_account.custom_filters.create!(resource_params)
filter_category = current_account.custom_filters.create!(filter_params)
@filter = filter_category.keywords.create!(keyword_params)
end
@ -52,11 +52,11 @@ class Api::V1::FiltersController < Api::BaseController
end
def resource_params
params.permit(:phrase, :expires_in, :irreversible, context: [])
params.permit(:phrase, :expires_in, :irreversible, :whole_word, context: [])
end
def filter_params
resource_params.slice(:expires_in, :irreversible, :context)
resource_params.slice(:phrase, :expires_in, :irreversible, :context)
end
def keyword_params

+ 1
- 1
app/models/custom_filter.rb View File

@ -54,7 +54,7 @@ class CustomFilter < ApplicationRecord
end
def irreversible=(value)
self.action = value ? :hide : :warn
self.action = ActiveModel::Type::Boolean.new.cast(value) ? :hide : :warn
end
def irreversible?

+ 23
- 3
spec/controllers/api/v1/filters_controller_spec.rb View File

@ -22,9 +22,11 @@ RSpec.describe Api::V1::FiltersController, type: :controller do
describe 'POST #create' do
let(:scopes) { 'write:filters' }
let(:irreversible) { true }
let(:whole_word) { false }
before do
post :create, params: { phrase: 'magic', context: %w(home), irreversible: true }
post :create, params: { phrase: 'magic', context: %w(home), irreversible: irreversible, whole_word: whole_word }
end
it 'returns http success' do
@ -34,11 +36,29 @@ RSpec.describe Api::V1::FiltersController, type: :controller do
it 'creates a filter' do
filter = user.account.custom_filters.first
expect(filter).to_not be_nil
expect(filter.keywords.pluck(:keyword)).to eq ['magic']
expect(filter.keywords.pluck(:keyword, :whole_word)).to eq [['magic', whole_word]]
expect(filter.context).to eq %w(home)
expect(filter.irreversible?).to be true
expect(filter.irreversible?).to be irreversible
expect(filter.expires_at).to be_nil
end
context 'with different parameters' do
let(:irreversible) { false }
let(:whole_word) { true }
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'creates a filter' do
filter = user.account.custom_filters.first
expect(filter).to_not be_nil
expect(filter.keywords.pluck(:keyword, :whole_word)).to eq [['magic', whole_word]]
expect(filter.context).to eq %w(home)
expect(filter.irreversible?).to be irreversible
expect(filter.expires_at).to be_nil
end
end
end
describe 'GET #show' do

Loading…
Cancel
Save