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 248 end.compact unless params[:marked_groups].nil?
249 249 if request.post?
250 250 @failed = {}
  251 + if @marked_groups.empty?
  252 + return session[:notice] = _("Select some group to publish your article")
  253 + end
251 254 @marked_groups.each do |item|
252 255 task = ApproveArticle.create!(:article => @article, :name => item[:name], :target => item[:group], :requestor => profile)
253 256 begin
254 257 task.finish unless item[:group].moderated_articles?
255 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 260 end
258 261 end
259 262 if @failed.blank?
... ...
app/controllers/my_profile/friends_controller.rb
... ... @@ -11,7 +11,7 @@ class FriendsController &lt; MyProfileController
11 11 def remove
12 12 @friend = profile.friends.find(params[:id])
13 13 if request.post? && params[:confirmation]
14   - profile.remove_friend(@friend)
  14 + Friendship.remove_friendship(profile, @friend)
15 15 redirect_to :action => 'index'
16 16 end
17 17 end
... ...
app/models/friendship.rb
... ... @@ -15,4 +15,9 @@ class Friendship &lt; ActiveRecord::Base
15 15 Friendship.update_cache_counter(:friends_count, friendship.person, -1)
16 16 Friendship.update_cache_counter(:friends_count, friendship.friend, -1)
17 17 end
  18 +
  19 + def self.remove_friendship(person1, person2)
  20 + person1.remove_friend(person2)
  21 + person2.remove_friend(person1)
  22 + end
18 23 end
... ...
app/models/slideshow_block.rb
... ... @@ -6,6 +6,8 @@ class SlideshowBlock &lt; Block
6 6 settings_items :navigation, :type => 'boolean', :default => false
7 7 settings_items :image_size, :type => 'string', :default => 'thumb'
8 8  
  9 + attr_accessible :gallery_id, :image_size, :interval, :shuffle, :navigation
  10 +
9 11 def self.description
10 12 _('Slideshow')
11 13 end
... ...
app/views/cms/view.html.erb
... ... @@ -25,7 +25,9 @@
25 25 <div id='article-full-path'>
26 26 <strong><%= _('Current folder: ') %></strong>
27 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 31 </div>
30 32 <% end %>
31 33  
... ...
lib/tasks/plugins_tests.rake
1 1 @all_plugins = Dir.glob('plugins/*').map { |f| File.basename(f) } - ['template']
  2 +@all_plugins.sort!
2 3 @all_tasks = [:units, :functionals, :integration, :cucumber, :selenium]
3 4  
4 5 def enabled_plugins
... ... @@ -110,7 +111,7 @@ def run_cucumber(profile, files)
110 111 sh 'xvfb-run', 'ruby', '-S', 'cucumber', '--profile', profile.to_s, '--format', ENV['CUCUMBER_FORMAT'] || 'progress' , *files
111 112 end
112 113  
113   -def custom_run(name, files, run=:individually)
  114 +def custom_run(name, files, run=:all)
114 115 case run
115 116 when :all
116 117 run_test name, files
... ... @@ -122,7 +123,7 @@ def custom_run(name, files, run=:individually)
122 123 end
123 124 end
124 125  
125   -def run_tests(name, plugins, run=:individually)
  126 +def run_tests(name, plugins, run=:all)
126 127 plugins = Array(plugins)
127 128 glob = "plugins/{#{plugins.join(',')}}/test/#{task2folder(name)}/**/*.#{task2ext(name)}"
128 129 files = Dir.glob(glob)
... ... @@ -169,7 +170,7 @@ def test_sequence(plugins, tasks)
169 170 fail 'There are broken tests to be fixed!' if fail_flag
170 171 end
171 172  
172   -def plugin_test_task(plugin, task, run=:individually)
  173 +def plugin_test_task(plugin, task, run=:all)
173 174 desc "Run #{task} tests for #{plugin_name(plugin)}"
174 175 task task do
175 176 test_sequence(plugin, task)
... ...
test/functional/cms_controller_test.rb
... ... @@ -1791,6 +1791,14 @@ class CmsControllerTest &lt; ActionController::TestCase
1791 1791 assert_equal other_person, a.created_by
1792 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 1802 protected
1795 1803  
1796 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 36  
37 37 should 'actually remove friend' do
38 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 42 post :remove, :id => friend.id, :confirmation => '1'
42 43 assert_redirected_to :action => 'index'
43 44 end
44   - assert_equal friend, Profile.find(friend.id)
45 45 end
46 46  
47 47 should 'display find people button' do
... ...
test/integration/manage_friendships_test.rb 0 → 100644
... ... @@ -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 277  
278 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 280 Profile
... ...
test/unit/application_helper_test.rb
... ... @@ -472,13 +472,13 @@ class ApplicationHelperTest &lt; ActionView::TestCase
472 472 profile = mock
473 473 profile.stubs(:theme).returns('some-theme')
474 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 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 482 end
483 483  
484 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 58 assert_equal ['a'], ta.get_friend_name
59 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 75 end
... ...
test/unit/google_maps_test.rb
... ... @@ -3,13 +3,12 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
3 3 class GoogleMapsTest < ActiveSupport::TestCase
4 4  
5 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 8 end
10 9  
11 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 12 assert_equal 4, GoogleMaps.initial_zoom
14 13 end
15 14  
... ...
test/unit/mail_conf_test.rb
... ... @@ -3,22 +3,22 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
3 3 class MailConfTest < ActiveSupport::TestCase
4 4  
5 5 should 'enable if told to' do
6   - NOOSFERO_CONF['mail_enabled'] = true
  6 + NOOSFERO_CONF.stubs(:[]).with('mail_enabled').returns(true)
7 7 assert_equal true, MailConf.enabled?
8 8 end
9 9  
10 10 should 'disable if told to' do
11   - NOOSFERO_CONF['mail_enabled'] = false
  11 + NOOSFERO_CONF.stubs(:[]).with('mail_enabled').returns(false)
12 12 assert_equal false, MailConf.enabled?
13 13 end
14 14  
15 15 should 'disable by default' do
16   - NOOSFERO_CONF['mail_enabled'] = nil
  16 + NOOSFERO_CONF.stubs(:[]).with('mail_enabled').returns(nil)
17 17 assert_equal false, MailConf.enabled?
18 18 end
19 19  
20 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 22 assert_equal 'http://some.url/webmail/login/example.com', MailConf.webmail_url('login', 'example.com')
23 23 end
24 24  
... ...