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

Fixes admin content creation js response #1316

Merged
merged 2 commits into from
Oct 24, 2017
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions app/views/alchemy/admin/contents/create.js.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
var editor_html = '<%= j(render "alchemy/essences/#{@content.essence_partial_name}_editor", {
content: @content,
options: options_from_params.symbolize_keys,
html_options: @html_options.symbolize_keys
content: @content, options: options_from_params, html_options: @html_options
}) %>';

<% if params[:was_missing] %>
Expand Down
10 changes: 5 additions & 5 deletions config/brakeman.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"check_name": "MassAssignment",
"message": "Parameters should be whitelisted for mass assignment",
"file": "app/controllers/alchemy/admin/resources_controller.rb",
"line": 128,
"line": 130,
"link": "http://brakemanscanner.org/docs/warning_types/mass_assignment/",
"code": "params.require(resource_handler.namespaced_resource_name).permit!",
"render_path": null,
Expand All @@ -23,13 +23,13 @@
{
"warning_type": "Dynamic Render Path",
"warning_code": 15,
"fingerprint": "26461414e9f6be7b68dd8c7dda1c69b09c92a8e9997c0ac204e1756cae7f3d68",
"fingerprint": "79e194e21561d40888d86ebc7fd2ab474fdb0ce32d605dbe9ac6e8984ecc5e92",
"check_name": "Render",
"message": "Render path contains parameter value",
"file": "app/views/alchemy/admin/contents/create.js.erb",
"line": 1,
"link": "http://brakemanscanner.org/docs/warning_types/dynamic_render_path/",
"code": "render(action => \"alchemy/essences/#{Content.create_from_scratch(Element.find(params[:content][:element_id]), content_params).essence_partial_name}_editor\", { :content => Content.create_from_scratch(Element.find(params[:content][:element_id]), content_params), :options => options_from_params.symbolize_keys, :html_options => (params[:html_options] or {}).symbolize_keys })",
"code": "render(action => \"alchemy/essences/#{Content.create_from_scratch(Element.find(params[:content][:element_id]), content_params).essence_partial_name}_editor\", { :content => Content.create_from_scratch(Element.find(params[:content][:element_id]), content_params), :options => options_from_params, :html_options => ((params[:html_options] or {})) })",
"render_path": [{"type":"controller","class":"Alchemy::Admin::ContentsController","method":"create","line":21,"file":"app/controllers/alchemy/admin/contents_controller.rb"}],
"location": {
"type": "template",
Expand Down Expand Up @@ -60,6 +60,6 @@
"note": "`Alchemy::Content` is a polymorphic association of any kind of model extending `Alchemy::Essence`. Since we can't know the attributes of all potential essences we need to permit all attributes. As this all happens inside the password protected /admin namespace this can be considered a false positive."
}
],
"updated": "2017-08-16 15:07:26 +0200",
"brakeman_version": "3.7.0"
"updated": "2017-10-23 11:49:41 +0200",
"brakeman_version": "4.0.1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

module Alchemy
describe Admin::ContentsController do
routes { Alchemy::Engine.routes }

before do
authorize_user(:as_admin)
end
Expand All @@ -14,17 +12,18 @@ module Alchemy

it "creates a content from name" do
expect {
post :create, params: {content: {element_id: element.id, name: 'headline'}}, xhr: true
post admin_contents_path(content: {element_id: element.id, name: 'headline'}, format: :js)
}.to change { Alchemy::Content.count }.by(1)
end

it "creates a content from essence_type" do
expect {
post :create, params: {
post admin_contents_path(
content: {
element_id: element.id, essence_type: 'EssencePicture'
}
}, xhr: true
},
format: :js
)
}.to change { Alchemy::Content.count }.by(1)
end
end
Expand All @@ -40,18 +39,19 @@ module Alchemy
},
options: {
grouped: 'true'
}
},
format: :js
}
end

it "adds it into the gallery editor" do
post :create, params: attributes, xhr: true
post admin_contents_path(attributes)
expect(assigns(:content_dom_id)).to eq("#add_picture_#{element.id}")
end

context 'with picture_id given' do
it "assigns the picture to the essence" do
post :create, params: attributes.merge(picture_id: '1'), xhr: true
post admin_contents_path(attributes.merge(picture_id: '1'))
expect(Alchemy::Content.last.essence.picture_id).to eq(1)
end
end
Expand All @@ -67,7 +67,7 @@ module Alchemy

it "should update a content via ajax" do
expect {
post :update, params: {id: content.id, content: {ingredient: 'Peters Petshop'}}, xhr: true
patch admin_content_path(id: content.id, content: {ingredient: 'Peters Petshop'}, format: :js)
}.to change { content.ingredient }.to 'Peters Petshop'
end
end
Expand All @@ -81,7 +81,7 @@ module Alchemy
let(:content_ids) { element.contents.pluck(:id).shuffle }

it "should reorder the contents" do
post :order, params: {content_ids: content_ids}, xhr: true
post order_admin_contents_path(content_ids: content_ids, format: :js)

expect(response.status).to eq(200)
expect(element.contents.reload.pluck(:id)).to eq(content_ids)
Expand Down