Update to the Rails Services Gem
A couple of years back I released my first gem, Rails Services. It’s a very simple gem and project, adding two generators to your Rails application: rails_services:create and rails_services:destroy.

The long and short of it is that you run a rails generator, providing a few arguments and wait while the generator creates a Service class and a corresponding test file.

What’s New
Basically, I finally got around to making the generation of the test file (spec or unit) dynamic … and maybe did a little code clean-up along the way.

Install

gem install 'rails_services'

# bundler  
gem 'rails_services'

Usage
Generate your service.

Terminal

~/path/to/your_rails_app/ $ rails generate rails_services:create ServiceClassName ParentModelOrController SubFolder[optional]

Output
That command will generate a base service class with the following data.

app/services/parent_model_or_controllers/sub_folder/service_class_name_test.rb

module ParentModelOrControllers
  module SubFolder
    class ServiceClassName
      def self.call

      end
    end
  end
end

It will also create a related test file for you.

test/services/parent_model_or_controllers/sub_folder/service_class_name_test.rb

require 'test_helper'

class ServiceClassName < ActiveSupport::TestCase
  def test_access
    assert (1 == 2), 'You best test yourself before you wreck yourself'
  end
end

Or, if you’re using Rspec

test/services/parent_model_or_controllers/sub_folder/service_class_name_spec.rb

describe ParentModelOrControllers::SubFolder::ServiceClassName
  context 'do something' do
    it 'should test something' do
      skip
    end
  end
end

It has served me well and saved me time as I tend to use services a lot in my Rails apps over loading up a models or controller (or delving too deeply into the concerns).