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
# Bad | |
describe User, type: :model do | |
it do | |
expect(create(:user)).to be_valid | |
end | |
end | |
# Good |
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
require 'rails_helper' | |
RSpec.describe User, type: :model do | |
context 'let!' do | |
let!(:paul) { create(:user, first_name: 'Paul') } | |
let!(:ringo) { create(:user, first_name: 'Ringo') } | |
let!(:george) { create(:user, first_name: 'George') } | |
let!(:john) { create(:user, first_name: 'John') } | |
it { expect(paul.first_name).to eq('Paul') } |
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
schema = Dry::Validation.Schema(Dry::Validation::Schema::Params) do | |
required(:email).filled(:str?) | |
end | |
schema.(email: true).success? # => false | |
schema.(email: true).messages # => {:email=>["must be a string"]} |
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
schema = Dry::Validation.Schema(Dry::Validation::Schema::Params) do | |
configure do | |
option :user | |
def email_confirmed?(value) | |
# your code | |
end | |
def authenticated?(value) | |
# your code |
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
schema = Dry::Validation.Schema(Dry::Validation::Schema::Params) do | |
configure do | |
option :user | |
def exists?(value) | |
# your code | |
end | |
def free?(uid, value) | |
# your code |
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
module Api | |
module V1 | |
class SsoController < ApiController | |
before_action :authenticate | |
def show | |
service = ::Sso::Show.new(params_h.merge(current_user: current_user)) | |
service.execute! | |
if service.success? | |
render json: ::V1::SsoSerializer.new(current_user) |
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
module Sso | |
class Show < ApplicationService | |
schema do | |
required(:sso).filled(:str?) | |
required(:sig).filled(:str?) | |
end | |
def execute! | |
current_user.build_sso_url(query_string) | |
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
schema = Dry::Validation.Schema(Dry::Validation::Schema::Params) do | |
configure { config.namespace = :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
schema = Dry::Validation.Schema(Dry::Validation::Schema::Params) do | |
optional(:password).maybe(:str?, min_size?: 6) | |
optional(:identity_id).maybe(:int?) | |
rule(password_or_identity_id_filled: %i[password identity_id]) do |password, identity_id| | |
password.filled? | identity_id.filled? | |
end | |
end |