Commit e562726f32be1cdaae882d947e44ab58018eb92d

Authored by Victor Costa
2 parents e70703a1 7fdbafc3

Merge branch 'rails3' into rails3_stable

Conflicts:
	Gemfile
Gemfile
... ... @@ -16,6 +16,7 @@ gem 'hpricot'
16 16 gem 'nokogiri'
17 17 gem 'rake', :require => false
18 18 gem 'grape', '0.2.1'
  19 +gem 'rest-client'
19 20  
20 21 # FIXME list here all actual dependencies (i.e. the ones in debian/control),
21 22 # with their GEM names (not the Debian package names)
... ...
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  
... ...
features/step_definitions/web_steps.rb
... ... @@ -27,13 +27,13 @@ end
27 27  
28 28 When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector|
29 29 with_scope(selector) do
30   - first(:button, button).click
  30 + click_button(button, :match => :prefer_exact)
31 31 end
32 32 end
33 33  
34 34 When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
35 35 with_scope(selector) do
36   - first(:link, link).click
  36 + click_link(link, :match => :prefer_exact)
37 37 end
38 38 end
39 39  
... ...
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)
... ...
public/javascripts/chat.js
... ... @@ -529,11 +529,27 @@ jQuery(function($) {
529 529 function create_conversation_tab(title, jid_id) {
530 530 if (! $('#' + Jabber.tab_prefix + jid_id).length > 0) {
531 531 // opening chat with selected online friend
532   - var tab = $tabs.tabs('add', '#' + Jabber.tab_prefix + jid_id, title);
  532 + var panel = $('<div id="'+Jabber.tab_prefix + jid_id+'"></div>').appendTo($tabs);
  533 + panel.append("<div class='conversation'><div class='history'></div><div class='input-div'><div class='icon-chat'></div><textarea class='input'></textarea></div></div>");
  534 +
  535 + //FIXME
  536 + //var notice = $starting_chat_notice.replace('%{name}', $(ui.tab).html());
  537 + //Jabber.show_notice(jid_id, notice);
  538 +
  539 + // define textarea name as '<TAB_ID>'
  540 + panel.find('textarea').attr('name', panel.id);
  541 +
  542 + if (Jabber.is_a_room(jid_id)) {
  543 + panel.append(Jabber.templates.occupant_list);
  544 + panel.find('.history').addClass('room');
  545 + }
  546 +
  547 + $tabs.find('.ui-tabs-nav').append( "<li><a href='"+('#' + Jabber.tab_prefix + jid_id)+"'><span class=\"unread-messages\" style=\"display:none\"></span>"+title+"</a></li>" );
  548 + $tabs.tabs('refresh');
  549 +
533 550 var jid = Jabber.jid_of(jid_id);
534 551 $("a[href='#" + Jabber.tab_prefix + jid_id + "']").addClass($('#' + jid_id).attr('class') || 'icon-chat');
535 552 $('#' + Jabber.tab_prefix + jid_id).find('textarea').attr('data-to', jid);
536   - $tabs.tabs('select', '#' + Jabber.tab_prefix + jid_id);
537 553 }
538 554 }
539 555  
... ... @@ -555,7 +571,7 @@ jQuery(function($) {
555 571 var $tabs = $('#chat-window #tabs').tabs({
556 572 tabTemplate: '<li class="tab"><a href="#{href}"><span class="unread-messages" style="display:none"></span>#{label}</a></li>',
557 573 panelTemplate: "<div class='conversation'><div class='history'></div><div class='input-div'><div class='icon-chat'></div><textarea class='input'></textarea></div></div>",
558   - add: function(event, ui) {
  574 + add: function(event, ui) { //FIXME DEPRECATED
559 575 var jid_id = ui.panel.id.replace(Jabber.tab_prefix, '');
560 576  
561 577 var notice = $starting_chat_notice.replace('%{name}', $(ui.tab).html());
... ... @@ -575,7 +591,7 @@ jQuery(function($) {
575 591 var jid_id = ui.panel.id.replace(Jabber.tab_prefix, '');
576 592 count_unread_messages(jid_id, true);
577 593 },
578   - remove: function(event, ui) {
  594 + remove: function(event, ui) { //FIXME DEPRECATED
579 595 var jid_id = ui.panel.id.replace(Jabber.tab_prefix, '');
580 596 if (Jabber.is_a_room(jid_id)) {
581 597 // exiting from a chat room
... ...
public/stylesheets/application.css
... ... @@ -2642,6 +2642,9 @@ div#activation_enterprise label, div#activation_enterprise input, div#activation
2642 2642 background: #B8CFE7;
2643 2643 padding: 0px 20px 5px 20px;
2644 2644 }
  2645 +#TB_window .login-box .button-bar {
  2646 + padding-top: 0;
  2647 +}
2645 2648 .login-box-content .button-bar .button {
2646 2649 position: relative;
2647 2650 }
... ...
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  
... ...
vendor/plugins/ruby_bosh/lib/ruby_bosh.rb
... ... @@ -4,7 +4,6 @@ require &#39;rexml/document&#39;
4 4 require 'base64'
5 5 require 'hpricot'
6 6 require 'timeout'
7   -require 'system_timer'
8 7  
9 8 class RubyBOSH
10 9 BOSH_XMLNS = 'http://jabber.org/protocol/httpbind'
... ... @@ -15,7 +14,7 @@ class RubyBOSH
15 14 CLIENT_XMLNS = 'jabber:client'
16 15  
17 16 class Error < StandardError; end
18   - class Timeout < RubyBOSH::Error; end
  17 + class TimeoutError < RubyBOSH::Error; end
19 18 class AuthFailed < RubyBOSH::Error; end
20 19 class ConnFailed < RubyBOSH::Error; end
21 20  
... ... @@ -134,12 +133,12 @@ class RubyBOSH
134 133 end
135 134  
136 135 def deliver(xml)
137   - SystemTimer.timeout(@timeout) do
  136 + Timeout::timeout(@timeout) do
138 137 send(xml)
139 138 recv(RestClient.post(@service_url, xml, @headers))
140 139 end
141 140 rescue ::Timeout::Error => e
142   - raise RubyBOSH::Timeout, e.message
  141 + raise RubyBOSH::TimeoutError, e.message
143 142 rescue Errno::ECONNREFUSED => e
144 143 raise RubyBOSH::ConnFailed, "could not connect to #{@host}\n#{e.message}"
145 144 rescue Exception => e
... ...