1
0
Fork 0
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:
kbparagua 2014-02-15 17:32:32 +08:00
parent 95d7e3c10e
commit c1c2528616
6 changed files with 221 additions and 108 deletions

View file

@ -89,7 +89,7 @@ module Paloma
# :param_1 => 1, :param_2 => 2
elsif path_or_options.is_a? Hash
self.paloma.params.merge! path_or_options[:params] || {}
self.paloma.params.merge! path_or_options || {}
end
end

View file

@ -16,21 +16,23 @@
//= require_tree .
// Will be manipulated by Paloma controllers.
window.called = [];
//
//
// Controllers
//
//
var Main = Paloma.controller('Main');
Main.prototype.index = function(){
window.called.push('Main#index');
};
var Main = Paloma.controller('Main');
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(){};

View file

@ -1,14 +1,52 @@
class MainController < ApplicationController
js :params => {:y => 300}, :only => :index
# Default behavior
def index
js 'MainShit', :params => {:z => 2}
render :inline => 'Main#index', :layout => 'application'
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
render :json => {:x => 1}
end

View file

@ -5,7 +5,9 @@ TestApp::Application.routes.draw do
root :to => 'main#index'
resources :main, :controller => 'Main' do
member do
collection do
get :prevent
get :basic_params
get :json_response
get :js_response
get :xml_response

View file

@ -4,9 +4,10 @@ require 'spec_helper'
describe MainController do
context 'default behavior' do
it 'test' do
it 'executes the same controller/action pair' do
get :index
raise MainController.instance
x = page.evaluate_script 'Paloma.engine.lastRequest'
raise x.inspect
end
end

View file

@ -3,101 +3,171 @@ require 'spec_helper'
feature 'executing Paloma controller', :js => true do
describe 'after rendering' do
#
#
# Basic
#
#
it 'executes the corresponding Paloma controller action' do
visit foo_path(1)
called = page.evaluate_script 'window.called'
context 'default behavior' do
it 'executes the same controller/action' do
visit main_index_path
request = page.evaluate_script 'Paloma.engine.lastRequest'
expect(called).to include 'MyFoo#show'
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'
expect(request).to eq({
'controller' => 'Main',
'action' => 'index',
'params' => {}})
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'
context 'override default controller' do
it 'executes the specified controller' do
visit main_path(1)
request = page.evaluate_script 'Paloma.engine.lastRequest'
expect(parameter).to eq 'Parameter From Paloma'
expect(request).to eq({
'controller' => 'OtherMain',
'action' => 'show',
'params' => {}})
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()'
context 'override default action' do
it 'executes the specified action' do
visit new_main_path
request = page.evaluate_script 'Paloma.engine.lastRequest'
expect(called).to eq 'Admin/Bar#show'
expect(request).to eq({
'controller' => 'Main',
'action' => 'otherAction',
'params' => {}})
end
end
context 'when js(false) is triggered' do
it 'does not append paloma hook' do
visit edit_foo_path(1)
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'
page.should_not have_selector '.js-paloma-hook'
expect(request).to eq({
'controller' => 'OtherMain',
'action' => 'otherAction',
'params' => {}})
end
end
context 'when requests from a controller with multiple name' do
it 'executes the corresponding Paloma action' do
visit multiple_names_path
context 'parameter passed' do
it 'passes the parameter' do
visit basic_params_main_index_path
params = page.evaluate_script 'Paloma.engine.lastRequest.params'
called = page.evaluate_script 'window.called.pop()'
expect(called).to eq 'MultipleNames#index'
expect(params).to eq({'x' => 1, 'y' => 2})
end
end
#
#
# Prevent Paloma
#
# [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'
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 'when rendering js' do
it 'does not execute Paloma' do
visit js_response_main_path 1
page.should_not have_selector '.js-paloma-hook'
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 'when rendering xml' do
it 'does not execute Paloma' do
visit xml_response_main_path 1
page.should_not have_selector '.js-paloma-hook'
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 '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
# 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