From 229986250069d1065b459d2e3a6a2d337a050b3e Mon Sep 17 00:00:00 2001 From: kbparauga Date: Fri, 28 Aug 2015 14:13:13 +0800 Subject: [PATCH] Handle js(true) and raise error on invalid argument --- lib/paloma/action_controller_extension.rb | 30 ++++++++++++++++++--- test_app/app/controllers/main_controller.rb | 3 ++- test_app/spec/units/controller_spec.rb | 2 +- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/paloma/action_controller_extension.rb b/lib/paloma/action_controller_extension.rb index da919e4..c405d24 100644 --- a/lib/paloma/action_controller_extension.rb +++ b/lib/paloma/action_controller_extension.rb @@ -67,6 +67,9 @@ module Paloma # # def js path_or_options, params = {} + puts '-----------------------------------------------------------------' + puts "js #{path_or_options.inspect}, #{params.inspect}" + return self.paloma.clear_request if !path_or_options self.paloma.params.merge! params || {} @@ -80,8 +83,8 @@ module Paloma # if path_or_options.is_a? String route = ::Paloma::Utilities.interpret_route path_or_options - self.paloma.resource = route[:resource] unless route[:resource].blank? - self.paloma.action = route[:action] unless route[:action].blank? + self.paloma.resource = route[:resource] || self.default_resource + self.paloma.action = route[:action] || self.default_action # :action elsif path_or_options.is_a? Symbol @@ -91,7 +94,16 @@ 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 + raise "Paloma: Invalid argument (#{path_or_options}) for js method" end + + puts "Paloma.request = #{self.paloma.request.inspect}" + puts "Paloma has request? #{self.paloma.has_request?}" end @@ -101,8 +113,8 @@ module Paloma # Keeps track of what Rails controller/action is executed. # def track_paloma_request - self.paloma.resource ||= ::Paloma::Utilities.get_resource controller_path - self.paloma.action ||= self.action_name + self.paloma.resource ||= self.default_resource + self.paloma.action ||= self.default_action end @@ -134,6 +146,16 @@ module Paloma @paloma ||= ::Paloma::Controller.new end + + def default_resource + ::Paloma::Utilities.get_resource self.controller_path + end + + + def default_action + self.action_name + end + end diff --git a/test_app/app/controllers/main_controller.rb b/test_app/app/controllers/main_controller.rb index cc74637..529fec7 100644 --- a/test_app/app/controllers/main_controller.rb +++ b/test_app/app/controllers/main_controller.rb @@ -2,13 +2,14 @@ class MainController < ApplicationController # Default behavior def index + js false + js 11231242 render :inline => 'Main#index', :layout => 'application' end # Override controller def show - js false js 'OtherMain', :x => 1 render :inline => 'Main#show', :layout => 'application' end diff --git a/test_app/spec/units/controller_spec.rb b/test_app/spec/units/controller_spec.rb index be15d12..f93bc8a 100644 --- a/test_app/spec/units/controller_spec.rb +++ b/test_app/spec/units/controller_spec.rb @@ -106,4 +106,4 @@ describe Paloma::Controller do end end -end \ No newline at end of file +end