Permalink
Browse files

Skip alt-text validation if the news article is being deleted or arch…

…ived
  • Loading branch information...
1 parent c3e40fd commit 9e50b6d3a6ce4f2bf596f1355c90d6e837c4a3d2 @tomafro tomafro committed Feb 3, 2012
Showing with 20 additions and 4 deletions.
  1. +5 −0 app/models/document.rb
  2. +0 −1 app/models/document/workflow.rb
  3. +1 −1 app/models/news_article.rb
  4. +14 −2 test/unit/news_article_test.rb
View
@@ -29,6 +29,11 @@ def validate(record)
validates_with UnmodifiableOncePublishedValidator
UNMODIFIABLE_STATES = %w(published archived deleted).freeze
+ FROZEN_STATES = %w(archived deleted).freeze
+
+ def skip_main_validation?
+ FROZEN_STATES.include?(state)
+ end
def unmodifiable?
persisted? && UNMODIFIABLE_STATES.include?(state_was)
@@ -71,5 +71,4 @@ def validate(record)
end
end
end
-
end
@@ -8,7 +8,7 @@ class NewsArticle < Document
mount_uploader :image, DocumentImageUploader, mount_on: :carrierwave_image
mount_uploader :featuring_image, FeaturingImageUploader, mount_on: :carrierwave_featuring_image
- validate :image_must_have_a_description
+ validate :image_must_have_a_description, unless: :skip_main_validation?
add_trait do
def process_associations_before_save(document)
@@ -11,19 +11,31 @@ class NewsArticleTest < ActiveSupport::TestCase
assert article.valid?
end
- test "should be invalid if has image but no image description" do
+ test "should be invalid if has image but no alt text" do
article = build(:news_article, image: fixture_file_upload('portas-review.jpg'))
article.image_alt_text = nil
refute article.valid?
end
- test "should still be valid if has not image and no image description" do
+ test "should still be valid if has no image and no alt text" do
article = build(:news_article)
article.image = nil
article.image_alt_text = nil
assert article.valid?
end
+ test "should still be archivable if alt text validation would normally fail" do
+ article = create(:published_news_article, image: fixture_file_upload('portas-review.jpg'), image_alt_text: 'candid-photo')
+ article.update_attribute(:image_alt_text, nil)
+ NewsArticle.find(article.id).archive!
+ end
+
+ test "should still be deleteable if alt text validation would normally fail" do
+ article = create(:submitted_news_article, image: fixture_file_upload('portas-review.jpg'), image_alt_text: 'candid-photo')
+ article.update_attribute(:image_alt_text, nil)
+ NewsArticle.find(article.id).delete!
+ end
+
test "should be able to relate to other documents" do
article = build(:news_article)
assert article.can_be_related_to_policies?

0 comments on commit 9e50b6d

Please sign in to comment.