/post_replacements: allow updating image metadata in past replacements.
This commit is contained in:
@@ -14,6 +14,13 @@ class PostReplacementsController < ApplicationController
|
|||||||
respond_with(@post_replacement, location: @post)
|
respond_with(@post_replacement, location: @post)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@post_replacement = PostReplacement.find(params[:id])
|
||||||
|
@post_replacement.update(update_params)
|
||||||
|
|
||||||
|
respond_with(@post_replacement)
|
||||||
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
params[:search][:post_id] = params.delete(:post_id) if params.has_key?(:post_id)
|
params[:search][:post_id] = params.delete(:post_id) if params.has_key?(:post_id)
|
||||||
@post_replacements = PostReplacement.search(params[:search]).paginate(params[:page], limit: params[:limit])
|
@post_replacements = PostReplacement.search(params[:search]).paginate(params[:page], limit: params[:limit])
|
||||||
@@ -25,4 +32,12 @@ private
|
|||||||
def create_params
|
def create_params
|
||||||
params.require(:post_replacement).permit(:replacement_url, :replacement_file, :final_source, :tags)
|
params.require(:post_replacement).permit(:replacement_url, :replacement_file, :final_source, :tags)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_params
|
||||||
|
params.require(:post_replacement).permit(
|
||||||
|
:file_ext_was, :file_size_was, :image_width_was, :image_height_was, :md5_was,
|
||||||
|
:file_ext, :file_size, :image_width, :image_height, :md5,
|
||||||
|
:original_url, :replacement_url
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ Rails.application.routes.draw do
|
|||||||
get :diff
|
get :diff
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :post_replacements, :only => [:index, :new, :create]
|
resources :post_replacements, :only => [:index, :new, :create, :update]
|
||||||
resources :posts do
|
resources :posts do
|
||||||
resources :events, :only => [:index], :controller => "post_events"
|
resources :events, :only => [:index], :controller => "post_events"
|
||||||
resources :replacements, :only => [:index, :new, :create], :controller => "post_replacements"
|
resources :replacements, :only => [:index, :new, :create], :controller => "post_replacements"
|
||||||
|
|||||||
@@ -43,6 +43,25 @@ class PostReplacementsControllerTest < ActionController::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "update action" do
|
||||||
|
should "update the replacement" do
|
||||||
|
params = {
|
||||||
|
format: :json,
|
||||||
|
id: @post_replacement.id,
|
||||||
|
post_replacement: {
|
||||||
|
file_size_was: 23,
|
||||||
|
file_size: 42,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
put :update, params, { user_id: @user.id }
|
||||||
|
@post_replacement.reload
|
||||||
|
|
||||||
|
assert_equal(23, @post_replacement.file_size_was)
|
||||||
|
assert_equal(42, @post_replacement.file_size)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "index action" do
|
context "index action" do
|
||||||
should "render" do
|
should "render" do
|
||||||
get :index, {format: :json}
|
get :index, {format: :json}
|
||||||
|
|||||||
Reference in New Issue
Block a user