From 9afca4a2a5790ed8842a7e5f0a3a3c716d28bb24 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Mon, 27 Jul 2009 13:19:54 +0000 Subject: [PATCH] Merging changes from trunk into stable branch --- app/controllers/feed_controller.rb | 17 ++++------------- app/models/feed_item.rb | 18 +++++++++++------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/app/controllers/feed_controller.rb b/app/controllers/feed_controller.rb index 30ddb0c..819dab1 100644 --- a/app/controllers/feed_controller.rb +++ b/app/controllers/feed_controller.rb @@ -12,7 +12,7 @@ class FeedController < ApplicationController def show - if valid_feed_name?(params[:feed_name]) + if FeedItem::valid_feed_name?(params[:feed_name]) @feed_items = FeedItem.find_all_by_feed_name(params[:feed_name]) @feed_name = params[:feed_name] respond_to do |format| @@ -36,7 +36,7 @@ class FeedController < ApplicationController def update - if valid_feed_name?(params[:feed_name]) + if FeedItem::valid_feed_name?(params[:feed_name]) item = FeedItem.find_by_feed_name_and_title(params[:feed_name], params[:title]) if item if params[:description] == '' @@ -59,15 +59,6 @@ class FeedController < ApplicationController private - def valid_feed_name?(feed_name) - Rack::Utils::escape(feed_name) == feed_name and - Rack::Utils::unescape(feed_name) == feed_name and - feed_name != 'index' and - feed_name != 'show' and - feed_name != 'update' and - feed_name != 'action' - end - def create_item item = FeedItem.new(:feed_name => params[:feed_name], @@ -107,13 +98,13 @@ class FeedController < ApplicationController def destroy_item(item) if item.destroy - flash[:notice] = "Element #{params[:title]} destroyed" + flash[:notice] = "Element #{params[:title]} deleted" respond_to do |format| format.html { redirect_to feed_url(params[:feed_name]) } format.rss { head :ok } end else - flash[:notice] = "Element #{params[:title]} could not be destroyed" + flash[:notice] = "Element #{params[:title]} could not be deleted" respond_to do |format| format.html { redirect_to feed_url(params[:feed_name]) } format.rss { head :unprocessable_entity } diff --git a/app/models/feed_item.rb b/app/models/feed_item.rb index 75830a5..6dac7bc 100644 --- a/app/models/feed_item.rb +++ b/app/models/feed_item.rb @@ -5,15 +5,19 @@ class FeedItem < ActiveRecord::Base validates_presence_of :feed_name, :title, :description validate :feed_name_must_be_legal -private + def FeedItem.valid_feed_name?(feed_name) + Rack::Utils::escape(feed_name) == feed_name and + Rack::Utils::unescape(feed_name) == feed_name and + feed_name != 'index' and + feed_name != 'show' and + feed_name != 'update' and + feed_name != 'action' + end + + private def feed_name_must_be_legal - if Rack::Utils::escape(feed_name) != feed_name or - Rack::Utils::unescape(feed_name) != feed_name or - feed_name == 'index' or - feed_name == 'show' or - feed_name == 'update' or - feed_name == 'action' + unless FeedItem.valid_feed_name?(feed_name) errors.add(:feed_name, 'is an invalid feed name') end end -- 2.34.1