🏃♀️
This file contains 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
# ActiveModel::SerializerをActiveModel::Modelで使う | |
class Model < ApplicationRecord | |
end | |
# Modelの操作をするクラス | |
class Dummy | |
include ActiveModel::Serialization | |
include ActiveModel::Model | |
attr_accessor :model |
This file contains 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
# Helper spec内でrequestのmockをする | |
let(:request) { instance_double("request", methods) } | |
let(:devices) { %w(android iphone pc) } | |
let(:methods) { | |
{}.tap do |t| | |
devices.map do |device| | |
t.merge!({ "from_#{device}?": false }) | |
end | |
end | |
} |
This file contains 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
# first CIで落ちたseedを指定 | |
$ bin/spring rspec spec -fd --order rand:40433 | |
# second 対象のspec前のspecでデータ周り、前提条件で依存している為ディレクトリずつ実行してみる。 | |
$ bin/spring rspec spec/models/ spec/features/failer_spec.rb -fd --order rand:40433 --fail-fast | |
# third ディレクトリを変えて絞っていく | |
$ bin/spring rspec spec/lib/ spec/features/failer_spec.rb -fd --order rand:40433 --fail-fast | |
# loop |
This file contains 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 EnumI18n | |
extend ActiveSupport::Concern | |
included do | |
after_initialize :set_enum_text | |
end | |
def set_enum_text | |
name = (self.class == ::User) ? 'user' : model_name&.element | |
defined_enums.each do |enum| | |
enum_column = enum.first |
This file contains 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
let(:methods) { %w(content array sub_class) } | |
expect(methods).not_to include(match /_text/) |
This file contains 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
# Sample Guardfile use options chdir | |
paths = %w(spec submodule/spec) | |
dirs = %w(./ submodule/) | |
dirs.each do |dir| | |
guard :rspec, cmd: 'bin/spring rspec', chdir: dir do | |
require 'guard/rspec/dsl' | |
dsl = Guard::RSpec::Dsl.new(self) | |
# RSpec files |
This file contains 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 Hook | |
def increment | |
super | |
expire | |
end | |
end | |
class Ranking | |
prepend Hook |
This file contains 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
# Gem | |
gem 'composite_primary_keys' | |
# 複合keyの設定の為、idのprimary_keyを解除して、複合keyでindex追加 | |
class CreatePageviews < ActiveRecord::Migration | |
def change | |
create_table :pageviews, id: false do |t| | |
t.integer :id, null: false | |
t.integer :article_id, null: false | |
t.integer :category_id, null: false |
This file contains 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
# app/models/syllabus.rb | |
class Syllabus | |
include ActiveModel::Model | |
attr_accessor :records, :academic_year, :course | |
validates :academic_year, presence: true | |
def initialize(academic_year, course = nil) | |
@academic_year = academic_year | |
@course = course |
This file contains 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
# app/models/account.rb | |
class Account | |
include ActiveModel::Model | |
validates :name, presence: true | |
def initialize | |
# ~ | |
end | |
end |
NewerOlder