Skip to content

Commit f7169a8

Browse files
committed
chore: Add UNPROCESSABLE_STATUS constant
Replace inline unprocessable method with UNPROCESSABLE_STATUS constant.
1 parent b22249e commit f7169a8

3 files changed

Lines changed: 12 additions & 16 deletions

File tree

app/controllers/active_storage_db/files_controller.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ def show
1717
def update
1818
if (token = decode_verified_token)
1919
file_uploaded = upload_file(token)
20-
head(file_uploaded ? :no_content : unprocessable)
20+
head(file_uploaded ? :no_content : ActiveStorageDB::UNPROCESSABLE_STATUS)
2121
else
2222
head(:not_found)
2323
end
2424
rescue ActiveStorage::IntegrityError
25-
head(unprocessable)
25+
head(ActiveStorageDB::UNPROCESSABLE_STATUS)
2626
end
2727

2828
private
@@ -60,13 +60,5 @@ def upload_file(token) # rubocop:disable Naming/PredicateMethod
6060
db_service.upload(token[:key], request.body, checksum: token[:checksum])
6161
true
6262
end
63-
64-
def unprocessable
65-
if Rails::VERSION::MAJOR > 7 || (Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR >= 1)
66-
:unprocessable_content
67-
else
68-
:unprocessable_entity
69-
end
70-
end
7163
end
7264
end

lib/active_storage_db/engine.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# frozen_string_literal: true
22

33
module ActiveStorageDB
4+
# :nocov:
5+
UNPROCESSABLE_STATUS = if Rails::VERSION::MAJOR > 7 || (Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR >= 1)
6+
:unprocessable_content
7+
else
8+
:unprocessable_entity
9+
end
10+
# :nocov:
11+
412
class Engine < ::Rails::Engine
513
isolate_namespace ActiveStorageDB
614
end

spec/dummy/app/controllers/posts_controller.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def create
3232
format.json { render :show, status: :created, location: @post }
3333
else
3434
format.html { render :new }
35-
format.json { render json: { errors: @post.errors }, status: unprocessable }
35+
format.json { render json: { errors: @post.errors }, status: ActiveStorageDB::UNPROCESSABLE_STATUS }
3636
end
3737
end
3838
end
@@ -46,7 +46,7 @@ def update
4646
format.json { render :show, status: :ok, location: @post }
4747
else
4848
format.html { render :edit }
49-
format.json { render json: { errors: @post.errors }, status: unprocessable }
49+
format.json { render json: { errors: @post.errors }, status: ActiveStorageDB::UNPROCESSABLE_STATUS }
5050
end
5151
end
5252
end
@@ -70,8 +70,4 @@ def load_post
7070
def post_params
7171
params.fetch(:post) { {} }.permit!
7272
end
73-
74-
def unprocessable
75-
Rails::VERSION::MAJOR > 7 || (Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR >= 1) ? :unprocessable_content : :unprocessable_entity
76-
end
7773
end

0 commit comments

Comments
 (0)