mirror of
https://github.com/kbparagua/paloma
synced 2023-03-27 23:21:17 -04:00
Tests for multiple js calls
This commit is contained in:
parent
ead698874f
commit
7543d985df
6 changed files with 134 additions and 10 deletions
|
@ -55,6 +55,20 @@ module Paloma
|
|||
# Can call a different Controller or execute a different action, and
|
||||
# pass parameters.
|
||||
#
|
||||
# NOTE:
|
||||
# Calling this more than once in a single action will not clear
|
||||
# the previous config from the previous call.
|
||||
#
|
||||
# Example:
|
||||
# def new
|
||||
# js 'MyController#new'
|
||||
# js :edit
|
||||
# js :x => 1, :y => 2
|
||||
#
|
||||
# # Paloma will execute JS for
|
||||
# # MyController#edit and will pass the parameters :x => 1, :y => 2
|
||||
# end
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# js 'Controller', {params}
|
||||
|
@ -82,8 +96,8 @@ module Paloma
|
|||
#
|
||||
if path_or_options.is_a? String
|
||||
route = ::Paloma::Utilities.interpret_route path_or_options
|
||||
self.paloma.resource = route[:resource] || self.default_resource
|
||||
self.paloma.action = route[:action] || self.default_action
|
||||
self.paloma.resource = route[:resource] if route[:resource].present?
|
||||
self.paloma.action = route[:action] if route[:action].present?
|
||||
|
||||
# :action
|
||||
elsif path_or_options.is_a? Symbol
|
||||
|
@ -93,13 +107,12 @@ module Paloma
|
|||
elsif path_or_options.is_a? Hash
|
||||
self.paloma.params.merge! path_or_options || {}
|
||||
|
||||
elsif path_or_options == true
|
||||
self.paloma.resource = self.default_resource
|
||||
self.paloma.action = self.default_action
|
||||
|
||||
else
|
||||
elsif path_or_options != true
|
||||
raise "Paloma: Invalid argument (#{path_or_options}) for js method"
|
||||
end
|
||||
|
||||
self.paloma.resource ||= self.default_resource
|
||||
self.paloma.action ||= self.default_action
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -36,12 +36,13 @@ Main.prototype.index = function(){};
|
|||
Main.prototype.otherAction = function(){};
|
||||
Main.prototype.prevent = function(){};
|
||||
Main.prototype.basic_params = function(){};
|
||||
Main.prototype.multiple_calls_1 = function(){};
|
||||
|
||||
|
||||
var OtherMain = Paloma.controller('OtherMain');
|
||||
OtherMain.prototype.show = function(){};
|
||||
OtherMain.prototype.otherAction = function(){};
|
||||
|
||||
OtherMain.prototype.multiple_calls_2 = function(){};
|
||||
|
||||
|
||||
var Foos = Paloma.controller('Admin/Foos');
|
||||
|
|
|
@ -2,8 +2,6 @@ class MainController < ApplicationController
|
|||
|
||||
# Default behavior
|
||||
def index
|
||||
js false
|
||||
js 11231242
|
||||
render :inline => 'Main#index', :layout => 'application'
|
||||
end
|
||||
|
||||
|
@ -29,6 +27,43 @@ class MainController < ApplicationController
|
|||
end
|
||||
|
||||
|
||||
def multiple_calls_1
|
||||
js false
|
||||
js :x => 70
|
||||
render :inline => 'Main#multiple_calls', :layout => 'application'
|
||||
end
|
||||
|
||||
|
||||
def multiple_calls_2
|
||||
js false
|
||||
js 'OtherMain'
|
||||
render :inline => 'Main#multiple_calls_2', :layout => 'application'
|
||||
end
|
||||
|
||||
|
||||
def multiple_calls_3
|
||||
js 'OtherMain'
|
||||
js :show
|
||||
render :inline => 'Main#multiple_calls_3', :layout => 'application'
|
||||
end
|
||||
|
||||
|
||||
def multiple_calls_4
|
||||
js 'OtherMain#show'
|
||||
js false
|
||||
render :inline => 'Main#multiple_calls_4', :layout => 'application'
|
||||
end
|
||||
|
||||
|
||||
def multiple_calls_5
|
||||
js false
|
||||
js true
|
||||
render :inline => 'Main#multiple_calls_5', :layout => 'application'
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
# Stop paloma from execution
|
||||
def prevent
|
||||
js false
|
||||
|
|
|
@ -17,6 +17,11 @@
|
|||
<li><%= link_to 'Main#edit', edit_main_path(1) %></li>
|
||||
<li><%= link_to 'Main#prevent', prevent_main_index_path %></li>
|
||||
<li><%= link_to 'Main#basic_params', basic_params_main_index_path %></li>
|
||||
<li><%= link_to 'Main#multiple_calls_1', multiple_calls_1_main_index_path %></li>
|
||||
<li><%= link_to 'Main#multiple_calls_2', multiple_calls_2_main_index_path %></li>
|
||||
<li><%= link_to 'Main#multiple_calls_3', multiple_calls_3_main_index_path %></li>
|
||||
<li><%= link_to 'Main#multiple_calls_4', multiple_calls_4_main_index_path %></li>
|
||||
<li><%= link_to 'Main#multiple_calls_5', multiple_calls_5_main_index_path %></li>
|
||||
<li><%= link_to 'Main#xml_response', xml_response_main_index_path %></li>
|
||||
<li><%= link_to 'Main#file_response', file_response_main_index_path %></li>
|
||||
<li><%= link_to 'Main#ajax', ajax_main_index_path, :id => 'js-ajax-link' %></li>
|
||||
|
|
|
@ -13,6 +13,11 @@ TestApp::Application.routes.draw do
|
|||
get :xml_response
|
||||
get :file_response
|
||||
get :ajax
|
||||
get :multiple_calls_1
|
||||
get :multiple_calls_2
|
||||
get :multiple_calls_3
|
||||
get :multiple_calls_4
|
||||
get :multiple_calls_5
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -79,6 +79,71 @@ feature 'executing Paloma controller', :js => true do
|
|||
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
# Multiple Calls
|
||||
#
|
||||
#
|
||||
|
||||
context 'false at first then pass a parameter' do
|
||||
it 'executes default controller#action plus the parameter' do
|
||||
visit multiple_calls_1_main_index_path
|
||||
|
||||
expect(
|
||||
request['controller'] == 'Main' &&
|
||||
request['action'] == 'multiple_calls_1' &&
|
||||
request['params'] == {'x' => 70}
|
||||
).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'false at first then pass a controller string' do
|
||||
it 'executes passed controller and default action' do
|
||||
visit multiple_calls_2_main_index_path
|
||||
|
||||
expect(
|
||||
request['controller'] == 'OtherMain' &&
|
||||
request['action'] == 'multiple_calls_2'
|
||||
).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'controller at first then action' do
|
||||
it 'executes the controller and action' do
|
||||
visit multiple_calls_3_main_index_path
|
||||
|
||||
expect(
|
||||
request['controller'] == 'OtherMain' &&
|
||||
request['action'] == 'show'
|
||||
).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'controller#action at first then false' do
|
||||
it 'does not execute any js' do
|
||||
visit multiple_calls_4_main_index_path
|
||||
expect(request).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'false at first then true' do
|
||||
it 'executes default controller#action' do
|
||||
visit multiple_calls_5_main_index_path
|
||||
|
||||
expect(
|
||||
request['controller'] == 'Main' &&
|
||||
request['action'] == 'multiple_calls_5'
|
||||
).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
# Prevent Paloma
|
||||
|
|
Loading…
Reference in a new issue