mirror of
https://github.com/kbparagua/paloma
synced 2023-03-27 23:21:17 -04:00
Specs for namespace filters
This commit is contained in:
parent
3e37c6f8b1
commit
d036b31dfe
8 changed files with 169 additions and 30 deletions
|
@ -1,5 +1,5 @@
|
|||
// For testing only
|
||||
window.filtersExecuted = {before : [], after : []};
|
||||
window.filtersExecuted = window.filtersExecuted || {before : [], after : []};
|
||||
|
||||
|
||||
(function(){ var filter = new Paloma.FilterScope('bar');
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
//= require ./_filters.js
|
||||
//= require ./baz/_callbacks.js
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
// For testing only
|
||||
window.filtersExecuted = window.filtersExecuted || {before : [], after : []};
|
||||
|
||||
|
||||
(function(){ var filter = new Paloma.FilterScope('sample_namespace');
|
||||
|
||||
// Before
|
||||
filter.as('Standard Before').
|
||||
before('basic_action', 'another_basic_action').
|
||||
perform(function(params)
|
||||
{
|
||||
filtersExecuted.before.push('Namespaced Standard Before');
|
||||
});
|
||||
|
||||
|
||||
filter.as('Before All').
|
||||
before_all().perform(function(params)
|
||||
{
|
||||
filtersExecuted.before.push('Namespaced Before All');
|
||||
});
|
||||
|
||||
|
||||
filter.as('Except Before').
|
||||
except_before('basic_action').
|
||||
perform(function(params)
|
||||
{
|
||||
filtersExecuted.before.push('Namespaced Except Before');
|
||||
});
|
||||
|
||||
|
||||
// After
|
||||
filter.as('Standard After').
|
||||
after('basic_action', 'another_basic_action').
|
||||
perform(function(params)
|
||||
{
|
||||
filtersExecuted.after.push('Namespaced Standard After');
|
||||
});
|
||||
|
||||
|
||||
filter.as('After All').
|
||||
after_all().perform(function(params)
|
||||
{
|
||||
filtersExecuted.after.push('Namespaced After All');
|
||||
});
|
||||
|
||||
|
||||
filter.as('Except After').
|
||||
except_after('basic_action').
|
||||
perform(function(params)
|
||||
{
|
||||
filtersExecuted.after.push('Namespaced Except After');
|
||||
});
|
||||
|
||||
|
||||
// Around
|
||||
filter.as('Standard Around').
|
||||
around('basic_action', 'another_basic_action').
|
||||
perform(function(params)
|
||||
{
|
||||
var execution = window.callback ? 'after' : 'before';
|
||||
filtersExecuted[execution].push('Namespaced Standard Around');
|
||||
});
|
||||
|
||||
|
||||
filter.as('Around All').
|
||||
around_all().perform(function(params)
|
||||
{
|
||||
var execution = window.callback ? 'after' : 'before';
|
||||
filtersExecuted[execution].push('Namespaced Around All');
|
||||
});
|
||||
|
||||
|
||||
filter.as('Except Around').
|
||||
except_around('basic_action').
|
||||
perform(function(params)
|
||||
{
|
||||
var execution = window.callback ? 'after' : 'before';
|
||||
filtersExecuted[execution].push('Namespaced Except Around');
|
||||
});
|
||||
|
||||
})();
|
|
@ -0,0 +1,5 @@
|
|||
Paloma.callbacks['sample_namespace/baz']['another_basic_action'] = function(params)
|
||||
{
|
||||
window.callback = "['sample_namespace/baz']['another_basic_action']";
|
||||
window.params = params;
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
Paloma.callbacks['sample_namespace/baz']['yet_another_basic_action'] = function(params)
|
||||
{
|
||||
window.callback = "['sample_namespace/baz']['yet_another_basic_action']";
|
||||
window.params = params;
|
||||
};
|
|
@ -23,6 +23,8 @@ TestApp::Application.routes.draw do
|
|||
resource :baz, :controller => 'baz' do
|
||||
collection do
|
||||
get :basic_action
|
||||
get :another_basic_action
|
||||
get :yet_another_basic_action
|
||||
get :callback_from_another_action
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,21 +1,37 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Paloma.FilterScope', :type => :feature, :js => true do
|
||||
describe 'Paloma.FilterScope', :type => :feature, :js => true do
|
||||
|
||||
shared_context 'paths' do
|
||||
let(:basic_action) { basic_action_bar_path }
|
||||
let(:another_basic_action) { another_basic_action_bar_path }
|
||||
let(:yet_another_basic_action) { yet_another_basic_action_bar_path}
|
||||
end
|
||||
|
||||
|
||||
shared_context 'paths-namespaced' do
|
||||
let(:basic_action) { basic_action_sample_namespace_baz_path }
|
||||
let(:another_basic_action) { another_basic_action_sample_namespace_baz_path }
|
||||
let(:yet_another_basic_action) { yet_another_basic_action_sample_namespace_baz_path }
|
||||
end
|
||||
|
||||
|
||||
|
||||
shared_examples 'standard' do |options|
|
||||
type = options[:type]
|
||||
name = options[:name]
|
||||
method = options[:method] || "##{type}"
|
||||
|
||||
filter = (options[:namespaced] ? 'Namespaced ' : '') + "Standard #{name}"
|
||||
|
||||
describe method do
|
||||
it "executes filter #{type} callbacks for the passed actions" do
|
||||
visit basic_action_bar_path
|
||||
page.evaluate_script("filtersExecuted.#{type}").should include "Standard #{name}"
|
||||
visit basic_action
|
||||
page.evaluate_script("filtersExecuted.#{type}").should include filter
|
||||
end
|
||||
|
||||
it "does not execute filter #{type} callbacks for other actions" do
|
||||
visit yet_another_basic_action_bar_path
|
||||
page.evaluate_script("filtersExecuted.#{type}").should_not include "Standard #{name}"
|
||||
visit yet_another_basic_action
|
||||
page.evaluate_script("filtersExecuted.#{type}").should_not include filter
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -25,11 +41,12 @@ describe 'Paloma.FilterScope', :type => :feature, :js => true do
|
|||
type = options[:type]
|
||||
name = options[:name]
|
||||
method = options[:method] || "##{type}_all"
|
||||
|
||||
filter = (options[:namespaced] ? 'Namespaced ' : '') + "#{name} All"
|
||||
|
||||
describe method do
|
||||
it "executes filter #{type} callbacks on all actions" do
|
||||
visit basic_action_bar_path
|
||||
page.evaluate_script("filtersExecuted.#{type}").should include "#{name} All"
|
||||
visit basic_action
|
||||
page.evaluate_script("filtersExecuted.#{type}").should include filter
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -39,37 +56,57 @@ describe 'Paloma.FilterScope', :type => :feature, :js => true do
|
|||
type = options[:type]
|
||||
name = options[:name]
|
||||
method = options[:method] || "#except_#{type}"
|
||||
filter = (options[:namespaced] ? 'Namespaced ' : '') + "Except #{name}"
|
||||
|
||||
describe method do
|
||||
it "executes filter #{type} callback on all actions except for passed actions" do
|
||||
visit another_basic_action_bar_path
|
||||
page.evaluate_script("filtersExecuted.#{type}").should include "Except #{name}"
|
||||
visit another_basic_action
|
||||
page.evaluate_script("filtersExecuted.#{type}").should include filter
|
||||
end
|
||||
|
||||
it "does not execute filter #{type} callback on passed actions" do
|
||||
visit basic_action_bar_path
|
||||
page.evaluate_script("filtersExecuted.#{type}").should_not include "Except #{name}"
|
||||
visit basic_action
|
||||
page.evaluate_script("filtersExecuted.#{type}").should_not include filter
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
shared_examples 'filter subtypes' do |type|
|
||||
options = {:type => type, :name => type.titleize}
|
||||
include_examples 'standard', options
|
||||
include_examples 'all', options
|
||||
include_examples 'except', options
|
||||
shared_examples 'filter subtypes' do |options|
|
||||
params = {:type => options[:type],
|
||||
:name => options[:type].titleize,
|
||||
:namespaced => options[:namespaced]}
|
||||
|
||||
include_examples 'standard', params
|
||||
include_examples 'all', params
|
||||
include_examples 'except', params
|
||||
end
|
||||
|
||||
include_examples 'filter subtypes', 'before'
|
||||
include_examples 'filter subtypes', 'after'
|
||||
|
||||
shared_examples 'filters' do |namespaced|
|
||||
include_context ('paths' + (namespaced ? '-namespaced' : ''))
|
||||
|
||||
# Before and After Filters
|
||||
include_examples 'filter subtypes', {:type => 'before', :namespaced => namespaced}
|
||||
include_examples 'filter subtypes', {:type => 'after', :namespaced => namespaced}
|
||||
|
||||
# Around Filters
|
||||
include_examples 'standard', {:name => 'Around', :type => 'before', :method => '#around',
|
||||
:namespaced => namespaced}
|
||||
include_examples 'standard', {:name => 'Around', :type => 'after', :method => '#around',
|
||||
:namespaced => namespaced}
|
||||
include_examples 'all', {:name => 'Around', :type => 'before', :method => '#around_all',
|
||||
:namespaced => namespaced}
|
||||
include_examples 'all', {:name => 'Around', :type => 'after', :method => '#around_all',
|
||||
:namespaced => namespaced}
|
||||
include_examples 'except', {:name => 'Around', :type => 'before', :method => '#except_around',
|
||||
:namespaced => namespaced}
|
||||
include_examples 'except', {:name => 'Around', :type => 'after', :method => '#except_around',
|
||||
:namespaced => namespaced}
|
||||
end
|
||||
|
||||
|
||||
include_examples 'standard', {:name => 'Around', :type => 'before', :method => '#around'}
|
||||
include_examples 'standard', {:name => 'Around', :type => 'after', :method => '#around'}
|
||||
include_examples 'all', {:name => 'Around', :type => 'before', :method => '#around_all'}
|
||||
include_examples 'all', {:name => 'Around', :type => 'after', :method => '#around_all'}
|
||||
include_examples 'except', {:name => 'Around', :type => 'before', :method => '#except_around'}
|
||||
include_examples 'except', {:name => 'Around', :type => 'after', :method => '#except_around'}
|
||||
|
||||
# Testing starts here
|
||||
include_examples 'filters', false # non-namespaced filters
|
||||
# include_examples 'filters', true # namespaced filters
|
||||
end
|
||||
|
|
12
vendor/assets/javascripts/paloma_core.js
vendored
12
vendor/assets/javascripts/paloma_core.js
vendored
|
@ -28,9 +28,12 @@ Paloma.execute = function(controller, action, params){
|
|||
params['callback_action'] = action;
|
||||
|
||||
|
||||
// Filters
|
||||
|
||||
// Start executions
|
||||
if (params['callback_namespace'] != ''){
|
||||
Paloma._performFilters('before', params['callback_namespace'], action, params);
|
||||
Paloma._performFilters('around', params['callback_namespace'], action, params);
|
||||
}
|
||||
|
||||
Paloma._performFilters('before', controller, action, params);
|
||||
Paloma._performFilters('around', controller, action, params);
|
||||
|
||||
|
@ -38,6 +41,11 @@ Paloma.execute = function(controller, action, params){
|
|||
|
||||
Paloma._performFilters('after', controller, action, params);
|
||||
Paloma._performFilters('around', controller, action, params);
|
||||
|
||||
if (params['callback_namespace'] != ''){
|
||||
Paloma._performFilters('after', params['callback_namespace'], action, params);
|
||||
Paloma._performFilters('around', params['callback_namespace'], action, params);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue