Commit 87a25ade46aa48e9f962f684a2bae334ba0bb504

Authored by Daniela Feitosa
1 parent 980bcb81

external_feed: allow only_once to mass-assignment

Also removed "id" on update of external_feed_data. It must not be updated or
mass-assigned
app/models/blog.rb
@@ -53,7 +53,7 @@ class Blog < Folder @@ -53,7 +53,7 @@ class Blog < Folder
53 def prepare_external_feed 53 def prepare_external_feed
54 unless self.external_feed_data.nil? 54 unless self.external_feed_data.nil?
55 if self.external_feed(true) && self.external_feed.id == self.external_feed_data[:id].to_i 55 if self.external_feed(true) && self.external_feed.id == self.external_feed_data[:id].to_i
56 - self.external_feed.attributes = self.external_feed_data 56 + self.external_feed.attributes = self.external_feed_data.except(:id)
57 else 57 else
58 self.build_external_feed(self.external_feed_data, :without_protection => true) 58 self.build_external_feed(self.external_feed_data, :without_protection => true)
59 end 59 end
app/models/external_feed.rb
@@ -10,7 +10,7 @@ class ExternalFeed < ActiveRecord::Base @@ -10,7 +10,7 @@ class ExternalFeed < ActiveRecord::Base
10 { :conditions => ['(fetched_at is NULL) OR (fetched_at < ?)', Time.now - FeedUpdater.update_interval] } 10 { :conditions => ['(fetched_at is NULL) OR (fetched_at < ?)', Time.now - FeedUpdater.update_interval] }
11 } 11 }
12 12
13 - attr_accessible :address, :enabled 13 + attr_accessible :address, :enabled, :only_once
14 14
15 def add_item(title, link, date, content) 15 def add_item(title, link, date, content)
16 return if content.blank? 16 return if content.blank?
test/unit/external_feed_test.rb
@@ -176,4 +176,13 @@ class ExternalFeedTest &lt; ActiveSupport::TestCase @@ -176,4 +176,13 @@ class ExternalFeedTest &lt; ActiveSupport::TestCase
176 176
177 end 177 end
178 178
  179 + should 'allow mass assign attributes' do
  180 + p = create_user('testuser').person
  181 + blog = fast_create(Blog, :profile_id => p.id, :name => 'Blog test')
  182 +
  183 + assert_difference 'ExternalFeed.count', 1 do
  184 + efeed = blog.create_external_feed(:address => 'http://invalid.url', :enabled => true, :only_once => 'false')
  185 + end
  186 + end
  187 +
179 end 188 end