Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Created September 17, 2015 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YumaInaura/9296536d4131ed64c9a8 to your computer and use it in GitHub Desktop.
Save YumaInaura/9296536d4131ed64c9a8 to your computer and use it in GitHub Desktop.
Rails: アクションによってバリデーションを切り替えた時の、モデルのテスト方法 ref: http://qiita.com/Yinaura/items/7cd94e338ae031c04820
class User
validates :name, presence: true, on: :index
validates_length_of :introduction, maximum: 10000. on: :create
end
require 'spec_helper'
describe User, type: :model do
it { should validate_presence_of(:name).on(:index) }
it { should validate_length_of(:introduction).is_at_most(10000).on(:create) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment