<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>app/views/groups/_image.html.erb</filename>
    </added>
    <added>
      <filename>app/views/groups/_post.html.erb</filename>
    </added>
    <added>
      <filename>db/migrate/20090608173007_add_featured_at_to_post_images.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -18,8 +18,10 @@ class GroupsController &lt; ApplicationController
   
   def show
     @group = Group.find_by_name!(params[:id])
-    @images = @group.images
+    @recent_images = @group.images.limit_to 20
     @posts = @group.posts.paginate(:page =&gt; params[:page], :per_page =&gt; 15)
+    @featured_images = @group.images.featured.limit_to 10 
+    @featured_texts = @group.posts.featured.limit_to 10 
   end
   
   def new</diff>
      <filename>app/controllers/groups_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,30 @@
 class ImagesController &lt; ApplicationController
+  before_filter :find_image
+  before_filter :current_user_can_edit_image
+  
   def destroy
     @image = PostImage.find(params[:id])
     @image.destroy
     flash[:notice] = &quot;Successfully deleted the image.&quot;
     redirect_to post_url(@image.post)
   end
+  
+  def feature
+    @image.update_attributes(:featured_at=&gt;Time.now)
+    redirect_to post_url(@image.post)
+  end
+  
+  def unfeature
+    @image.update_attributes(:featured_at=&gt;nil)
+    redirect_to post_url(@image.post)
+  end
+  
+  protected
+  def find_image
+    @image = PostImage.find(params[:id])
+  end
+  
+  def current_user_can_edit_image
+    current_user_can_edit @image.post
+  end
 end</diff>
      <filename>app/controllers/images_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@ class Group &lt; ActiveRecord::Base
   has_many :group_permissions, :include =&gt; :user, :uniq =&gt; true, :dependent=&gt;:destroy
   has_many :rss_feeds, :dependent =&gt; :destroy
   has_many :posts, :dependent =&gt; :destroy
-  has_many :post_images, :through =&gt; :posts, :order =&gt; &quot;updated_at DESC&quot; 
+  has_many :post_images, :through =&gt; :posts, :order =&gt; &quot;updated_at DESC&quot;
 
   belongs_to :group_category
   </diff>
      <filename>app/models/group.rb</filename>
    </modified>
    <modified>
      <diff>@@ -24,7 +24,7 @@ class Post &lt; ActiveRecord::Base
   named_scope :sorted_by_created_at, lambda { { :order =&gt; &quot;created_at DESC&quot; }}
   named_scope :sorted_by_updated_at, lambda { { :order =&gt; &quot;updated_at DESC&quot; }}
   named_scope :sorted_by_commented_at, lambda { { :order =&gt; &quot;commented_at DESC&quot; }}
-  named_scope :featured, lambda { { :conditions =&gt; [ &quot;featured_at IS NOT NULL&quot; ], :order =&gt; &quot;featured_at DESC&quot;, :limit =&gt; 6 }} 
+  named_scope :featured, lambda { { :conditions =&gt; [ &quot;featured_at IS NOT NULL&quot; ], :order =&gt; &quot;featured_at DESC&quot; }} 
   named_scope :limit_to, lambda { | limit | { :limit =&gt; limit } }
   
   alias_attribute :to_s, :title</diff>
      <filename>app/models/post.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,8 @@ class PostImage &lt; ActiveRecord::Base
   belongs_to :post
   
   named_scope :latest3, :limit=&gt;3, :order =&gt; &quot;updated_at DESC&quot;
-  named_scope :featured, :order =&gt; &quot;updated_at DESC&quot;
+  named_scope :featured, lambda { | limit | { :conditions =&gt; [ &quot;post_images.featured_at IS NOT NULL&quot; ], :order =&gt; &quot;post_images.featured_at DESC&quot; }} 
+  named_scope :limit_to, lambda { | limit | { :limit =&gt; limit } }
   
   def width_for_height(h)
     return nil if self.width.nil? || self.height.nil? 
@@ -12,4 +13,8 @@ class PostImage &lt; ActiveRecord::Base
     return nil if self.width.nil? || self.height.nil?
     w*self.height/self.width
   end
+  
+  def featured?
+    !featured_at.nil?
+  end
 end</diff>
      <filename>app/models/post_image.rb</filename>
    </modified>
    <modified>
      <diff>@@ -41,23 +41,28 @@
 &lt;/div&gt;  
 
 &lt;div id=&quot;main&quot;&gt;  
+    &lt;h2&gt;Featured images by &lt;%= @group%&gt;&lt;/h2&gt;
+		&lt;div class=&quot;&quot;&gt;
+		&lt;%= render :partial=&gt;'image', :collection=&gt;@featured_images %&gt;
+    &lt;div class=&quot;clearThis&quot;&gt; &lt;/div&gt;
+    &lt;/div&gt;
+		
+		&lt;h2&gt;Featured text by &lt;%= @group%&gt;&lt;/h2&gt;
+	  &lt;div class=&quot;&quot;&gt;
+    &lt;%= render :partial=&gt;'post', :collection=&gt;@featured_texts %&gt;
+    &lt;div class=&quot;clearThis&quot;&gt; &lt;/div&gt;
+    &lt;/div&gt;
+
     &lt;h2&gt;Recent works by &lt;%= @group %&gt;&lt;/h2&gt;
     &lt;div class=&quot;imageStrip&quot;&gt;
-    	&lt;% for image in @images%&gt;
-      	&lt;a href=&quot;&lt;%= post_path(image.post) %&gt;&quot; class=&quot;imageStripImage&quot;&gt;
-          &lt;%= image_tag_for(image, :strip) %&gt;
-          &lt;div class=&quot;label&quot; style=&quot;width:&lt;%= image.width_for_height(128) %&gt;px;&quot;&gt;
-            &lt;span class=&quot;title&quot;&gt;&lt;%= image.post.title %&gt;.&lt;/span&gt;
-          &lt;/div&gt;  
-        &lt;/a&gt;
-      &lt;% end %&gt;
+    &lt;%= render :partial=&gt;'image', :collection=&gt;@recent_images %&gt;
     &lt;div class=&quot;clearThis&quot;&gt; &lt;/div&gt;
      &lt;p&gt;&lt;a href=&quot;#&quot;&gt;More works&lt;/a&gt; by &lt;%= @group %&gt;&lt;/p&gt;
 		&lt;/div&gt;
   
 	  &lt;h2&gt;More recent works&lt;/h2&gt;
     &lt;div class=&quot;imageCloud&quot;&gt;
-    	&lt;% for image in @images%&gt;
+    	&lt;% for image in @recent_images%&gt;
       	&lt;a href=&quot;&lt;%= post_path(image.post) %&gt;&quot;&gt;
           &lt;%= image_tag_for(image, :small_square) %&gt;
         &lt;/a&gt;
@@ -65,4 +70,5 @@
     &lt;div class=&quot;clearThis&quot;&gt; &lt;/div&gt;
     &lt;p&gt;&lt;a href=&quot;#&quot;&gt;Browse all works&lt;/a&gt; by &lt;%= @group %&gt;.&lt;/p&gt;
 		&lt;/div&gt;
+
 &lt;/div&gt;
\ No newline at end of file</diff>
      <filename>app/views/groups/show.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -3,9 +3,6 @@
   with_controls = local_assigns[:with_controls]
 %&gt;
 &lt;p class=&quot;meta&quot;&gt;
-   &lt;%if post.featured?%&gt;
-     &lt;strong&gt;Featured&lt;/strong&gt;. 
-   &lt;%end%&gt;
     &lt;% if !post.remote_url.nil? &amp;&amp; !post.remote_url.empty? %&gt;
   		&lt;span class=&quot;author&quot;&gt;&lt;%= link_to_user(post.group) %&gt; work retrieved from  &lt;%= link_to &quot;external site&quot;,post.remote_url %&gt;&lt;/span&gt;  
 		&lt;% end %&gt;
@@ -27,9 +24,17 @@
       &lt;/span&gt; 
     &lt;% end %&gt;
     --&gt;
+		&lt;/p&gt;
 		&lt;% if with_controls &amp;&amp; logged_in? &amp;&amp; current_user.can_edit?(post) %&gt;
+		&lt;p class=&quot;meta&quot;&gt;
 		  &lt;%= link_to(&quot;Edit post&quot;, edit_post_url(post), :class =&gt; &quot;option&quot;) %&gt; 
       &lt;%= link_to(&quot;Delete post&quot;, post_url(post), :class =&gt; &quot;option&quot;, :method =&gt; :delete, :confirm =&gt; &quot;Are you sure you'd like to delete this post?&quot;) %&gt;
+      &lt;%if post.featured?%&gt;
+        &lt;strong&gt;Text featured&lt;/strong&gt;. 
+        &lt;%= link_to(&quot;Unfeature post text&quot;, unfeature_post_url(post), :class =&gt; &quot;option&quot;, :method =&gt; :put) %&gt;
+			&lt;% else %&gt;
+        &lt;%= link_to(&quot;Feature post text&quot;, feature_post_url(post), :class =&gt; &quot;option&quot;, :method =&gt; :put) %&gt;
+			&lt;% end %&gt;
+			&lt;/p&gt;
 		&lt;% end %&gt; 
-&lt;/p&gt;
   
\ No newline at end of file</diff>
      <filename>app/views/posts/_meta.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -37,10 +37,15 @@
 
    &lt;div class='image-controls'&gt;
   	 &lt;% @post.images.each do |image| %&gt;
-  	   &lt;span&gt;
+  	   &lt;span id=&quot;image-&lt;%=image.id%&gt;&quot;&gt;
          &lt;%= link_to image_tag_for(image, :medium_square), image.src, :title =&gt; &quot;Open orignal image on remote site&quot; %&gt;
          &lt;% if logged_in? &amp;&amp; current_user.can_edit?(@post) %&gt;
-      	 &lt;%= link_to 'Delete?', image_path(image), :method=&gt;:delete, :confirm=&gt;'Delete this image?' %&gt;
+	      	 &lt;%= link_to 'Delete?', image_path(image), :method=&gt;:delete, :class=&gt;'option', :confirm=&gt;'Delete this image?' %&gt;
+					 &lt;% if image.featured? %&gt;
+             &lt;%= link_to 'Unfeature', unfeature_image_path(image), :method=&gt;:put, :class=&gt;'option' %&gt;
+					 &lt;% else %&gt;
+             &lt;%= link_to 'Feature', feature_image_path(image), :method=&gt;:put, :class=&gt;'option' %&gt;
+					 &lt;% end %&gt;
       	 &lt;% end %&gt;	
   		 &lt;/span&gt;
   	 &lt;% end %&gt;</diff>
      <filename>app/views/posts/show.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -25,7 +25,7 @@ ActionController::Routing::Routes.draw do |map|
     post.resources :tags, :requirements =&gt; { :id =&gt; /.*/ }
   end
 
-  map.resources :images
+  map.resources :images, :member =&gt; {:feature=&gt;:put, :unfeature=&gt;:put}
   map.resources :tags, :requirements =&gt; { :id =&gt; /.*/ }
   map.resource  :settings, :collection =&gt; { :save_new_avatar =&gt; :put, :picture =&gt; :get, :username_email =&gt; :any, :bio =&gt; :any, :password =&gt; :any}
   </diff>
      <filename>config/routes.rb</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; 20090608161446) do
+ActiveRecord::Schema.define(:version =&gt; 20090608173007) do
 
   create_table &quot;attachments&quot;, :force =&gt; true do |t|
     t.integer  &quot;post_id&quot;
@@ -113,6 +113,7 @@ ActiveRecord::Schema.define(:version =&gt; 20090608161446) do
     t.datetime &quot;updated_at&quot;
     t.integer  &quot;width&quot;
     t.integer  &quot;height&quot;
+    t.datetime &quot;featured_at&quot;
   end
 
   create_table &quot;posts&quot;, :force =&gt; true do |t|</diff>
      <filename>db/schema.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,12 +2,20 @@
 
 article_from_rss_image1:
   post: article_from_rss 
-  src: MyString
+  src: image1.png
   width: 10
   height: 20
-
+  
 article_from_rss_image2:
   post: article_from_rss 
-  src: MyString
+  src: image2.png
   width: 104
   height: 105
+  featured_at: &lt;%=1.day.ago%&gt;
+  
+cool_article_image1:
+  post: cool_article
+  src: image3.png
+  width: 110
+  height: 110
+  featured_at: &lt;%=1.hour.ago%&gt;
\ No newline at end of file</diff>
      <filename>test/fixtures/post_images.yml</filename>
    </modified>
    <modified>
      <diff>@@ -90,5 +90,53 @@ class PostingTest &lt; ActionController::IntegrationTest
       assert_response 404
     end
   end
-  
-end
\ No newline at end of file
+  should &quot;only be able to delete or feature an image if  a the manager of it&quot; do
+    new_session_as(:duff) do
+      post_id = posts(:article_from_rss).id
+      get_ok &quot;/posts/#{post_id}&quot;
+      i1 = post_images(:article_from_rss_image1)
+      i2 = post_images(:article_from_rss_image2)
+      assert_select &quot;#image-#{i2.id}&quot; do 
+        assert_link_does_not_exist DELETE_IMAGE_LINK
+        assert_link_does_not_exist FEATURE_IMAGE_LINK
+      end
+    end
+    
+    new_session_as(:alex) do
+      #because alex_can_moderate_studio1
+      post_id = posts(:article_from_rss).id
+      get_ok &quot;/posts/#{post_id}&quot;
+      i1 = post_images(:article_from_rss_image1)
+      i2 = post_images(:article_from_rss_image2)
+      assert_select &quot;#image-#{i1.id}&quot; do 
+        assert_link_exists DELETE_IMAGE_LINK
+        assert_link_exists FEATURE_IMAGE_LINK
+        assert_link_does_not_exist UNFEATURE_IMAGE_LINK
+      end
+      assert_select &quot;#image-#{i2.id}&quot; do 
+        assert_link_exists DELETE_IMAGE_LINK
+        assert_link_exists UNFEATURE_IMAGE_LINK
+        assert_link_does_not_exist FEATURE_IMAGE_LINK
+      end
+      delete_via_redirect &quot;/images/#{i2.id}&quot;
+      get &quot;/posts/#{post_id}&quot;
+      assert_select &quot;#image-#{i2.id}&quot;, :count=&gt;0
+      
+      put_via_redirect &quot;/images/#{i1.id}/feature&quot; 
+      get &quot;/posts/#{post_id}&quot;
+      assert_select &quot;#image-#{i1.id}&quot; do 
+        assert_link_exists UNFEATURE_IMAGE_LINK
+        assert_link_does_not_exist FEATURE_IMAGE_LINK
+      end
+      put_via_redirect &quot;/images/#{i1.id}/unfeature&quot; 
+      get &quot;/posts/#{post_id}&quot;
+      assert_select &quot;#image-#{i1.id}&quot; do 
+        assert_link_exists FEATURE_IMAGE_LINK
+        assert_link_does_not_exist UNFEATURE_IMAGE_LINK
+      end
+    end
+  end
+end
+DELETE_IMAGE_LINK = &quot;Delete?&quot;
+FEATURE_IMAGE_LINK = &quot;Feature&quot;
+UNFEATURE_IMAGE_LINK = &quot;Unfeature&quot;
\ No newline at end of file</diff>
      <filename>test/integration/posting_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,4 @@
 require 'test_helper'
 
 class GroupTest &lt; ActiveSupport::TestCase
-  # Replace this with your real tests.
-  test &quot;the truth&quot; do
-    assert true
-  end
 end</diff>
      <filename>test/unit/group_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,28 @@
 require 'test_helper'
 
 class PostImageTest &lt; ActiveSupport::TestCase
-  # Replace this with your real tests.
-  test &quot;the truth&quot; do
-    assert true
+
+  should &quot;be able to find featured images for a group&quot; do
+    st1 = groups(:studio1)
+    fi = st1.images.featured
+    assert_equal 1, fi.count
+    assert_equal post_images(:article_from_rss_image2).src, fi[0].src
+
+    st3 = groups(:studio3)
+    fi = st3.images.featured
+    assert_equal 1, fi.count
+    assert_equal post_images(:cool_article_image1).src, fi[0].src
   end
+
+  should &quot;be able to find all featured images&quot; do
+    fi = PostImage.featured
+    assert_equal 2, fi.count
+    assert_equal post_images(:cool_article_image1).src, fi[0].src
+    assert_equal post_images(:article_from_rss_image2).src, fi[1].src
+    
+    fi2 = PostImage.featured.limit_to(1)
+    assert_equal 1, fi2.all.size
+    assert_equal post_images(:cool_article_image1).src, fi2[0].src
+  end
+
 end</diff>
      <filename>test/unit/post_image_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>f1f10f619a1513df391e0dc26542332898e69b73</id>
    </parent>
  </parents>
  <author>
    <name>Tim Diggins</name>
    <email>tim@red56.co.uk</email>
  </author>
  <url>http://github.com/red56/the-connected-website/commit/bb4a394977866620f3fee967dc97ca46fdced1c0</url>
  <id>bb4a394977866620f3fee967dc97ca46fdced1c0</id>
  <committed-date>2009-06-08T15:45:15-07:00</committed-date>
  <authored-date>2009-06-08T15:45:15-07:00</authored-date>
  <message>allowing for featuring of images and texts - got finders for featured and recent images and featured texts (not yet recent texts)</message>
  <tree>7130b6de3bb6a67388ce4a79b517a9d44de51827</tree>
  <committer>
    <name>Tim Diggins</name>
    <email>tim@red56.co.uk</email>
  </committer>
</commit>
