fixed test helper
Oleg
committed Mar 02, 2012
commit 336e417e8ece4ccc4fc013a92ca3ffd6f36c6427
Showing 5
changed files with
10 additions
and 16 deletions
test/test_helper.rb
+6
-12
| @@ | @@ -45,18 +45,12 @@ class ActiveSupport::TestCase |
| end | |
| # Example usage: | |
| - | # assert_has_errors_on( @record, [:field_1, :field_2] ) |
| - | # assert_has_errors_on( @record, {:field_1 => 'Message1', :field_2 => 'Message 2'} ) |
| - | def assert_has_errors_on(record, fields) |
| - | fields = [fields].flatten unless fields.is_a?(Hash) |
| - | fields.each do |field, message| |
| - | assert record.errors.to_hash.has_key?(field.to_sym), "#{record.class.name} should error on invalid #{field}" |
| - | if message && record.errors[field].is_a?(Array) && !message.is_a?(Array) |
| - | assert_not_nil record.errors[field].index(message) |
| - | elsif message |
| - | assert_equal message, record.errors[field] |
| - | end |
| - | end |
| + | # assert_has_errors_on @record, :field_1, :field_2 |
| + | def assert_has_errors_on(record, *fields) |
| + | unmatched = record.errors.keys - fields.flatten |
| + | assert unmatched.blank?, "#{record.class} has errors on '#{unmatched.join(', ')}'" |
| + | unmatched = fields.flatten - record.errors.keys |
| + | assert unmatched.blank?, "#{record.class} doesn't have errors on '#{unmatched.join(', ')}'" |
| end | |
| # Example usage: | |
test/unit/models/categorization_test.rb
+1
-1
| @@ | @@ -11,7 +11,7 @@ class CmsCategorizationTest < ActiveSupport::TestCase |
| def test_validation | |
| category = Cms::Categorization.new | |
| assert category.invalid? | |
| - | assert_has_errors_on category, [:categorized_type, :categorized_id] |
| + | assert_has_errors_on category, :category_id, :categorized_type, :categorized_id |
| end | |
| def test_creation | |
test/unit/models/file_test.rb
+1
-1
| @@ | @@ -12,7 +12,7 @@ class CmsFileTest < ActiveSupport::TestCase |
| assert_no_difference 'Cms::File.count' do | |
| file = Cms::File.create | |
| assert file.errors.present? | |
| - | assert_has_errors_on file, [:file_file_name] |
| + | assert_has_errors_on file, :site_id, :file_file_name, :file |
| end | |
| end | |
test/unit/models/page_test.rb
+1
-1
| @@ | @@ -13,7 +13,7 @@ class CmsPageTest < ActiveSupport::TestCase |
| page = Cms::Page.new | |
| page.save | |
| assert page.invalid? | |
| - | assert_has_errors_on page, [:layout, :slug, :label] |
| + | assert_has_errors_on page, :site_id, :layout, :slug, :label |
| end | |
| def test_validation_of_parent_presence | |
test/unit/models/snippet_test.rb
+1
-1
| @@ | @@ -12,7 +12,7 @@ class CmsSnippetTest < ActiveSupport::TestCase |
| snippet = Cms::Snippet.new | |
| snippet.save | |
| assert snippet.invalid? | |
| - | assert_has_errors_on snippet, [:label, :identifier] |
| + | assert_has_errors_on snippet, :site_id, :label, :identifier |
| end | |
| def test_label_assignment | |