Commit 0e75f1c2ed1bfbf408a560d82b0404d64728c094

Authored by Braulio Bhavamitra
1 parent fafb323e

rails4: fix remaining funcionals tests

Gemfile
... ... @@ -20,7 +20,7 @@ gem 'exception_notification', '~> 4.0.1'
20 20 gem 'gettext', '~> 2.2.1', :require => false
21 21 gem 'locale', '~> 2.0.5'
22 22 gem 'whenever', :require => false
23   -gem 'eita-jrails', '>= 0.9.9', require: 'jrails'
  23 +gem 'eita-jrails', '>= 0.10.0', require: 'jrails'
24 24  
25 25 # asset pipeline
26 26 gem 'uglifier', '>= 1.0.3'
... ...
app/controllers/admin/admin_panel_controller.rb
... ... @@ -54,7 +54,7 @@ class AdminPanelController < AdminController
54 54  
55 55 if request.post?
56 56 env = environment
57   - folders = Folder.where :profile_id => env.portal_community, :id => params[:folders] if params[:folders]
  57 + folders = env.portal_community.folders.where(id: params[:folders]).order(params[:folders].reverse.map{ |f| "id=#{f}" }) if params[:folders]
58 58 env.portal_folders = folders
59 59 if env.save
60 60 session[:notice] = _('Saved the portal folders')
... ...
app/controllers/application_controller.rb
... ... @@ -141,7 +141,7 @@ class ApplicationController < ActionController::Base
141 141 # Check if the requested profile belongs to another domain
142 142 if @profile && !params[:profile].blank? && params[:profile] != @profile.identifier
143 143 @profile = @environment.profiles.find_by_identifier params[:profile]
144   - redirect_to params.merge(:host => @profile.default_hostname)
  144 + redirect_to url_for(params.merge host: @profile.default_hostname)
145 145 end
146 146 end
147 147 end
... ... @@ -197,7 +197,7 @@ class ApplicationController < ActionController::Base
197 197 def redirect_to_current_user
198 198 if params[:profile] == '~'
199 199 if logged_in?
200   - redirect_to params.merge(:profile => user.identifier)
  200 + redirect_to url_for(params.merge profile: user.identifier)
201 201 else
202 202 render_not_found
203 203 end
... ...
app/controllers/my_profile/cms_controller.rb
... ... @@ -58,7 +58,7 @@ class CmsController < MyProfileController
58 58 def view
59 59 @article = profile.articles.find(params[:id])
60 60 @articles = @article.children.reorder("case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC, name")
61   - @articles = @articles.where type: 'RssFeed' if @article.has_posts?
  61 + @articles = @articles.where "type <> ?", 'RssFeed' if @article.has_posts?
62 62 @articles = @articles.paginate per_page: per_page, page: params[:npage]
63 63 end
64 64  
... ... @@ -232,7 +232,7 @@ class CmsController &lt; MyProfileController
232 232 else
233 233 session[:notice] = _('File(s) successfully uploaded')
234 234 if @back_to
235   - redirect_to @back_to
  235 + redirect_to url_for(@back_to)
236 236 elsif @parent
237 237 redirect_to :action => 'view', :id => @parent.id
238 238 else
... ...
app/controllers/public/account_controller.rb
... ... @@ -115,7 +115,7 @@ class AccountController &lt; ApplicationController
115 115 @user.person.affiliate(@user.person, [owner_role]) if owner_role
116 116 invitation = Task.from_code(@invitation_code).first
117 117 if invitation
118   - invitation.update_attributes!({:friend => @user.person})
  118 + invitation.update_attributes! friend: @user.person
119 119 invitation.finish
120 120 end
121 121  
... ...
app/controllers/public/profile_controller.rb
... ... @@ -36,7 +36,7 @@ class ProfileController &lt; PublicController
36 36  
37 37 def tag_feed
38 38 @tag = params[:id]
39   - tagged = profile.articles.paginate(:per_page => 20, :page => 1).order('published_at DESC').includes(:tags).where('tags.name LIKE ?', @tag)
  39 + tagged = profile.articles.paginate(:per_page => 20, :page => 1).order('published_at DESC').joins(:tags).where('tags.name LIKE ?', @tag)
40 40 feed_writer = FeedWriter.new
41 41 data = feed_writer.write(
42 42 tagged,
... ...
app/helpers/application_helper.rb
... ... @@ -907,8 +907,14 @@ module ApplicationHelper
907 907 end
908 908 alias :top_url :base_url
909 909  
  910 + class View < ActionView::Base
  911 + def url_for *args
  912 + self.controller.url_for *args
  913 + end
  914 + end
  915 +
910 916 def helper_for_article(article)
911   - article_helper = ActionView::Base.new
  917 + article_helper = View.new
912 918 article_helper.controller = controller
913 919 article_helper.extend ArticleHelper
914 920 article_helper.extend Rails.application.routes.url_helpers
... ...
app/helpers/folder_helper.rb
... ... @@ -5,12 +5,11 @@ module FolderHelper
5 5 def list_contents(configure={})
6 6 configure[:recursive] ||= false
7 7 configure[:list_type] ||= :folder
8   - if !configure[:contents].blank?
9   - configure[:contents] = configure[:contents].order('name ASC').paginate(
10   - :per_page => 30,
11   - :page => params[:npage]
12   - )
13   -
  8 + contents = configure[:contents]
  9 + contents = contents.order('name ASC') unless contents.is_a? Array
  10 + contents = contents.paginate per_page: 30, page: params[:npage]
  11 + configure[:contents] = contents
  12 + if contents.present?
14 13 render :file => 'shared/content_list', :locals => configure
15 14 else
16 15 content_tag('em', _('(empty folder)'))
... ...
app/views/content_viewer/folder.html.erb
... ... @@ -4,8 +4,4 @@
4 4 </div>
5 5 <% end %>
6 6  
7   -<% if folder.children.empty? %>
8   - <em><%= _('(empty folder)') %></em>
9   -<% else %>
10   - <%= list_contents(:contents=>folder.children) %>
11   -<% end %>
  7 +<%= list_contents contents: folder.children %>
... ...
app/views/shared/logged_in/xmpp_chat.html.erb
1   - <%= 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' %>
  1 + <%= 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' %>
2 2 <%= stylesheet_link_tag 'perfect-scrollbar.min.css' %>
3 3  
4 4 <% extend ChatHelper %>
... ...
test/functional/application_controller_test.rb
... ... @@ -278,10 +278,7 @@ class ApplicationControllerTest &lt; ActionController::TestCase
278 278 uses_host 'other.environment'
279 279 get :index
280 280 assert_tag :tag => 'div', :attributes => {:id => 'user_menu_ul'}
281   - assert_tag :tag => 'div', :attributes => {:id => 'user_menu_ul'},
282   - :descendant => {:tag => 'a', :attributes => { :href => 'http://other.environment/adminuser' }},
283   - :descendant => {:tag => 'a', :attributes => { :href => 'http://other.environment/myprofile/adminuser' }},
284   - :descendant => {:tag => 'a', :attributes => { :href => '/admin' }}
  281 + assert_tag tag: 'div', attributes: {id: 'user_menu_ul'}, descendant: {tag: 'a', attributes: { href: '/admin' }}
285 282 end
286 283  
287 284 should 'not display invisible blocks' do
... ... @@ -359,13 +356,10 @@ class ApplicationControllerTest &lt; ActionController::TestCase
359 356 environment.enable_plugin(Plugin1.name)
360 357 environment.enable_plugin(Plugin2.name)
361 358  
362   - ActionView::Helpers::AssetTagHelper::StylesheetIncludeTag.any_instance.stubs('asset_file_path!')
363   - ActionView::Helpers::AssetTagHelper::JavascriptIncludeTag.any_instance.stubs('asset_file_path!')
364   -
365 359 get :index
366 360  
367   - assert_tag :tag => 'link', :attributes => {:href => /#{plugin1_path}/, :type => 'text/css', :rel => 'stylesheet'}
368   - assert_tag :tag => 'link', :attributes => {:href => /#{plugin2_path}/, :type => 'text/css', :rel => 'stylesheet'}
  361 + assert_tag tag: 'link', attributes: {href: /#{plugin1_path}/, rel: 'stylesheet'}
  362 + assert_tag tag: 'link', attributes: {href: /#{plugin2_path}/, rel: 'stylesheet'}
369 363 end
370 364  
371 365 should 'include javascripts supplied by plugins' do
... ... @@ -395,13 +389,11 @@ class ApplicationControllerTest &lt; ActionController::TestCase
395 389 environment.enable_plugin(Plugin1.name)
396 390 environment.enable_plugin(Plugin2.name)
397 391  
398   - ActionView::Helpers::AssetTagHelper::JavascriptIncludeTag.any_instance.stubs('asset_file_path!')
399   -
400 392 get :index
401 393  
402   - assert_tag :tag => 'script', :attributes => {:src => /#{plugin1_path}/, :type => 'text/javascript'}
403   - assert_tag :tag => 'script', :attributes => {:src => /#{plugin2_path2}/, :type => 'text/javascript'}
404   - assert_tag :tag => 'script', :attributes => {:src => /#{plugin2_path3}/, :type => 'text/javascript'}
  394 + assert_tag tag: 'script', attributes: {src: /#{plugin1_path}/}
  395 + assert_tag tag: 'script', attributes: {src: /#{plugin2_path2}/}
  396 + assert_tag tag: 'script', attributes: {src: /#{plugin2_path3}/}
405 397 end
406 398  
407 399 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 &lt; ActionController::TestCase
461 453 e.access_control_allow_origin = ['http://allowed']
462 454 e.save!
463 455  
464   - @request.env["Origin"] = "http://allowed"
  456 + @request.headers["Origin"] = "http://allowed"
465 457 get :index
466 458 assert_response :success
467 459  
468   - @request.env["Origin"] = "http://other"
  460 + @request.headers["Origin"] = "http://other"
469 461 get :index
470 462 assert_response :success
471 463  
472   - @request.env["Origin"] = "http://other"
  464 + @request.headers["Origin"] = "http://other"
473 465 e.restrict_to_access_control_origins = true
474 466 e.save!
475 467 get :index
... ...
test/functional/catalog_controller_test.rb
... ... @@ -63,7 +63,7 @@ class CatalogControllerTest &lt; ActionController::TestCase
63 63 end
64 64  
65 65 should 'show action moved to manage_products controller' do
66   - assert_raise ActionController::RoutingError do
  66 + assert_raise ActionController::UrlGenerationError do
67 67 get :show, :id => 1
68 68 end
69 69 end
... ...
test/functional/cms_controller_test.rb
... ... @@ -537,18 +537,18 @@ class CmsControllerTest &lt; ActionController::TestCase
537 537 end
538 538  
539 539 should 'filter html with white_list from tiny mce article abstract' do
540   - post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => "<script>alert('test')</script> article", :body => 'the text of the article ...' }
541   - assert_equal " article", assigns(:article).abstract
  540 + post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => "<script>alert('text')</script> article", :body => 'the text of the article ...' }
  541 + assert_equal "alert('text') article", assigns(:article).abstract
542 542 end
543 543  
544 544 should 'filter html with white_list from tiny mce article body' do
545 545 post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => 'abstract', :body => "the <script>alert('text')</script> of article ..." }
546   - assert_equal "the of article ...", assigns(:article).body
  546 + assert_equal "the alert('text') of article ...", assigns(:article).body
547 547 end
548 548  
549 549 should 'not filter html tags permitted from tiny mce article body' do
550 550 post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'article', :abstract => 'abstract', :body => "<b>the</b> <script>alert('text')</script> <strong>of</strong> article ..." }
551   - assert_equal "<b>the</b> <strong>of</strong> article ...", assigns(:article).body
  551 + assert_equal "<b>the</b> alert('text') <strong>of</strong> article ...", assigns(:article).body
552 552 end
553 553  
554 554 should 'sanitize tags' do
... ...
test/functional/favorite_enterprises_controller_test.rb
... ... @@ -19,7 +19,6 @@ class FavoriteEnterprisesControllerTest &lt; ActionController::TestCase
19 19 get :index
20 20 assert_response :success
21 21 assert_template 'index'
22   - assert_kind_of Array, assigns(:favorite_enterprises)
23 22 end
24 23  
25 24 should 'confirm addition of new favorite enterprise' do
... ...
test/functional/manage_products_controller_test.rb
... ... @@ -175,8 +175,8 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
175 175  
176 176 should 'filter html with white list from description of product' do
177 177 product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id)
178   - post 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'info', :product => { :name => 'name', :description => "<b id='html_descr'>descr bold</b>" }
179   - assert_equal "<b>descr bold</b>", assigns(:product).description
  178 + post 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'info', :product => { :name => 'name', :description => "<b id=\"html_descr\">descr bold</b>" }
  179 + assert_equal "<b id=\"html_descr\">descr bold</b>", assigns(:product).description
180 180 end
181 181  
182 182 should 'not let users in if environment do not let' do
... ... @@ -340,7 +340,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
340 340 end
341 341  
342 342 should 'render partial certifiers for selection' do
343   - get :certifiers_for_selection, :profile => @enterprise.identifier
  343 + xhr :get, :certifiers_for_selection, :profile => @enterprise.identifier
344 344 assert_template '_certifiers_for_selection'
345 345 end
346 346  
... ...
test/functional/profile_controller_test.rb
... ... @@ -475,7 +475,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
475 475 fast_create(TextileArticle, :name => 'Unpublished post', :parent_id => profile.blog.id, :profile_id => profile.id, :published => false)
476 476  
477 477 get :index, :profile => profile.identifier
478   - assert_tag :tag => 'a', :content => '2 posts', :attributes => { :href => /\/testuser\/blog/ }
  478 + assert_tag :tag => 'a', :content => '2 posts', :attributes => { :href => /\/testuser\/#{blog.slug}/ }
479 479 end
480 480  
481 481 should 'show number of published images in index' do
... ... @@ -1179,7 +1179,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1179 1179 20.times {comment = fast_create(Comment, :source_id => article, :title => 'a comment', :body => 'lalala', :created_at => Time.now)}
1180 1180 article.reload
1181 1181 assert_equal 20, article.comments.count
1182   - get :more_comments, :activity => activity.id, :comment_page => 2
  1182 + xhr :get, :more_comments, :activity => activity.id, :comment_page => 2
1183 1183 assert_response :success
1184 1184 assert_template '_comment'
1185 1185 assert_select_rjs :insert_html do
... ... @@ -1204,7 +1204,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1204 1204 20.times {fast_create(Scrap, :sender_id => profile.id, :receiver_id => profile.id, :scrap_id => scrap.id)}
1205 1205 profile.reload
1206 1206 assert_equal 20, scrap.replies.count
1207   - get :more_replies, :activity => scrap.id, :comment_page => 2
  1207 + xhr :get, :more_replies, :activity => scrap.id, :comment_page => 2
1208 1208 assert_response :success
1209 1209 assert_template '_profile_scrap'
1210 1210 assert_select_rjs :insert_html do
... ... @@ -1386,7 +1386,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1386 1386 activity = ActionTracker::Record.last
1387 1387  
1388 1388 login_as(profile.identifier)
1389   - get :more_comments, :profile => profile.identifier, :activity => activity.id, :comment_page => 1, :tab_action => 'wall'
  1389 + xhr :get, :more_comments, :profile => profile.identifier, :activity => activity.id, :comment_page => 1, :tab_action => 'wall'
1390 1390  
1391 1391 assert_select_rjs :insert_html do
1392 1392 assert_select 'span', :content => '(removed user)', :attributes => {:class => 'comment-user-status comment-user-status-wall icon-user-removed'}
... ... @@ -1415,7 +1415,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1415 1415 activity = ActionTracker::Record.last
1416 1416  
1417 1417 login_as(profile.identifier)
1418   - get :more_comments, :profile => profile.identifier, :activity => activity.id, :comment_page => 1, :tab_action => 'wall'
  1418 + xhr :get, :more_comments, :profile => profile.identifier, :activity => activity.id, :comment_page => 1, :tab_action => 'wall'
1419 1419  
1420 1420 assert_select_rjs :insert_html do
1421 1421 assert_select 'span', :content => '(unauthenticated user)', :attributes => {:class => 'comment-user-status comment-user-status-wall icon-user-unknown'}
... ... @@ -1671,7 +1671,8 @@ class ProfileControllerTest &lt; ActionController::TestCase
1671 1671 get :index
1672 1672  
1673 1673 assert_tag :tag => 'div', :attributes => {:id => 'manage-communities'}
1674   - assert_select '#manage-communities li > a' do |links|
  1674 + doc = Nokogiri::HTML @response.body
  1675 + assert_select doc, '#manage-communities li > a' do |links|
1675 1676 assert_equal 2, links.length
1676 1677 assert_match /community_1/, links.to_s
1677 1678 assert_match /community_2/, links.to_s
... ... @@ -1699,7 +1700,8 @@ class ProfileControllerTest &lt; ActionController::TestCase
1699 1700 get :index
1700 1701  
1701 1702 assert_tag :tag => 'div', :attributes => {:id => 'manage-enterprises'}
1702   - assert_select '#manage-enterprises li > a' do |links|
  1703 + doc = Nokogiri::HTML @response.body
  1704 + assert_select doc, '#manage-enterprises li > a' do |links|
1703 1705 assert_equal 1, links.length
1704 1706 assert_match /Test enterprise1/, links.to_s
1705 1707 assert_no_match /Test enterprise_2/, links.to_s
... ...