mirror of
https://github.com/kbparagua/paloma
synced 2023-03-27 23:21:17 -04:00
Disabling paloma with js(false)
This commit is contained in:
parent
d5a4861c8c
commit
c85f3737d4
4 changed files with 28 additions and 3 deletions
|
@ -10,7 +10,7 @@ module Paloma
|
|||
prepend_view_path "#{Paloma.root}/app/views/"
|
||||
|
||||
before_filter :track_paloma_request
|
||||
after_filter :append_paloma_hook, :if => :html_response_from_render?
|
||||
after_filter :append_paloma_hook, :if => :html_is_rendered?
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -24,6 +24,7 @@ module Paloma
|
|||
# Use on controllers to pass variables to Paloma controller.
|
||||
#
|
||||
def js params = {}
|
||||
return session[:paloma_requests].pop if !params
|
||||
session[:paloma_requests].last[:params] = params
|
||||
end
|
||||
|
||||
|
@ -52,6 +53,8 @@ module Paloma
|
|||
# will execute the tracked Paloma requests.
|
||||
#
|
||||
def append_paloma_hook
|
||||
return true if session[:paloma_requests].empty?
|
||||
|
||||
hook = view_context.render(
|
||||
:partial => 'paloma/hook',
|
||||
:locals => {:requests => session[:paloma_requests]})
|
||||
|
@ -74,8 +77,9 @@ module Paloma
|
|||
end
|
||||
|
||||
|
||||
def html_response_from_render?
|
||||
[nil, 'text/html'].include?(response.content_type) && self.status != 302
|
||||
def html_is_rendered?
|
||||
not_redirect = self.status != 302
|
||||
[nil, 'text/html'].include?(response.content_type) && not_redirect
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -62,6 +62,11 @@ MyFoo.prototype.show = function(){
|
|||
};
|
||||
|
||||
|
||||
MyFoo.prototype.edit = function(){
|
||||
window.called.push('MyFoo#edit');
|
||||
};
|
||||
|
||||
|
||||
|
||||
var AnotherFoo = Paloma.controller('AnotherFoo');
|
||||
|
||||
|
|
|
@ -4,9 +4,16 @@ class FooController < ApplicationController
|
|||
redirect_to main_index_path
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
js :parameter => 'Parameter From Paloma'
|
||||
render :inline => '<h1>Foo#show</h1>', :layout => 'application'
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
js false
|
||||
render :inline => 'Foo#edit', :layout => 'application'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -47,6 +47,15 @@ feature 'executing Paloma controller', :js => true do
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
context 'when js(false) is triggered' do
|
||||
it 'does not append paloma hook' do
|
||||
visit edit_foo_path(1)
|
||||
|
||||
page.should_not have_selector '.js-paloma-hook'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue