diff --git a/Rakefile b/Rakefile index fd5f495..c1b7ca3 100644 --- a/Rakefile +++ b/Rakefile @@ -9,8 +9,20 @@ RSpec::Core::RakeTask.new(:spec) do |spec| end -desc "Run tests" +desc "Run all tests" task :test do - puts "Testing..." sh "bundle exec rake spec" 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 + diff --git a/lib/paloma/action_controller_extension.rb b/lib/paloma/action_controller_extension.rb index 2773471..98c0ccd 100644 --- a/lib/paloma/action_controller_extension.rb +++ b/lib/paloma/action_controller_extension.rb @@ -22,7 +22,7 @@ module Paloma # js_callback :params => {} # def js_callback options = {}, extras = {} - default_callback = "#{controller_name}/#{action_name}" + default_callback = "#{controller_path}/#{action_name}" params = {} if options.is_a? Hash @@ -33,7 +33,7 @@ module Paloma elsif options.is_a? Symbol params = extras[:params] - callback = "#{controller_name}/#{options}" + callback = "#{controller_path}/#{options}" elsif options.nil? || options.is_a?(TrueClass) callback = default_callback diff --git a/spec/callback_spec.rb b/spec/callback_spec.rb index 7058cd7..00e08e9 100644 --- a/spec/callback_spec.rb +++ b/spec/callback_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -=begin + feature 'Callbacks' 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 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 diff --git a/spec/sample_app/app/assets/javascripts/paloma/articles/callbacks.js b/spec/sample_app/app/assets/javascripts/paloma/articles/_callbacks.js similarity index 100% rename from spec/sample_app/app/assets/javascripts/paloma/articles/callbacks.js rename to spec/sample_app/app/assets/javascripts/paloma/articles/_callbacks.js diff --git a/spec/sample_app/app/assets/javascripts/paloma/index.js b/spec/sample_app/app/assets/javascripts/paloma/index.js index e8ec454..2e31a27 100644 --- a/spec/sample_app/app/assets/javascripts/paloma/index.js +++ b/spec/sample_app/app/assets/javascripts/paloma/index.js @@ -1,2 +1,3 @@ //= require ./paloma -//= require ./articles/callbacks +//= require ./articles/_callbacks.js +//= require ./sample_namespace/_callbacks.js diff --git a/spec/sample_app/app/assets/javascripts/paloma/sample_namespace/_callbacks.js b/spec/sample_app/app/assets/javascripts/paloma/sample_namespace/_callbacks.js new file mode 100644 index 0000000..45f7ecb --- /dev/null +++ b/spec/sample_app/app/assets/javascripts/paloma/sample_namespace/_callbacks.js @@ -0,0 +1 @@ +//= require ./categories/_callbacks.js diff --git a/spec/sample_app/app/assets/javascripts/paloma/sample_namespace/categories/_callbacks.js b/spec/sample_app/app/assets/javascripts/paloma/sample_namespace/categories/_callbacks.js new file mode 100644 index 0000000..2c03f2d --- /dev/null +++ b/spec/sample_app/app/assets/javascripts/paloma/sample_namespace/categories/_callbacks.js @@ -0,0 +1 @@ +//= require_tree . diff --git a/spec/sample_app/app/assets/javascripts/paloma/sample_namespace/categories/index.js b/spec/sample_app/app/assets/javascripts/paloma/sample_namespace/categories/index.js new file mode 100644 index 0000000..442679d --- /dev/null +++ b/spec/sample_app/app/assets/javascripts/paloma/sample_namespace/categories/index.js @@ -0,0 +1,3 @@ +Paloma.callbacks['sample_namespace/categories/index'] = function(params){ + $('body').append($("
")); +}; diff --git a/spec/sample_app/app/views/sample_namespace/categories/index.html.erb b/spec/sample_app/app/views/sample_namespace/categories/index.html.erb new file mode 100644 index 0000000..172a7fe --- /dev/null +++ b/spec/sample_app/app/views/sample_namespace/categories/index.html.erb @@ -0,0 +1,5 @@ +<% @categories.each do |category| %> +
+ <%= category.name %> +
+<% end %> diff --git a/spec/sample_app/controllers.rb b/spec/sample_app/controllers.rb index 771a994..90f4c8f 100644 --- a/spec/sample_app/controllers.rb +++ b/spec/sample_app/controllers.rb @@ -56,7 +56,7 @@ end module SampleNamespace class CategoriesController < ApplicationController def index - raise controller_path.inspect + @categories = Category.all end end end diff --git a/spec/sample_app/init.rb b/spec/sample_app/init.rb index 76f9d5c..4321d3a 100644 --- a/spec/sample_app/init.rb +++ b/spec/sample_app/init.rb @@ -27,7 +27,10 @@ app.initialize! # Routes app.routes.draw do resources :articles, :controller => 'Articles' - resources :categories, :module => 'SampleNamespace' + + namespace :sample_namespace do + resources :categories + end end require "#{Paloma.root}/spec/sample_app/models"