开发者

Why can my functional test not see my methods created using define_method?

开发者 https://www.devze.com 2023-02-13 14:30 出处:网络
I have this in my application_controller.rb: Group.all.each do |g| define_method( \"is_#{ g.name }?\".to_sym ) do

I have this in my application_controller.rb:

Group.all.each do |g|
  define_method( "is_#{ g.name }?".to_sym ) do
    unless @current_user.in_group?( g.name )
      flash[:notice] = "You must be in the #{ g.name.titleize } group to access that page"
      redirect_to '/'
      return false
    end
  end
end

It u开发者_运维百科ses entries in my groups table to create methods on the fly.

My problem is my functional tests can't see those methods:

  1) Error:
test_has_an_index(Sc::QuestionsControllerTest):
NoMethodError: undefined method `is_admin?' for #<Sc::QuestionsController:0x000000067749c0>

What do I need to do so my functional tests can see my dynamically created methods?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号