1
0
Fork 0
mirror of https://github.com/kbparagua/paloma synced 2023-03-27 23:21:17 -04:00

Test for calling callback for namespaced controller

This commit is contained in:
kbparagua 2013-01-17 01:55:09 +08:00
parent 30caabddcb
commit 6b02d8b6fa
11 changed files with 42 additions and 9 deletions

View file

@ -9,8 +9,20 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
end end
desc "Run tests" desc "Run all tests"
task :test do task :test do
puts "Testing..."
sh "bundle exec rake spec" sh "bundle exec rake spec"
end end
desc "Run callback tests"
task :test_callbacks do
sh "rspec ./spec/callback_spec.rb"
end
desc "Run generator tests"
task :test_generators do
sh "rspec ./spec/generator_spec.rb"
end

View file

@ -22,7 +22,7 @@ module Paloma
# js_callback :params => {} # js_callback :params => {}
# #
def js_callback options = {}, extras = {} def js_callback options = {}, extras = {}
default_callback = "#{controller_name}/#{action_name}" default_callback = "#{controller_path}/#{action_name}"
params = {} params = {}
if options.is_a? Hash if options.is_a? Hash
@ -33,7 +33,7 @@ module Paloma
elsif options.is_a? Symbol elsif options.is_a? Symbol
params = extras[:params] params = extras[:params]
callback = "#{controller_name}/#{options}" callback = "#{controller_path}/#{options}"
elsif options.nil? || options.is_a?(TrueClass) elsif options.nil? || options.is_a?(TrueClass)
callback = default_callback callback = default_callback

View file

@ -1,5 +1,5 @@
require 'spec_helper' require 'spec_helper'
=begin
feature 'Callbacks' do feature 'Callbacks' do
it 'should execute articles/new callback', :js => true do it 'should execute articles/new callback', :js => true do
@ -62,5 +62,12 @@ feature 'Callbacks' do
page.has_selector?('#from-articles-edit-callback').should == true page.has_selector?('#from-articles-edit-callback').should == true
end end
it 'should execute sample_namespace/categories/index callback', :js => true do
1.upto(10).each { |i| Category.create :name => "Category #{i}" }
visit sample_namespace_categories_path
page.has_selector?('#from-categories-index').should == true
end
end end
=end

View file

@ -1,2 +1,3 @@
//= require ./paloma //= require ./paloma
//= require ./articles/callbacks //= require ./articles/_callbacks.js
//= require ./sample_namespace/_callbacks.js

View file

@ -0,0 +1 @@
//= require ./categories/_callbacks.js

View file

@ -0,0 +1 @@
//= require_tree .

View file

@ -0,0 +1,3 @@
Paloma.callbacks['sample_namespace/categories/index'] = function(params){
$('body').append($("<div id='from-categories-index'></div>"));
};

View file

@ -0,0 +1,5 @@
<% @categories.each do |category| %>
<div>
<%= category.name %>
</div>
<% end %>

View file

@ -56,7 +56,7 @@ end
module SampleNamespace module SampleNamespace
class CategoriesController < ApplicationController class CategoriesController < ApplicationController
def index def index
raise controller_path.inspect @categories = Category.all
end end
end end
end end

View file

@ -27,7 +27,10 @@ app.initialize!
# Routes # Routes
app.routes.draw do app.routes.draw do
resources :articles, :controller => 'Articles' resources :articles, :controller => 'Articles'
resources :categories, :module => 'SampleNamespace'
namespace :sample_namespace do
resources :categories
end
end end
require "#{Paloma.root}/spec/sample_app/models" require "#{Paloma.root}/spec/sample_app/models"