Skip to content

Commit

Permalink
Merge pull request #1846 from resolve/dialog_404s_on_unknown_actions
Browse files Browse the repository at this point in the history
404 on unknown dialog actions.
  • Loading branch information
ugisozols committed Jul 30, 2012
2 parents f98dc3d + 1d3bee2 commit aec35de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
21 changes: 16 additions & 5 deletions core/app/controllers/refinery/admin/dialogs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
module ::Refinery
module Admin
class DialogsController < ::Refinery::AdminController
TYPES = %w[image link]

before_filter :find_dialog_type, :only => [:show]

def index
redirect_to refinery.admin_root_path
end

def show
@dialog_type = params[:id].downcase

url_params = params.reject {|key, value| key =~ /(action)|(controller)/}
url_params = params.reject {|key, value|
/(action)|(controller)/ === key
}.merge(:id => nil)

@iframe_src = if @dialog_type == 'image'
refinery.insert_admin_images_path(url_params.merge(:id => nil, :modal => true))
refinery.insert_admin_images_path url_params.merge(:modal => true)
elsif @dialog_type == 'link'
refinery.link_to_admin_pages_dialogs_path(url_params.merge(:id => nil))
refinery.link_to_admin_pages_dialogs_path url_params
end

render :layout => false
Expand All @@ -23,6 +27,13 @@ def from_dialog?
true
end

protected
def find_dialog_type
error_404 if TYPES.exclude? params[:id].downcase

@dialog_type = params[:id].downcase
end

end
end
end
5 changes: 3 additions & 2 deletions core/spec/requests/refinery/admin/dialogs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ module Refinery
end

context "a" do
it "have empty iframe src" do
it "404s" do
Admin::DialogsController.any_instance.should_receive(:error_404).once

visit refinery.admin_dialog_path('a')
page.should have_selector("iframe[src='']")
end
end
end
Expand Down

0 comments on commit aec35de

Please sign in to comment.