Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/ngty/have_filter into ngty/…
Browse files Browse the repository at this point in the history
…master
  • Loading branch information
fester committed Jan 29, 2009
2 parents 53afd3c + 2fa4156 commit 464a255
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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__
11 changes: 11 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion init.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require 'spec/rails/matchers/have_filter'
require 'have_filter'
ActionController::Filters::Filter.send( :include, Spec::Rails::Filter )
1 change: 1 addition & 0 deletions install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Install hook code here
17 changes: 15 additions & 2 deletions lib/spec/rails/matchers/have_filter.rb → lib/have_filter.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -72,3 +84,4 @@ def have_around_filter(method_name)
end
end
end

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 }
Expand All @@ -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 }
Expand All @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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 }
Expand All @@ -128,6 +133,7 @@ class DummyApplicationController < ActionController::Base
end
end


describe "matcher variations" do
include Spec::Rails::Matchers
before(:each) { @controller = DummyApplicationController.new }
Expand Down
11 changes: 10 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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")

4 changes: 4 additions & 0 deletions tasks/have_filter_tasks.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# desc "Explaining what the task does"
# task :have_filter do
# # Task goes here
# end
1 change: 1 addition & 0 deletions uninstall.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Uninstall hook code here

0 comments on commit 464a255

Please sign in to comment.