Skip to content

Commit

Permalink
Update Admin::ResourceController to overcome respond_to weaknesses by…
Browse files Browse the repository at this point in the history
… choosing HTML format by default.
  • Loading branch information
seancribbs committed Jan 27, 2009
1 parent 9125720 commit 9c8e24b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
13 changes: 8 additions & 5 deletions CHANGELOG
@@ -1,11 +1,14 @@
== Change Log

=== Edge
* Update Admin::ResourceController to overcome respond_to weaknesses by
choosing HTML format by default. [Sean Cribbs]
* Add an IE-specific integration spec. [Jeroen Janssen]
* Update dataset, spec_integration, and vizres plugins. [Sean Cribbs]

=== 0.7.0-RC2
* Make specs and bootstrap work in instance mode. [Sean Cribbs]
* Override spec:integration task and rescope some spec task options to
* Override spec:integration task and rescope some spec task options to
RADIANT_ROOT. [Sean Cribbs]
* Improve rspec-1.1.12 compatibility. [Sean Cribbs]
* Add Ruby 1.8.7 compatibility patch. [Sean Cribbs]
Expand All @@ -20,9 +23,9 @@ RADIANT_ROOT. [Sean Cribbs]
* Fix broken URL in snippets/remove. [Sean Cribbs]
* Correct assume_migrated_upto_version behavior in instance mode. [Sean Cribbs]
* Correct missing @@configuration variable in initializer. [John Muhl]
* Handle SQL special characters in extension names in migrations.
* Handle SQL special characters in extension names in migrations.
[Erik Ostrom]
* Converted extension migrations to use schema_migrations table instead
* Converted extension migrations to use schema_migrations table instead
of extension_meta. [Nathaniel Talbott, Sean Cribbs, Rick DeNatale]
* Replaced scenarios with dataset. [Nathaniel Talbott, Adam Williams, Rick DeNatale]
* Fix RSpec git submodules. [Nathaniel Talbott, Clinton Nixon]
Expand All @@ -40,7 +43,7 @@ on packaged libraries. [Sean Cribbs, Jason Garber]
tracking. [Sean Cribbs]
* Add generator specs and more generators. [Brian Landau]
* Add initial integration specs. [Adam Williams, Mark Imbriaco]
* Refactor admin controllers and views toward RESTful principles.
* Refactor admin controllers and views toward RESTful principles.
[Sean Cribbs, Clinton Nixon, Rick DeNatale]
* Remove RSpec from packaged libraries. [Sean Cribbs]
* Correct CSS validation errors. [John Muhl]
Expand All @@ -67,7 +70,7 @@ tracking. [Sean Cribbs]
* Make Git extension install method recognize submodules. [Sean Cribbs]
* Fix malformed Textile in standard tag descriptions. [Jason Garber]
* Update script/extension help output. [Jim Gay]
* Allow load_subclasses to work when multiple apps are on the same database.
* Allow load_subclasses to work when multiple apps are on the same database.
[Jim Gay]
* Add REXML expansion fix. [Sean Cribbs]
* Fix filter_reference admin helper for filter names that have spaces in
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Expand Up @@ -6,6 +6,7 @@ core:

=== Edge

* Jeroen Janssen
* Sean Cribbs

=== 0.7.0-RC2
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/admin/resource_controller.rb
Expand Up @@ -2,6 +2,7 @@ class Admin::ResourceController < ApplicationController
extend Radiant::ResourceResponses

helper_method :model, :current_object, :models, :current_objects, :model_symbol, :plural_model_symbol, :model_class, :model_name, :plural_model_name
before_filter :populate_format
before_filter :load_models, :only => :index
before_filter :load_model, :only => [:new, :create, :edit, :update, :remove, :destroy]
after_filter :clear_model_cache, :only => [:create, :update, :destroy]
Expand Down Expand Up @@ -170,4 +171,9 @@ def format_symbol
def format
params[:format] || 'html'
end

# Assist with user agents that cause improper content-negotiation
def populate_format
params[:format] ||= 'html' unless request.xhr?
end
end
27 changes: 27 additions & 0 deletions spec/integration/admin/content_negotiation_spec.rb
@@ -0,0 +1,27 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe "Proper content negotiation" do
dataset :pages, :users

before do
Radiant::Config['defaults.page.parts'] = 'body'
login :admin
end

it 'should use a default html format and navigate to the pages when logged in' do
get '/admin/pages', nil, :accept => "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"
response.should be_showing("/admin/pages")
response.should_not have_text(/Missing\ template/)
end

it "should allow the user agent to request a different format via the extension" do
get '/admin/pages.xml', nil, :accept => "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"
response.should have_text(/<\?xml/)
end

it "should not render html format when requesting via Ajax" do
get "/admin/pages/#{page_id(:home)}/children", {'level' => 0}, "X-Requested-With" => "XMLHttpRequest", :accept => "text/javascript, text/html, application/xml, text/xml, */*"
response.should_not have_text(/Radiant CMS/)
response.should have_tag("tr[id$=#{page_id(:another)}]")
end
end
16 changes: 0 additions & 16 deletions spec/integration/admin/ie_spec.rb

This file was deleted.

0 comments on commit 9c8e24b

Please sign in to comment.