<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>db/migrate/20090208061237_add_allow_comments_to_posts.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -10,6 +10,8 @@ class Post &lt; ActiveRecord::Base
   validates_presence_of :user_id, :unless =&gt; :feed_id
   validates_presence_of :feed_id, :unless =&gt; :user_id
   
+  before_save :mark_uncommentable, :if =&gt; :from_feed?
+  
   class &lt;&lt; self
     def paginate_index(options={})
       active.paginate({:order =&gt; 'posts.created_at DESC', :include =&gt; [:comments, :feed]}.merge(options))
@@ -27,7 +29,7 @@ class Post &lt; ActiveRecord::Base
   end
   
   def type
-    attributes['type']
+    self[:type]
   end
   
   def to_param
@@ -49,9 +51,16 @@ class Post &lt; ActiveRecord::Base
 
   def to_html
     text = case format
-           when 'HTML' then content
-           else RedCloth.new(content, [:filter_styles, :no_span_caps]).to_html
-           end
+    when 'HTML' then content
+    else RedCloth.new(content, [:filter_styles, :no_span_caps]).to_html
+    end
+  end
+  
+  private
+  
+  def mark_uncommentable
+    self.allow_comments = false
+    self # otherwise this returns false and we can't save
   end
 
 end</diff>
      <filename>app/models/post.rb</filename>
    </modified>
    <modified>
      <diff>@@ -9,14 +9,6 @@ class Article &lt; Post
   
   attr_accessible :content, :header, :permalink, :allow_comments
   
-  def allow_comments=(status)
-    self.feed_id = (status == '0') ? 0 : nil
-  end
-  
-  def allow_comments?
-    feed_id.nil?
-  end
-  
   def link(root='')
     from_feed? ? permalink : super
   end</diff>
      <filename>app/models/posts/article.rb</filename>
    </modified>
    <modified>
      <diff>@@ -21,7 +21,7 @@
 
 &lt;%- else -%&gt;
 
-&lt;%= render :partial =&gt; &quot;/posts/types/comments.html.erb&quot; %&gt;
+&lt;%= render :partial =&gt; &quot;/posts/types/comments.html.erb&quot; if post.allow_comments? %&gt;
 
 &lt;small&gt;&lt;%= link_to 'Click here to go home', root_path %&gt;&lt;/small&gt;
 </diff>
      <filename>app/views/posts/types/_snippet.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -9,7 +9,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version =&gt; 7) do
+ActiveRecord::Schema.define(:version =&gt; 20090208061237) do
 
   create_table &quot;comments&quot;, :force =&gt; true do |t|
     t.integer  &quot;commentable_id&quot;
@@ -52,6 +52,7 @@ ActiveRecord::Schema.define(:version =&gt; 7) do
     t.datetime &quot;updated_at&quot;
     t.datetime &quot;deleted_at&quot;
     t.string   &quot;format&quot;
+    t.boolean  &quot;allow_comments&quot;,  :default =&gt; true
   end
 
   create_table &quot;users&quot;, :force =&gt; true do |t|</diff>
      <filename>db/schema.rb</filename>
    </modified>
    <modified>
      <diff>@@ -30,7 +30,7 @@ class CommentsControllerTest &lt; ActionController::TestCase
   
   def test_should_clear_spammy_comments
     login_as :quentin
-    Comment.update_all(['spam = ?', true])
+    Comment.update_all(['spam = ?', 1])
     assert_difference('Comment.count', -2) do
       delete :spammy
     end</diff>
      <filename>test/functional/comments_controller_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -27,14 +27,6 @@ class ArticleTest &lt; ActiveSupport::TestCase
     assert_not_nil article.permalink
   end
   
-  def test_should_have_allow_comments_boolean_helper
-    article = create_article
-    assert article.allow_comments?
-    article.user_id = nil
-    article.feed_id = feeds(:one).id
-    assert ! article.allow_comments?
-  end
-  
   def test_should_have_from_feed_boolean_helper
     article = create_article
     assert ! article.from_feed?</diff>
      <filename>test/unit/article_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -15,17 +15,10 @@ class BlogTest &lt; ActiveSupport::TestCase
   
   def test_should_create_articles
     assert_difference 'Article.count', 9 do
-      blog = create_blog
-      blog.refresh!
-    end
-
-    blog_articles = Article.find(:all, :conditions =&gt; 'feed_id NOT NULL')
-    assert blog_articles.size &gt;= 9
-    blog_articles.each do |j|
-      assert_equal &quot;HTML&quot;, j.format
+      create_blog.refresh!
     end
   end
-
+  
   def test_should_not_create_posts_twice
     blog = create_blog
     blog.refresh!</diff>
      <filename>test/unit/blog_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,7 +4,7 @@ class PostTest &lt; ActiveSupport::TestCase
   
   def test_should_create_post
     assert_difference 'Post.count' do
-      post = create_post
+      create_post
     end
   end
   
@@ -35,6 +35,11 @@ class PostTest &lt; ActiveSupport::TestCase
     post = create_post :feed_id =&gt; 1
     assert_equal post.id.to_s, post.to_param
   end
+  
+  def test_not_allow_comments_if_from_feed
+    post = create_post :feed_id =&gt; 1
+    assert ! post.allow_comments?
+  end
 
   def test_should_be_deleted_not_destroyed
     post = posts(:one)</diff>
      <filename>test/unit/post_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>000e160b78780c034e2963031d2159e5146ec45c</id>
    </parent>
  </parents>
  <author>
    <name>Pat Nakajima</name>
    <email>patnakajima@gmail.com</email>
  </author>
  <url>http://github.com/nakajima/aintablog/commit/cec423e5af97125f0fa938cdceaf2aa470bdce0d</url>
  <id>cec423e5af97125f0fa938cdceaf2aa470bdce0d</id>
  <committed-date>2009-02-07T22:38:59-08:00</committed-date>
  <authored-date>2009-02-07T22:38:59-08:00</authored-date>
  <message>Made Post#allow_comments a proper attribute.

This was a long time coming. Instead of the hacky &quot;feed_id = 0&quot;,
there's a proper attribute to determine whether or not a given
post should allow comments.</message>
  <tree>83881e25b3a996692053bc5e918f27e68e6a2d76</tree>
  <committer>
    <name>Pat Nakajima</name>
    <email>patnakajima@gmail.com</email>
  </committer>
</commit>
