Initial commit of foodsoft 2

This commit is contained in:
Benjamin Meichsner 2009-01-06 11:49:19 +01:00
commit 5b9a7e05df
657 changed files with 70444 additions and 0 deletions

View file

@ -0,0 +1,175 @@
<p>Use this page to test helpers of the Localization Simplified plugin.
Put this file in your applications view directory, add a controller action "helper_tests", and view this page</p>
<p>Sentence with UTF-8 characters: Café, Danish(æ,ø,å), Swedish(ä,ö,å), Spanish: (ñ) </p>
<table border="1">
<tr>
<th>fn</th>
<th>result</th>
<th>expected</th>
</tr>
<tr>
<td><code>time_ago_in_words(3.seconds.ago, true)</code></td>
<td><%= time_ago_in_words(3.seconds.ago, true) %></td>
<td>'less than 5 seconds'</td>
</tr>
<tr>
<td><code>time_ago_in_words(9.seconds.ago, true)</code></td>
<td><%= time_ago_in_words(9.seconds.ago, true) %></td>
<td>'less than 10 seconds'</td>
</tr>
<tr>
<td><code>time_ago_in_words(20.seconds.ago, true)</code></td>
<td><%= time_ago_in_words(20.seconds.ago, true) %></td>
<td>'less than 20 seconds'</td>
</tr>
<tr>
<td><code>time_ago_in_words(31.seconds.ago, true)</code></td>
<td><%= time_ago_in_words(31.seconds.ago, true) %></td>
<td>'half a minute'</td>
</tr>
<tr>
<td><code>time_ago_in_words(50.seconds.ago, true)</code></td>
<td><%= time_ago_in_words(50.seconds.ago, true) %></td>
<td>'less than a minute'</td>
</tr>
<tr>
<td><code>time_ago_in_words(80.seconds.ago, true)</code></td>
<td><%= time_ago_in_words(80.seconds.ago, true) %></td>
<td>'1 minute'</td>
</tr>
<tr>
<td><code>time_ago_in_words(4.minutes.ago, true)</code></td>
<td><%= time_ago_in_words(4.minutes.ago, true) %></td>
<td>'4 minutes'</td>
</tr>
<tr>
<td><code>time_ago_in_words(50.minutes.ago, true)</code></td>
<td><%= time_ago_in_words(50.minutes.ago, true) %></td>
<td>'about 1 hour'</td>
</tr>
<tr>
<td><code>time_ago_in_words(4.hours.ago, true)</code></td>
<td><%= time_ago_in_words(4.hours.ago, true) %></td>
<td>'about 4 hours'</td>
</tr>
<tr>
<td><code>time_ago_in_words(1.day.ago, true)</code></td>
<td><%= time_ago_in_words(1.day.ago, true) %></td>
<td>'1 day'</td>
</tr>
<tr>
<td><code>time_ago_in_words(4.days.ago, true)</code></td>
<td><%= time_ago_in_words(4.days.ago, true) %></td>
<td>'4 days'</td>
</tr>
<tr>
<td><code>time_ago_in_words(1.month.ago, true)</code></td>
<td><%= time_ago_in_words(1.month.ago, true) %></td>
<td>'1 month'</td>
</tr>
<tr>
<td><code>time_ago_in_words(4.months.ago, true)</code></td>
<td><%= time_ago_in_words(4.months.ago, true) %></td>
<td>'4 months'</td>
</tr>
<tr>
<td><code>time_ago_in_words(13.months.ago, true)</code></td>
<td><%= time_ago_in_words(13.months.ago, true) %></td>
<td>'1 year'</td>
</tr>
<tr>
<td><code>time_ago_in_words(26.months.ago, true)</code></td>
<td><%= time_ago_in_words(26.months.ago, true) %></td>
<td>'2 years'</td>
</tr>
</table>
<p>number_to_currency test:</p>
<ul>
<li><%= number_to_currency(1008323) %></li>
<li><%= number_to_currency(10083.777) %></li>
<li><%= number_to_currency(0.2) %></li>
</ul>
<p>Array.to_sentence test: [1,2,3].to_sentence: "<%= [1,2,3].to_sentence %>" <em>(expected "1,2, and 3")</em></p>
<% t = Time.parse('2006-12-25 11:55') -%>
<% d = Date.parse('2006-12-25 11:55') -%>
<table>
<tr>
<th>Formatted time:</th>
<th>result</th>
<th>expected</th>
</tr>
<tr>
<td>t.to_formatted_s()</td>
<td><%= t.to_formatted_s() %></td>
<td>Mon Dec 25 11:55:00 Romance Standard Time 2006 </td>
</tr>
<tr>
<td>t.to_formatted_s(:default)</td>
<td><%= t.to_formatted_s(:default) %></td>
<td>Mon Dec 25 11:55:00 Romance Standard Time 2006 </td>
</tr>
<tr>
<td>t.to_formatted_s(:long)</td>
<td><%= t.to_formatted_s(:long) %></td>
<td>December 25, 2006 11:55</td>
</tr>
<tr>
<td>t.to_formatted_s(:short)</td>
<td><%= t.to_formatted_s(:short) %></td>
<td> 25 Dec 11:55</td>
</tr>
<tr>
<th>Formatted date:</th>
<th>result</th>
<th>expected</th>
</tr>
<tr>
<td>d.to_formatted_s()</td>
<td><%= d.to_formatted_s() %></td>
<td>2006-12-25</td>
</tr>
<tr>
<td>d.to_formatted_s(:default)</td>
<td><%= d.to_formatted_s(:default) %></td>
<td>2006-12-25</td>
</tr>
<tr>
<td>d.to_formatted_s(:long)</td>
<td><%= d.to_formatted_s(:long) %></td>
<td>December 25, 2006</td>
</tr>
<tr>
<td>d.to_formatted_s(:short)</td>
<td><%= d.to_formatted_s(:short) %></td>
<td> 25 Dec</td>
</tr>
</table>
<h3>date_select and datetime_select tests</h3>
<%
%>
<p>
<label for="testmodel_date">Test order and localized content of date_select</label><br />
<%= date_select :testmodel, :date %>
</p>
<p>
<label for="testmodel_datetime">Test order and localized content of datetime_select</label><br />
<%= datetime_select :testmodel, :datetime %>
</p>
<p>
<label for="testmodel_select_date">Test order and localized content of select_date</label><br />
<%=
# this gives exception
# select_date :testmodel, :select_date
%>
</p>
<h3>String concatenation tests</h3>
<p><code> truncate 'Iñtërnâtiônàlizætiøn', 12</code>: <strong><%= truncate 'Iñtërnâtiônàlizætiøn', 12 %></strong> (expected: "Iñtërnâti…")</p>

View file

@ -0,0 +1,115 @@
# run from command line "ruby test_the_hooks.rb"
#
# These tests are testing hooks that this plugin modifies
# These tests are written to test standard ruby/rails functions
# Note that it requires access to the standard ruby/rails plugins that it modifies
# require standard gems
require 'rubygems'
require 'test/unit'
require 'active_record'
require 'action_view'
require 'active_support'
require File.dirname(__FILE__) + '/../lib/lang_en'
class LocalizationSimplifiedTest < Test::Unit::TestCase
include LocalizationSimplified
def test_language_file_en
assert_equal "en",LocalizationSimplified::About[:lang]
assert_kind_of Class,LocalizationSimplified::About.class
assert_kind_of Class,LocalizationSimplified::ActiveRecord::ErrorMessages.class
assert_kind_of Class,LocalizationSimplified::DateHelper::Texts.class
assert_kind_of Class,LocalizationSimplified::NumberHelper::CurrencyOptions.class
assert_kind_of Class,LocalizationSimplified::ArrayHelper::ToSentenceTexts.class
end
def test_default_active_record_exists
assert ::ActiveRecord
assert ::ActiveRecord::Errors
assert_kind_of Hash, ::ActiveRecord::Errors.default_error_messages
end
def test_default_active_record_hooks
hook = ::ActiveRecord::Errors.default_error_messages
expect = {
:inclusion => "is not included in the list",
:exclusion => "is reserved",
:invalid => "is invalid",
:confirmation => "doesn't match confirmation",
:accepted => "must be accepted",
:empty => "can't be empty",
:blank => "can't be blank",
:too_long => "is too long (maximum is %d characters)",
:too_short => "is too short (minimum is %d characters)",
:wrong_length => "is the wrong length (should be %d characters)",
:taken => "has already been taken",
:not_a_number => "is not a number",
#Jespers additions:
:error_translation => "error",
:error_header => "%s prohibited this %s from being saved",
:error_subheader => "There were problems with the following fields:"
}
assert_equal expect[:inclusion], hook[:inclusion]
assert_equal expect[:exclusion], hook[:exclusion]
assert_equal expect[:invalid], hook[:invalid]
assert_equal expect[:confirmation], hook[:confirmation]
assert_equal expect[:accepted], hook[:accepted]
assert_equal expect[:empty], hook[:empty]
assert_equal expect[:blank], hook[:blank]
assert_equal expect[:too_long], hook[:too_long]
assert_equal expect[:too_short], hook[:too_short]
assert_equal expect[:wrong_length], hook[:wrong_length]
assert_equal expect[:taken], hook[:taken]
assert_equal expect[:not_a_number], hook[:not_a_number]
end
def test_plugin_hooks_dont exist
hook = ::ActiveRecord::Errors.default_error_messages
#plugin s additions is supposed to not exist on ActiveRecord before plugin is added
assert_nil hook[:error_translation], "Should fail if plugin already added"
assert_nil hook[:error_header], "Should fail if plugin already added"
assert_nil hook[:error_subheader], "Should fail if plugin already added"
end
def test_number_to_currency
assert ActionView::Helpers::NumberHelper
obj = ActionView::Base.new
assert_respond_to obj, 'number_to_currency'
#assert_nil obj.orig_number_to_currency #FIXME this line makes assertion fail. Should be nil.
assert_equal "$1,234,567,890.51", obj.number_to_currency(1234567890.506)
end
def test_to_sentence
assert ActiveSupport::CoreExtensions::Array::Conversions
a = Array.new
assert_respond_to a, 'to_sentence'
assert_equal "1, 2, and 3", [1,2,3].to_sentence
end
def test_date_helpers
assert ActionView::Helpers::NumberHelper
a = ActionView::Base.new
assert 'less than 5 seconds' , a.time_ago_in_words(3.seconds.ago, true)
assert 'less than 10 seconds' , a.time_ago_in_words(9.seconds.ago, true)
assert 'less than 20 seconds' , a.time_ago_in_words(20.seconds.ago, true)
assert 'half a minute' , a.time_ago_in_words(31.seconds.ago, true)
assert 'less than a minute' , a.time_ago_in_words(50.seconds.ago, false)
assert 'less than a minute' , a.time_ago_in_words(50.seconds.ago)
assert '1 minute' , a.time_ago_in_words(80.seconds.ago)
assert '4 minutes' , a.time_ago_in_words(4.minutes.ago)
assert 'about 1 hour' , a.time_ago_in_words(50.minutes.ago)
assert '4 hours' , a.time_ago_in_words(4.hours.ago)
assert '1 day' , a.time_ago_in_words(1.day.ago)
assert '4 days' , a.time_ago_in_words(4.days.ago)
end
end

View file

@ -0,0 +1,117 @@
# run from command line: "ruby test_the_plugin.rb"
#
# Testing hooks that this plugin modifies
# These tests are written to test standard ruby/rails functions
# Note that it requires access to the standard ruby/rails plugins that it modifies
# require standard gems
require 'rubygems'
require 'test/unit'
require 'active_record'
require 'action_view'
require 'active_support'
# FIXME: I want a way to test all languages at a time.
# Currently this $language flag has to be changed with every test run
$language = "en" unless $language
require File.dirname(__FILE__) + '/../lib/lang_' + $language
require File.dirname(__FILE__) + '/../lib/localization_simplified'
class LocalizationSimplifiedTest < Test::Unit::TestCase
include LocalizationSimplified
def setup
@languages=%w{chef da de en es se} #languages that should be tested
end
def test_language_file
assert_equal $language,LocalizationSimplified::About[:lang]
assert_kind_of Class,LocalizationSimplified::About.class
assert_kind_of Class,LocalizationSimplified::ActiveRecord::ErrorMessages.class
assert_kind_of Class,LocalizationSimplified::DateHelper::Texts.class
assert_kind_of Class,LocalizationSimplified::NumberHelper::CurrencyOptions.class
assert_kind_of Class,LocalizationSimplified::ArrayHelper::ToSentenceTexts.class
end
def test_active_record_hooks_should_be_present
expect =LocalizationSimplified::ActiveRecord::ErrorMessages
model = ::ActiveRecord::Errors.default_error_messages
assert_equal expect[:inclusion], model[:inclusion]
assert_equal expect[:exclusion], model[:exclusion]
assert_equal expect[:invalid], model[:invalid]
assert_equal expect[:confirmation], model[:confirmation]
assert_equal expect[:accepted], model[:accepted]
assert_equal expect[:empty], model[:empty]
assert_equal expect[:blank], model[:blank]
assert_equal expect[:too_long], model[:too_long]
assert_equal expect[:too_short], model[:too_short]
assert_equal expect[:wrong_length], model[:wrong_length]
assert_equal expect[:taken], model[:taken]
assert_equal expect[:not_a_number], model[:not_a_number]
#expect's additions is supposed to not exist on ActiveRecord before expect is added
assert_equal expect[:error_translation], model[:error_translation]
assert_equal expect[:error_header], model[:error_header]
assert_equal expect[:error_subheader], model[:error_subheader]
end
def test_active_record_is_loaded_with_plugin_hooks
assert_not_nil ::ActiveRecord::Errors.default_error_messages[:error_translation]
assert_not_nil ::ActiveRecord::Errors.default_error_messages[:error_header]
assert_not_nil ::ActiveRecord::Errors.default_error_messages[:error_subheader]
end
#note that this test will fail if currency format is different from "$1.234,00"
def test_number_to_currency
assert ActionView::Helpers::NumberHelper
obj = ActionView::Base.new
assert_respond_to obj, 'number_to_currency'
assert_respond_to obj, 'orig_number_to_currency'
assert_equal "$1,234,567,890.51", obj.number_to_currency(1234567890.506), "NOTE: This currency test should fail if locale has different currency format"
end
def test_to_sentence
options =LocalizationSimplified::ArrayHelper::ToSentenceTexts
arr = [1,2,3]
s = "1, 2" + ("," unless options[:skip_last_comma]).to_s + " "+ options[:connector].to_s + " 3"
assert_equal s, arr.to_sentence
# FIXME: test below fails for some reason I cannot understand
# assert_respond_to arr, orig_to_sentence
end
def test_time_ago_in_words
assert ActionView::Helpers::NumberHelper
a = ActionView::Base.new
messages =LocalizationSimplified::DateHelper::Texts
assert messages[:less_than_a_minute] , a.time_ago_in_words(3.seconds.ago, false)
assert format( messages[:less_than_x_seconds], 5 ) , a.time_ago_in_words(3.seconds.ago, true)
assert format( messages[:less_than_x_seconds], 10 ) , a.time_ago_in_words(9.seconds.ago, true)
assert format( messages[:less_than_x_seconds], 20 ) , a.time_ago_in_words(20.seconds.ago, true)
assert messages[:half_a_minute] , a.time_ago_in_words(31.seconds.ago, true)
assert messages[:less_than_a_minute] , a.time_ago_in_words(50.seconds.ago)
assert messages[:one_minute] , a.time_ago_in_words(80.seconds.ago)
assert messages[:one_hour] , a.time_ago_in_words(50.minutes.ago)
assert messages[:one_day] , a.time_ago_in_words(1.day.ago)
assert messages[:one_month] , a.time_ago_in_words(1.month.ago)
assert messages[:one_year] , a.time_ago_in_words(1.year.ago)
# FIXME: 3 tests below are not tested, as they require more logic in the test
# Please fix, if possible and simple
# assert format(messages[:x_minutes], distance_in_minutes) , a.time_ago_in_words(4.minutes.ago)
# assert format( messages[:x_hours], (distance_in_minutes.to_f / 60.0).round ) , a.time_ago_in_words(4.hours.ago)
# assert format( messages[:x_days], (distance_in_minutes / 1440).round ) , a.time_ago_in_words(4.days.ago)
end
def test_time_is_localized
t = Time.parse('2006-08-23 11:55:44')
assert_equal "Wed Aug 23 11:55:44 Romance Daylight Time 2006", t.to_s, "NOTE: This test should fail if locale has different daynames, monthnames, timezone"
end
def test_date_is_localized
end
end