1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00

Clean up helpers spec.

This commit is contained in:
Gabe Berke-Williams 2012-03-23 11:12:09 -04:00
parent 7950d00b69
commit 7d708058f0

View file

@ -1,40 +1,52 @@
# encoding: UTF-8
require "spec_helper"
include Shoulda::Matchers::ActiveModel
def store_translations(options = {:without => []})
options[:without] ||= []
options[:without] = [options[:without]] unless options[:without].is_a? Array
options[:without] = Array.wrap(options[:without] || [])
translations = {
:activerecord => {
:errors => {
:models => {
:example => {
:attributes => {
:attr => {}
}
}
},
:messages => {}
}
},
:errors => {
:models => {
:example => {
:attributes => {
:attr => {}
:attributes => {
:attr => {}
},
:messages => {}
}
}
}
},
:messages => {}
}
},
:errors => {
:attributes => {
:attr => {}
},
:messages => {}
}}
translations[:activerecord][:errors][:models][:example][:attributes][:attr][:blank] = 'Dont you do that to me!' unless options[:without].include?(:model_attribute)
translations[:activerecord][:errors][:models][:example][:blank] = 'Give it one more try!' unless options[:without].include?(:model)
translations[:activerecord][:errors][:messages][:blank] = 'Oh no!' unless options[:without].include?(:message)
translations[:errors][:attributes][:attr][:blank] = 'Seriously?' unless options[:without].include?(:attribute)
I18n.backend.store_translations :en, translations
unless options[:without].include?(:model_attribute)
translations[:activerecord][:errors][:models][:example][:attributes][:attr][:blank] = 'Dont you do that to me!'
end
unless options[:without].include?(:model)
translations[:activerecord][:errors][:models][:example][:blank] = 'Give it one more try!'
end
unless options[:without].include?(:message)
translations[:activerecord][:errors][:messages][:blank] = 'Oh no!'
end
unless options[:without].include?(:attribute)
translations[:errors][:attributes][:attr][:blank] = 'Seriously?'
end
I18n.backend.store_translations(:en, translations)
end
describe Shoulda::Matchers::ActiveModel::Helpers do
include Shoulda::Matchers::ActiveModel
describe "default_error_message" do
before do
define_model :example, :attr => :string do
@ -55,7 +67,7 @@ describe Shoulda::Matchers::ActiveModel::Helpers do
context "if no translation for the model attributes error exists" do
context "and the translation for the models error exists" do
it "provides the right error message" do
store_translations :without => :model_attribute
store_translations(:without => :model_attribute)
@model.should validate_presence_of(:attr)
end
end
@ -63,7 +75,7 @@ describe Shoulda::Matchers::ActiveModel::Helpers do
context "and no translation for the models error exists" do
context "and the translation for the message exists" do
it "provides the right error message" do
store_translations :without => [:model_attribute, :model]
store_translations(:without => [:model_attribute, :model])
@model.should validate_presence_of(:attr)
end
end
@ -71,7 +83,7 @@ describe Shoulda::Matchers::ActiveModel::Helpers do
context "and no translation for the message exists" do
context "and the translation for the attribute exists" do
it "provides the right error message" do
store_translations :without => [:model_attribute, :model, :message]
store_translations(:without => [:model_attribute, :model, :message])
@model.should validate_presence_of(:attr)
end
end