Commit 87a25ade46aa48e9f962f684a2bae334ba0bb504
1 parent
980bcb81
Exists in
master
and in
27 other branches
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
Showing
3 changed files
with
11 additions
and
2 deletions
Show diff stats
app/models/blog.rb
| ... | ... | @@ -53,7 +53,7 @@ class Blog < Folder |
| 53 | 53 | def prepare_external_feed |
| 54 | 54 | unless self.external_feed_data.nil? |
| 55 | 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 | 57 | else |
| 58 | 58 | self.build_external_feed(self.external_feed_data, :without_protection => true) |
| 59 | 59 | end | ... | ... |
app/models/external_feed.rb
| ... | ... | @@ -10,7 +10,7 @@ class ExternalFeed < ActiveRecord::Base |
| 10 | 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 | 15 | def add_item(title, link, date, content) |
| 16 | 16 | return if content.blank? | ... | ... |
test/unit/external_feed_test.rb
| ... | ... | @@ -176,4 +176,13 @@ class ExternalFeedTest < ActiveSupport::TestCase |
| 176 | 176 | |
| 177 | 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 | 188 | end | ... | ... |