Commit 3e3bcd973a3461d0247c1c35a76cc370bdcbe639

Authored by Rodrigo Souto
1 parent adbc99e5

rails3: fix forum tests

PS: still failing due to obscure unsettable feed.
lib/acts_as_having_posts.rb
@@ -28,7 +28,9 @@ module ActsAsHavingPosts @@ -28,7 +28,9 @@ 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 - self.feed.update_attributes(attrs) 31 + attrs.each do |key, value|
  32 + self.feed.send(key.to_s+'=', value)
  33 + end
32 else 34 else
33 self.feed_attrs = attrs 35 self.feed_attrs = attrs
34 end 36 end
test/unit/forum_test.rb
@@ -34,14 +34,14 @@ class ForumTest < ActiveSupport::TestCase @@ -34,14 +34,14 @@ class ForumTest < ActiveSupport::TestCase
34 34
35 should 'save feed options' do 35 should 'save feed options' do
36 p = create_user('testuser').person 36 p = create_user('testuser').person
37 - p.articles << forum = Forum.new(:profile => p, :name => 'forum_feed_test', :body => 'Forum test') 37 + p.articles << forum = build(Forum, :profile => p, :name => 'forum_feed_test', :body => 'Forum test')
38 p.forum.feed = { :limit => 7 } 38 p.forum.feed = { :limit => 7 }
39 assert_equal 7, Forum.find(forum.id).feed.limit 39 assert_equal 7, Forum.find(forum.id).feed.limit
40 end 40 end
41 41
42 should 'save feed options after create forum' do 42 should 'save feed options after create forum' do
43 p = create_user('testuser').person 43 p = create_user('testuser').person
44 - p.articles << forum = Forum.new(:profile => p, :name => 'forum_feed_test', :body => 'Forum test', :feed => { :limit => 7 }) 44 + p.articles << forum = build(Forum, :profile => p, :name => 'forum_feed_test', :body => 'Forum test', :feed => { :limit => 7 })
45 assert_equal 7, Forum.find(forum.id).feed.limit 45 assert_equal 7, Forum.find(forum.id).feed.limit
46 end 46 end
47 47
@@ -52,7 +52,7 @@ class ForumTest &lt; ActiveSupport::TestCase @@ -52,7 +52,7 @@ class ForumTest &lt; ActiveSupport::TestCase
52 52
53 should 'update posts per page setting' do 53 should 'update posts per page setting' do
54 p = create_user('testuser').person 54 p = create_user('testuser').person
55 - p.articles << forum = Forum.new(:profile => p, :name => 'Forum test', :body => 'Forum test') 55 + p.articles << forum = build(Forum, :profile => p, :name => 'Forum test', :body => 'Forum test')
56 forum.posts_per_page = 7 56 forum.posts_per_page = 7
57 assert forum.save! 57 assert forum.save!
58 assert_equal 7, Forum.find(forum.id).posts_per_page 58 assert_equal 7, Forum.find(forum.id).posts_per_page
@@ -60,7 +60,7 @@ class ForumTest &lt; ActiveSupport::TestCase @@ -60,7 +60,7 @@ class ForumTest &lt; ActiveSupport::TestCase
60 60
61 should 'has posts' do 61 should 'has posts' do
62 p = create_user('testuser').person 62 p = create_user('testuser').person
63 - p.articles << forum = Forum.new(:profile => p, :name => 'Forum test', :body => 'Forum test') 63 + p.articles << forum = build(Forum, :profile => p, :name => 'Forum test', :body => 'Forum test')
64 post = fast_create(TextileArticle, :name => 'First post', :profile_id => p.id, :parent_id => forum.id) 64 post = fast_create(TextileArticle, :name => 'First post', :profile_id => p.id, :parent_id => forum.id)
65 forum.children << post 65 forum.children << post
66 assert_includes forum.posts, post 66 assert_includes forum.posts, post
@@ -88,13 +88,13 @@ class ForumTest &lt; ActiveSupport::TestCase @@ -88,13 +88,13 @@ class ForumTest &lt; ActiveSupport::TestCase
88 p = create_user('testuser').person 88 p = create_user('testuser').person
89 fast_create(Forum, :name => 'Forum test', :profile_id => p.id) 89 fast_create(Forum, :name => 'Forum test', :profile_id => p.id)
90 assert_nothing_raised ActiveRecord::RecordInvalid do 90 assert_nothing_raised ActiveRecord::RecordInvalid do
91 - Forum.create!(:name => 'Another Forum', :profile => p, :body => 'Forum test') 91 + create(Forum, :name => 'Another Forum', :profile => p, :body => 'Forum test')
92 end 92 end
93 end 93 end
94 94
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 = Forum.create(: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 98 assert_equal 'forum-test', forum.slug
99 forum.name = 'Changed name' 99 forum.name = 'Changed name'
100 assert_not_equal 'changed-name', forum.slug 100 assert_not_equal 'changed-name', forum.slug