From 0e75f1c2ed1bfbf408a560d82b0404d64728c094 Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Tue, 7 Jul 2015 13:34:32 -0300 Subject: [PATCH] rails4: fix remaining funcionals tests --- Gemfile | 2 +- app/controllers/admin/admin_panel_controller.rb | 2 +- app/controllers/application_controller.rb | 4 ++-- app/controllers/my_profile/cms_controller.rb | 4 ++-- app/controllers/public/account_controller.rb | 2 +- app/controllers/public/profile_controller.rb | 2 +- app/helpers/application_helper.rb | 8 +++++++- app/helpers/folder_helper.rb | 11 +++++------ app/views/content_viewer/folder.html.erb | 6 +----- app/views/shared/logged_in/xmpp_chat.html.erb | 2 +- test/functional/application_controller_test.rb | 26 +++++++++----------------- test/functional/catalog_controller_test.rb | 2 +- test/functional/cms_controller_test.rb | 8 ++++---- test/functional/favorite_enterprises_controller_test.rb | 1 - test/functional/manage_products_controller_test.rb | 6 +++--- test/functional/profile_controller_test.rb | 16 +++++++++------- 16 files changed, 48 insertions(+), 54 deletions(-) diff --git a/Gemfile b/Gemfile index 9cac92e..14ee72e 100644 --- a/Gemfile +++ b/Gemfile @@ -20,7 +20,7 @@ gem 'exception_notification', '~> 4.0.1' gem 'gettext', '~> 2.2.1', :require => false gem 'locale', '~> 2.0.5' gem 'whenever', :require => false -gem 'eita-jrails', '>= 0.9.9', require: 'jrails' +gem 'eita-jrails', '>= 0.10.0', require: 'jrails' # asset pipeline gem 'uglifier', '>= 1.0.3' diff --git a/app/controllers/admin/admin_panel_controller.rb b/app/controllers/admin/admin_panel_controller.rb index 9ecbe6d..df51fa0 100644 --- a/app/controllers/admin/admin_panel_controller.rb +++ b/app/controllers/admin/admin_panel_controller.rb @@ -54,7 +54,7 @@ class AdminPanelController < AdminController if request.post? env = environment - folders = Folder.where :profile_id => env.portal_community, :id => params[:folders] if params[:folders] + folders = env.portal_community.folders.where(id: params[:folders]).order(params[:folders].reverse.map{ |f| "id=#{f}" }) if params[:folders] env.portal_folders = folders if env.save session[:notice] = _('Saved the portal folders') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3c1282a..709535e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -141,7 +141,7 @@ class ApplicationController < ActionController::Base # Check if the requested profile belongs to another domain if @profile && !params[:profile].blank? && params[:profile] != @profile.identifier @profile = @environment.profiles.find_by_identifier params[:profile] - redirect_to params.merge(:host => @profile.default_hostname) + redirect_to url_for(params.merge host: @profile.default_hostname) end end end @@ -197,7 +197,7 @@ class ApplicationController < ActionController::Base def redirect_to_current_user if params[:profile] == '~' if logged_in? - redirect_to params.merge(:profile => user.identifier) + redirect_to url_for(params.merge profile: user.identifier) else render_not_found end diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index fb2e0e1..f7acca6 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -58,7 +58,7 @@ class CmsController < MyProfileController def view @article = profile.articles.find(params[:id]) @articles = @article.children.reorder("case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC, name") - @articles = @articles.where type: 'RssFeed' if @article.has_posts? + @articles = @articles.where "type <> ?", 'RssFeed' if @article.has_posts? @articles = @articles.paginate per_page: per_page, page: params[:npage] end @@ -232,7 +232,7 @@ class CmsController < MyProfileController else session[:notice] = _('File(s) successfully uploaded') if @back_to - redirect_to @back_to + redirect_to url_for(@back_to) elsif @parent redirect_to :action => 'view', :id => @parent.id else diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index e7d75ae..47cd121 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -115,7 +115,7 @@ class AccountController < ApplicationController @user.person.affiliate(@user.person, [owner_role]) if owner_role invitation = Task.from_code(@invitation_code).first if invitation - invitation.update_attributes!({:friend => @user.person}) + invitation.update_attributes! friend: @user.person invitation.finish end diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 77509b1..ec840ec 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -36,7 +36,7 @@ class ProfileController < PublicController def tag_feed @tag = params[:id] - tagged = profile.articles.paginate(:per_page => 20, :page => 1).order('published_at DESC').includes(:tags).where('tags.name LIKE ?', @tag) + tagged = profile.articles.paginate(:per_page => 20, :page => 1).order('published_at DESC').joins(:tags).where('tags.name LIKE ?', @tag) feed_writer = FeedWriter.new data = feed_writer.write( tagged, diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 27c63f4..6e36296 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -907,8 +907,14 @@ module ApplicationHelper end alias :top_url :base_url + class View < ActionView::Base + def url_for *args + self.controller.url_for *args + end + end + def helper_for_article(article) - article_helper = ActionView::Base.new + article_helper = View.new article_helper.controller = controller article_helper.extend ArticleHelper article_helper.extend Rails.application.routes.url_helpers diff --git a/app/helpers/folder_helper.rb b/app/helpers/folder_helper.rb index bbe9b4e..3c33d4f 100644 --- a/app/helpers/folder_helper.rb +++ b/app/helpers/folder_helper.rb @@ -5,12 +5,11 @@ module FolderHelper def list_contents(configure={}) configure[:recursive] ||= false configure[:list_type] ||= :folder - if !configure[:contents].blank? - configure[:contents] = configure[:contents].order('name ASC').paginate( - :per_page => 30, - :page => params[:npage] - ) - + contents = configure[:contents] + contents = contents.order('name ASC') unless contents.is_a? Array + contents = contents.paginate per_page: 30, page: params[:npage] + configure[:contents] = contents + if contents.present? render :file => 'shared/content_list', :locals => configure else content_tag('em', _('(empty folder)')) diff --git a/app/views/content_viewer/folder.html.erb b/app/views/content_viewer/folder.html.erb index 7317b6d..1ec8d42 100644 --- a/app/views/content_viewer/folder.html.erb +++ b/app/views/content_viewer/folder.html.erb @@ -4,8 +4,4 @@ <% end %> -<% if folder.children.empty? %> - <%= _('(empty folder)') %> -<% else %> - <%= list_contents(:contents=>folder.children) %> -<% end %> +<%= list_contents contents: folder.children %> diff --git a/app/views/shared/logged_in/xmpp_chat.html.erb b/app/views/shared/logged_in/xmpp_chat.html.erb index 9a63c60..f3f0a87 100644 --- a/app/views/shared/logged_in/xmpp_chat.html.erb +++ b/app/views/shared/logged_in/xmpp_chat.html.erb @@ -1,4 +1,4 @@ - <%= javascript_include_tag 'strophejs-1.1.3/strophe.min', 'jquery.emoticon', '../designs/icons/pidgin/emoticons.js', 'ba-linkify', 'jquery.ba-hashchange', 'jquery.sound', 'chat', 'perfect-scrollbar.min.js', 'perfect-scrollbar.with-mousewheel.min.js', 'jquery.timeago.js' %> + <%= javascript_include_tag 'strophejs-1.1.3/strophe.min', 'jquery.emoticon', 'designs/icons/pidgin/emoticons.js', 'ba-linkify', 'jquery.ba-hashchange', 'jquery.sound', 'chat', 'perfect-scrollbar.min.js', 'perfect-scrollbar.with-mousewheel.min.js', 'jquery.timeago.js' %> <%= stylesheet_link_tag 'perfect-scrollbar.min.css' %> <% extend ChatHelper %> diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index c8c1d48..938792d 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -278,10 +278,7 @@ class ApplicationControllerTest < ActionController::TestCase uses_host 'other.environment' get :index assert_tag :tag => 'div', :attributes => {:id => 'user_menu_ul'} - assert_tag :tag => 'div', :attributes => {:id => 'user_menu_ul'}, - :descendant => {:tag => 'a', :attributes => { :href => 'http://other.environment/adminuser' }}, - :descendant => {:tag => 'a', :attributes => { :href => 'http://other.environment/myprofile/adminuser' }}, - :descendant => {:tag => 'a', :attributes => { :href => '/admin' }} + assert_tag tag: 'div', attributes: {id: 'user_menu_ul'}, descendant: {tag: 'a', attributes: { href: '/admin' }} end should 'not display invisible blocks' do @@ -359,13 +356,10 @@ class ApplicationControllerTest < ActionController::TestCase environment.enable_plugin(Plugin1.name) environment.enable_plugin(Plugin2.name) - ActionView::Helpers::AssetTagHelper::StylesheetIncludeTag.any_instance.stubs('asset_file_path!') - ActionView::Helpers::AssetTagHelper::JavascriptIncludeTag.any_instance.stubs('asset_file_path!') - get :index - assert_tag :tag => 'link', :attributes => {:href => /#{plugin1_path}/, :type => 'text/css', :rel => 'stylesheet'} - assert_tag :tag => 'link', :attributes => {:href => /#{plugin2_path}/, :type => 'text/css', :rel => 'stylesheet'} + assert_tag tag: 'link', attributes: {href: /#{plugin1_path}/, rel: 'stylesheet'} + assert_tag tag: 'link', attributes: {href: /#{plugin2_path}/, rel: 'stylesheet'} end should 'include javascripts supplied by plugins' do @@ -395,13 +389,11 @@ class ApplicationControllerTest < ActionController::TestCase environment.enable_plugin(Plugin1.name) environment.enable_plugin(Plugin2.name) - ActionView::Helpers::AssetTagHelper::JavascriptIncludeTag.any_instance.stubs('asset_file_path!') - get :index - assert_tag :tag => 'script', :attributes => {:src => /#{plugin1_path}/, :type => 'text/javascript'} - assert_tag :tag => 'script', :attributes => {:src => /#{plugin2_path2}/, :type => 'text/javascript'} - assert_tag :tag => 'script', :attributes => {:src => /#{plugin2_path3}/, :type => 'text/javascript'} + assert_tag tag: 'script', attributes: {src: /#{plugin1_path}/} + assert_tag tag: 'script', attributes: {src: /#{plugin2_path2}/} + assert_tag tag: 'script', attributes: {src: /#{plugin2_path3}/} end should 'include content in the beginning of body supplied by plugins regardless it is a block or html code' do @@ -461,15 +453,15 @@ class ApplicationControllerTest < ActionController::TestCase e.access_control_allow_origin = ['http://allowed'] e.save! - @request.env["Origin"] = "http://allowed" + @request.headers["Origin"] = "http://allowed" get :index assert_response :success - @request.env["Origin"] = "http://other" + @request.headers["Origin"] = "http://other" get :index assert_response :success - @request.env["Origin"] = "http://other" + @request.headers["Origin"] = "http://other" e.restrict_to_access_control_origins = true e.save! get :index diff --git a/test/functional/catalog_controller_test.rb b/test/functional/catalog_controller_test.rb index 1b39b81..14370f5 100644 --- a/test/functional/catalog_controller_test.rb +++ b/test/functional/catalog_controller_test.rb @@ -63,7 +63,7 @@ class CatalogControllerTest < ActionController::TestCase end should 'show action moved to manage_products controller' do - assert_raise ActionController::RoutingError do + assert_raise ActionController::UrlGenerationError do get :show, :id => 1 end end diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index fdc4049..d24fcf3 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -537,18 +537,18 @@ class CmsControllerTest < ActionController::TestCase end should 'filter html with white_list from tiny mce article abstract' do - post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => " article", :body => 'the text of the article ...' } - assert_equal " article", assigns(:article).abstract + post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => " article", :body => 'the text of the article ...' } + assert_equal "alert('text') article", assigns(:article).abstract end should 'filter html with white_list from tiny mce article body' do post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => 'abstract', :body => "the of article ..." } - assert_equal "the of article ...", assigns(:article).body + assert_equal "the alert('text') of article ...", assigns(:article).body end should 'not filter html tags permitted from tiny mce article body' do post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => 'abstract', :body => "the of article ..." } - assert_equal "the of article ...", assigns(:article).body + assert_equal "the alert('text') of article ...", assigns(:article).body end should 'sanitize tags' do diff --git a/test/functional/favorite_enterprises_controller_test.rb b/test/functional/favorite_enterprises_controller_test.rb index f58d0a7..df534e8 100644 --- a/test/functional/favorite_enterprises_controller_test.rb +++ b/test/functional/favorite_enterprises_controller_test.rb @@ -19,7 +19,6 @@ class FavoriteEnterprisesControllerTest < ActionController::TestCase get :index assert_response :success assert_template 'index' - assert_kind_of Array, assigns(:favorite_enterprises) end should 'confirm addition of new favorite enterprise' do diff --git a/test/functional/manage_products_controller_test.rb b/test/functional/manage_products_controller_test.rb index dfddb40..13d8d1b 100644 --- a/test/functional/manage_products_controller_test.rb +++ b/test/functional/manage_products_controller_test.rb @@ -175,8 +175,8 @@ class ManageProductsControllerTest < ActionController::TestCase should 'filter html with white list from description of product' do product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id) - post 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'info', :product => { :name => 'name', :description => "descr bold" } - assert_equal "descr bold", assigns(:product).description + post 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'info', :product => { :name => 'name', :description => "descr bold" } + assert_equal "descr bold", assigns(:product).description end should 'not let users in if environment do not let' do @@ -340,7 +340,7 @@ class ManageProductsControllerTest < ActionController::TestCase end should 'render partial certifiers for selection' do - get :certifiers_for_selection, :profile => @enterprise.identifier + xhr :get, :certifiers_for_selection, :profile => @enterprise.identifier assert_template '_certifiers_for_selection' end diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index b2f1270..6034e9c 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -475,7 +475,7 @@ class ProfileControllerTest < ActionController::TestCase fast_create(TextileArticle, :name => 'Unpublished post', :parent_id => profile.blog.id, :profile_id => profile.id, :published => false) get :index, :profile => profile.identifier - assert_tag :tag => 'a', :content => '2 posts', :attributes => { :href => /\/testuser\/blog/ } + assert_tag :tag => 'a', :content => '2 posts', :attributes => { :href => /\/testuser\/#{blog.slug}/ } end should 'show number of published images in index' do @@ -1179,7 +1179,7 @@ class ProfileControllerTest < ActionController::TestCase 20.times {comment = fast_create(Comment, :source_id => article, :title => 'a comment', :body => 'lalala', :created_at => Time.now)} article.reload assert_equal 20, article.comments.count - get :more_comments, :activity => activity.id, :comment_page => 2 + xhr :get, :more_comments, :activity => activity.id, :comment_page => 2 assert_response :success assert_template '_comment' assert_select_rjs :insert_html do @@ -1204,7 +1204,7 @@ class ProfileControllerTest < ActionController::TestCase 20.times {fast_create(Scrap, :sender_id => profile.id, :receiver_id => profile.id, :scrap_id => scrap.id)} profile.reload assert_equal 20, scrap.replies.count - get :more_replies, :activity => scrap.id, :comment_page => 2 + xhr :get, :more_replies, :activity => scrap.id, :comment_page => 2 assert_response :success assert_template '_profile_scrap' assert_select_rjs :insert_html do @@ -1386,7 +1386,7 @@ class ProfileControllerTest < ActionController::TestCase activity = ActionTracker::Record.last login_as(profile.identifier) - get :more_comments, :profile => profile.identifier, :activity => activity.id, :comment_page => 1, :tab_action => 'wall' + xhr :get, :more_comments, :profile => profile.identifier, :activity => activity.id, :comment_page => 1, :tab_action => 'wall' assert_select_rjs :insert_html do assert_select 'span', :content => '(removed user)', :attributes => {:class => 'comment-user-status comment-user-status-wall icon-user-removed'} @@ -1415,7 +1415,7 @@ class ProfileControllerTest < ActionController::TestCase activity = ActionTracker::Record.last login_as(profile.identifier) - get :more_comments, :profile => profile.identifier, :activity => activity.id, :comment_page => 1, :tab_action => 'wall' + xhr :get, :more_comments, :profile => profile.identifier, :activity => activity.id, :comment_page => 1, :tab_action => 'wall' assert_select_rjs :insert_html do assert_select 'span', :content => '(unauthenticated user)', :attributes => {:class => 'comment-user-status comment-user-status-wall icon-user-unknown'} @@ -1671,7 +1671,8 @@ class ProfileControllerTest < ActionController::TestCase get :index assert_tag :tag => 'div', :attributes => {:id => 'manage-communities'} - assert_select '#manage-communities li > a' do |links| + doc = Nokogiri::HTML @response.body + assert_select doc, '#manage-communities li > a' do |links| assert_equal 2, links.length assert_match /community_1/, links.to_s assert_match /community_2/, links.to_s @@ -1699,7 +1700,8 @@ class ProfileControllerTest < ActionController::TestCase get :index assert_tag :tag => 'div', :attributes => {:id => 'manage-enterprises'} - assert_select '#manage-enterprises li > a' do |links| + doc = Nokogiri::HTML @response.body + assert_select doc, '#manage-enterprises li > a' do |links| assert_equal 1, links.length assert_match /Test enterprise1/, links.to_s assert_no_match /Test enterprise_2/, links.to_s -- libgit2 0.21.2