Commit b0c2ddba authored by Albert Yi's avatar Albert Yi

update tests

parent 0e6c3587
......@@ -34,7 +34,6 @@
$dest.empty();
Danbooru.RelatedTag.build_recent_and_frequent($dest);
$dest.append("<em>Loading...</em>");
$("#related-tags-container").show();
$.get("/related_tag.json", {
"query": Danbooru.RelatedTag.current_tag(),
"category": category
......@@ -93,6 +92,9 @@
}
Danbooru.RelatedTag.process_response = function(data) {
if (data.tags.length || data.wiki_page_tags.length || data.other_wikis.length) {
$("#related-tags-container").show();
}
Danbooru.RelatedTag.recent_search = data;
Danbooru.RelatedTag.build_all();
}
......
......@@ -471,9 +471,10 @@ div#c-post-versions, div#c-artist-versions {
div#c-posts, div#c-uploads {
/* Fetch source data box */
div#source-info {
border-radius: 4px;
margin: 1em 0;
padding: 1em;
border: 1px solid gray;
border: 1px solid #666;
p {
margin: 0;
......
@import "../common/000_vars.scss";
div#related-tags-container {
display: none;
padding-right: 2em;
h1 {
......@@ -14,6 +15,7 @@ div.related-tags {
padding: 1em;
background: #EEE;
overflow: auto;
border-radius: 4px;
div.tag-column {
max-width: 15em;
......
......@@ -41,11 +41,18 @@ div#c-uploads {
max-width: 700px;
min-height: 50px;
.placeholder {
font-style: italic;
color: #333;
}
&.error {
border-color: darken(#f2dede, 30%);
background-color: #f2dede;
}
&.success {
border-color: darken(#dff0d8, 30%);
background-color: #dff0d8;
}
}
......
......@@ -302,8 +302,8 @@ class UploadService
end
end
def finish!
pred = self.predecessor()
def finish!(upload = nil)
pred = upload || self.predecessor()
pred.attributes = self.params
pred.status = "completed"
pred.save
......@@ -356,7 +356,7 @@ class UploadService
[td]#{post.md5_was}[/td]
[td]#{post.file_ext_was}[/td]
[td]#{post.image_width_was} x #{post.image_height_was}[/td]
[td]#{post.file_size_was.human_size(precision: 4)}[/td]
[td]#{post.file_size_was.to_s(:human_size, precision: 4)}[/td]
[/tr]
[tr]
[th]New[/th]
......@@ -364,7 +364,7 @@ class UploadService
[td]#{post.md5}[/td]
[td]#{post.file_ext}[/td]
[td]#{post.image_width} x #{post.image_height}[/td]
[td]#{post.file_size.human_size(precision: 4)}[/td]
[td]#{post.file_size.to_s(:human_size, precision: 4)}[/td]
[/tr]
[/tbody]
[/table]
......@@ -384,10 +384,10 @@ class UploadService
end
end
def suggested_tags_for_removal
tags = post.tag_array.select { |tag| Danbooru.config.remove_tag_after_replacement?(tag) }
tags = tags.map { |tag| "-#{tag}" }
tags.join(" ")
def undo!
undo_replacement = post.replacements.create(replacement_url: replacement.original_url)
undoer = Replacer.new(post: post, replacement: undo_replacement)
undoer.process!
end
def process!
......@@ -398,9 +398,9 @@ class UploadService
file: replacement.replacement_file
)
upload = preprocessor.start!(CurrentUser.id)
upload = preprocessor.finish!
upload = preprocessor.finish!(upload)
md5_changed = upload.md5 != post.md5
if replacement.replacement_file.present?
replacement.replacement_url = "file://#{replacement.replacement_file.original_filename}"
elsif upload.downloaded_source.present?
......@@ -422,10 +422,9 @@ class UploadService
post.image_width = upload.image_width
post.image_height = upload.image_height
post.file_size = upload.file_size
post.source = upload.source
post.source = upload.downloaded_source || upload.source
post.tag_string = upload.tag_string
rescale_notes(post)
update_ugoira_frame_data(post, upload)
if md5_changed
......@@ -434,22 +433,38 @@ class UploadService
end
end
if replacement.final_source.present?
post.update(source: replacement.final_source)
end
replacement.save!
post.save!
rescale_notes(post)
end
def rescale_notes(post)
x_scale = post.image_width.to_f / post.image_width_was.to_f
y_scale = post.image_height.to_f / post.image_height_was.to_f
x_scale = post.image_width.to_f / post.image_width_before_last_save.to_f
y_scale = post.image_height.to_f / post.image_height_before_last_save.to_f
post.notes.each do |note|
note.reload
note.rescale!(x_scale, y_scale)
end
end
def update_ugoira_frame_data(post, upload)
post.pixiv_ugoira_frame_data.destroy if post.pixiv_ugoira_frame_data.present?
upload.ugoira_service.save_frame_data(post) if post.is_ugoira?
unless post.is_ugoira?
return
end
PixivUgoiraFrameData.create(
post_id: post.id,
data: upload.context["ugoira"]["frame_data"],
content_type: upload.context["ugoira"]["content_type"]
)
end
end
......
......@@ -1396,7 +1396,8 @@ class Post < ApplicationRecord
def replace!(params)
transaction do
replacement = replacements.create(params)
replacement.process!
processor = UploadService::Replacer.new(post: self, replacement: replacement)
processor.process!
replacement
end
end
......
......@@ -18,43 +18,40 @@ class PostReplacement < ApplicationRecord
self.md5_was = post.md5
end
def undo!
undo_replacement = post.replacements.create(replacement_url: original_url)
undo_replacement.process!
end
concerning :Search do
class_methods do
def post_tags_match(query)
PostQueryBuilder.new(query).build(self.joins(:post))
end
def update_ugoira_frame_data(upload)
post.pixiv_ugoira_frame_data.destroy if post.pixiv_ugoira_frame_data.present?
upload.ugoira_service.save_frame_data(post) if post.is_ugoira?
end
def search(params = {})
q = super
module SearchMethods
def post_tags_match(query)
PostQueryBuilder.new(query).build(self.joins(:post))
end
if params[:creator_id].present?
q = q.where(creator_id: params[:creator_id].split(",").map(&:to_i))
end
def search(params = {})
q = super
if params[:creator_name].present?
q = q.where(creator_id: User.name_to_id(params[:creator_name]))
end
if params[:creator_id].present?
q = q.where(creator_id: params[:creator_id].split(",").map(&:to_i))
end
if params[:post_id].present?
q = q.where(post_id: params[:post_id].split(",").map(&:to_i))
end
if params[:creator_name].present?
q = q.where(creator_id: User.name_to_id(params[:creator_name]))
end
if params[:post_tags_match].present?
q = q.post_tags_match(params[:post_tags_match])
end
if params[:post_id].present?
q = q.where(post_id: params[:post_id].split(",").map(&:to_i))
q.apply_default_order(params)
end
if params[:post_tags_match].present?
q = q.post_tags_match(params[:post_tags_match])
end
q.apply_default_order(params)
end
end
extend SearchMethods
def suggested_tags_for_removal
tags = post.tag_array.select { |tag| Danbooru.config.remove_tag_after_replacement?(tag) }
tags = tags.map { |tag| "-#{tag}" }
tags.join(" ")
end
end
......@@ -111,7 +111,7 @@
<div class="input">
<div>
<%= f.label :tag_string, "Tags" %>
<%= f.text_area :tag_string, :size => "60x5", :data => { :autocomplete => "tag-edit" } %>
<%= f.text_area :tag_string, :size => "60x5", :spellcheck => false, :data => { :autocomplete => "tag-edit" } %>
<span id="open-edit-dialog" class="ui-icon ui-icon-arrow-1-ne" title="detach" style="display: none;"/>
</div>
......
This diff is collapsed.
This diff is collapsed.
......@@ -28,8 +28,7 @@ class PostTest < ActiveSupport::TestCase
context "Deletion:" do
context "Expunging a post" do
setup do
@upload = FactoryBot.create(:jpg_upload)
@upload.process!
@upload = UploadService.new(FactoryBot.attributes_for(:jpg_upload)).start!
@post = @upload.post
Favorite.add(post: @post, user: @user)
end
......@@ -2677,4 +2676,19 @@ class PostTest < ActiveSupport::TestCase
end
end
end
context "#replace!" do
subject { @post.replace!(tags: "something", replacement_url: "https://danbooru.donmai.us/data/preview/download.png") }
setup do
@post = FactoryBot.create(:post)
@post.stubs(:queue_delete_files)
end
should "update the post" do
assert_changes(-> { @post.md5 }) do
subject
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment