Commit de7aba86b443e86345347d89c135f1a2233be17c

Authored by Joenio Costa
1 parent 1c125da7

small fixes on chat

* removing one level of includes in apache conf
* be verbose about apache config update
* chat_message should not be created without "from" or "to"
* the database table indexes is "from_id / to_id" not "from / to"
app/models/chat_message.rb
@@ -3,4 +3,6 @@ class ChatMessage < ActiveRecord::Base @@ -3,4 +3,6 @@ class ChatMessage < ActiveRecord::Base
3 3
4 belongs_to :to, :class_name => 'Profile' 4 belongs_to :to, :class_name => 'Profile'
5 belongs_to :from, :class_name => 'Profile' 5 belongs_to :from, :class_name => 'Profile'
  6 +
  7 + validates_presence_of :from, :to
6 end 8 end
db/migrate/20141014205254_create_chat_messages.rb
1 class CreateChatMessages < ActiveRecord::Migration 1 class CreateChatMessages < ActiveRecord::Migration
2 def up 2 def up
3 create_table :chat_messages do |t| 3 create_table :chat_messages do |t|
4 - t.references :from  
5 - t.references :to 4 + t.references :from, :null => false
  5 + t.references :to, :null => false
6 t.text :body 6 t.text :body
7 t.timestamps 7 t.timestamps
8 end 8 end
@@ -12,9 +12,9 @@ class CreateChatMessages &lt; ActiveRecord::Migration @@ -12,9 +12,9 @@ class CreateChatMessages &lt; ActiveRecord::Migration
12 end 12 end
13 13
14 def down 14 def down
15 - drop_table :chat_messages  
16 - remove_index :chat_messages, :from  
17 - remove_index :chat_messages, :to 15 + remove_index :chat_messages, :from_id
  16 + remove_index :chat_messages, :to_id
18 remove_index :chat_messages, :created_at 17 remove_index :chat_messages, :created_at
  18 + drop_table :chat_messages
19 end 19 end
20 end 20 end
@@ -245,8 +245,8 @@ ActiveRecord::Schema.define(:version =&gt; 20150513213939) do @@ -245,8 +245,8 @@ ActiveRecord::Schema.define(:version =&gt; 20150513213939) do
245 end 245 end
246 246
247 create_table "chat_messages", :force => true do |t| 247 create_table "chat_messages", :force => true do |t|
248 - t.integer "from_id"  
249 - t.integer "to_id" 248 + t.integer "from_id", :null => false
  249 + t.integer "to_id", :null => false
250 t.text "body" 250 t.text "body"
251 t.datetime "created_at", :null => false 251 t.datetime "created_at", :null => false
252 t.datetime "updated_at", :null => false 252 t.datetime "updated_at", :null => false
debian/noosfero.install
@@ -34,4 +34,3 @@ public usr/share/noosfero @@ -34,4 +34,3 @@ public usr/share/noosfero
34 script usr/share/noosfero 34 script usr/share/noosfero
35 util usr/share/noosfero 35 util usr/share/noosfero
36 vendor usr/share/noosfero 36 vendor usr/share/noosfero
37 -  
debian/update-noosfero-apache
@@ -18,18 +18,14 @@ if test -x /usr/share/noosfero/script/apacheconf; then @@ -18,18 +18,14 @@ if test -x /usr/share/noosfero/script/apacheconf; then
18 fi 18 fi
19 19
20 apache_site='/etc/apache2/sites-available/noosfero' 20 apache_site='/etc/apache2/sites-available/noosfero'
21 - apache_site_configs='/etc/noosfero/apache.d'  
22 if ! test -e "$apache_site"; then 21 if ! test -e "$apache_site"; then
23 echo "Generating apache virtual host ..." 22 echo "Generating apache virtual host ..."
24 cd /usr/share/noosfero && su noosfero -c "RAILS_ENV=production ./script/apacheconf virtualhosts" > "$apache_site" 23 cd /usr/share/noosfero && su noosfero -c "RAILS_ENV=production ./script/apacheconf virtualhosts" > "$apache_site"
25 - if ! test -d "$apache_site_configs"; then  
26 - echo "Creating noosfero site config folder ..."  
27 - mkdir $apache_site_configs  
28 - fi  
29 else 24 else
30 pattern="Include \/etc\/noosfero\/apache\/virtualhost.conf" 25 pattern="Include \/etc\/noosfero\/apache\/virtualhost.conf"
31 - include="Include \/etc\/noosfero\/apache.d\/*" 26 + include="Include \/usr\/share\/noosfero\/util\/chat\/apache\/xmpp.conf"
32 if ! cat $apache_site | grep "^ *$include" > /dev/null ; then 27 if ! cat $apache_site | grep "^ *$include" > /dev/null ; then
  28 + echo "Updating apache virtual host ..."
33 sed -i "s/.*$pattern.*/ $include\n&/" $apache_site 29 sed -i "s/.*$pattern.*/ $include\n&/" $apache_site
34 fi 30 fi
35 fi 31 fi
etc/noosfero/apache.d/noosfero-chat
@@ -1,2 +0,0 @@ @@ -1,2 +0,0 @@
1 -RewriteEngine On  
2 -Include /usr/share/noosfero/util/chat/apache/xmpp.conf  
test/functional/chat_controller_test.rb
@@ -100,7 +100,7 @@ class ChatControllerTest &lt; ActionController::TestCase @@ -100,7 +100,7 @@ class ChatControllerTest &lt; ActionController::TestCase
100 @request.stubs(:xhr?).returns(true) 100 @request.stubs(:xhr?).returns(true)
101 101
102 post :save_message, {:body =>'Hello!'} 102 post :save_message, {:body =>'Hello!'}
103 - assert ActiveSupport::JSON.decode(@response.body)['status'] == 1 103 + assert_equal 3, ActiveSupport::JSON.decode(@response.body)['status']
104 end 104 end
105 105
106 should 'forbid to register a message without body' do 106 should 'forbid to register a message without body' do
@@ -108,7 +108,7 @@ class ChatControllerTest &lt; ActionController::TestCase @@ -108,7 +108,7 @@ class ChatControllerTest &lt; ActionController::TestCase
108 @request.stubs(:xhr?).returns(true) 108 @request.stubs(:xhr?).returns(true)
109 109
110 post :save_message, {:to =>'mary'} 110 post :save_message, {:to =>'mary'}
111 - assert ActiveSupport::JSON.decode(@response.body)['status'] == 1 111 + assert_equal 3, ActiveSupport::JSON.decode(@response.body)['status']
112 end 112 end
113 113
114 should 'forbid user to register a message to a stranger' do 114 should 'forbid user to register a message to a stranger' do
@@ -116,7 +116,7 @@ class ChatControllerTest &lt; ActionController::TestCase @@ -116,7 +116,7 @@ class ChatControllerTest &lt; ActionController::TestCase
116 @request.stubs(:xhr?).returns(true) 116 @request.stubs(:xhr?).returns(true)
117 117
118 post :save_message, {:to =>'random', :body => 'Hello, stranger!'} 118 post :save_message, {:to =>'random', :body => 'Hello, stranger!'}
119 - assert ActiveSupport::JSON.decode(@response.body)['status'] == 2 119 + assert_equal 3, ActiveSupport::JSON.decode(@response.body)['status']
120 end 120 end
121 121
122 should 'register a message to a friend' do 122 should 'register a message to a friend' do