1
0
Fork 0
mirror of https://github.com/kbparagua/paloma synced 2023-03-27 23:21:17 -04:00

Bug Fix and handling non-html renders

This commit is contained in:
kbparagua 2013-10-24 17:33:12 +08:00
parent 78259f4428
commit fc54e48d18
11 changed files with 117 additions and 9 deletions

View file

@ -35,7 +35,7 @@ module Paloma
# Keeps track of what Rails controller/action is executed.
#
def track_paloma_request
resource = controller_path.split('/').map(&:titleize).join('/')
resource = controller_path.split('/').map(&:classify).join('/')
paloma_request = {:resource => resource,
:action => self.action_name}
@ -81,6 +81,18 @@ module Paloma
not_redirect = self.status != 302
[nil, 'text/html'].include?(response.content_type) && not_redirect
end
#
# Make sure not to execute paloma on the following response type
#
def render options = nil, extra_options = {}, &block
[:json, :js, :xml, :file].each do |format|
js false if options.has_key?(format)
end if options.is_a?(Hash)
super
end
end

View file

@ -10,7 +10,7 @@ Gem::Specification.new do |s|
s.add_dependency 'jquery-rails'
s.add_development_dependency 'rails', ['>= 3.2.0']
s.add_development_dependency 'rails', ['~> 3.2.0']
s.add_development_dependency 'rake', ['>= 0']
s.add_development_dependency 'rspec', ['>= 0']
s.add_development_dependency 'rspec-rails', ['~> 2.0']

View file

@ -80,4 +80,14 @@ var Bar = Paloma.controller('Admin/Bar');
Bar.prototype.show = function(){
window.called.push('Admin/Bar#show');
};
};
var MultipleName = Paloma.controller('MultipleName');
MultipleName.prototype.index = function(){
window.called.push('MultipleName#index')
};

View file

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View file

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View file

@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

View file

@ -4,4 +4,24 @@ class MainController < ApplicationController
render :inline => 'Main#index', :layout => 'application'
end
def json_response
render :json => {:x => 1}
end
def js_response
render :js => 'alert(1);'
end
def xml_response
render :xml => '<xml></xml>'
end
def file_response
render :file => "#{Rails.root}/Gemfile"
end
end

View file

@ -0,0 +1,7 @@
class MultipleNamesController < ApplicationController
def index
render :inline => 'MultipleName#index', :layout => 'application'
end
end

View file

@ -0,0 +1,2 @@
module MultipleNamesHelper
end

View file

@ -4,11 +4,21 @@ TestApp::Application.routes.draw do
root :to => 'main#index'
resources :main, :controller => 'Main'
resources :main, :controller => 'Main' do
member do
get :json_response
get :js_response
get :xml_response
get :file_response
end
end
resources :foo, :controller => 'Foo'
namespace :admin do
resources :bar, :controller => 'Bar'
end
resources :multiple_names
end

View file

@ -56,6 +56,53 @@ feature 'executing Paloma controller', :js => true do
end
end
context 'when requests from a controller with multiple name' do
it 'executes the corresponding Paloma action' do
visit multiple_names_path
called = page.evaluate_script 'window.called.pop()'
expect(called).to eq 'MultipleName#index'
end
end
#
# [TODO]
# Create proper test for the following:
#
context 'when rendering json' do
it 'does not execute Paloma' do
visit json_response_main_path 1
page.should_not have_selector '.js-paloma-hook'
end
end
context 'when rendering js' do
it 'does not execute Paloma' do
visit js_response_main_path 1
page.should_not have_selector '.js-paloma-hook'
end
end
context 'when rendering xml' do
it 'does not execute Paloma' do
visit xml_response_main_path 1
page.should_not have_selector '.js-paloma-hook'
end
end
context 'when rendering a file' do
it 'does not execute Paloma' do
visit file_response_main_path 1
page.should_not have_selector '.js-paloma-hook'
end
end
end
end
end