Skip to content

Commit

Permalink
Cleanuing feed unit tests & fixtures [concerto#94]
Browse files Browse the repository at this point in the history
  • Loading branch information
bamnet committed Jun 7, 2010
1 parent 93b3311 commit e0f38a3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 66 deletions.
12 changes: 6 additions & 6 deletions test/fixtures/feeds.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
name: MyString
description: MyText
service:
name: Service Events
description: This feed is for community service related announcments
parent_id:
group: wtg

two:
name: MyString1
description: MyText
announcements:
name: Announcements
description: Important Organizational Announcements
parent_id:
group: wtg
75 changes: 15 additions & 60 deletions test/unit/feed_test.rb
Original file line number Diff line number Diff line change
@@ -1,67 +1,22 @@
require 'test_helper'

class FeedTest < ActiveSupport::TestCase
#Test the fields that should be required
test "name cannot be blank" do
f = feeds(:one)
feed = Feed.new(f.attributes)
feed.name = ""
assert !feed.valid?, "Feed name is blank"
feed.name = "Blah"
assert feed.valid?, "Feed name has entry"
end
test "group cannot be blank or unassociated" do
f = feeds(:one)
feed = Feed.new(f.attributes)
feed.name = "ASDF" + feed.name #Make the name unique
feed.group_id = ""
assert !feed.valid?, "Feed group is blank"
feed.group_id = 0
assert !feed.valid?, "Feed group is unassociated"
feed.group_id = groups(:wtg).id
assert feed.valid?, "Feed group is associated with wtg group"
end
#Test for duplicate names
test "name cannot be duplicated" do
f = feeds(:one)
feed = Feed.new({:name => f.name, :group_id => groups(:rpitv).id})
assert_equal f.name, feed.name, "Names are set equal"
assert !feed.valid?, "Names can't be equal"
feed.name = "Fooasdasdasda"
assert feed.valid?, "Unique name is OK"
end

#Test the content relationship
# This test serves more to verify the setup of the
# testing enviroment than the actual application
test "has content" do
f = feeds(:one)
assert_equal f.contents.length, 2, "Feed only has 2 contents"
assert f.contents.include?(contents(:one)), "Content one is included"
assert f.contents.include?(contents(:old)), "Content old is included"
# Attributes cannot be left empty/blank
test "feed attributes must not be empty" do
feed = Feed.new
assert feed.invalid?
assert feed.errors[:name].any?
assert feed.errors[:group].any?
end

#Test the approved/pending/denied content relationship
test "approved content" do
f = feeds(:one)
assert_equal f.approved_contents, [contents(:one)], "Approved content is approved"

no_approved = feeds(:two)
assert no_approved.approved_contents.empty?, "Denied content is not approved"
# The feed name must be unique
test "feed is now valid without a unique name" do
feed = Feed.new(:name => feeds(:service).name,
:description => "Another feed.",
:group => groups(:rpitv))

assert feed.invalid?
assert feed.errors[:name].any?
end
test "pending content" do
f = feeds(:one)
assert_equal f.pending_contents, [contents(:old)], "Pending content is pending"

no_pending = feeds(:two)
assert no_pending.pending_contents.empty?, "Denied content is not pending"
end
test "denied content" do
f = feeds(:two)
assert_equal f.denied_contents, [contents(:one)], "Denied content is denied"

no_denied = feeds(:one)
assert no_denied.denied_contents.empty?, "Pending|Approved is not denied"
end


end

0 comments on commit e0f38a3

Please sign in to comment.