Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove to_jq_upload #2931

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions app/controllers/concerns/alchemy/admin/uploader_responses.rb
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ def successful_uploader_response(file:, status: :created)
name: file.name)

{
json: uploader_response(file: file, message: message),
json: {message: message},
status: status
}
end
@@ -23,19 +23,10 @@ def failed_uploader_response(file:)
name: file.name)

{
json: uploader_response(file: file, message: message),
json: {message: message},
status: :unprocessable_entity
}
end

private

def uploader_response(file:, message:)
{
files: [file.to_jq_upload],
message: message
}
end
end
end
end
8 changes: 0 additions & 8 deletions app/models/alchemy/attachment.rb
Original file line number Diff line number Diff line change
@@ -102,14 +102,6 @@ def allowed_filetypes

# Instance methods

def to_jq_upload
{
"name" => read_attribute(:file_name),
"size" => read_attribute(:file_size),
"error" => errors[:file].join
}
end

def url(options = {})
if file
self.class.url_class.new(self).call(options)
10 changes: 0 additions & 10 deletions app/models/alchemy/picture.rb
Original file line number Diff line number Diff line change
@@ -224,16 +224,6 @@ def update_name_and_tag_list!(params)
save!
end

# Returns a Hash suitable for jquery fileupload json.
#
def to_jq_upload
{
name: image_file_name,
size: image_file_size,
error: errors[:image_file].join
}
end

# Returns the picture description for a given language.
def description_for(language)
descriptions.find_by(language: language)&.text
1 change: 0 additions & 1 deletion lib/alchemy/test_support/shared_uploader_examples.rb
Original file line number Diff line number Diff line change
@@ -7,6 +7,5 @@
expect(response.status).to eq(422)
json = JSON.parse(response.body)
expect(json).to have_key("message")
expect(json).to have_key("files")
end
end
Original file line number Diff line number Diff line change
@@ -88,7 +88,6 @@ module Alchemy
expect(response.status).to eq(201)
json = JSON.parse(response.body)
expect(json).to have_key("message")
expect(json).to have_key("files")
end
end

@@ -135,7 +134,6 @@ module Alchemy
expect(response.status).to eq(202)
json = JSON.parse(response.body)
expect(json).to have_key("message")
expect(json).to have_key("files")
end

it "replaces the file" do
Original file line number Diff line number Diff line change
@@ -134,7 +134,7 @@ module Alchemy
subject { post :create, params: params }

let(:params) { {picture: {name: ""}} }
let(:picture) { mock_model("Picture", humanized_name: "Cute kittens", to_jq_upload: {}) }
let(:picture) { mock_model("Picture", humanized_name: "Cute kittens") }

context "with passing validations" do
before do
@@ -150,7 +150,6 @@ module Alchemy
expect(response.status).to eq(201)
json = JSON.parse(response.body)
expect(json).to have_key("message")
expect(json).to have_key("files")
end
end

25 changes: 0 additions & 25 deletions spec/models/alchemy/picture_spec.rb
Original file line number Diff line number Diff line change
@@ -396,31 +396,6 @@ module Alchemy
end
end

describe "#to_jq_upload" do
subject { picture.to_jq_upload }

let(:picture) { build_stubbed(:alchemy_picture, image_file_name: "cute-kittens.jpg", image_file_size: 1024) }

it "returns a hash containing data for jquery fileuploader" do
is_expected.to be_an_instance_of(Hash)
is_expected.to include(name: picture.image_file_name)
is_expected.to include(size: picture.image_file_size)
end

context "with error" do
let(:picture) { build_stubbed(:alchemy_picture) }

before do
expect(picture).to receive(:errors).and_return({image_file: %w[stupid_cats]})
end

it "returns hash with error message" do
is_expected.to be_an_instance_of(Hash)
is_expected.to include(error: "stupid_cats")
end
end
end

describe "#restricted?" do
subject { picture.restricted? }