2013-10-12 07:20:23 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2014-02-15 05:07:44 -05:00
|
|
|
#
|
|
|
|
#
|
|
|
|
# All examples are not using namespaces.
|
|
|
|
#
|
|
|
|
#
|
2013-10-12 07:20:23 -04:00
|
|
|
|
|
|
|
feature 'executing Paloma controller', :js => true do
|
|
|
|
|
2014-02-15 04:32:32 -05:00
|
|
|
#
|
|
|
|
#
|
|
|
|
# Basic
|
2014-02-15 05:07:44 -05:00
|
|
|
# All except for basic_params and index action will pass :x => 1 parameter
|
2014-02-15 04:32:32 -05:00
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
context 'default behavior' do
|
|
|
|
it 'executes the same controller/action' do
|
|
|
|
visit main_index_path
|
|
|
|
|
2015-03-24 09:40:53 -04:00
|
|
|
expect(
|
|
|
|
request['controller'] == 'Main' &&
|
|
|
|
request['action'] == 'index' &&
|
|
|
|
request['params'] == {}
|
|
|
|
).to be_truthy
|
2014-02-15 04:32:32 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-12 07:33:44 -04:00
|
|
|
|
2014-02-15 04:32:32 -05:00
|
|
|
context 'override default controller' do
|
|
|
|
it 'executes the specified controller' do
|
|
|
|
visit main_path(1)
|
2013-10-12 07:20:23 -04:00
|
|
|
|
2015-03-24 09:40:53 -04:00
|
|
|
expect(
|
|
|
|
request['controller'] == 'OtherMain' &&
|
|
|
|
request['action'] == 'show' &&
|
|
|
|
request['params'] == {'x' => 1}
|
|
|
|
).to be_truthy
|
2013-10-12 07:20:23 -04:00
|
|
|
end
|
2014-02-15 04:32:32 -05:00
|
|
|
end
|
2013-10-12 07:20:23 -04:00
|
|
|
|
|
|
|
|
2014-02-15 04:32:32 -05:00
|
|
|
context 'override default action' do
|
|
|
|
it 'executes the specified action' do
|
|
|
|
visit new_main_path
|
2013-10-12 07:20:23 -04:00
|
|
|
|
2015-03-24 09:40:53 -04:00
|
|
|
expect(
|
|
|
|
request['controller'] == 'Main' &&
|
|
|
|
request['action'] == 'otherAction' &&
|
|
|
|
request['params'] == {'x' => 1}
|
|
|
|
).to be_truthy
|
2013-10-12 07:20:23 -04:00
|
|
|
end
|
2014-02-15 04:32:32 -05:00
|
|
|
end
|
2013-10-12 07:20:23 -04:00
|
|
|
|
|
|
|
|
2014-02-15 04:32:32 -05:00
|
|
|
context 'override default controller/action' do
|
|
|
|
it 'executes the specified controller/action' do
|
|
|
|
visit edit_main_path(1)
|
2013-10-12 07:20:23 -04:00
|
|
|
|
2015-03-24 09:40:53 -04:00
|
|
|
expect(
|
|
|
|
request['controller'] == 'OtherMain' &&
|
|
|
|
request['action'] == 'otherAction' &&
|
|
|
|
request['params'] == {'x' => 1}
|
|
|
|
).to be_truthy
|
2013-10-12 07:20:23 -04:00
|
|
|
end
|
2014-02-15 04:32:32 -05:00
|
|
|
end
|
2013-10-12 07:20:23 -04:00
|
|
|
|
|
|
|
|
2014-02-15 04:32:32 -05:00
|
|
|
context 'parameter passed' do
|
|
|
|
it 'passes the parameter' do
|
|
|
|
visit basic_params_main_index_path
|
2013-10-12 07:33:44 -04:00
|
|
|
|
2014-02-15 05:51:02 -05:00
|
|
|
expect(request['params']).to eq({'x' => 1, 'y' => 2})
|
2013-10-12 07:33:44 -04:00
|
|
|
end
|
2014-02-15 04:32:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-10-12 07:20:23 -04:00
|
|
|
|
2013-10-12 08:26:00 -04:00
|
|
|
|
|
|
|
|
2015-08-28 03:13:28 -04:00
|
|
|
#
|
|
|
|
#
|
|
|
|
# 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
|
2016-03-01 22:27:36 -05:00
|
|
|
expect(paloma_executed?).to be_falsy
|
2015-08-28 03:13:28 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-15 04:32:32 -05:00
|
|
|
#
|
|
|
|
#
|
|
|
|
# Prevent Paloma
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
shared_examples 'no paloma' do
|
|
|
|
it 'does not add paloma hook' do
|
2015-03-24 09:40:53 -04:00
|
|
|
expect(page.has_selector?('.js-paloma-hook')).to be_falsy
|
2013-10-12 08:26:00 -04:00
|
|
|
end
|
2014-02-15 04:32:32 -05:00
|
|
|
end
|
2013-10-12 08:26:00 -04:00
|
|
|
|
2013-10-24 05:33:12 -04:00
|
|
|
|
2014-02-15 04:32:32 -05:00
|
|
|
context 'js(false)' do
|
|
|
|
before { visit prevent_main_index_path }
|
2013-10-24 05:33:12 -04:00
|
|
|
|
2014-02-15 04:32:32 -05:00
|
|
|
include_examples 'no paloma'
|
2013-10-24 05:33:12 -04:00
|
|
|
|
2014-02-15 04:32:32 -05:00
|
|
|
it 'prevents execution of Paloma controller' do
|
2016-03-01 22:27:36 -05:00
|
|
|
expect(paloma_executed?).to be_falsy
|
2013-10-24 05:33:12 -04:00
|
|
|
end
|
2014-02-15 04:32:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'json response' do
|
|
|
|
before { visit json_response_main_index_path }
|
|
|
|
include_examples 'no paloma'
|
|
|
|
end
|
2013-10-24 05:33:12 -04:00
|
|
|
|
2014-02-15 04:32:32 -05:00
|
|
|
context 'js response' do
|
|
|
|
before { visit js_response_main_index_path }
|
|
|
|
include_examples 'no paloma'
|
|
|
|
end
|
2013-10-24 05:33:12 -04:00
|
|
|
|
2014-02-15 04:32:32 -05:00
|
|
|
context 'xml response' do
|
|
|
|
before { visit xml_response_main_index_path }
|
2015-03-24 09:58:41 -04:00
|
|
|
|
|
|
|
it 'does not add paloma hook' do
|
|
|
|
# TODO: implement this
|
|
|
|
# XML is not supported by capybara.
|
|
|
|
end
|
2014-02-15 04:32:32 -05:00
|
|
|
end
|
2013-10-24 05:33:12 -04:00
|
|
|
|
2014-02-15 04:32:32 -05:00
|
|
|
context 'file response' do
|
|
|
|
before { visit file_response_main_index_path }
|
|
|
|
include_examples 'no paloma'
|
|
|
|
end
|
2013-10-24 05:33:12 -04:00
|
|
|
|
|
|
|
|
|
|
|
end
|