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 | 46 | self.external_feed_data = efeed |
47 | 47 | end |
48 | 48 | |
49 | - def validate | |
49 | + validate :prepare_external_feed | |
50 | + | |
51 | + def prepare_external_feed | |
50 | 52 | unless self.external_feed_data.nil? |
51 | 53 | if self.external_feed(true) && self.external_feed.id == self.external_feed_data[:id].to_i |
52 | 54 | self.external_feed.attributes = self.external_feed_data | ... | ... |
app/models/external_feed.rb
... | ... | @@ -10,6 +10,8 @@ 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 | |
14 | + | |
13 | 15 | def add_item(title, link, date, content) |
14 | 16 | doc = Hpricot(content) |
15 | 17 | doc.search('*').each do |p| | ... | ... |
app/models/rss_feed.rb
lib/acts_as_having_posts.rb
test/unit/blog_test.rb
... | ... | @@ -38,14 +38,14 @@ class BlogTest < ActiveSupport::TestCase |
38 | 38 | |
39 | 39 | should 'save feed options' do |
40 | 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 | 42 | p.blog.feed = { :limit => 7 } |
43 | 43 | assert_equal 7, p.blog.feed.limit |
44 | 44 | end |
45 | 45 | |
46 | 46 | should 'save feed options after create blog' do |
47 | 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 | 49 | assert_equal 7, p.blog.feed.limit |
50 | 50 | end |
51 | 51 | |
... | ... | @@ -56,7 +56,7 @@ class BlogTest < ActiveSupport::TestCase |
56 | 56 | |
57 | 57 | should 'update posts per page setting' do |
58 | 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 | 60 | blog = p.blog |
61 | 61 | blog.posts_per_page = 7 |
62 | 62 | assert blog.save! |
... | ... | @@ -95,7 +95,7 @@ class BlogTest < ActiveSupport::TestCase |
95 | 95 | |
96 | 96 | should 'build external feed after save' do |
97 | 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 | 99 | blog.external_feed_builder = { :address => 'feed address' } |
100 | 100 | blog.save! |
101 | 101 | assert blog.external_feed.valid? |
... | ... | @@ -103,9 +103,9 @@ class BlogTest < ActiveSupport::TestCase |
103 | 103 | |
104 | 104 | should 'update external feed' do |
105 | 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 | 107 | blog.save |
108 | - e = ExternalFeed.new(:address => 'feed address') | |
108 | + e = build(ExternalFeed, :address => 'feed address') | |
109 | 109 | e.blog = blog |
110 | 110 | e.save |
111 | 111 | blog.reload |
... | ... | @@ -116,14 +116,14 @@ class BlogTest < ActiveSupport::TestCase |
116 | 116 | |
117 | 117 | should 'invalid blog if has invalid external_feed' do |
118 | 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 | 120 | blog.save |
121 | 121 | assert ! blog.valid? |
122 | 122 | end |
123 | 123 | |
124 | 124 | should 'remove external feed when removing blog' do |
125 | 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 | 127 | assert blog.external_feed |
128 | 128 | assert_difference ExternalFeed, :count, -1 do |
129 | 129 | blog.destroy |
... | ... | @@ -134,16 +134,17 @@ class BlogTest < ActiveSupport::TestCase |
134 | 134 | p = create_user('testuser').person |
135 | 135 | fast_create(Blog, :name => 'Blog test', :profile_id => p.id) |
136 | 136 | assert_nothing_raised ActiveRecord::RecordInvalid do |
137 | - Blog.create!(:name => 'Another Blog', :profile => p) | |
137 | + create(Blog, :name => 'Another Blog', :profile => p) | |
138 | 138 | end |
139 | 139 | end |
140 | 140 | |
141 | 141 | should 'not update slug from name for existing blog' do |
142 | 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 | 148 | end |
148 | 149 | |
149 | 150 | should 'display full posts by default' do |
... | ... | @@ -153,7 +154,7 @@ class BlogTest < ActiveSupport::TestCase |
153 | 154 | |
154 | 155 | should 'update visualization_format setting' do |
155 | 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 | 158 | blog = p.blog |
158 | 159 | blog.visualization_format = 'short' |
159 | 160 | assert blog.save! |
... | ... | @@ -161,7 +162,7 @@ class BlogTest < ActiveSupport::TestCase |
161 | 162 | end |
162 | 163 | |
163 | 164 | should 'allow only full and short as visualization_format' do |
164 | - blog = Blog.new(:name => 'blog') | |
165 | + blog = build(Blog, :name => 'blog') | |
165 | 166 | blog.visualization_format = 'wrong_format' |
166 | 167 | blog.valid? |
167 | 168 | assert blog.errors[:visualization_format.to_s].present? |
... | ... | @@ -187,7 +188,7 @@ class BlogTest < ActiveSupport::TestCase |
187 | 188 | |
188 | 189 | should 'update display posts in current language setting' do |
189 | 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 | 192 | blog = p.blog |
192 | 193 | blog.display_posts_in_current_language = false |
193 | 194 | assert blog.save! && blog.reload | ... | ... |
test/unit/forum_test.rb
... | ... | @@ -95,9 +95,10 @@ class ForumTest < ActiveSupport::TestCase |
95 | 95 | should 'not update slug from name for existing forum' do |
96 | 96 | p = create_user('testuser').person |
97 | 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 | 102 | end |
102 | 103 | |
103 | 104 | should 'have posts' do | ... | ... |