Commit 94df4822b49817ef52d1a8c39d500184691a3a9a
1 parent
2fe1ebd0
Exists in
master
and in
29 other branches
rails3: fix blog and forum tests
Showing
6 changed files
with
29 additions
and
23 deletions
Show diff stats
app/models/blog.rb
@@ -46,7 +46,9 @@ class Blog < Folder | @@ -46,7 +46,9 @@ class Blog < Folder | ||
46 | self.external_feed_data = efeed | 46 | self.external_feed_data = efeed |
47 | end | 47 | end |
48 | 48 | ||
49 | - def validate | 49 | + validate :prepare_external_feed |
50 | + | ||
51 | + def prepare_external_feed | ||
50 | unless self.external_feed_data.nil? | 52 | unless self.external_feed_data.nil? |
51 | if self.external_feed(true) && self.external_feed.id == self.external_feed_data[:id].to_i | 53 | if self.external_feed(true) && self.external_feed.id == self.external_feed_data[:id].to_i |
52 | self.external_feed.attributes = self.external_feed_data | 54 | self.external_feed.attributes = self.external_feed_data |
app/models/external_feed.rb
@@ -10,6 +10,8 @@ class ExternalFeed < ActiveRecord::Base | @@ -10,6 +10,8 @@ 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 | ||
14 | + | ||
13 | def add_item(title, link, date, content) | 15 | def add_item(title, link, date, content) |
14 | doc = Hpricot(content) | 16 | doc = Hpricot(content) |
15 | doc.search('*').each do |p| | 17 | doc.search('*').each do |p| |
app/models/rss_feed.rb
lib/acts_as_having_posts.rb
@@ -28,9 +28,7 @@ module ActsAsHavingPosts | @@ -28,9 +28,7 @@ module ActsAsHavingPosts | ||
28 | def feed=(attrs) | 28 | def feed=(attrs) |
29 | if attrs | 29 | if attrs |
30 | if self.feed | 30 | if self.feed |
31 | - attrs.each do |key, value| | ||
32 | - self.feed.send(key.to_s+'=', value) | ||
33 | - end | 31 | + self.feed.update_attributes(attrs) |
34 | else | 32 | else |
35 | self.feed_attrs = attrs | 33 | self.feed_attrs = attrs |
36 | end | 34 | end |
test/unit/blog_test.rb
@@ -38,14 +38,14 @@ class BlogTest < ActiveSupport::TestCase | @@ -38,14 +38,14 @@ class BlogTest < ActiveSupport::TestCase | ||
38 | 38 | ||
39 | should 'save feed options' do | 39 | should 'save feed options' do |
40 | p = create_user('testuser').person | 40 | p = create_user('testuser').person |
41 | - p.articles << Blog.new(:profile => p, :name => 'blog_feed_test') | 41 | + p.articles << build(Blog, :profile => p, :name => 'blog_feed_test') |
42 | p.blog.feed = { :limit => 7 } | 42 | p.blog.feed = { :limit => 7 } |
43 | assert_equal 7, p.blog.feed.limit | 43 | assert_equal 7, p.blog.feed.limit |
44 | end | 44 | end |
45 | 45 | ||
46 | should 'save feed options after create blog' do | 46 | should 'save feed options after create blog' do |
47 | p = create_user('testuser').person | 47 | p = create_user('testuser').person |
48 | - p.articles << Blog.new(:profile => p, :name => 'blog_feed_test', :feed => { :limit => 7 }) | 48 | + p.articles << build(Blog, :profile => p, :name => 'blog_feed_test', :feed => { :limit => 7 }) |
49 | assert_equal 7, p.blog.feed.limit | 49 | assert_equal 7, p.blog.feed.limit |
50 | end | 50 | end |
51 | 51 | ||
@@ -56,7 +56,7 @@ class BlogTest < ActiveSupport::TestCase | @@ -56,7 +56,7 @@ class BlogTest < ActiveSupport::TestCase | ||
56 | 56 | ||
57 | should 'update posts per page setting' do | 57 | should 'update posts per page setting' do |
58 | p = create_user('testuser').person | 58 | p = create_user('testuser').person |
59 | - p.articles << Blog.new(:profile => p, :name => 'Blog test') | 59 | + p.articles << build(Blog, :profile => p, :name => 'Blog test') |
60 | blog = p.blog | 60 | blog = p.blog |
61 | blog.posts_per_page = 7 | 61 | blog.posts_per_page = 7 |
62 | assert blog.save! | 62 | assert blog.save! |
@@ -95,7 +95,7 @@ class BlogTest < ActiveSupport::TestCase | @@ -95,7 +95,7 @@ class BlogTest < ActiveSupport::TestCase | ||
95 | 95 | ||
96 | should 'build external feed after save' do | 96 | should 'build external feed after save' do |
97 | p = create_user('testuser').person | 97 | p = create_user('testuser').person |
98 | - blog = Blog.new(:profile => p, :name => 'Blog test') | 98 | + blog = build(Blog, :profile => p, :name => 'Blog test') |
99 | blog.external_feed_builder = { :address => 'feed address' } | 99 | blog.external_feed_builder = { :address => 'feed address' } |
100 | blog.save! | 100 | blog.save! |
101 | assert blog.external_feed.valid? | 101 | assert blog.external_feed.valid? |
@@ -103,9 +103,9 @@ class BlogTest < ActiveSupport::TestCase | @@ -103,9 +103,9 @@ class BlogTest < ActiveSupport::TestCase | ||
103 | 103 | ||
104 | should 'update external feed' do | 104 | should 'update external feed' do |
105 | p = create_user('testuser').person | 105 | p = create_user('testuser').person |
106 | - blog = Blog.new(:profile => p, :name => 'Blog test') | 106 | + blog = build(Blog, :profile => p, :name => 'Blog test') |
107 | blog.save | 107 | blog.save |
108 | - e = ExternalFeed.new(:address => 'feed address') | 108 | + e = build(ExternalFeed, :address => 'feed address') |
109 | e.blog = blog | 109 | e.blog = blog |
110 | e.save | 110 | e.save |
111 | blog.reload | 111 | blog.reload |
@@ -116,14 +116,14 @@ class BlogTest < ActiveSupport::TestCase | @@ -116,14 +116,14 @@ class BlogTest < ActiveSupport::TestCase | ||
116 | 116 | ||
117 | should 'invalid blog if has invalid external_feed' do | 117 | should 'invalid blog if has invalid external_feed' do |
118 | p = create_user('testuser').person | 118 | p = create_user('testuser').person |
119 | - blog = Blog.new(:profile => p, :name => 'Blog test', :external_feed_builder => {:enabled => true}) | 119 | + blog = build(Blog, :profile => p, :name => 'Blog test', :external_feed_builder => {:enabled => true}) |
120 | blog.save | 120 | blog.save |
121 | assert ! blog.valid? | 121 | assert ! blog.valid? |
122 | end | 122 | end |
123 | 123 | ||
124 | should 'remove external feed when removing blog' do | 124 | should 'remove external feed when removing blog' do |
125 | p = create_user('testuser').person | 125 | p = create_user('testuser').person |
126 | - blog = Blog.create!(:name => 'Blog test', :profile => p, :external_feed_builder => {:enabled => true, :address => "http://bli.org/feed"}) | 126 | + blog = create(Blog, :name => 'Blog test', :profile => p, :external_feed_builder => {:enabled => true, :address => "http://bli.org/feed"}) |
127 | assert blog.external_feed | 127 | assert blog.external_feed |
128 | assert_difference ExternalFeed, :count, -1 do | 128 | assert_difference ExternalFeed, :count, -1 do |
129 | blog.destroy | 129 | blog.destroy |
@@ -134,16 +134,17 @@ class BlogTest < ActiveSupport::TestCase | @@ -134,16 +134,17 @@ class BlogTest < ActiveSupport::TestCase | ||
134 | p = create_user('testuser').person | 134 | p = create_user('testuser').person |
135 | fast_create(Blog, :name => 'Blog test', :profile_id => p.id) | 135 | fast_create(Blog, :name => 'Blog test', :profile_id => p.id) |
136 | assert_nothing_raised ActiveRecord::RecordInvalid do | 136 | assert_nothing_raised ActiveRecord::RecordInvalid do |
137 | - Blog.create!(:name => 'Another Blog', :profile => p) | 137 | + create(Blog, :name => 'Another Blog', :profile => p) |
138 | end | 138 | end |
139 | end | 139 | end |
140 | 140 | ||
141 | should 'not update slug from name for existing blog' do | 141 | should 'not update slug from name for existing blog' do |
142 | p = create_user('testuser').person | 142 | p = create_user('testuser').person |
143 | - blog = Blog.create!(:name => 'Blog test', :profile => p) | ||
144 | - assert_equal 'blog-test', blog.slug | ||
145 | - blog.name = 'Changed name' | ||
146 | - assert_not_equal 'changed-name', blog.slug | 143 | + blog = create(Blog, :profile => p) |
144 | + new_name = 'Changed name' | ||
145 | + assert_not_equal new_name.to_slug, blog.slug | ||
146 | + blog.name = new_name | ||
147 | + assert_not_equal new_name.to_slug, blog.slug | ||
147 | end | 148 | end |
148 | 149 | ||
149 | should 'display full posts by default' do | 150 | should 'display full posts by default' do |
@@ -153,7 +154,7 @@ class BlogTest < ActiveSupport::TestCase | @@ -153,7 +154,7 @@ class BlogTest < ActiveSupport::TestCase | ||
153 | 154 | ||
154 | should 'update visualization_format setting' do | 155 | should 'update visualization_format setting' do |
155 | p = create_user('testuser').person | 156 | p = create_user('testuser').person |
156 | - p.articles << Blog.new(:profile => p, :name => 'Blog test') | 157 | + p.articles << build(Blog, :profile => p, :name => 'Blog test') |
157 | blog = p.blog | 158 | blog = p.blog |
158 | blog.visualization_format = 'short' | 159 | blog.visualization_format = 'short' |
159 | assert blog.save! | 160 | assert blog.save! |
@@ -161,7 +162,7 @@ class BlogTest < ActiveSupport::TestCase | @@ -161,7 +162,7 @@ class BlogTest < ActiveSupport::TestCase | ||
161 | end | 162 | end |
162 | 163 | ||
163 | should 'allow only full and short as visualization_format' do | 164 | should 'allow only full and short as visualization_format' do |
164 | - blog = Blog.new(:name => 'blog') | 165 | + blog = build(Blog, :name => 'blog') |
165 | blog.visualization_format = 'wrong_format' | 166 | blog.visualization_format = 'wrong_format' |
166 | blog.valid? | 167 | blog.valid? |
167 | assert blog.errors[:visualization_format.to_s].present? | 168 | assert blog.errors[:visualization_format.to_s].present? |
@@ -187,7 +188,7 @@ class BlogTest < ActiveSupport::TestCase | @@ -187,7 +188,7 @@ class BlogTest < ActiveSupport::TestCase | ||
187 | 188 | ||
188 | should 'update display posts in current language setting' do | 189 | should 'update display posts in current language setting' do |
189 | p = create_user('testuser').person | 190 | p = create_user('testuser').person |
190 | - p.articles << Blog.new(:profile => p, :name => 'Blog test') | 191 | + p.articles << build(Blog, :profile => p, :name => 'Blog test') |
191 | blog = p.blog | 192 | blog = p.blog |
192 | blog.display_posts_in_current_language = false | 193 | blog.display_posts_in_current_language = false |
193 | assert blog.save! && blog.reload | 194 | assert blog.save! && blog.reload |
test/unit/forum_test.rb
@@ -95,9 +95,10 @@ class ForumTest < ActiveSupport::TestCase | @@ -95,9 +95,10 @@ class ForumTest < ActiveSupport::TestCase | ||
95 | should 'not update slug from name for existing forum' do | 95 | should 'not update slug from name for existing forum' do |
96 | p = create_user('testuser').person | 96 | p = create_user('testuser').person |
97 | forum = create(Forum, :name => 'Forum test', :profile_id => p.id, :body => 'Forum') | 97 | forum = create(Forum, :name => 'Forum test', :profile_id => p.id, :body => 'Forum') |
98 | - assert_equal 'forum-test', forum.slug | ||
99 | - forum.name = 'Changed name' | ||
100 | - assert_not_equal 'changed-name', forum.slug | 98 | + new_name = 'Changed name' |
99 | + assert_not_equal new_name.to_slug, forum.slug | ||
100 | + forum.name = new_name | ||
101 | + assert_not_equal new_name.to_slug, forum.slug | ||
101 | end | 102 | end |
102 | 103 | ||
103 | should 'have posts' do | 104 | should 'have posts' do |