Skip to content
This repository has been archived by the owner on Nov 11, 2017. It is now read-only.

Commit

Permalink
removed support for String filters
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.thoughtbot.com/plugins/when/trunk@347 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
  • Loading branch information
jcarroll committed Feb 15, 2008
1 parent 06047c4 commit f863008
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 152 deletions.
2 changes: 1 addition & 1 deletion lib/callbacks.rb
Expand Up @@ -26,7 +26,7 @@ def #{callback}_with_conditions(*callbacks, &block)
callback.call(record)
else
raise ActiveRecord::ActiveRecordError,
"Callbacks must be a symbol denoting the method to call, a string to be evaluated, a block to be invoked, or an object responding to the callback method."
'Callbacks must be a symbol denoting the method to call, a string to be evaluated or a block to be invoked.'
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/filters.rb
Expand Up @@ -18,13 +18,11 @@ def #{filter}_with_conditions(*filters, &block)
(! options[:unless].nil? && ActiveRecord::Base.evaluate_condition(options[:unless], controller))
if filter.class == Symbol
controller.send filter
elsif filter.class == String
eval(filter, binding)
elsif filter.class == Proc || filter.class == Method
filter.call(controller)
else
raise ActionController::ActionControllerError,
"Filters must be a symbol denoting the method to call, a string to be evaluated, a block to be invoked, or an object responding to the callback method."
'Filters must be a symbol denoting the method to call evaluated or a block to be invoked.'
end
end
end
Expand Down
148 changes: 0 additions & 148 deletions test/filters_test.rb
Expand Up @@ -195,154 +195,6 @@ def rescue_action(exception)
end
end

conditions.each do |condition|
basic_filters.each do |filter|
define_method "test_#{filter}_with_if_condition_#{condition.class}_which_returns_true_should_change_company_bio" do
CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :if => condition

CompaniesController.bio = 'thoughtbot'
@controller.flag = true

get :index
assert_equal 'new bio', CompaniesController.bio
end

define_method "test_#{filter}_with_if_condition_#{condition.class}_which_returns_false_should_not_change_company_bio" do
CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :if => condition

CompaniesController.bio = 'thoughtbot'
@controller.flag = false

get :index
assert_equal 'thoughtbot', CompaniesController.bio
end

define_method "test_#{filter}_with_unless_condition_#{condition.class}_which_returns_true_should_not_change_company_bio" do
CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :unless => condition

CompaniesController.bio = 'thoughtbot'
@controller.flag = true

get :index
assert_equal 'thoughtbot', CompaniesController.bio
end

define_method "test_#{filter}_with_unless_condition_#{condition.class}_which_returns_false_should_change_company_bio" do
CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :unless => condition

CompaniesController.bio = 'thoughtbot'
@controller.flag = false

get :index
assert_equal 'new bio', CompaniesController.bio
end

define_method "test_#{filter}_with_only_option_with_if_condition_#{condition.class}_which_returns_true_should_change_company_bio" do
CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :only => :show, :if => condition

CompaniesController.bio = 'thoughtbot'
@controller.flag = true

get :index
assert_equal 'thoughtbot', CompaniesController.bio

get :show
assert_equal 'new bio', CompaniesController.bio
end

define_method "test_#{filter}_with_only_option_if_condition_#{condition.class}_which_returns_false_should_not_change_company_bio" do
CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :only => :show, :if => condition

CompaniesController.bio = 'thoughtbot'
@controller.flag = false

get :index
assert_equal 'thoughtbot', CompaniesController.bio

get :show
assert_equal 'thoughtbot', CompaniesController.bio
end

define_method "test_#{filter}_with_only_option_unless_condition_#{condition.class}_which_returns_true_should_not_change_company_bio" do
CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :only => :show, :unless => condition

CompaniesController.bio = 'thoughtbot'
@controller.flag = true

get :index
assert_equal 'thoughtbot', CompaniesController.bio

get :show
assert_equal 'thoughtbot', CompaniesController.bio
end

define_method "test_#{filter}_with_only_option_unless_condition_#{condition.class}_which_returns_false_should_change_company_bio" do
CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :only => :show, :unless => condition

CompaniesController.bio = 'thoughtbot'
@controller.flag = false

get :index
assert_equal 'thoughtbot', CompaniesController.bio

get :show
assert_equal 'new bio', CompaniesController.bio
end

define_method "test_#{filter}_with_except_option_with_if_condition_#{condition.class}_which_returns_true_should_change_company_bio" do
CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :except => :show, :if => condition

CompaniesController.bio = 'thoughtbot'
@controller.flag = true

get :show
assert_equal 'thoughtbot', CompaniesController.bio

get :index
assert_equal 'new bio', CompaniesController.bio
end

define_method "test_#{filter}_with_except_option_if_condition_#{condition.class}_which_returns_false_should_not_change_company_bio" do
CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :except => :show, :if => condition

CompaniesController.bio = 'thoughtbot'
@controller.flag = false

get :show
assert_equal 'thoughtbot', CompaniesController.bio

get :index
assert_equal 'thoughtbot', CompaniesController.bio
end

define_method "test_#{filter}_with_except_option_unless_condition_#{condition.class}_which_returns_true_should_not_change_company_bio" do
CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :except => :show, :unless => condition

CompaniesController.bio = 'thoughtbot'
@controller.flag = true

get :show
assert_equal 'thoughtbot', CompaniesController.bio

get :index
assert_equal 'thoughtbot', CompaniesController.bio
end

define_method "test_#{filter}_with_except_option_unless_condition_#{condition.class}_which_returns_false_should_change_company_bio" do
CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :except => :show, :unless => condition

CompaniesController.bio = 'thoughtbot'
@controller.flag = false

get :show
assert_equal 'thoughtbot', CompaniesController.bio

get :index
assert_equal 'new bio', CompaniesController.bio
end
end
end

conditions.each do |condition|
basic_filters.each do |filter|
define_method "test_#{filter}_with_block_callback_with_if_condition_#{condition.class}_which_returns_true_should_change_company_name" do
Expand Down

0 comments on commit f863008

Please sign in to comment.