This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe CommentCreator do | |
| it 'should persist record' do | |
| assert_difference 'Comment.count', +1 do | |
| CommentCreator.new(comment_params).call | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SignupsController < ActionController::Base | |
| def create | |
| @signup = TenantCreator.new(signup_params) | |
| if @signup.call | |
| redirect_to welcome_url(account_id: @signup.tenant.subdomain, auth_token: @signup.user.auth_token) | |
| else | |
| flash.now[:error] = @signup.errors.full_messages.join(', ') | |
| render action: :index | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TenantCreator | |
| def initialize(user_name, email, company_name) | |
| @tenant = Tenant.new(name: company_name) | |
| @user = @tenant.users.new(name: user_name, email: email) | |
| end | |
| def call | |
| if persist! | |
| SignupMailer.welcome(user).deliver_now | |
| AnalyticsTracker.new(tenant).call |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MessageCreator | |
| # ... | |
| def call | |
| process! | |
| return result | |
| end | |
| private | |
| def process! | |
| if message.save |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class WidgetCreator | |
| # ... | |
| attr_reader :widget, :success, :errors | |
| def result | |
| OpenStruct.new(success?: !errors, errors: errors.try(:flatten), widget: widget) | |
| end | |
| end | |
| widget_creator = WidgetCreator.new(params).call | |
| widget_creator.success? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UserCreator | |
| # ... | |
| # UserCreator.new(params).call | |
| def call | |
| do_the_work(args) | |
| end | |
| # Alternatively some people think this reads nicer: | |
| # UserCreateor.call(params) | |
| def self.call(*args) | |
| new(*args).call |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UserCreator | |
| def initialize(params) | |
| @user = User.new(params) | |
| end | |
| private | |
| attr_reader :user | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class LeadMagnetsController < FormsController | |
| private | |
| def skope | |
| current_user.lead_magnets | |
| end | |
| def form_params | |
| params[:form] = params[:lead_magnet] | |
| params.require(:form).permit(permitted_params) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class FormsController < ApplicationController | |
| before_action :set_form, only: [:show, :edit, :update, :destroy, :embed, :customize] | |
| # GET /forms | |
| # GET /forms.json | |
| def index | |
| @forms = skope.newest_first | |
| respond_to do |format| | |
| format.html | |
| format.json { render json: @forms } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class OptInsController < FormsController | |
| private | |
| def skope | |
| current_user.opt_ins | |
| end | |
| def form_params | |
| params[:form] = params[:opt_in] | |
| params.require(:form).permit(permitted_params) | |
| end |