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 28 def feed=(attrs)
29 29 if attrs
30 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 34 else
33 35 self.feed_attrs = attrs
34 36 end
... ...
test/unit/forum_test.rb
... ... @@ -34,14 +34,14 @@ class ForumTest < ActiveSupport::TestCase
34 34  
35 35 should 'save feed options' do
36 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 38 p.forum.feed = { :limit => 7 }
39 39 assert_equal 7, Forum.find(forum.id).feed.limit
40 40 end
41 41  
42 42 should 'save feed options after create forum' do
43 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 45 assert_equal 7, Forum.find(forum.id).feed.limit
46 46 end
47 47  
... ... @@ -52,7 +52,7 @@ class ForumTest &lt; ActiveSupport::TestCase
52 52  
53 53 should 'update posts per page setting' do
54 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 56 forum.posts_per_page = 7
57 57 assert forum.save!
58 58 assert_equal 7, Forum.find(forum.id).posts_per_page
... ... @@ -60,7 +60,7 @@ class ForumTest &lt; ActiveSupport::TestCase
60 60  
61 61 should 'has posts' do
62 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 64 post = fast_create(TextileArticle, :name => 'First post', :profile_id => p.id, :parent_id => forum.id)
65 65 forum.children << post
66 66 assert_includes forum.posts, post
... ... @@ -88,13 +88,13 @@ class ForumTest &lt; ActiveSupport::TestCase
88 88 p = create_user('testuser').person
89 89 fast_create(Forum, :name => 'Forum test', :profile_id => p.id)
90 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 92 end
93 93 end
94 94  
95 95 should 'not update slug from name for existing forum' do
96 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 98 assert_equal 'forum-test', forum.slug
99 99 forum.name = 'Changed name'
100 100 assert_not_equal 'changed-name', forum.slug
... ...