← Back to Upcase

Overriding Clearance gem helpers


(Jon Seidel) #1

I’m using the Clearance gem to replace an old, home-grown login system. I’ve got most of it working (still can’t get all the specs to pass) but so far mostly so good.

My old system requires both a user (login) name as well as an email address, whereas Clearance only requires the email address. I’ve overridden the Clearance Sessions and Sessions controller classes to add what I need, but there’s one method – sign_up_with – that I need to override in the Clearance helpers’ file:

./spec/support/features/clearance_helpers.rb

by adding a third parameter for the login name. That’s easily done and works just fine.

My question: How can I override that method so that even if I apply a Clearance gem upgrade, my override still works?

So I just added the overrides to spec/spec_helper.rb and that seems to work, e.g., after the config block I put:

module Features
  module ClearanceHelpers
    def sign_up_with(email, password, login='joe')
    ....
    end
  end
end

and that actually seemed to work (I added a default value to the new parameter so that I wouldn’t have to go in and modify the Clearance specs themselves). I’d like to know if there’s a better, more “standard” way to address something like this?


(Dan Croak) #2

Since spec/support/features/clearance_helpers.rb is generated, I think I would override sign_up_with right in spec/support/features/clearance_helpers.rb. You can always re-run rails generate clearance:views again in the future. Then, you can use git diff spec/support/features/clearance_helpers.rb to see if there is anything in the current version of Clearance for that generator that you want to keep.

That particular file has seen very little churn, however (1 commit ever). So, I expect it probably won’t change that often in the future:


(Jon Seidel) #3

Thanks, @croaky; I see your point, but I think I’ll stick with it in spec_helpers.rb so I don’t have to modify generated code.