Replace changeset_comments fixtures with a factory.

There's little point in testing ChangesetComment.count so I've removed that
test.
This commit is contained in:
Andy Allan 2016-10-12 15:43:54 +01:00
parent c2e12ed77d
commit a91e50d308
7 changed files with 32 additions and 48 deletions

View file

@ -75,6 +75,9 @@ class BrowseControllerTest < ActionController::TestCase
end end
def test_read_changeset_hidden_comments def test_read_changeset_hidden_comments
create_list(:changeset_comment, 3)
create(:changeset_comment, :visible => false)
browse_check "changeset", changesets(:normal_user_closed_change).id, "browse/changeset" browse_check "changeset", changesets(:normal_user_closed_change).id, "browse/changeset"
assert_select "div.changeset-comments ul li", :count => 3 assert_select "div.changeset-comments ul li", :count => 3

View file

@ -3,7 +3,7 @@ require "changeset_controller"
class ChangesetControllerTest < ActionController::TestCase class ChangesetControllerTest < ActionController::TestCase
api_fixtures api_fixtures
fixtures :changeset_comments, :changesets_subscribers fixtures :changesets_subscribers
## ##
# test all routes which lead to this controller # test all routes which lead to this controller
@ -197,6 +197,7 @@ class ChangesetControllerTest < ActionController::TestCase
assert_select "osm>changeset>discussion>comment", 0 assert_select "osm>changeset>discussion>comment", 0
changeset_id = changesets(:normal_user_closed_change).id changeset_id = changesets(:normal_user_closed_change).id
create_list(:changeset_comment, 3, :changeset_id => changeset_id)
get :read, :id => changeset_id, :include_discussion => true get :read, :id => changeset_id, :include_discussion => true
assert_response :success, "cannot get closed changeset with comments" assert_response :success, "cannot get closed changeset with comments"
@ -2149,7 +2150,7 @@ EOF
# test hide comment fail # test hide comment fail
def test_hide_comment_fail def test_hide_comment_fail
# unauthorized # unauthorized
comment = changeset_comments(:normal_comment_1) comment = create(:changeset_comment)
assert_equal true, comment.visible assert_equal true, comment.visible
post :hide_comment, :id => comment.id post :hide_comment, :id => comment.id
@ -2174,7 +2175,7 @@ EOF
## ##
# test hide comment succes # test hide comment succes
def test_hide_comment_success def test_hide_comment_success
comment = changeset_comments(:normal_comment_1) comment = create(:changeset_comment)
assert_equal true, comment.visible assert_equal true, comment.visible
basic_authorization(users(:moderator_user).email, "test") basic_authorization(users(:moderator_user).email, "test")
@ -2188,7 +2189,7 @@ EOF
# test unhide comment fail # test unhide comment fail
def test_unhide_comment_fail def test_unhide_comment_fail
# unauthorized # unauthorized
comment = changeset_comments(:hidden_comment) comment = create(:changeset_comment, :visible => false)
assert_equal false, comment.visible assert_equal false, comment.visible
post :unhide_comment, :id => comment.id post :unhide_comment, :id => comment.id
@ -2213,7 +2214,7 @@ EOF
## ##
# test unhide comment succes # test unhide comment succes
def test_unhide_comment_success def test_unhide_comment_success
comment = changeset_comments(:hidden_comment) comment = create(:changeset_comment, :visible => false)
assert_equal false, comment.visible assert_equal false, comment.visible
basic_authorization(users(:moderator_user).email, "test") basic_authorization(users(:moderator_user).email, "test")
@ -2226,6 +2227,8 @@ EOF
## ##
# test comments feed # test comments feed
def test_comments_feed def test_comments_feed
create_list(:changeset_comment, 3, :changeset_id => changesets(:normal_user_closed_change).id)
get :comments_feed, :format => "rss" get :comments_feed, :format => "rss"
assert_response :success assert_response :success
assert_equal "application/rss+xml", @response.content_type assert_equal "application/rss+xml", @response.content_type

View file

@ -0,0 +1,12 @@
FactoryGirl.define do
factory :changeset_comment do
sequence(:body) { |n| "Changeset comment #{n}" }
visible true
# FIXME: needs changeset factory
changeset_id 3
# FIXME: needs user factory
author_id 1
end
end

View file

@ -1,31 +0,0 @@
normal_comment_1:
id: 1
changeset_id: 3
created_at: 2007-01-01 00:00:00
author_id: 1
body: 'A comment from a logged-in user'
visible: true
normal_comment_2:
id: 2
changeset_id: 3
created_at: 2007-02-01 00:00:00
author_id: 4
body: 'A comment from another logged-in user'
visible: true
normal_comment_3:
id: 4
changeset_id: 3
created_at: 2007-02-01 00:00:00
author_id: 4
body: 'A comment from another logged-in user'
visible: true
hidden_comment:
id: 3
changeset_id: 3
created_at: 2007-02-01 00:00:00
author_id: 4
body: 'A non-visible comment'
visible: false

View file

@ -1,7 +1,7 @@
require "test_helper" require "test_helper"
class UserChangesetCommentsTest < ActionDispatch::IntegrationTest class UserChangesetCommentsTest < ActionDispatch::IntegrationTest
fixtures :users, :changesets, :changeset_comments fixtures :users, :changesets
# Test 'log in to comment' message for nonlogged in user # Test 'log in to comment' message for nonlogged in user
def test_log_in_message def test_log_in_message

View file

@ -2,15 +2,11 @@
require "test_helper" require "test_helper"
class ChangesetCommentTest < ActiveSupport::TestCase class ChangesetCommentTest < ActiveSupport::TestCase
fixtures :changesets, :changeset_comments fixtures :changesets
def test_changeset_comment_count
assert_equal 4, ChangesetComment.count
end
# validations # validations
def test_does_not_accept_invalid_author def test_does_not_accept_invalid_author
comment = changeset_comments(:normal_comment_1) comment = create(:changeset_comment)
comment.author = nil comment.author = nil
assert !comment.valid? assert !comment.valid?
@ -20,7 +16,7 @@ class ChangesetCommentTest < ActiveSupport::TestCase
end end
def test_does_not_accept_invalid_changeset def test_does_not_accept_invalid_changeset
comment = changeset_comments(:normal_comment_1) comment = create(:changeset_comment)
comment.changeset = nil comment.changeset = nil
assert !comment.valid? assert !comment.valid?
@ -30,13 +26,14 @@ class ChangesetCommentTest < ActiveSupport::TestCase
end end
def test_does_not_accept_empty_visible def test_does_not_accept_empty_visible
comment = changeset_comments(:normal_comment_1) comment = create(:changeset_comment)
comment.visible = nil comment.visible = nil
assert !comment.valid? assert !comment.valid?
end end
def test_comments_of_changeset_count def test_comments_of_changeset_count
create_list(:changeset_comment, 3, :changeset_id => changesets(:normal_user_closed_change).id)
assert_equal 3, Changeset.find(changesets(:normal_user_closed_change).id).comments.count assert_equal 3, Changeset.find(changesets(:normal_user_closed_change).id).comments.count
end end
@ -47,13 +44,13 @@ class ChangesetCommentTest < ActiveSupport::TestCase
"foo\ufffebar", "foo\uffffbar"] "foo\ufffebar", "foo\uffffbar"]
ok.each do |body| ok.each do |body|
changeset_comment = changeset_comments(:normal_comment_1) changeset_comment = create(:changeset_comment)
changeset_comment.body = body changeset_comment.body = body
assert changeset_comment.valid?, "#{body} is invalid, when it should be" assert changeset_comment.valid?, "#{body} is invalid, when it should be"
end end
bad.each do |body| bad.each do |body|
changeset_comment = changeset_comments(:normal_comment_1) changeset_comment = create(:changeset_comment)
changeset_comment.body = body changeset_comment.body = body
assert !changeset_comment.valid?, "#{body} is valid when it shouldn't be" assert !changeset_comment.valid?, "#{body} is valid when it shouldn't be"
end end

View file

@ -14,7 +14,7 @@ module ActiveSupport
def self.api_fixtures def self.api_fixtures
# print "setting up the api_fixtures" # print "setting up the api_fixtures"
fixtures :users, :user_roles, :user_blocks fixtures :users, :user_roles, :user_blocks
fixtures :changesets, :changeset_tags, :changeset_comments fixtures :changesets, :changeset_tags
fixtures :current_nodes, :nodes fixtures :current_nodes, :nodes
set_fixture_class :current_nodes => Node set_fixture_class :current_nodes => Node