mirror of
https://github.com/kbparagua/paloma
synced 2023-03-27 23:21:17 -04:00
Basic spec and param fix
This commit is contained in:
parent
95d7e3c10e
commit
c1c2528616
6 changed files with 221 additions and 108 deletions
|
@ -89,7 +89,7 @@ module Paloma
|
||||||
|
|
||||||
# :param_1 => 1, :param_2 => 2
|
# :param_1 => 1, :param_2 => 2
|
||||||
elsif path_or_options.is_a? Hash
|
elsif path_or_options.is_a? Hash
|
||||||
self.paloma.params.merge! path_or_options[:params] || {}
|
self.paloma.params.merge! path_or_options || {}
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,21 +16,23 @@
|
||||||
//= require_tree .
|
//= require_tree .
|
||||||
|
|
||||||
|
|
||||||
// Will be manipulated by Paloma controllers.
|
|
||||||
window.called = [];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Controllers
|
// Controllers
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
var Main = Paloma.controller('Main');
|
|
||||||
|
|
||||||
Main.prototype.index = function(){
|
var Main = Paloma.controller('Main');
|
||||||
window.called.push('Main#index');
|
Main.prototype.index = function(){};
|
||||||
};
|
Main.prototype.otherAction = function(){};
|
||||||
|
Main.prototype.prevent = function(){};
|
||||||
|
Main.prototype.basic_params = function(){};
|
||||||
|
|
||||||
|
|
||||||
|
var OtherMain = Paloma.controller('OtherMain');
|
||||||
|
OtherMain.prototype.show = function(){};
|
||||||
|
OtherMain.prototype.otherAction = function(){};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,52 @@
|
||||||
class MainController < ApplicationController
|
class MainController < ApplicationController
|
||||||
|
|
||||||
js :params => {:y => 300}, :only => :index
|
# Default behavior
|
||||||
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
js 'MainShit', :params => {:z => 2}
|
|
||||||
render :inline => 'Main#index', :layout => 'application'
|
render :inline => 'Main#index', :layout => 'application'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# Override controller
|
||||||
|
def show
|
||||||
|
js 'OtherMain'
|
||||||
|
render :inline => 'Main#show', :layout => 'application'
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# Override action
|
||||||
|
def new
|
||||||
|
js :otherAction
|
||||||
|
render :inline => 'Main#new', :layout => 'application'
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# Override controller/action
|
||||||
|
def edit
|
||||||
|
js 'OtherMain#otherAction'
|
||||||
|
render :inline => 'Main#edit', :layout => 'application'
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# Stop paloma from execution
|
||||||
|
def prevent
|
||||||
|
js false
|
||||||
|
render :inline => 'Main#prevent', :layout => 'application'
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def basic_params
|
||||||
|
js :x => 1, :y => 2
|
||||||
|
render :inline => 'Main#basic_params', :layout => 'application'
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Non-HTML response
|
||||||
|
#
|
||||||
|
|
||||||
def json_response
|
def json_response
|
||||||
render :json => {:x => 1}
|
render :json => {:x => 1}
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,9 @@ TestApp::Application.routes.draw do
|
||||||
root :to => 'main#index'
|
root :to => 'main#index'
|
||||||
|
|
||||||
resources :main, :controller => 'Main' do
|
resources :main, :controller => 'Main' do
|
||||||
member do
|
collection do
|
||||||
|
get :prevent
|
||||||
|
get :basic_params
|
||||||
get :json_response
|
get :json_response
|
||||||
get :js_response
|
get :js_response
|
||||||
get :xml_response
|
get :xml_response
|
||||||
|
|
|
@ -4,9 +4,10 @@ require 'spec_helper'
|
||||||
describe MainController do
|
describe MainController do
|
||||||
|
|
||||||
context 'default behavior' do
|
context 'default behavior' do
|
||||||
it 'test' do
|
it 'executes the same controller/action pair' do
|
||||||
get :index
|
get :index
|
||||||
raise MainController.instance
|
x = page.evaluate_script 'Paloma.engine.lastRequest'
|
||||||
|
raise x.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,101 +3,171 @@ require 'spec_helper'
|
||||||
|
|
||||||
feature 'executing Paloma controller', :js => true do
|
feature 'executing Paloma controller', :js => true do
|
||||||
|
|
||||||
describe 'after rendering' do
|
#
|
||||||
|
#
|
||||||
|
# Basic
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
it 'executes the corresponding Paloma controller action' do
|
context 'default behavior' do
|
||||||
visit foo_path(1)
|
it 'executes the same controller/action' do
|
||||||
called = page.evaluate_script 'window.called'
|
visit main_index_path
|
||||||
|
request = page.evaluate_script 'Paloma.engine.lastRequest'
|
||||||
|
|
||||||
expect(called).to include 'MyFoo#show'
|
expect(request).to eq({
|
||||||
end
|
'controller' => 'Main',
|
||||||
|
'action' => 'index',
|
||||||
|
'params' => {}})
|
||||||
context 'coming from a redirect' do
|
|
||||||
before { visit foo_index_path }
|
|
||||||
|
|
||||||
it 'executes next the Paloma action of the last Rails action' do
|
|
||||||
last = page.evaluate_script 'window.called.pop()'
|
|
||||||
expect(last).to eq 'Main#index'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
context 'when js params is passed' do
|
|
||||||
it 'passes the parameters to Paloma controller action' do
|
|
||||||
visit foo_path(1)
|
|
||||||
parameter = page.evaluate_script 'window.parameter'
|
|
||||||
|
|
||||||
expect(parameter).to eq 'Parameter From Paloma'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
context 'from namespaced controller' do
|
|
||||||
it 'executes the corresponding Paloma controller action' do
|
|
||||||
visit admin_bar_path(1)
|
|
||||||
called = page.evaluate_script 'window.called.pop()'
|
|
||||||
|
|
||||||
expect(called).to eq 'Admin/Bar#show'
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
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 'MultipleNames#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
|
||||||
|
|
||||||
|
|
||||||
|
context 'override default controller' do
|
||||||
|
it 'executes the specified controller' do
|
||||||
|
visit main_path(1)
|
||||||
|
request = page.evaluate_script 'Paloma.engine.lastRequest'
|
||||||
|
|
||||||
|
expect(request).to eq({
|
||||||
|
'controller' => 'OtherMain',
|
||||||
|
'action' => 'show',
|
||||||
|
'params' => {}})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
context 'override default action' do
|
||||||
|
it 'executes the specified action' do
|
||||||
|
visit new_main_path
|
||||||
|
request = page.evaluate_script 'Paloma.engine.lastRequest'
|
||||||
|
|
||||||
|
expect(request).to eq({
|
||||||
|
'controller' => 'Main',
|
||||||
|
'action' => 'otherAction',
|
||||||
|
'params' => {}})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
context 'override default controller/action' do
|
||||||
|
it 'executes the specified controller/action' do
|
||||||
|
visit edit_main_path(1)
|
||||||
|
request = page.evaluate_script 'Paloma.engine.lastRequest'
|
||||||
|
|
||||||
|
expect(request).to eq({
|
||||||
|
'controller' => 'OtherMain',
|
||||||
|
'action' => 'otherAction',
|
||||||
|
'params' => {}})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
context 'parameter passed' do
|
||||||
|
it 'passes the parameter' do
|
||||||
|
visit basic_params_main_index_path
|
||||||
|
params = page.evaluate_script 'Paloma.engine.lastRequest.params'
|
||||||
|
|
||||||
|
expect(params).to eq({'x' => 1, 'y' => 2})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Prevent Paloma
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
shared_examples 'no paloma' do
|
||||||
|
it 'does not add paloma hook' do
|
||||||
|
expect(page.has_selector?('.js-paloma-hook')).to be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
context 'js(false)' do
|
||||||
|
before { visit prevent_main_index_path }
|
||||||
|
|
||||||
|
include_examples 'no paloma'
|
||||||
|
|
||||||
|
it 'prevents execution of Paloma controller' do
|
||||||
|
request = page.evaluate_script 'Paloma.engine.lastRequest'
|
||||||
|
expect(request).to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'json response' do
|
||||||
|
before { visit json_response_main_index_path }
|
||||||
|
include_examples 'no paloma'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'js response' do
|
||||||
|
before { visit js_response_main_index_path }
|
||||||
|
include_examples 'no paloma'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'xml response' do
|
||||||
|
before { visit xml_response_main_index_path }
|
||||||
|
include_examples 'no paloma'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'file response' do
|
||||||
|
before { visit file_response_main_index_path }
|
||||||
|
include_examples 'no paloma'
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# context 'coming from a redirect' do
|
||||||
|
# before { visit foo_index_path }
|
||||||
|
|
||||||
|
# it 'executes next the Paloma action of the last Rails action' do
|
||||||
|
# last = page.evaluate_script 'window.called.pop()'
|
||||||
|
# expect(last).to eq 'Main#index'
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
|
|
||||||
|
# context 'when js params is passed' do
|
||||||
|
# it 'passes the parameters to Paloma controller action' do
|
||||||
|
# visit foo_path(1)
|
||||||
|
# parameter = page.evaluate_script 'window.parameter'
|
||||||
|
|
||||||
|
# expect(parameter).to eq 'Parameter From Paloma'
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
|
|
||||||
|
# context 'from namespaced controller' do
|
||||||
|
# it 'executes the corresponding Paloma controller action' do
|
||||||
|
# visit admin_bar_path(1)
|
||||||
|
# called = page.evaluate_script 'window.called.pop()'
|
||||||
|
|
||||||
|
# expect(called).to eq 'Admin/Bar#show'
|
||||||
|
# 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
|
||||||
|
|
||||||
|
|
||||||
|
# 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 'MultipleNames#index'
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue