diff --git a/test_app/app/assets/javascripts/application.js b/test_app/app/assets/javascripts/application.js index e24b9af..9fd060e 100644 --- a/test_app/app/assets/javascripts/application.js +++ b/test_app/app/assets/javascripts/application.js @@ -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') -}; \ No newline at end of file +var NotFoos = Paloma.controller('NotAdmin/Foos'); +NotFoos.prototype.show = function(){}; +NotFoos.prototype.otherAction = function(){}; \ No newline at end of file diff --git a/test_app/app/controllers/admin/bar_controller.rb b/test_app/app/controllers/admin/bar_controller.rb deleted file mode 100644 index f1447aa..0000000 --- a/test_app/app/controllers/admin/bar_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Admin::BarController < ApplicationController - - def show - render :inline => 'Admin/Bar#show', :layout => 'application' - end - -end diff --git a/test_app/app/controllers/admin/foos_controller.rb b/test_app/app/controllers/admin/foos_controller.rb new file mode 100644 index 0000000..97e3e33 --- /dev/null +++ b/test_app/app/controllers/admin/foos_controller.rb @@ -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 diff --git a/test_app/app/controllers/foo_controller.rb b/test_app/app/controllers/foo_controller.rb deleted file mode 100644 index 58d9fba..0000000 --- a/test_app/app/controllers/foo_controller.rb +++ /dev/null @@ -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 => '

Foo#show

', :layout => 'application' - end - - - def edit - js false - render :inline => 'Foo#edit', :layout => 'application' - end - -end diff --git a/test_app/app/controllers/main_controller.rb b/test_app/app/controllers/main_controller.rb index 051729f..aa79908 100644 --- a/test_app/app/controllers/main_controller.rb +++ b/test_app/app/controllers/main_controller.rb @@ -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 diff --git a/test_app/app/controllers/multiple_names_controller.rb b/test_app/app/controllers/multiple_names_controller.rb deleted file mode 100644 index db9860c..0000000 --- a/test_app/app/controllers/multiple_names_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class MultipleNamesController < ApplicationController - - def index - render :inline => 'MultipleName#index', :layout => 'application' - end - -end diff --git a/test_app/config/routes.rb b/test_app/config/routes.rb index a0511cb..d12e761 100644 --- a/test_app/config/routes.rb +++ b/test_app/config/routes.rb @@ -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 diff --git a/test_app/spec/controllers/main_controller_spec.rb b/test_app/spec/controllers/main_controller_spec.rb deleted file mode 100644 index 19bfc21..0000000 --- a/test_app/spec/controllers/main_controller_spec.rb +++ /dev/null @@ -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 \ No newline at end of file diff --git a/test_app/spec/integration/advanced_spec.rb b/test_app/spec/integration/advanced_spec.rb new file mode 100644 index 0000000..5276f36 --- /dev/null +++ b/test_app/spec/integration/advanced_spec.rb @@ -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 \ No newline at end of file diff --git a/test_app/spec/integration/main_spec.rb b/test_app/spec/integration/basic_spec.rb similarity index 64% rename from test_app/spec/integration/main_spec.rb rename to test_app/spec/integration/basic_spec.rb index af00aee..70c6e3f 100644 --- a/test_app/spec/integration/main_spec.rb +++ b/test_app/spec/integration/basic_spec.rb @@ -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