diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..8fe7ab8 --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,8 @@ +Sat Aug 23 12:26:14 SGT 2008 (TAG: fix_compatibility_issues_with_rails_2_1_0) + + * Fixed compatibiity issues with rails-2.1.0 + + * Revised directory structure to conform to the one recommended by rspec-plugin-generator + (see http://github.com/pat-maddox/rspec-plugin-generator) + +# __END__ diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..7e1954b --- /dev/null +++ b/Rakefile @@ -0,0 +1,11 @@ +require 'rake' +require 'spec/rake/spectask' + +desc 'Default: run specs.' +task :default => :spec + +desc 'Run the specs' +Spec::Rake::SpecTask.new(:spec) do |t| + t.spec_opts = ['--colour --format progress --loadby mtime --reverse'] + t.spec_files = FileList['spec/**/*_spec.rb'] +end diff --git a/init.rb b/init.rb index d538444..de47072 100644 --- a/init.rb +++ b/init.rb @@ -1 +1,2 @@ -require 'spec/rails/matchers/have_filter' +require 'have_filter' +ActionController::Filters::Filter.send( :include, Spec::Rails::Filter ) diff --git a/install.rb b/install.rb new file mode 100644 index 0000000..f7732d3 --- /dev/null +++ b/install.rb @@ -0,0 +1 @@ +# Install hook code here diff --git a/lib/spec/rails/matchers/have_filter.rb b/lib/have_filter.rb similarity index 77% rename from lib/spec/rails/matchers/have_filter.rb rename to lib/have_filter.rb index 6f192d2..8ab9a94 100644 --- a/lib/spec/rails/matchers/have_filter.rb +++ b/lib/have_filter.rb @@ -1,5 +1,17 @@ module Spec module Rails + + module Filter + def self.included(base) + base.send( :include, InstanceMethods ) + end + module InstanceMethods + def runnable_callback?(action) + should_run_callback?( Struct.new(:action_name).new(action) ) + end + end + end + module Matchers class HaveFilter def initialize(filter_name) @@ -10,13 +22,13 @@ def initialize(filter_name) def matches?(target) @target = target.class - filter = @target.find_filter(@filter_name) { |filter| filter.type == @filter_type } + filter = @target.filter_chain.find(@filter_name) { |filter| filter.type == @filter_type } if @actions == :any_action filter else @actions = stringify(@actions) - filter and !@actions.find { |action| @target.filter_excluded_from_action?(filter, action) } + filter and @actions.find { |action| filter.runnable_callback?(action) } end end @@ -72,3 +84,4 @@ def have_around_filter(method_name) end end end + diff --git a/spec/rails/matchers/have_filter_spec.rb b/spec/have_filter_spec.rb similarity index 97% rename from spec/rails/matchers/have_filter_spec.rb rename to spec/have_filter_spec.rb index 7422d55..92527f0 100644 --- a/spec/rails/matchers/have_filter_spec.rb +++ b/spec/have_filter_spec.rb @@ -1,6 +1,6 @@ -require File.dirname(__FILE__) + '/../../spec_helper' -require 'action_controller' -require 'spec/rails/matchers/have_filter' +# require File.dirname(__FILE__) + '/../../spec_helper' +require File.dirname(__FILE__) + '/spec_helper' + class DummyApplicationController < ActionController::Base before_filter :before_filter_method @@ -18,6 +18,7 @@ class DummyApplicationController < ActionController::Base before_filter :before_some_actions_filter, :only => [:method_1, :method_2] end + describe "Default filter lookup settings" do include Spec::Rails::Matchers before(:each) { @controller = DummyApplicationController.new } @@ -43,6 +44,7 @@ class DummyApplicationController < ActionController::Base end end + describe "Lookup for filter with specified type" do include Spec::Rails::Matchers before(:each) { @controller = DummyApplicationController.new } @@ -60,6 +62,7 @@ class DummyApplicationController < ActionController::Base end end + describe "Lookup for filter restricted with :only" do include Spec::Rails::Matchers before(:each) {@controller = DummyApplicationController.new} @@ -88,6 +91,7 @@ class DummyApplicationController < ActionController::Base end end + describe "Lookup for filter restricted with :except" do include Spec::Rails::Matchers before(:each) {@controller = DummyApplicationController.new} @@ -116,6 +120,7 @@ class DummyApplicationController < ActionController::Base end end + describe "Filter lookup with array of actions specified" do include Spec::Rails::Matchers before(:each){ @controller = DummyApplicationController.new } @@ -128,6 +133,7 @@ class DummyApplicationController < ActionController::Base end end + describe "matcher variations" do include Spec::Rails::Matchers before(:each) { @controller = DummyApplicationController.new } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f6ebaa2..3424846 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,10 @@ -$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib') +begin + require File.dirname(__FILE__) + '/../../../../spec/spec_helper' +rescue LoadError + puts "You need to install rspec in your base app" + exit +end + +plugin_spec_dir = File.dirname(__FILE__) +ActiveRecord::Base.logger = Logger.new(plugin_spec_dir + "/debug.log") + diff --git a/tasks/have_filter_tasks.rake b/tasks/have_filter_tasks.rake new file mode 100644 index 0000000..d5a915b --- /dev/null +++ b/tasks/have_filter_tasks.rake @@ -0,0 +1,4 @@ +# desc "Explaining what the task does" +# task :have_filter do +# # Task goes here +# end diff --git a/uninstall.rb b/uninstall.rb new file mode 100644 index 0000000..9738333 --- /dev/null +++ b/uninstall.rb @@ -0,0 +1 @@ +# Uninstall hook code here