stories must have at least one tag
This commit is contained in:
parent
2375e3f210
commit
13a584854e
|
@ -16,7 +16,7 @@ class Story < ActiveRecord::Base
|
|||
MAX_EDIT_MINS = 30
|
||||
|
||||
attr_accessor :vote, :story_type, :already_posted_story, :fetched_content
|
||||
attr_accessor :tags_to_add, :tags_to_delete
|
||||
attr_accessor :new_tags, :tags_to_add, :tags_to_delete
|
||||
|
||||
after_save :deal_with_tags
|
||||
before_create :assign_short_id
|
||||
|
@ -35,7 +35,12 @@ class Story < ActiveRecord::Base
|
|||
errors.add(:url, "is not valid")
|
||||
end
|
||||
elsif self.description.to_s.strip == ""
|
||||
self.errors(:description, "must contain text if no URL posted")
|
||||
errors.add(:description, "must contain text if no URL posted")
|
||||
end
|
||||
|
||||
if !(self.new_tags || []).reject{|t| t.to_s.strip == "" }.any?
|
||||
errors.add(:base, "Must have at least one tag. If no tags apply to " +
|
||||
"your content, it probably doesn't belong here.")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -138,6 +143,7 @@ class Story < ActiveRecord::Base
|
|||
def tags_a=(new_tags)
|
||||
self.tags_to_delete = []
|
||||
self.tags_to_add = []
|
||||
self.new_tags = new_tags
|
||||
|
||||
self.tags.each do |tag|
|
||||
if !new_tags.include?(tag.tag)
|
||||
|
|
|
@ -28,6 +28,11 @@ describe Story do
|
|||
expect { Story.make!(:title => ("hello" * 100)) }.to raise_error
|
||||
end
|
||||
|
||||
it "must have at least one tag" do
|
||||
expect { Story.make!(:tags_a => nil) }.to raise_error
|
||||
expect { Story.make!(:tags_a => [ "", " " ]) }.to raise_error
|
||||
end
|
||||
|
||||
it "checks for invalid urls" do
|
||||
expect { Story.make!(:title => "test", :url => "http://gooses.com/")
|
||||
}.to_not raise_error
|
||||
|
|
|
@ -11,6 +11,7 @@ Story.blueprint do
|
|||
user_id { User.make }
|
||||
title { "story title #{sn}" }
|
||||
url { "http://example.com/#{sn}" }
|
||||
tags_a { [ "tag1", "tag2" ] }
|
||||
end
|
||||
|
||||
Tag.blueprint do
|
||||
|
|
Loading…
Reference in a new issue