Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of class level configuration, singleton pattern makes testing difficult #15

Open
CloCkWeRX opened this issue Aug 6, 2012 · 0 comments

Comments

@CloCkWeRX
Copy link

The way the code is put together implies There Will Only Ever Be One Filter.

This is particularly annoying to test, as:

  • You have to proxy the implementation to apply common stubbing techniques (Try RubyCAS::Filter.any_instance.expects(...) for example)
  • @@config is global state
  • The common way in which RubyCAS::Filter is recommended to be used (in a before_filter), and how it relies on the global configuration behaviour is complex

Having looked at the origins of this, I understand it's from the depths of 2006 or earlier, but it could do with a bit of love to remove the singleton nature and configuration pattern in favour of something more DI flavoured.

ie:

    class YourController
      before_filter :configurize, :restrict
      
      def configurize
        client = CASClient.new()
        @filter = RubyCAS::Filter.new(client, config.rubycas)
      end




      def restrict
        @filter.filter(self)
      end
    end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant