rubycas / rubycas-client-rails

Rails plugin for the RubyCAS-Client
MIT License
77 stars 70 forks source link

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

Open CloCkWeRX opened 12 years ago

CloCkWeRX commented 12 years ago

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

This is particularly annoying to test, as:

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