Commit f3ac17d4c094d4f04032915a7f2da1b9ee339d0e

Authored by Braulio Bhavamitra
1 parent a3bfec81

rails4: fix broken tests after merge

app/controllers/application_controller.rb
@@ -65,8 +65,6 @@ class ApplicationController < ActionController::Base @@ -65,8 +65,6 @@ class ApplicationController < ActionController::Base
65 helper :language 65 helper :language
66 66
67 include DesignHelper 67 include DesignHelper
68 -  
69 - # Be sure to include AuthenticationSystem in Application Controller instead  
70 include AuthenticatedSystem 68 include AuthenticatedSystem
71 include PermissionCheck 69 include PermissionCheck
72 70
app/helpers/action_tracker_helper.rb
@@ -67,19 +67,19 @@ module ActionTrackerHelper @@ -67,19 +67,19 @@ module ActionTrackerHelper
67 } 67 }
68 end 68 end
69 69
70 - def create_product_description 70 + def create_product_description ta
71 _('created the product %{title}') % { 71 _('created the product %{title}') % {
72 title: link_to(truncate(ta.get_name), ta.get_url), 72 title: link_to(truncate(ta.get_name), ta.get_url),
73 } 73 }
74 end 74 end
75 75
76 - def update_product_description 76 + def update_product_description ta
77 _('updated the product %{title}') % { 77 _('updated the product %{title}') % {
78 title: link_to(truncate(ta.get_name), ta.get_url), 78 title: link_to(truncate(ta.get_name), ta.get_url),
79 } 79 }
80 end 80 end
81 81
82 - def remove_product_description 82 + def remove_product_description ta
83 _('removed the product %{title}') % { 83 _('removed the product %{title}') % {
84 title: truncate(ta.get_name), 84 title: truncate(ta.get_name),
85 } 85 }
app/mailers/application_mailer.rb
  1 +require_relative '../helpers/application_helper'
  2 +
1 class ApplicationMailer < ActionMailer::Base 3 class ApplicationMailer < ActionMailer::Base
2 4
  5 + include AuthenticatedSystem
  6 +
  7 + helper ApplicationHelper
  8 +
3 attr_accessor :environment 9 attr_accessor :environment
4 10
5 def default_url_options options = nil 11 def default_url_options options = nil
app/models/person_notifier.rb
@@ -77,9 +77,8 @@ class PersonNotifier @@ -77,9 +77,8 @@ class PersonNotifier
77 77
78 end 78 end
79 79
80 - class Mailer < ActionMailer::Base 80 + class Mailer < ApplicationMailer
81 81
82 - helper ApplicationHelper  
83 helper ActionTrackerHelper 82 helper ActionTrackerHelper
84 83
85 def session 84 def session
@@ -88,8 +87,8 @@ class PersonNotifier @@ -88,8 +87,8 @@ class PersonNotifier
88 87
89 def content_summary(person, notifications, tasks) 88 def content_summary(person, notifications, tasks)
90 if person.environment 89 if person.environment
91 - ActionMailer::Base.asset_host = person.environment.top_url  
92 - ActionMailer::Base.default_url_options[:host] = person.environment.default_hostname 90 + ApplicationMailer.asset_host = person.environment.top_url
  91 + ApplicationMailer.default_url_options[:host] = person.environment.default_hostname
93 end 92 end
94 93
95 @current_theme = 'default' 94 @current_theme = 'default'
app/models/profile_list_block.rb
@@ -16,7 +16,7 @@ class ProfileListBlock &lt; Block @@ -16,7 +16,7 @@ class ProfileListBlock &lt; Block
16 16
17 def profile_list 17 def profile_list
18 result = nil 18 result = nil
19 - public_profiles = profiles.public.includes([:image,:domains,:preferred_domain,:environment]) 19 + public_profiles = profiles.is_public.includes([:image,:domains,:preferred_domain,:environment])
20 if !prioritize_profiles_with_image 20 if !prioritize_profiles_with_image
21 result = public_profiles.all(:limit => get_limit, :order => 'profiles.updated_at DESC').sort_by{ rand } 21 result = public_profiles.all(:limit => get_limit, :order => 'profiles.updated_at DESC').sort_by{ rand }
22 elsif profiles.visible.with_image.count >= get_limit 22 elsif profiles.visible.with_image.count >= get_limit
@@ -28,7 +28,7 @@ result = public_profiles.all(:limit =&gt; get_limit, :order =&gt; &#39;profiles.updated_at @@ -28,7 +28,7 @@ result = public_profiles.all(:limit =&gt; get_limit, :order =&gt; &#39;profiles.updated_at
28 end 28 end
29 29
30 def profile_count 30 def profile_count
31 - profiles.public.length 31 + profiles.is_public.length
32 end 32 end
33 33
34 # the title of the block. Probably will be overriden in subclasses. 34 # the title of the block. Probably will be overriden in subclasses.
app/views/person_notifier/mailer/_create_product.html.erb 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +../../profile/_create_product.html.erb
0 \ No newline at end of file 2 \ No newline at end of file
app/views/person_notifier/mailer/_favorite_enterprise.html.erb 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +../../profile/_favorite_enterprise.html.erb
0 \ No newline at end of file 2 \ No newline at end of file
app/views/person_notifier/mailer/_remove_product.html.erb 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +../../profile/_remove_product.html.erb
0 \ No newline at end of file 2 \ No newline at end of file
app/views/person_notifier/mailer/_update_product.html.erb 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +../../profile/_update_product.html.erb
0 \ No newline at end of file 2 \ No newline at end of file
app/views/profile/_create_product.html.erb
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 </div> 3 </div>
4 <div class='profile-activity-description'> 4 <div class='profile-activity-description'>
5 <p class='profile-activity-text'><%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %></p> 5 <p class='profile-activity-text'><%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %></p>
6 - <p class='profile-activity-time'><%= time_ago_as_sentence activity.created_at %></p> 6 + <p class='profile-activity-time'><%= time_ago_in_words activity.created_at %></p>
7 7
8 <div class='profile-wall-actions'> 8 <div class='profile-wall-actions'>
9 <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> 9 <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %>
app/views/profile/_favorite_enterprise.html.erb
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 <p class='profile-activity-text'> 5 <p class='profile-activity-text'>
6 <%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %> 6 <%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %>
7 </p> 7 </p>
8 - <p class='profile-activity-time'><%= time_ago_as_sentence activity.created_at %></p> 8 + <p class='profile-activity-time'><%= time_ago_in_words activity.created_at %></p>
9 9
10 <div class='profile-wall-actions'> 10 <div class='profile-wall-actions'>
11 <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> 11 <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %>
app/views/profile/_remove_product.html.erb
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 </div> 2 </div>
3 <div class='profile-activity-description'> 3 <div class='profile-activity-description'>
4 <p class='profile-activity-text'><%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %></p> 4 <p class='profile-activity-text'><%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %></p>
5 - <p class='profile-activity-time'><%= time_ago_as_sentence activity.created_at %></p> 5 + <p class='profile-activity-time'><%= time_ago_in_words activity.created_at %></p>
6 6
7 <div class='profile-wall-actions'> 7 <div class='profile-wall-actions'>
8 <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> 8 <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %>
app/views/profile/_update_product.html.erb
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 </div> 3 </div>
4 <div class='profile-activity-description'> 4 <div class='profile-activity-description'>
5 <p class='profile-activity-text'><%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %></p> 5 <p class='profile-activity-text'><%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %></p>
6 - <p class='profile-activity-time'><%= time_ago_as_sentence activity.created_at %></p> 6 + <p class='profile-activity-time'><%= time_ago_in_words activity.created_at %></p>
7 7
8 <div class='profile-wall-actions'> 8 <div class='profile-wall-actions'>
9 <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> 9 <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %>
config/application.rb
@@ -22,11 +22,10 @@ module Noosfero @@ -22,11 +22,10 @@ module Noosfero
22 # -- all .rb files in that directory are automatically loaded. 22 # -- all .rb files in that directory are automatically loaded.
23 23
24 # Custom directories with classes and modules you want to be autoloadable. 24 # Custom directories with classes and modules you want to be autoloadable.
25 - config.autoload_paths += %W( #{Rails.root.join('app', 'sweepers')} ) 25 + config.autoload_paths += %W( #{config.root.join('app', 'sweepers')} )
26 config.autoload_paths += Dir["#{config.root}/lib"] 26 config.autoload_paths += Dir["#{config.root}/lib"]
27 config.autoload_paths += Dir["#{config.root}/app/controllers/**/"] 27 config.autoload_paths += Dir["#{config.root}/app/controllers/**/"]
28 - config.autoload_paths += %W( #{Rails.root.join('test', 'mocks', Rails.env)} )  
29 - 28 + config.autoload_paths += %W( #{config.root.join('test', 'mocks', Rails.env)} )
30 29
31 # Only load the plugins named here, in the order given (default is alphabetical). 30 # Only load the plugins named here, in the order given (default is alphabetical).
32 # :all can be used as a placeholder for all plugins not explicitly named. 31 # :all can be used as a placeholder for all plugins not explicitly named.
lib/authenticated_system.rb
@@ -3,7 +3,7 @@ module AuthenticatedSystem @@ -3,7 +3,7 @@ module AuthenticatedSystem
3 protected 3 protected
4 4
5 # See impl. from http://stackoverflow.com/a/2513456/670229 5 # See impl. from http://stackoverflow.com/a/2513456/670229
6 - def self.included? base 6 + def self.included base
7 base.around_filter do 7 base.around_filter do
8 begin 8 begin
9 User.current = current_user 9 User.current = current_user
@@ -12,7 +12,11 @@ module AuthenticatedSystem @@ -12,7 +12,11 @@ module AuthenticatedSystem
12 # to address the thread variable leak issues in Puma/Thin webserver 12 # to address the thread variable leak issues in Puma/Thin webserver
13 User.current = nil 13 User.current = nil
14 end 14 end
15 - end 15 + end if base.is_a? ActionController::Base
  16 +
  17 + # Inclusion hook to make #current_user and #logged_in?
  18 + # available as ActionView helper methods.
  19 + base.send :helper_method, :current_user, :logged_in?
16 end 20 end
17 21
18 # Returns true or false if the user is logged in. 22 # Returns true or false if the user is logged in.
@@ -134,12 +138,6 @@ module AuthenticatedSystem @@ -134,12 +138,6 @@ module AuthenticatedSystem
134 end 138 end
135 end 139 end
136 140
137 - # Inclusion hook to make #current_user and #logged_in?  
138 - # available as ActionView helper methods.  
139 - def self.included(base)  
140 - base.send :helper_method, :current_user, :logged_in?  
141 - end  
142 -  
143 # When called with before_filter :login_from_cookie will check for an :auth_token 141 # When called with before_filter :login_from_cookie will check for an :auth_token
144 # cookie and log the user back in if apropriate 142 # cookie and log the user back in if apropriate
145 def login_from_cookie 143 def login_from_cookie
lib/noosfero/plugin.rb
@@ -713,5 +713,4 @@ end @@ -713,5 +713,4 @@ end
713 713
714 require 'noosfero/plugin/hot_spot' 714 require 'noosfero/plugin/hot_spot'
715 require 'noosfero/plugin/manager' 715 require 'noosfero/plugin/manager'
716 -require 'noosfero/plugin/mailer_base'  
717 require 'noosfero/plugin/settings' 716 require 'noosfero/plugin/settings'
test/functional/profile_controller_test.rb
@@ -1132,7 +1132,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1132,7 +1132,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1132 ActionTracker::Record.destroy_all 1132 ActionTracker::Record.destroy_all
1133 40.times{ create(ActionTracker::Record, :user_id => profile.id, :user_type => 'Profile', :verb => 'create_article', :target_id => article.id, :target_type => 'Article', :params => {'name' => article.name, 'url' => article.url, 'lead' => article.lead, 'first_image' => article.first_image})} 1133 40.times{ create(ActionTracker::Record, :user_id => profile.id, :user_type => 'Profile', :verb => 'create_article', :target_id => article.id, :target_type => 'Article', :params => {'name' => article.name, 'url' => article.url, 'lead' => article.lead, 'first_image' => article.first_image})}
1134 assert_equal 40, profile.tracked_actions.count 1134 assert_equal 40, profile.tracked_actions.count
1135 - assert_equal 40, profile.activities.count 1135 + assert_equal 40, profile.activities.size
1136 get :view_more_activities, :profile => profile.identifier, :page => 2 1136 get :view_more_activities, :profile => profile.identifier, :page => 2
1137 assert_response :success 1137 assert_response :success
1138 assert_template '_profile_activities_list' 1138 assert_template '_profile_activities_list'
test/unit/person_notifier_test.rb
@@ -163,6 +163,21 @@ class PersonNotifierTest &lt; ActiveSupport::TestCase @@ -163,6 +163,21 @@ class PersonNotifierTest &lt; ActiveSupport::TestCase
163 end 163 end
164 end 164 end
165 165
  166 + Targets = {
  167 + create_article: -> { create Forum, profile: @profile },
  168 + new_friendship: -> { create Friendship, person: @member, friend: @member },
  169 + join_community: -> { @member },
  170 + add_member_in_community: -> { create_user.person },
  171 + upload_image: -> { create Forum, profile: @profile },
  172 + leave_scrap: -> { create Scrap, sender: @member, receiver: @profile },
  173 + leave_scrap_to_self: -> { create Scrap, sender: @member, receiver: @profile },
  174 + reply_scrap_on_self: -> { create Scrap, sender: @member, receiver: @profile },
  175 + create_product: -> { create Product, profile: @profile, product_category: create(ProductCategory, environment: Environment.default) },
  176 + update_product: -> { create Product, profile: @profile, product_category: create(ProductCategory, environment: Environment.default) },
  177 + remove_product: -> { create Product, profile: @profile, product_category: create(ProductCategory, environment: Environment.default) },
  178 + favorite_enterprise: -> { create FavoriteEnterprisePerson, enterprise: create(Enterprise), person: @member },
  179 + }
  180 +
166 ActionTrackerConfig.verb_names.each do |verb| 181 ActionTrackerConfig.verb_names.each do |verb|
167 should "render notification for verb #{verb}" do 182 should "render notification for verb #{verb}" do
168 @member.tracked_notifications = [] 183 @member.tracked_notifications = []
@@ -171,14 +186,15 @@ class PersonNotifierTest &lt; ActiveSupport::TestCase @@ -171,14 +186,15 @@ class PersonNotifierTest &lt; ActiveSupport::TestCase
171 a.verb = verb 186 a.verb = verb
172 a.user = @member 187 a.user = @member
173 a.created_at = @member.notifier.notify_from + 1.day 188 a.created_at = @member.notifier.notify_from + 1.day
174 - profile = create(Community)  
175 - a.target = create(Forum, profile: profile) 189 + @profile = create(Community)
  190 + a.target = instance_exec &Targets[verb.to_sym]
176 a.comments_count = 0 191 a.comments_count = 0
177 a.params = { 192 a.params = {
178 'name' => 'home', 'url' => '/', 'lead' => '', 193 'name' => 'home', 'url' => '/', 'lead' => '',
179 'receiver_url' => '/', 'content' => 'nothing', 194 'receiver_url' => '/', 'content' => 'nothing',
180 'friend_url' => '/', 'friend_profile_custom_icon' => [], 'friend_name' => ['joe'], 195 'friend_url' => '/', 'friend_profile_custom_icon' => [], 'friend_name' => ['joe'],
181 'resource_name' => ['resource'], 'resource_profile_custom_icon' => [], 'resource_url' => ['/'], 196 'resource_name' => ['resource'], 'resource_profile_custom_icon' => [], 'resource_url' => ['/'],
  197 + 'enterprise_name' => 'coop', 'enterprise_url' => '/coop',
182 'view_url'=> ['/'], 'thumbnail_path' => ['1'], 198 'view_url'=> ['/'], 'thumbnail_path' => ['1'],
183 } 199 }
184 a.get_url = '' 200 a.get_url = ''