mirror of
https://github.com/kbparagua/paloma
synced 2023-03-27 23:21:17 -04:00
Integration specs
This commit is contained in:
parent
c1c2528616
commit
abf85476fe
10 changed files with 111 additions and 149 deletions
|
@ -36,45 +36,11 @@ OtherMain.prototype.otherAction = function(){};
|
|||
|
||||
|
||||
|
||||
var MyFoo = Paloma.controller('MyFoo');
|
||||
|
||||
MyFoo.prototype.index = function(){
|
||||
window.called.push('MyFoo#index');
|
||||
};
|
||||
var Foos = Paloma.controller('Admin/Foos');
|
||||
Foos.prototype.index = function(){};
|
||||
Foos.prototype.otherAction = function(){};
|
||||
|
||||
|
||||
MyFoo.prototype.show = function(){
|
||||
window.called.push('MyFoo#show');
|
||||
window.parameter = this.params.parameter;
|
||||
};
|
||||
|
||||
|
||||
MyFoo.prototype.edit = function(){
|
||||
window.called.push('MyFoo#edit');
|
||||
};
|
||||
|
||||
|
||||
|
||||
var AnotherFoo = Paloma.controller('AnotherFoo');
|
||||
|
||||
AnotherFoo.prototype.build = function(){
|
||||
window.called.push('AnotherFoo#build');
|
||||
};
|
||||
|
||||
|
||||
|
||||
var Bar = Paloma.controller('Admin/Bar');
|
||||
|
||||
Bar.prototype.show = function(){
|
||||
window.called.push('Admin/Bar#show');
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var MultipleNames = Paloma.controller('MultipleNames');
|
||||
|
||||
MultipleNames.prototype.index = function(){
|
||||
window.called.push('MultipleNames#index')
|
||||
};
|
||||
var NotFoos = Paloma.controller('NotAdmin/Foos');
|
||||
NotFoos.prototype.show = function(){};
|
||||
NotFoos.prototype.otherAction = function(){};
|
|
@ -1,7 +0,0 @@
|
|||
class Admin::BarController < ApplicationController
|
||||
|
||||
def show
|
||||
render :inline => 'Admin/Bar#show', :layout => 'application'
|
||||
end
|
||||
|
||||
end
|
29
test_app/app/controllers/admin/foos_controller.rb
Normal file
29
test_app/app/controllers/admin/foos_controller.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
class Admin::FoosController < ApplicationController
|
||||
|
||||
# Default behavior
|
||||
def index
|
||||
render :inline => 'Admin/Foos#index', :layout => 'application'
|
||||
end
|
||||
|
||||
|
||||
# Override controller
|
||||
def show
|
||||
js 'NotAdmin/Foos', :x => 99
|
||||
render :inline => 'Admin/Foos#show', :layout => 'application'
|
||||
end
|
||||
|
||||
|
||||
# Override action
|
||||
def new
|
||||
js '#otherAction', :x => 99
|
||||
render :inline => 'Admin/Foos#new', :layout => 'application'
|
||||
end
|
||||
|
||||
|
||||
# Override controller/action
|
||||
def edit
|
||||
js 'NotAdmin/Foos#otherAction', :x => 99
|
||||
render :inline => 'Admin/Foos#edit', :layout => 'application'
|
||||
end
|
||||
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
class FooController < ApplicationController
|
||||
|
||||
def index
|
||||
redirect_to main_index_path
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
js :params => {: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
|
|
@ -8,21 +8,21 @@ class MainController < ApplicationController
|
|||
|
||||
# Override controller
|
||||
def show
|
||||
js 'OtherMain'
|
||||
js 'OtherMain', :x => 1
|
||||
render :inline => 'Main#show', :layout => 'application'
|
||||
end
|
||||
|
||||
|
||||
# Override action
|
||||
def new
|
||||
js :otherAction
|
||||
js :otherAction, :x => 1
|
||||
render :inline => 'Main#new', :layout => 'application'
|
||||
end
|
||||
|
||||
|
||||
# Override controller/action
|
||||
def edit
|
||||
js 'OtherMain#otherAction'
|
||||
js 'OtherMain#otherAction', :x => 1
|
||||
render :inline => 'Main#edit', :layout => 'application'
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
class MultipleNamesController < ApplicationController
|
||||
|
||||
def index
|
||||
render :inline => 'MultipleName#index', :layout => 'application'
|
||||
end
|
||||
|
||||
end
|
|
@ -15,12 +15,8 @@ TestApp::Application.routes.draw do
|
|||
end
|
||||
end
|
||||
|
||||
resources :foo, :controller => 'Foo'
|
||||
|
||||
namespace :admin do
|
||||
resources :bar, :controller => 'Bar'
|
||||
resources :foos
|
||||
end
|
||||
|
||||
|
||||
resources :multiple_names
|
||||
end
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
|
||||
describe MainController do
|
||||
|
||||
context 'default behavior' do
|
||||
it 'executes the same controller/action pair' do
|
||||
get :index
|
||||
x = page.evaluate_script 'Paloma.engine.lastRequest'
|
||||
raise x.inspect
|
||||
end
|
||||
end
|
||||
|
||||
end
|
63
test_app/spec/integration/advanced_spec.rb
Normal file
63
test_app/spec/integration/advanced_spec.rb
Normal file
|
@ -0,0 +1,63 @@
|
|||
require 'spec_helper'
|
||||
|
||||
#
|
||||
#
|
||||
# All examples are using namespaces
|
||||
#
|
||||
#
|
||||
|
||||
feature 'executing Paloma controller', :js => true do
|
||||
|
||||
|
||||
context 'default behavior' do
|
||||
it 'executes the same namespace/controller/action' do
|
||||
visit admin_foos_path
|
||||
request = page.evaluate_script 'Paloma.engine.lastRequest'
|
||||
|
||||
expect(request).to eq({
|
||||
'controller' => 'Admin/Foos',
|
||||
'action' => 'index',
|
||||
'params' => {}})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'override default controller' do
|
||||
it 'executes the specified controller' do
|
||||
visit admin_foo_path(1)
|
||||
request = page.evaluate_script 'Paloma.engine.lastRequest'
|
||||
|
||||
expect(request).to eq({
|
||||
'controller' => 'NotAdmin/Foos',
|
||||
'action' => 'show',
|
||||
'params' => {'x' => 99}})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'override default action' do
|
||||
it 'executes the specified action' do
|
||||
visit new_admin_foo_path
|
||||
request = page.evaluate_script 'Paloma.engine.lastRequest'
|
||||
|
||||
expect(request).to eq({
|
||||
'controller' => 'Admin/Foos',
|
||||
'action' => 'otherAction',
|
||||
'params' => {'x' => 99}})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'override default controller/action' do
|
||||
it 'executes the specified controller/action' do
|
||||
visit edit_admin_foo_path(1)
|
||||
request = page.evaluate_script 'Paloma.engine.lastRequest'
|
||||
|
||||
expect(request).to eq({
|
||||
'controller' => 'NotAdmin/Foos',
|
||||
'action' => 'otherAction',
|
||||
'params' => {'x' => 99}})
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,11 +1,17 @@
|
|||
require 'spec_helper'
|
||||
|
||||
#
|
||||
#
|
||||
# All examples are not using namespaces.
|
||||
#
|
||||
#
|
||||
|
||||
feature 'executing Paloma controller', :js => true do
|
||||
|
||||
#
|
||||
#
|
||||
# Basic
|
||||
# All except for basic_params and index action will pass :x => 1 parameter
|
||||
#
|
||||
#
|
||||
|
||||
|
@ -30,7 +36,7 @@ feature 'executing Paloma controller', :js => true do
|
|||
expect(request).to eq({
|
||||
'controller' => 'OtherMain',
|
||||
'action' => 'show',
|
||||
'params' => {}})
|
||||
'params' => {'x' => 1}})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -43,7 +49,7 @@ feature 'executing Paloma controller', :js => true do
|
|||
expect(request).to eq({
|
||||
'controller' => 'Main',
|
||||
'action' => 'otherAction',
|
||||
'params' => {}})
|
||||
'params' => {'x' => 1}})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -56,7 +62,7 @@ feature 'executing Paloma controller', :js => true do
|
|||
expect(request).to eq({
|
||||
'controller' => 'OtherMain',
|
||||
'action' => 'otherAction',
|
||||
'params' => {}})
|
||||
'params' => {'x' => 1}})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -119,55 +125,4 @@ feature 'executing Paloma controller', :js => true do
|
|||
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
|
Loading…
Reference in a new issue