From 1fafa75f4eb04b8d2efb6f2c3af1879279a1dbd1 Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Thu, 25 Feb 2016 12:28:09 -0300 Subject: [PATCH] Fix FeedReaderBlock unit tests and view --- app/views/blocks/feed_reader.html.erb | 11 +++++------ test/unit/feed_reader_block_test.rb | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- 2 files changed, 56 insertions(+), 35 deletions(-) diff --git a/app/views/blocks/feed_reader.html.erb b/app/views/blocks/feed_reader.html.erb index aaa1a1b..0712f76 100644 --- a/app/views/blocks/feed_reader.html.erb +++ b/app/views/blocks/feed_reader.html.erb @@ -1,12 +1,11 @@ -<%= block_title(title) %> +<%= block_title(block.title) %> -<% - - if error_message.blank? +<%= + if block.error_message.blank? "".html_safe else - "

#{error_message}

".html_safe + "

#{block.error_message}

".html_safe end %> diff --git a/test/unit/feed_reader_block_test.rb b/test/unit/feed_reader_block_test.rb index bd14af5..41ee77a 100644 --- a/test/unit/feed_reader_block_test.rb +++ b/test/unit/feed_reader_block_test.rb @@ -26,19 +26,6 @@ class FeedReaderBlockTest < ActiveSupport::TestCase 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 @@ -90,26 +77,10 @@ class FeedReaderBlockTest < ActiveSupport::TestCase assert_equal %w[ last-post second-post first-post ], feed.feed_items.map{|i|i[:title]} end - should 'display only limit posts' do - feed.limit = 1; feed.save! - %w[ first-post second-post ].each do |i| - feed.add_item(i, "http://localhost/#{i}", Date.today, "some contet for #{i}") - end - - assert_tag_in_string feed.formatted_feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/second-post' }, :content => 'second-post' - assert_no_tag_in_string feed.formatted_feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/first-post' }, :content => 'first-post' - end - should 'have empty error message by default' do assert FeedReaderBlock.new.error_message.blank?, 'new feed reader block expected to have empty error message' end - should "display error message as content when it's the case" do - msg = "there was a problem" - feed.error_message = msg - assert_match(msg, feed.content) - end - should 'expire after a period' do # save current time now = Time.now @@ -195,3 +166,54 @@ class FeedReaderBlockTest < ActiveSupport::TestCase end end + +require 'boxes_helper' +require 'block_helper' + +class FeedReaderBlockViewTest < ActionView::TestCase + include BoxesHelper + + ActionView::Base.send :include, BlockHelper + + def setup + @feed = create(:feed_reader_block) + end + attr_reader :feed + + should "display error message as content when it's the case" do + msg = "there was a problem" + feed.error_message = msg + + ActionView::Base.any_instance.stubs(:block_title).returns("") + + assert_match(msg, render_block_content(feed)) + 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 = render_block_content(feed) + + 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 only limit posts' do + feed.limit = 1; feed.save! + %w[ first-post second-post ].each do |i| + feed.add_item(i, "http://localhost/#{i}", Date.today, "some contet for #{i}") + end + + ActionView::Base.any_instance.stubs(:block_title).returns("") + + assert_tag_in_string render_block_content(feed), :tag => 'a', :attributes => { :href => 'http://localhost/second-post' }, :content => 'second-post' + assert_no_tag_in_string render_block_content(feed), :tag => 'a', :attributes => { :href => 'http://localhost/first-post' }, :content => 'first-post' + end + +end -- libgit2 0.21.2