Commit 9d491b79e95aa5585ab9b0d6bf5dddb4e838a6b7

Authored by Victor Costa
2 parents 63fa33ce 32f88e65

Merge branch 'master' into rails3

app/controllers/my_profile/cms_controller.rb
@@ -248,12 +248,15 @@ class CmsController < MyProfileController @@ -248,12 +248,15 @@ class CmsController < MyProfileController
248 end.compact unless params[:marked_groups].nil? 248 end.compact unless params[:marked_groups].nil?
249 if request.post? 249 if request.post?
250 @failed = {} 250 @failed = {}
  251 + if @marked_groups.empty?
  252 + return session[:notice] = _("Select some group to publish your article")
  253 + end
251 @marked_groups.each do |item| 254 @marked_groups.each do |item|
252 task = ApproveArticle.create!(:article => @article, :name => item[:name], :target => item[:group], :requestor => profile) 255 task = ApproveArticle.create!(:article => @article, :name => item[:name], :target => item[:group], :requestor => profile)
253 begin 256 begin
254 task.finish unless item[:group].moderated_articles? 257 task.finish unless item[:group].moderated_articles?
255 rescue Exception => ex 258 rescue Exception => ex
256 - @failed[ex.message] ? @failed[ex.message] << item[:group].name : @failed[ex.message] = [item[:group].name] 259 + @failed[ex.message] ? @failed[ex.message] << item[:group].name : @failed[ex.message] = [item[:group].name]
257 end 260 end
258 end 261 end
259 if @failed.blank? 262 if @failed.blank?
app/controllers/my_profile/friends_controller.rb
@@ -11,7 +11,7 @@ class FriendsController &lt; MyProfileController @@ -11,7 +11,7 @@ class FriendsController &lt; MyProfileController
11 def remove 11 def remove
12 @friend = profile.friends.find(params[:id]) 12 @friend = profile.friends.find(params[:id])
13 if request.post? && params[:confirmation] 13 if request.post? && params[:confirmation]
14 - profile.remove_friend(@friend) 14 + Friendship.remove_friendship(profile, @friend)
15 redirect_to :action => 'index' 15 redirect_to :action => 'index'
16 end 16 end
17 end 17 end
app/models/friendship.rb
@@ -15,4 +15,9 @@ class Friendship &lt; ActiveRecord::Base @@ -15,4 +15,9 @@ class Friendship &lt; ActiveRecord::Base
15 Friendship.update_cache_counter(:friends_count, friendship.person, -1) 15 Friendship.update_cache_counter(:friends_count, friendship.person, -1)
16 Friendship.update_cache_counter(:friends_count, friendship.friend, -1) 16 Friendship.update_cache_counter(:friends_count, friendship.friend, -1)
17 end 17 end
  18 +
  19 + def self.remove_friendship(person1, person2)
  20 + person1.remove_friend(person2)
  21 + person2.remove_friend(person1)
  22 + end
18 end 23 end
app/models/slideshow_block.rb
@@ -6,6 +6,8 @@ class SlideshowBlock &lt; Block @@ -6,6 +6,8 @@ class SlideshowBlock &lt; Block
6 settings_items :navigation, :type => 'boolean', :default => false 6 settings_items :navigation, :type => 'boolean', :default => false
7 settings_items :image_size, :type => 'string', :default => 'thumb' 7 settings_items :image_size, :type => 'string', :default => 'thumb'
8 8
  9 + attr_accessible :gallery_id, :image_size, :interval, :shuffle, :navigation
  10 +
9 def self.description 11 def self.description
10 _('Slideshow') 12 _('Slideshow')
11 end 13 end
app/views/cms/view.html.erb
@@ -25,7 +25,9 @@ @@ -25,7 +25,9 @@
25 <div id='article-full-path'> 25 <div id='article-full-path'>
26 <strong><%= _('Current folder: ') %></strong> 26 <strong><%= _('Current folder: ') %></strong>
27 <%= link_to profile.identifier, :action => 'index' %> 27 <%= link_to profile.identifier, :action => 'index' %>
28 - <%= @article.hierarchy.map {|item| " / " + ((item == @article) ? item.name : link_to(item.slug, :id => item.id)) } %> 28 + <% @article.hierarchy.each do |item| %>
  29 + <%= " / " + ((item == @article) ? item.name.html_safe : link_to(item.slug, :id => item.id).html_safe) %>
  30 + <% end %>
29 </div> 31 </div>
30 <% end %> 32 <% end %>
31 33
lib/tasks/plugins_tests.rake
1 @all_plugins = Dir.glob('plugins/*').map { |f| File.basename(f) } - ['template'] 1 @all_plugins = Dir.glob('plugins/*').map { |f| File.basename(f) } - ['template']
  2 +@all_plugins.sort!
2 @all_tasks = [:units, :functionals, :integration, :cucumber, :selenium] 3 @all_tasks = [:units, :functionals, :integration, :cucumber, :selenium]
3 4
4 def enabled_plugins 5 def enabled_plugins
@@ -110,7 +111,7 @@ def run_cucumber(profile, files) @@ -110,7 +111,7 @@ def run_cucumber(profile, files)
110 sh 'xvfb-run', 'ruby', '-S', 'cucumber', '--profile', profile.to_s, '--format', ENV['CUCUMBER_FORMAT'] || 'progress' , *files 111 sh 'xvfb-run', 'ruby', '-S', 'cucumber', '--profile', profile.to_s, '--format', ENV['CUCUMBER_FORMAT'] || 'progress' , *files
111 end 112 end
112 113
113 -def custom_run(name, files, run=:individually) 114 +def custom_run(name, files, run=:all)
114 case run 115 case run
115 when :all 116 when :all
116 run_test name, files 117 run_test name, files
@@ -122,7 +123,7 @@ def custom_run(name, files, run=:individually) @@ -122,7 +123,7 @@ def custom_run(name, files, run=:individually)
122 end 123 end
123 end 124 end
124 125
125 -def run_tests(name, plugins, run=:individually) 126 +def run_tests(name, plugins, run=:all)
126 plugins = Array(plugins) 127 plugins = Array(plugins)
127 glob = "plugins/{#{plugins.join(',')}}/test/#{task2folder(name)}/**/*.#{task2ext(name)}" 128 glob = "plugins/{#{plugins.join(',')}}/test/#{task2folder(name)}/**/*.#{task2ext(name)}"
128 files = Dir.glob(glob) 129 files = Dir.glob(glob)
@@ -169,7 +170,7 @@ def test_sequence(plugins, tasks) @@ -169,7 +170,7 @@ def test_sequence(plugins, tasks)
169 fail 'There are broken tests to be fixed!' if fail_flag 170 fail 'There are broken tests to be fixed!' if fail_flag
170 end 171 end
171 172
172 -def plugin_test_task(plugin, task, run=:individually) 173 +def plugin_test_task(plugin, task, run=:all)
173 desc "Run #{task} tests for #{plugin_name(plugin)}" 174 desc "Run #{task} tests for #{plugin_name(plugin)}"
174 task task do 175 task task do
175 test_sequence(plugin, task) 176 test_sequence(plugin, task)
test/functional/cms_controller_test.rb
@@ -1791,6 +1791,14 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1791,6 +1791,14 @@ class CmsControllerTest &lt; ActionController::TestCase
1791 assert_equal other_person, a.created_by 1791 assert_equal other_person, a.created_by
1792 end 1792 end
1793 1793
  1794 + should 'continue on the same page, when no group is selected' do
  1795 + c = Community.create!(:name => 'test comm', :identifier => 'test_comm')
  1796 + c.affiliate(profile, Profile::Roles.all_roles(c.environment.id))
  1797 + article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails')
  1798 + post :publish, :profile => profile.identifier, :id => article.id, :marked_groups => {c.id.to_s => {}}
  1799 + assert_template 'cms/publish'
  1800 + end
  1801 +
1794 protected 1802 protected
1795 1803
1796 # FIXME this is to avoid adding an extra dependency for a proper JSON parser. 1804 # FIXME this is to avoid adding an extra dependency for a proper JSON parser.
test/functional/friends_controller_test.rb
@@ -36,12 +36,12 @@ class FriendsControllerTest &lt; ActionController::TestCase @@ -36,12 +36,12 @@ class FriendsControllerTest &lt; ActionController::TestCase
36 36
37 should 'actually remove friend' do 37 should 'actually remove friend' do
38 profile.add_friend(friend) 38 profile.add_friend(friend)
  39 + friend.add_friend(profile)
39 40
40 - assert_difference 'Friendship.count', -1 do 41 + assert_difference 'Friendship.count', -2 do
41 post :remove, :id => friend.id, :confirmation => '1' 42 post :remove, :id => friend.id, :confirmation => '1'
42 assert_redirected_to :action => 'index' 43 assert_redirected_to :action => 'index'
43 end 44 end
44 - assert_equal friend, Profile.find(friend.id)  
45 end 45 end
46 46
47 should 'display find people button' do 47 should 'display find people button' do
test/integration/manage_friendships_test.rb 0 → 100644
@@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
  1 +require "#{File.dirname(__FILE__)}/../test_helper"
  2 +
  3 +class ManageFriendshipsTest < ActionController::IntegrationTest
  4 +
  5 + def setup
  6 + FriendsController.any_instance.stubs(:get_layout).returns('application')
  7 + ProfileController.any_instance.stubs(:get_layout).returns('application')
  8 +
  9 + Friendship.delete_all
  10 + Person.delete_all
  11 + @person = create_user("albert", :password => 'test',
  12 + :password_confirmation => 'test').person
  13 + @person.user.activate
  14 +
  15 + @friend = fast_create(Person, :identifier => "isaac")
  16 +
  17 + login(@person.identifier, 'test')
  18 + end
  19 +
  20 + should 'remove friendships' do
  21 + @person.add_friend(@friend)
  22 + @friend.add_friend(@person)
  23 +
  24 + get "/myprofile/#{@person.identifier}/friends/remove/#{@friend.id}"
  25 + assert_response :success
  26 +
  27 + post "/myprofile/#{@person.identifier}/friends/remove/#{@friend.id}",
  28 + :confirmation => '1'
  29 + assert_response :redirect
  30 +
  31 + follow_redirect!
  32 +
  33 + assert assigns(:friends).empty?
  34 + assert !@person.is_a_friend?(@friend)
  35 + assert !@friend.is_a_friend?(@person)
  36 + end
  37 +end
test/test_helper.rb
@@ -277,16 +277,4 @@ class ActionController::IntegrationTest @@ -277,16 +277,4 @@ class ActionController::IntegrationTest
277 277
278 end 278 end
279 279
280 -def with_constants(constants, &block)  
281 - old_constants = Hash.new  
282 - constants.each do |constant, val|  
283 - old_constants[constant] = Object.const_get(constant)  
284 - silence_stderr{ Object.const_set(constant, val) }  
285 - end  
286 - block.call  
287 - old_constants.each do |constant, val|  
288 - silence_stderr{ Object.const_set(constant, val) }  
289 - end  
290 -end  
291 -  
292 Profile 280 Profile
test/unit/application_helper_test.rb
@@ -472,13 +472,13 @@ class ApplicationHelperTest &lt; ActionView::TestCase @@ -472,13 +472,13 @@ class ApplicationHelperTest &lt; ActionView::TestCase
472 profile = mock 472 profile = mock
473 profile.stubs(:theme).returns('some-theme') 473 profile.stubs(:theme).returns('some-theme')
474 stubs(:profile).returns(profile) 474 stubs(:profile).returns(profile)
475 - with_constants :NOOSFERO_CONF => {'gravatar' => 'crazyvatar'} do  
476 - assert_equal gravatar_default, 'crazyvatar'  
477 - end 475 +
  476 + NOOSFERO_CONF.stubs(:[]).with('gravatar').returns('crazyvatar')
  477 + assert_equal gravatar_default, 'crazyvatar'
  478 +
478 stubs(:theme_option).returns('gravatar' => 'nicevatar') 479 stubs(:theme_option).returns('gravatar' => 'nicevatar')
479 - with_constants :NOOSFERO_CONF => {'gravatar' => 'crazyvatar'} do  
480 - assert_equal gravatar_default, 'nicevatar'  
481 - end 480 + NOOSFERO_CONF.stubs(:[]).with('gravatar').returns('nicevatar')
  481 + assert_equal gravatar_default, 'nicevatar'
482 end 482 end
483 483
484 should 'use theme passed via param when in development mode' do 484 should 'use theme passed via param when in development mode' do
test/unit/friendship_test.rb
@@ -58,4 +58,18 @@ class FriendshipTest &lt; ActiveSupport::TestCase @@ -58,4 +58,18 @@ class FriendshipTest &lt; ActiveSupport::TestCase
58 assert_equal ['a'], ta.get_friend_name 58 assert_equal ['a'], ta.get_friend_name
59 end 59 end
60 60
  61 + should 'remove friendships when a friend removal occurs' do
  62 + p1 = create_user('testuser1').person
  63 + p2 = create_user('testuser2').person
  64 + p1.add_friend(p2, 'friends')
  65 + p2.add_friend(p1, 'friends')
  66 +
  67 + assert_difference 'Friendship.count', -2 do
  68 + Friendship.remove_friendship(p1, p2)
  69 + end
  70 +
  71 + assert_not_includes p1.friends(true), p2
  72 + assert_not_includes p2.friends(true), p1
  73 + end
  74 +
61 end 75 end
test/unit/google_maps_test.rb
@@ -3,13 +3,12 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39; @@ -3,13 +3,12 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
3 class GoogleMapsTest < ActiveSupport::TestCase 3 class GoogleMapsTest < ActiveSupport::TestCase
4 4
5 should 'provide initial_zoom setting' do 5 should 'provide initial_zoom setting' do
6 - with_constants :NOOSFERO_CONF => {'googlemaps_initial_zoom' => 2} do  
7 - assert_equal 2, GoogleMaps.initial_zoom  
8 - end 6 + NOOSFERO_CONF.stubs(:[]).with('googlemaps_initial_zoom').returns(2)
  7 + assert_equal 2, GoogleMaps.initial_zoom
9 end 8 end
10 9
11 should 'use 4 as default initial_zoom' do 10 should 'use 4 as default initial_zoom' do
12 - GoogleMaps.stubs(:config).returns({}) 11 + NOOSFERO_CONF.stubs(:[]).with('googlemaps_initial_zoom').returns(nil)
13 assert_equal 4, GoogleMaps.initial_zoom 12 assert_equal 4, GoogleMaps.initial_zoom
14 end 13 end
15 14
test/unit/mail_conf_test.rb
@@ -3,22 +3,22 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39; @@ -3,22 +3,22 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
3 class MailConfTest < ActiveSupport::TestCase 3 class MailConfTest < ActiveSupport::TestCase
4 4
5 should 'enable if told to' do 5 should 'enable if told to' do
6 - NOOSFERO_CONF['mail_enabled'] = true 6 + NOOSFERO_CONF.stubs(:[]).with('mail_enabled').returns(true)
7 assert_equal true, MailConf.enabled? 7 assert_equal true, MailConf.enabled?
8 end 8 end
9 9
10 should 'disable if told to' do 10 should 'disable if told to' do
11 - NOOSFERO_CONF['mail_enabled'] = false 11 + NOOSFERO_CONF.stubs(:[]).with('mail_enabled').returns(false)
12 assert_equal false, MailConf.enabled? 12 assert_equal false, MailConf.enabled?
13 end 13 end
14 14
15 should 'disable by default' do 15 should 'disable by default' do
16 - NOOSFERO_CONF['mail_enabled'] = nil 16 + NOOSFERO_CONF.stubs(:[]).with('mail_enabled').returns(nil)
17 assert_equal false, MailConf.enabled? 17 assert_equal false, MailConf.enabled?
18 end 18 end
19 19
20 should 'provide webmail url preference' do 20 should 'provide webmail url preference' do
21 - NOOSFERO_CONF['webmail_url'] = 'http://some.url/webmail/%s/%s' 21 + NOOSFERO_CONF.stubs(:[]).with('webmail_url').returns('http://some.url/webmail/%s/%s')
22 assert_equal 'http://some.url/webmail/login/example.com', MailConf.webmail_url('login', 'example.com') 22 assert_equal 'http://some.url/webmail/login/example.com', MailConf.webmail_url('login', 'example.com')
23 end 23 end
24 24