Skip to content

Commit

Permalink
Specify search layout for export email controller, provide a DRY meth…
Browse files Browse the repository at this point in the history
…od for getting search layout except on XHR and include test case for export email controller.
  • Loading branch information
scotdalton committed Jan 24, 2013
1 parent 8986bb9 commit dfd40f1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
14 changes: 1 addition & 13 deletions app/controllers/export_email_controller.rb
@@ -1,25 +1,13 @@
class ExportEmailController < UmlautController

before_filter :load_objects
layout Proc.new { |controller|
if (controller.request.xhr? || controller.params["X-Requested-With"] == "XmlHttpRequest")
nil
else
umlaut_config.layout
end
}
layout :search_layout_except_xhr

def load_objects
@svc_response = ServiceResponse.find(params[:id])
@user_request = @svc_response.request if @svc_response
end

def email
end

def txt
end

def send_email
@email = params[:email]
@fulltexts = @user_request.get_service_type('fulltext', { :refresh=>true })
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/umlaut/controller_behavior.rb
Expand Up @@ -18,6 +18,12 @@ module Umlaut::ControllerBehavior

protected

# Returns the search layout name unless this is an XML HTTP Request.
def search_layout_except_xhr
@layout_name ||= (request.xhr? || params["X-Requested-With"] == "XmlHttpRequest") ?
nil : umlaut_config.search_layout
end

# Returns a Collection object with currently configured services.
# Loads from Rails.root/config/umlaut_services.yml
#
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/service_responses.yml
Expand Up @@ -37,6 +37,15 @@ service_response3:
---
:link_supports_ajax_call: true
service_response9:
service_id: TxtHoldingExport
display_text: Send to phone
request_id: 80
service_type_value_name: export_citation
service_data: |
---
:link_supports_ajax_call: true
service_response4:
service_id: SFX
display_text: EBSCOhost Newspaper Source Plus
Expand Down
25 changes: 25 additions & 0 deletions test/functional/export_email_controller_test.rb
@@ -0,0 +1,25 @@
require 'test_helper'
class ExportEmailControllerTest < ActionController::TestCase
fixtures :requests, :referents, :referent_values, :dispatched_services, :service_responses

setup do
@email_service_response = service_responses(:service_response3)
@txt_holding_service_response = service_responses(:service_response9)
end

test "layout" do
get(:email, :id => @email_service_response.id)
assert_response :success
assert_select "body div.umlaut-container", 1
assert_select "div.email", 1
end

test "layout xhr" do
xhr :get, :email, :id => @email_service_response.id
assert_response :success
# Assert that no layout was included in the request
assert_select "body", 0
assert_select "div.umlaut-container", 0
assert_select "div.email", 1
end
end

0 comments on commit dfd40f1

Please sign in to comment.