Got some controller specs working
[feedcatcher.git] / app / controllers / feed_controller.rb
index 819dab13c0dd344c376e38f73d544ba9a2fea61e..0339706833e51ea93d659faabaa5a7fe04d74a85 100644 (file)
@@ -1,9 +1,10 @@
 class FeedController < ApplicationController
-
+  
   skip_before_filter :verify_authenticity_token
 
   def index
-    @feeds = FeedItem.find(:all, :select => 'DISTINCT feed_name')
+    # @feeds = FeedItem.find(:all, :select => 'DISTINCT feed_name')
+    @feeds = FeedItem.select(:feed_name).distinct
     respond_to do |format|
       format.html
       format.rss { render :layout => false }
@@ -13,12 +14,12 @@ class FeedController < ApplicationController
   
   def show
     if FeedItem::valid_feed_name?(params[:feed_name])
-      @feed_items = FeedItem.find_all_by_feed_name(params[:feed_name])
       @feed_name = params[:feed_name]
+      @feed_items = FeedItem.in_feed(@feed_name)
       respond_to do |format|
         if @feed_items == []
-          flash[:notice] = "No items in feed #{params[:feed_name]}"
-          format.html { redirect_to index_url }
+          flash[:notice] = "No items in feed #{@feed_name}"
+          format.html { redirect_to index_path }
           format.rss  { render :layout => false }
         else
           format.html
@@ -28,7 +29,7 @@ class FeedController < ApplicationController
     else
       respond_to do |format|
         flash[:notice] = "Invalid feed name"
-        format.html { redirect_to index_url }
+        format.html { redirect_to index_path }
         format.rss  { head :not_found}
       end
     end
@@ -37,9 +38,9 @@ class FeedController < ApplicationController
 
   def update
     if FeedItem::valid_feed_name?(params[:feed_name])
-      item = FeedItem.find_by_feed_name_and_title(params[:feed_name], params[:title])
+      item = FeedItem.in_feed(params[:feed_name]).entitled(params[:title]).take
       if item
-        if params[:description] == ''
+        if params[:description].empty?
           destroy_item(item)
         else
           update_item(item)
@@ -50,7 +51,7 @@ class FeedController < ApplicationController
     else
       respond_to do |format|
         flash[:notice] = "Invalid feed name"
-        format.html { redirect_to index_url }
+        format.html { redirect_to index_path }
         format.rss  { head :not_found }
       end
     end
@@ -67,13 +68,13 @@ class FeedController < ApplicationController
     item.save!
     flash[:notice] = "Element #{params[:title]} created"
     respond_to do |format|
-      format.html { redirect_to feed_url(params[:feed_name]) }
+      format.html { redirect_to feed_path(params[:feed_name]) }
       format.rss  { head :ok }
     end
   rescue ActiveRecord::RecordInvalid => error
     flash[:notice] = "Element #{params[:title]} could not be created"
     respond_to do |format|
-      format.html { redirect_to feed_url(params[:feed_name]) }
+      format.html { redirect_to feed_path(params[:feed_name]) }
       format.rss  { head :unprocessable_entity }
     end
   end
@@ -83,13 +84,13 @@ class FeedController < ApplicationController
     if item.update_attribute(:description, params[:description])
       flash[:notice] = "Element #{params[:title]} updated"
       respond_to do |format|
-        format.html { redirect_to feed_url(params[:feed_name]) }
+        format.html { redirect_to feed_path(params[:feed_name]) }
         format.rss  { head :ok }
       end
     else
       flash[:notice] = "Element #{params[:title]} could not be updated"
       respond_to do |format|
-        format.html { redirect_to feed_url(params[:feed_name]) }
+        format.html { redirect_to feed_path(params[:feed_name]) }
         format.rss  { head :unprocessable_entity }
       end
     end
@@ -100,13 +101,13 @@ class FeedController < ApplicationController
     if item.destroy
       flash[:notice] = "Element #{params[:title]} deleted"
       respond_to do |format|
-        format.html { redirect_to feed_url(params[:feed_name]) }
+        format.html { redirect_to feed_path(params[:feed_name]) }
         format.rss  { head :ok }
       end
     else
       flash[:notice] = "Element #{params[:title]} could not be deleted"
       respond_to do |format|
-        format.html { redirect_to feed_url(params[:feed_name]) }
+        format.html { redirect_to feed_path(params[:feed_name]) }
         format.rss  { head :unprocessable_entity }
       end
     end