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:
parent
78259f4428
commit
fc54e48d18
11 changed files with 117 additions and 9 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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']
|
||||
|
|
|
@ -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')
|
||||
};
|
||||
|
|
|
@ -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.
|
|
@ -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.
|
4
test_app/app/assets/stylesheets/multiple_names.css
Normal file
4
test_app/app/assets/stylesheets/multiple_names.css
Normal file
|
@ -0,0 +1,4 @@
|
|||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
|
@ -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
|
||||
|
|
7
test_app/app/controllers/multiple_names_controller.rb
Normal file
7
test_app/app/controllers/multiple_names_controller.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class MultipleNamesController < ApplicationController
|
||||
|
||||
def index
|
||||
render :inline => 'MultipleName#index', :layout => 'application'
|
||||
end
|
||||
|
||||
end
|
2
test_app/app/helpers/multiple_names_helper.rb
Normal file
2
test_app/app/helpers/multiple_names_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module MultipleNamesHelper
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue