Created
September 17, 2015 09:12
-
-
Save YumaInaura/9296536d4131ed64c9a8 to your computer and use it in GitHub Desktop.
Rails: アクションによってバリデーションを切り替えた時の、モデルのテスト方法 ref: http://qiita.com/Yinaura/items/7cd94e338ae031c04820
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
class User | |
validates :name, presence: true, on: :index | |
validates_length_of :introduction, maximum: 10000. on: :create | |
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
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