From 1951c09645de491c5232fc9de7f30507cb70dd90 Mon Sep 17 00:00:00 2001 From: kbparagua Date: Sun, 24 Feb 2013 11:48:26 +0800 Subject: [PATCH] Completed params spec --- .../paloma/bar/different_params.js | 4 ++ .../app/controllers/bar_controller.rb | 13 ++++ spec/test_app/config/routes.rb | 1 + spec/test_app/spec/params_spec.rb | 63 ++++++++++++++++++- 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 spec/test_app/app/assets/javascripts/paloma/bar/different_params.js diff --git a/spec/test_app/app/assets/javascripts/paloma/bar/different_params.js b/spec/test_app/app/assets/javascripts/paloma/bar/different_params.js new file mode 100644 index 0000000..178041b --- /dev/null +++ b/spec/test_app/app/assets/javascripts/paloma/bar/different_params.js @@ -0,0 +1,4 @@ +Paloma.callbacks['bar']['different_params'] = function(params) +{ + window.params = params; +}; diff --git a/spec/test_app/app/controllers/bar_controller.rb b/spec/test_app/app/controllers/bar_controller.rb index 4c852a5..a37a17d 100644 --- a/spec/test_app/app/controllers/bar_controller.rb +++ b/spec/test_app/app/controllers/bar_controller.rb @@ -2,4 +2,17 @@ class BarController < ApplicationController def basic_action render :inline => '

Bar! Basic Action

', :layout => 'application' end + + + def different_params + js :params => { + :boolean => true, + :array => [1, 2, 3], + :string => 'Banana', + :integer => 69, + :float => 3.1416, + :hash => {:a => 'Hello', :b => 'World'}} + + render :inline => '

Bar! Different Params

', :layout => 'application' + end end diff --git a/spec/test_app/config/routes.rb b/spec/test_app/config/routes.rb index db3b79b..2cf3a54 100644 --- a/spec/test_app/config/routes.rb +++ b/spec/test_app/config/routes.rb @@ -13,6 +13,7 @@ TestApp::Application.routes.draw do resource :bar, :controller => 'bar' do collection do get :basic_action + get :different_params end end diff --git a/spec/test_app/spec/params_spec.rb b/spec/test_app/spec/params_spec.rb index 5ea0a8d..41fd529 100644 --- a/spec/test_app/spec/params_spec.rb +++ b/spec/test_app/spec/params_spec.rb @@ -51,5 +51,66 @@ describe 'Callback params', :type => :feature, :js => true do :callback_action => 'basic_action', :callback_namespace => '', :callback_controller_path => 'foo'}) - end + end + + + context 'within a namespaced callback' do + before do + visit callback_from_another_action_sample_namespace_baz_path + end + + include_examples('check params', { + :controller => 'baz', + :action => 'callback_from_another_action', + :namespace => 'sample_namespace', + :controller_path => 'sample_namespace/baz', + :callback_controller => 'baz', + :callback_action => 'basic_action', + :callback_namespace => 'sample_namespace', + :callback_controller_path => 'sample_namespace/baz'}) + end + + + context 'with passed parameter' do + before do + visit different_params_bar_path + end + + context 'of type TrueClass or FalseClass' do + it 'has the boolean equivalent' do + page.evaluate_script("params['boolean'] == true").should be_true + end + end + + context 'of type Array' do + it 'has the array equivalent' do + page.evaluate_script("JSON.stringify(params['array']) == JSON.stringify([1, 2, 3])").should be_true + end + end + + context 'of type String' do + it 'has the string equivalent' do + page.evaluate_script("params['string'] == 'Banana'").should be_true + end + end + + context 'of type Fixnum' do + it 'has the number equivalent' do + page.evaluate_script("params['integer'] == 69").should be_true + end + end + + context 'of type Float' do + it 'has the number equivalent' do + page.evaluate_script("params['float'] == 3.1416").should be_true + end + end + + context 'of type Hash' do + it 'has the object equivalent' do + page.evaluate_script( + "JSON.stringify(params['hash']) == JSON.stringify({a : 'Hello', b : 'World'})").should be_true + end + end + end end