Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ApplicationHelper test sample
module ApplicationHelper
def error_messages_for(*params)
# snip
end
end
# -*- coding: utf-8 -*-
require File.dirname(__FILE__) + '/../test_helper'
require 'application_helper'
class ApplicationHelperTest < Test::Unit::TestCase
include ActionView::Helpers::TextHelper
include ActionView::Helpers::TagHelper
include ApplicationHelper
context "error_messages_for" do
should "同じ文面のエラーメッセージは重複して表示されない" do
assert self.respond_to?(:error_messages_for)
user = Factory(:user)
@member = Member.new
@member.valid?
error_message = error_messages_for(:member)
(Hpricot(error_message)/'li').map(&:inner_html).each do |key|
assert_equal 1, error_message.scan(/#{key}/).size, "エラーメッセージ「#{key}」は一度だけ表示される"
end
end
end
end
class Member < ActiveRecord::Base
validates_presence_of :first_name_kana, :last_name_kana :message => "お名前(カナ)は必須入力の項目です。"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment