Commit 1fafa75f4eb04b8d2efb6f2c3af1879279a1dbd1
1 parent
db2e9cd3
Exists in
web_steps_improvements
and in
9 other branches
Fix FeedReaderBlock unit tests and view
After removing the content method it is now necessary to use BoxesHelper#render_block_content. The view required fixes as it was still supposing the old interface coupled into the model instead of receiving the model object. And it had a programming error that prevented results from getting displayed.
Showing
2 changed files
with
56 additions
and
35 deletions
Show diff stats
app/views/blocks/feed_reader.html.erb
| 1 | -<%= block_title(title) %> | 1 | +<%= block_title(block.title) %> |
| 2 | 2 | ||
| 3 | -<% | ||
| 4 | - | ||
| 5 | - if error_message.blank? | 3 | +<%= |
| 4 | + if block.error_message.blank? | ||
| 6 | "<ul>\n".html_safe + | 5 | "<ul>\n".html_safe + |
| 7 | - self.feed_items[0..(limit-1)].map{ |item| "<li><a href='#{item[:link]}'>#{item[:title]}</a></li>" }.join("\n").html_safe + | 6 | + block.feed_items[0..(block.limit-1)].map{ |item| "<li><a href='#{item[:link]}'>#{item[:title]}</a></li>" }.join("\n").html_safe + |
| 8 | "</ul>".html_safe | 7 | "</ul>".html_safe |
| 9 | else | 8 | else |
| 10 | - "<p>#{error_message}</p>".html_safe | 9 | + "<p>#{block.error_message}</p>".html_safe |
| 11 | end | 10 | end |
| 12 | %> | 11 | %> |
test/unit/feed_reader_block_test.rb
| @@ -26,19 +26,6 @@ class FeedReaderBlockTest < ActiveSupport::TestCase | @@ -26,19 +26,6 @@ class FeedReaderBlockTest < ActiveSupport::TestCase | ||
| 26 | assert feed.editable? | 26 | assert feed.editable? |
| 27 | end | 27 | end |
| 28 | 28 | ||
| 29 | - should 'display feed posts from content' do | ||
| 30 | - feed.feed_items = [] | ||
| 31 | - %w[ last-post second-post first-post ].each do |i| | ||
| 32 | - feed.feed_items << {:title => i, :link => "http://localhost/#{i}"} | ||
| 33 | - end | ||
| 34 | - feed.feed_title = 'Feed for unit tests' | ||
| 35 | - feed_content = feed.content | ||
| 36 | - assert_tag_in_string feed_content, :tag => 'h3', :content => 'Feed for unit tests' | ||
| 37 | - assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/last-post' }, :content => 'last-post' | ||
| 38 | - assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/second-post' }, :content => 'second-post' | ||
| 39 | - assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/first-post' }, :content => 'first-post' | ||
| 40 | - end | ||
| 41 | - | ||
| 42 | should 'display channel title as title by default' do | 29 | should 'display channel title as title by default' do |
| 43 | feed.feed_title = 'Feed for unit tests' | 30 | feed.feed_title = 'Feed for unit tests' |
| 44 | assert_equal 'Feed for unit tests', feed.title | 31 | assert_equal 'Feed for unit tests', feed.title |
| @@ -90,26 +77,10 @@ class FeedReaderBlockTest < ActiveSupport::TestCase | @@ -90,26 +77,10 @@ class FeedReaderBlockTest < ActiveSupport::TestCase | ||
| 90 | assert_equal %w[ last-post second-post first-post ], feed.feed_items.map{|i|i[:title]} | 77 | assert_equal %w[ last-post second-post first-post ], feed.feed_items.map{|i|i[:title]} |
| 91 | end | 78 | end |
| 92 | 79 | ||
| 93 | - should 'display only limit posts' do | ||
| 94 | - feed.limit = 1; feed.save! | ||
| 95 | - %w[ first-post second-post ].each do |i| | ||
| 96 | - feed.add_item(i, "http://localhost/#{i}", Date.today, "some contet for #{i}") | ||
| 97 | - end | ||
| 98 | - | ||
| 99 | - assert_tag_in_string feed.formatted_feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/second-post' }, :content => 'second-post' | ||
| 100 | - assert_no_tag_in_string feed.formatted_feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/first-post' }, :content => 'first-post' | ||
| 101 | - end | ||
| 102 | - | ||
| 103 | should 'have empty error message by default' do | 80 | should 'have empty error message by default' do |
| 104 | assert FeedReaderBlock.new.error_message.blank?, 'new feed reader block expected to have empty error message' | 81 | assert FeedReaderBlock.new.error_message.blank?, 'new feed reader block expected to have empty error message' |
| 105 | end | 82 | end |
| 106 | 83 | ||
| 107 | - should "display error message as content when it's the case" do | ||
| 108 | - msg = "there was a problem" | ||
| 109 | - feed.error_message = msg | ||
| 110 | - assert_match(msg, feed.content) | ||
| 111 | - end | ||
| 112 | - | ||
| 113 | should 'expire after a period' do | 84 | should 'expire after a period' do |
| 114 | # save current time | 85 | # save current time |
| 115 | now = Time.now | 86 | now = Time.now |
| @@ -195,3 +166,54 @@ class FeedReaderBlockTest < ActiveSupport::TestCase | @@ -195,3 +166,54 @@ class FeedReaderBlockTest < ActiveSupport::TestCase | ||
| 195 | end | 166 | end |
| 196 | 167 | ||
| 197 | end | 168 | end |
| 169 | + | ||
| 170 | +require 'boxes_helper' | ||
| 171 | +require 'block_helper' | ||
| 172 | + | ||
| 173 | +class FeedReaderBlockViewTest < ActionView::TestCase | ||
| 174 | + include BoxesHelper | ||
| 175 | + | ||
| 176 | + ActionView::Base.send :include, BlockHelper | ||
| 177 | + | ||
| 178 | + def setup | ||
| 179 | + @feed = create(:feed_reader_block) | ||
| 180 | + end | ||
| 181 | + attr_reader :feed | ||
| 182 | + | ||
| 183 | + should "display error message as content when it's the case" do | ||
| 184 | + msg = "there was a problem" | ||
| 185 | + feed.error_message = msg | ||
| 186 | + | ||
| 187 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | ||
| 188 | + | ||
| 189 | + assert_match(msg, render_block_content(feed)) | ||
| 190 | + end | ||
| 191 | + | ||
| 192 | + should 'display feed posts from content' do | ||
| 193 | + feed.feed_items = [] | ||
| 194 | + %w[ last-post second-post first-post ].each do |i| | ||
| 195 | + feed.feed_items << {:title => i, :link => "http://localhost/#{i}"} | ||
| 196 | + end | ||
| 197 | + feed.feed_title = 'Feed for unit tests' | ||
| 198 | + | ||
| 199 | + feed_content = render_block_content(feed) | ||
| 200 | + | ||
| 201 | + assert_tag_in_string feed_content, :tag => 'h3', :content => 'Feed for unit tests' | ||
| 202 | + assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/last-post' }, :content => 'last-post' | ||
| 203 | + assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/second-post' }, :content => 'second-post' | ||
| 204 | + assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/first-post' }, :content => 'first-post' | ||
| 205 | + end | ||
| 206 | + | ||
| 207 | + should 'display only limit posts' do | ||
| 208 | + feed.limit = 1; feed.save! | ||
| 209 | + %w[ first-post second-post ].each do |i| | ||
| 210 | + feed.add_item(i, "http://localhost/#{i}", Date.today, "some contet for #{i}") | ||
| 211 | + end | ||
| 212 | + | ||
| 213 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | ||
| 214 | + | ||
| 215 | + assert_tag_in_string render_block_content(feed), :tag => 'a', :attributes => { :href => 'http://localhost/second-post' }, :content => 'second-post' | ||
| 216 | + assert_no_tag_in_string render_block_content(feed), :tag => 'a', :attributes => { :href => 'http://localhost/first-post' }, :content => 'first-post' | ||
| 217 | + end | ||
| 218 | + | ||
| 219 | +end |