feed_reader_block_test.rb
2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require File.dirname(__FILE__) + '/../test_helper'
class FeedReaderBlockTest < ActiveSupport::TestCase
include DatesHelper
def setup
@feed = FeedReaderBlock.new
@fetched_at = Time.now
@feed.fetched_at = @fetched_at
@feed.save!
end
attr_reader :feed, :fetched_at
should 'default describe' do
assert_not_equal Block.description, FeedReaderBlock.description
end
should 'have address and limit' do
assert_respond_to feed, :address
assert_respond_to feed, :limit
end
should 'default value of limit' do
assert_equal 5, feed.limit
end
should 'is editable' do
assert feed.editable?
end
should 'display feed posts from content' do
feed.feed_items = []
%w[ last-post second-post first-post ].each do |i|
feed.feed_items << {:title => i, :link => "http://localhost/#{i}"}
end
feed.feed_title = 'Feed for unit tests'
feed_content = feed.content
assert_tag_in_string feed_content, :tag => 'h3', :content => 'Feed for unit tests'
assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/last-post' }, :content => 'last-post'
assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/second-post' }, :content => 'second-post'
assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/first-post' }, :content => 'first-post'
end
should 'display channel title as title by default' do
feed.feed_title = 'Feed for unit tests'
assert_equal 'Feed for unit tests', feed.title
end
should 'display default title when hasnt feed_content' do
assert_equal 'Feed Reader', feed.title
end
should 'notice when content not fetched yet' do
assert_equal'Feed content was not loaded yet', feed.footer
end
should 'display last fetched date' do
feed.feed_items = ['one', 'two']
assert_equal "Updated: #{show_date(@fetched_at)}", feed.footer
end
should 'clear feed title and items' do
feed.feed_items = %w[ last-post second-post first-post ]
feed.feed_title = 'Feed Test'
feed.clear
assert_nil feed.feed_title
assert_equal [], feed.feed_items
end
should 'save! when commit' do
feed.expects(:save!)
feed.finish_fetch
end
end