can no longer delete posts in locked forum topics
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
class ForumPost < ActiveRecord::Base
|
||||
attr_accessible :body, :topic_id
|
||||
attr_accessible :body, :topic_id, :as => [:admin, :moderator, :janitor]
|
||||
attr_accessible :body, :topic_id, :is_locked, :is_sticky, :as => [:admin, :moderator, :janitor]
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :topic, :class_name => "ForumTopic"
|
||||
before_validation :initialize_creator, :on => :create
|
||||
@@ -8,6 +8,7 @@ class ForumPost < ActiveRecord::Base
|
||||
after_save :update_topic_updated_at
|
||||
validates_presence_of :body, :creator_id
|
||||
validate :validate_topic_is_unlocked
|
||||
before_destroy :validate_topic_is_unlocked
|
||||
scope :body_matches, lambda {|body| where(["forum_posts.text_index @@ plainto_tsquery(?)", body])}
|
||||
scope :for_user, lambda {|user_id| where("forum_posts.creator_id = ?", user_id)}
|
||||
search_methods :body_matches
|
||||
|
||||
@@ -14,6 +14,25 @@ class ForumPostTest < ActiveSupport::TestCase
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "belonging to a locked topic" do
|
||||
setup do
|
||||
@post = Factory.create(:forum_post, :topic_id => @topic.id, :body => "zzz")
|
||||
@topic.update_attribute(:is_locked, true)
|
||||
@post.reload
|
||||
end
|
||||
|
||||
should "not be updateable" do
|
||||
@post.update_attributes(:body => "xxx")
|
||||
@post.reload
|
||||
assert_equal("zzz", @post.body)
|
||||
end
|
||||
|
||||
should "not be deletable" do
|
||||
@post.destroy
|
||||
assert_equal(1, ForumPost.count)
|
||||
end
|
||||
end
|
||||
|
||||
should "update its parent when saved" do
|
||||
sleep 1
|
||||
original_topic_updated_at = @topic.updated_at
|
||||
|
||||
Reference in New Issue
Block a user