Skip to content

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

@CloCkWeRX

Description

@CloCkWeRX

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions