Recently we were hired by a startup and quickly assigned a task to build a brand new feature for them. So no problemo here! The feature was fairly extensive which necessitated thorough testing – perhaps a third of the entire application depended directly on it. Did I mention that the application has a comprehensive system of roles and users? It meant we had to test it for each and every one of the roles.
Although integration and unit tests cover most of it, a developer will still try and test it out manually. This meant we often had to go through the tedious task of logging in, logging out, remembering passwords, etc. This took a lot of our precious time which would otherwise be spent on coffee breaks meaning we had to figure out a way to speed up things. And we did speed things up… I present to you UserSwitch.
UserSwitch is a Rails plugin for switching between commonly used roles and users. It’s particularly useful for development and staging environments when you often need to switch between various accounts. It saves you from the hassle of logging in or out.
Well, it’s pretty difficult and annoying to switch between users and various user roles on big projects. What UserSwitch does is make this process easy, fast and it’s pretty god damn nice. It’s also easy to plug into your existing app.
Here in Kodius we like to keep things simple for developers so you will install this gem in no time.
gem "bootstrap" gem "devise"
Add it to your app’s Gemfile and run bundle like this:
or you can install it manually with:
gem install userswitch
After installing the gem you will need to create userswitch.yml template file in your config folder with this command:
Inside of this file you will set up users that are to be shown shown, edit roles and pick colors for buttons – but be very cautious, user roles need to be written exactly like user model. For example, if your model is named AdminUser then it needs to look like this:
User: dark-blue AdminUser: red
And at the end just insert this inside of your view file where you want the switch buttons to show:
Voila! Just like that you are ready to switch users with UserSwitch. Have fun!