- <% form_remote_tag :url => {:controller => 'profile', :action => 'leave_scrap'}, :update => "profile_scraps", :success =>"hide_and_show(['#profile-wall-reply-form-#{scrap.id}'],['#profile-wall-reply-response-#{scrap.id}'])" do %>
+ <% form_remote_tag :url => {:controller => 'profile', :action => 'leave_scrap'}, :update => "profile_activities", :success =>"hide_and_show(['#profile-wall-reply-form-#{scrap.id}'],['#profile-wall-reply-response-#{scrap.id}'])" do %>
<%= limited_text_area :scrap, :content, 420, "reply_content_#{scrap.id}", :cols => 50, :rows => 2 %>
<%= hidden_field :scrap, :scrap_id, :id => "scrap_id_#{scrap.id}" %>
<%= hidden_field_tag 'receiver_id', scrap.sender.id %>
diff --git a/app/views/profile/_profile_wall.rhtml b/app/views/profile/_profile_wall.rhtml
index 2bec4e2..ebaa042 100644
--- a/app/views/profile/_profile_wall.rhtml
+++ b/app/views/profile/_profile_wall.rhtml
@@ -1,12 +1,28 @@
<%= _("%s's wall") % @profile.name %>
<%= flash[:error] %>
- <% form_remote_tag :url => {:controller => 'profile', :action => 'leave_scrap', :tab_action => 'wall' }, :update => 'profile_scraps', :success => "$('leave_scrap_content').value=''" do %>
+ <% form_remote_tag :url => {:controller => 'profile', :action => 'leave_scrap', :tab_action => 'wall' }, :update => 'profile_activities', :success => "$('leave_scrap_content').value=''" do %>
<%= limited_text_area :scrap, :content, 420, 'leave_scrap_content', :cols => 50, :rows => 2 %>
<%= submit_button :scrap, _('Leave a scrap') %>
<% end %>
+
+ <%= render :partial => 'profile_activities_scraps', :locals => {:activities => @activities} %>
+
+
+<% if @activities.current_page < @activities.total_pages %>
+
+ <%= button_to_remote :add, _('View more'), :url => {:action => 'view_more_activities', :page => (@activities.current_page + 1)}, :update => "profile_activities_page_#{@activities.current_page}" %>
+
+<% end %>
+
+
diff --git a/app/views/profile/_update_article.rhtml b/app/views/profile/_update_article.rhtml
new file mode 100644
index 0000000..118a275
--- /dev/null
+++ b/app/views/profile/_update_article.rhtml
@@ -0,0 +1 @@
+<%= render :partial => 'default_activity', :locals => {:activity => activity} %>
diff --git a/app/views/profile/_upload_image.rhtml b/app/views/profile/_upload_image.rhtml
new file mode 100644
index 0000000..118a275
--- /dev/null
+++ b/app/views/profile/_upload_image.rhtml
@@ -0,0 +1 @@
+<%= render :partial => 'default_activity', :locals => {:activity => activity} %>
diff --git a/config/initializers/action_tracker.rb b/config/initializers/action_tracker.rb
index 32e9610..614fc12 100644
--- a/config/initializers/action_tracker.rb
+++ b/config/initializers/action_tracker.rb
@@ -5,13 +5,7 @@ require 'noosfero/i18n'
ActionTrackerConfig.verbs = {
:create_article => {
- :description => lambda { n_('published 1 article: %{title}', 'published %{num} articles: %{title}', get_name.size) % { :num => get_name.size, :title => '{{ta.collect_group_with_index(:name){ |n,i| link_to(truncate(n), ta.get_url[i]) }.to_sentence(:connector => "%s")}}' % _("and") } },
- :type => :groupable
- },
-
- :update_article => {
- :description => lambda { n_('updated 1 article: %{title}', 'updated %{num} articles: %{title}', get_name.uniq.size) % { :num => get_name.uniq.size, :title => '{{ta.collect_group_with_index(:name){ |n,i| link_to(truncate(n), ta.get_url[i]) }.uniq.to_sentence(:connector => "%s")}}' % _("and") } },
- :type => :groupable
+ :description => lambda { _('published an article: %{title}') % { :title => '{{link_to(truncate(ta.get_name), ta.get_url)}}' } }
},
:remove_article => {
diff --git a/db/migrate/20111211204445_add_polymorphism_on_comment.rb b/db/migrate/20111211204445_add_polymorphism_on_comment.rb
new file mode 100644
index 0000000..eadebfd
--- /dev/null
+++ b/db/migrate/20111211204445_add_polymorphism_on_comment.rb
@@ -0,0 +1,12 @@
+class AddPolymorphismOnComment < ActiveRecord::Migration
+ def self.up
+ rename_column :comments, :article_id, :source_id
+ add_column :comments, :source_type, :string
+ execute("update comments set source_type = 'Article'")
+ end
+
+ def self.down
+ remove_column :comments, :source_type
+ rename_column :comments, :source_id, :article_id
+ end
+end
diff --git a/db/migrate/20111211233957_add_comment_count_to_action_tracker.rb b/db/migrate/20111211233957_add_comment_count_to_action_tracker.rb
new file mode 100644
index 0000000..80b68c8
--- /dev/null
+++ b/db/migrate/20111211233957_add_comment_count_to_action_tracker.rb
@@ -0,0 +1,9 @@
+class AddCommentCountToActionTracker < ActiveRecord::Migration
+ def self.up
+ add_column :action_tracker, :comments_count, :integer, :default => 0
+ end
+
+ def self.down
+ remove_column :action_tracker, :comments_count, :integer, :default => 0
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 18dc424..9a8ac15 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -29,6 +29,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do
t.string "verb"
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "comments_count", :default => 0
end
add_index "action_tracker", ["target_id", "target_type"], :name => "index_action_tracker_on_dispatcher_id_and_dispatcher_type"
@@ -198,7 +199,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do
create_table "comments", :force => true do |t|
t.string "title"
t.text "body"
- t.integer "article_id"
+ t.integer "source_id"
t.integer "author_id"
t.string "name"
t.string "email"
@@ -206,6 +207,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do
t.integer "reply_of_id"
t.string "ip_address"
t.boolean "spam"
+ t.string "source_type"
end
create_table "contact_lists", :force => true do |t|
@@ -252,6 +254,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do
t.datetime "created_at"
t.datetime "updated_at"
t.integer "reports_lower_bound", :default => 0, :null => false
+ t.text "send_email_plugin_allow_to"
end
create_table "external_feeds", :force => true do |t|
@@ -384,7 +387,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do
t.string "type"
t.string "identifier"
t.integer "environment_id"
- t.boolean "active", :default => true
+ t.boolean "active", :default => true
t.string "address"
t.string "contact_phone"
t.integer "home_page_id"
@@ -395,19 +398,24 @@ ActiveRecord::Schema.define(:version => 20120307200651) do
t.float "lat"
t.float "lng"
t.integer "geocode_precision"
- t.boolean "enabled", :default => true
- t.string "nickname", :limit => 16
+ t.boolean "enabled", :default => true
+ t.string "nickname", :limit => 16
t.text "custom_header"
t.text "custom_footer"
t.string "theme"
- t.boolean "public_profile", :default => true
+ t.boolean "public_profile", :default => true
t.date "birth_date"
t.integer "preferred_domain_id"
t.datetime "updated_at"
- t.boolean "visible", :default => true
+ t.boolean "visible", :default => true
t.integer "image_id"
- t.boolean "validated", :default => true
+ t.boolean "validated", :default => true
t.string "cnpj"
+ t.boolean "shopping_cart", :default => true
+ t.boolean "shopping_cart_delivery", :default => false
+ t.decimal "shopping_cart_delivery_price", :default => 0.0
+ t.integer "bsc_id"
+ t.string "company_name"
end
add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id"
@@ -496,6 +504,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do
t.datetime "created_at"
t.string "target_type"
t.integer "image_id"
+ t.integer "bsc_id"
end
create_table "thumbnails", :force => true do |t|
diff --git a/public/designs/themes/base/style.css b/public/designs/themes/base/style.css
index 46c683f..9d77fb5 100644
--- a/public/designs/themes/base/style.css
+++ b/public/designs/themes/base/style.css
@@ -1053,53 +1053,53 @@ hr.pre-posts, hr.sep-posts {
.comment-wrapper-1 {
margin-left: 60px;
- background: url(imgs/comment-bg-N.png) 0% 0% repeat-x;
+ Xbackground: url(imgs/comment-bg-N.png) 0% 0% repeat-x;
}
.comment-wrapper-2 {
- background: url(imgs/comment-bg-S.png) 0% 100% repeat-x;
+ Xbackground: url(imgs/comment-bg-S.png) 0% 100% repeat-x;
}
.comment-wrapper-3 {
- background: url(imgs/comment-bg-L.png) 100% 0% repeat-y;
+ Xbackground: url(imgs/comment-bg-L.png) 100% 0% repeat-y;
}
.comment-wrapper-4 {
- background: url(imgs/comment-bg-O.png) 0% 0% repeat-y;
+ Xbackground: url(imgs/comment-bg-O.png) 0% 0% repeat-y;
}
.comment-wrapper-5 {
- background: url(imgs/comment-bg-SL.png) 100% 100% no-repeat;
+ Xbackground: url(imgs/comment-bg-SL.png) 100% 100% no-repeat;
}
.comment-wrapper-6 {
- background: url(imgs/comment-bg-SO.png) 0% 100% no-repeat;
+ Xbackground: url(imgs/comment-bg-SO.png) 0% 100% no-repeat;
}
.comment-wrapper-7 {
- background: url(imgs/comment-bg-NL.png) 100% 0% no-repeat;
+ Xbackground: url(imgs/comment-bg-NL.png) 100% 0% no-repeat;
}
.comment-wrapper-8 {
- background: url(imgs/comment-bg-NO.png) 0% 0% no-repeat;
+ Xbackground: url(imgs/comment-bg-NO.png) 0% 0% no-repeat;
}
.comment-from-owner .comment-wrapper-1 {
- background: #fbf7b5 url(/images/comment-owner-bg-N.png) repeat-x;
+ Xbackground: #fbf7b5 url(/images/comment-owner-bg-N.png) repeat-x;
}
.comment-from-owner .comment-wrapper-2 {
- background: url(/images/comment-owner-bg-S.png) 0% 100% repeat-x;
+ Xbackground: url(/images/comment-owner-bg-S.png) 0% 100% repeat-x;
}
.comment-from-owner .comment-wrapper-3 {
- background: url(/images/comment-owner-bg-L.png) 100% 0% repeat-y;
+ Xbackground: url(/images/comment-owner-bg-L.png) 100% 0% repeat-y;
}
.comment-from-owner .comment-wrapper-4 {
- background: url(/images/comment-owner-bg-O.png) 0% 0% repeat-y;
+ Xbackground: url(/images/comment-owner-bg-O.png) 0% 0% repeat-y;
}
.comment-from-owner .comment-wrapper-5 {
- background: url(/images/comment-owner-bg-SL.png) 100% 100% no-repeat;
+ Xbackground: url(/images/comment-owner-bg-SL.png) 100% 100% no-repeat;
}
.comment-from-owner .comment-wrapper-6 {
- background: url(/images/comment-owner-bg-SO.png) 0% 100% no-repeat;
+ Xbackground: url(/images/comment-owner-bg-SO.png) 0% 100% no-repeat;
}
.comment-from-owner .comment-wrapper-7 {
- background: url(/images/comment-owner-bg-NL.png) 100% 0% no-repeat;
+ Xbackground: url(/images/comment-owner-bg-NL.png) 100% 0% no-repeat;
}
.comment-from-owner .comment-wrapper-8 {
- background: url(/images/comment-owner-bg-NO.png) 0% 0% no-repeat;
+ Xbackground: url(/images/comment-owner-bg-NO.png) 0% 0% no-repeat;
}
.comment-created-at {
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index cc5abc7..3686b4b 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -1314,7 +1314,7 @@ a.comment-picture {
}
.comment-balloon-content {
- margin-left: 15px;
+ Xmargin-left: 15px;
}
/* * * Comment Replies * * */
@@ -5883,7 +5883,15 @@ h1#agenda-title {
#profile-activity li, #profile-network li, #profile-wall li {
display: block;
padding: 0;
- margin-bottom: 8px;
+ Xmargin-bottom: 8px;
+ background-color: #E8E8E8;
+ border-bottom: 5px double #f2f2f2;
+}
+
+#profile-activity .profile-wall-scrap-replies li,
+#profile-network .profile-wall-scrap-replies li,
+#profile-wall .profile-wall-scrap-replies li {
+ border-bottom: none;
}
#profile-activity .profile-activity-image, #profile-network .profile-network-image, #profile-wall .profile-wall-image {
@@ -5897,12 +5905,12 @@ h1#agenda-title {
#profile-activity .profile-activity-description, #profile-network .profile-network-description, #profile-wall .profile-wall-description {
float: left;
- min-height: 60px;
+ Xmin-height: 60px;
margin: 0;
padding: 0;
border: 1px solid #ccc;
overflow: hidden;
- background-color: #fff;
+ Xbackground-color: #fff;
position: relative;
}
@@ -5931,17 +5939,18 @@ h1#agenda-title {
#profile-activity .profile-activity-text, #profile-network .profile-network-text, #profile-wall .profile-wall-text {
font-size: 13px;
- margin: 5px;
+ margin: 2px 5px;
}
#profile-wall .profile-wall-text {
padding-top: 0;
}
-#profile-activity .profile-activity-time, #profile-network .profile-network-time, #profile-wall .profile-wall-time {
+#profile_activities .profile-activity-time, #profile-network .profile-network-time, #profile-wall .profile-wall-time {
font-size: 11px;
margin: 5px;
color: #babdb6;
+ text-align: right;
}
#profile-activity hr, #profile-network hr, #profile-wall hr {
@@ -6083,21 +6092,30 @@ h1#agenda-title {
}
.profile-send-reply {
- background-color: #eee;
- border: 1px solid #aaa;
- padding: 2px;
- padding-left: 20px;
- background-repeat: no-repeat;
- background-position: 2px center;
+ xbackground-color: #eee;
+ xborder: 1px solid #aaa;
+ xpadding: 2px;
+ xpadding-left: 20px;
+ xbackground-repeat: no-repeat;
+ xbackground-position: 2px center;
color: #aaa;
- text-decoration: none;
- margin-left: 8px;
+ Xtext-decoration: none;
+ Xmargin-left: 8px;
}
#content .profile-send-reply:hover {
text-decoration: none;
}
+#profile-wall .profile-wall-actions {
+ text-align: right;
+}
+
+#profile-wall .profile-wall-send-reply {
+ display: inline-block;
+
+}
+
#profile-wall .profile-wall-scrap-replies .profile-wall-description {
background: transparent;
}
@@ -6244,7 +6262,7 @@ h1#agenda-title {
}
#profile-wall .comment-balloon-content {
- padding: 3px 0 3px 15px;
+ padding: 3px 0px;
}
.profile-wall-reply {
@@ -6266,8 +6284,9 @@ h1#agenda-title {
width: 98%;
}
-#profile-activity .profile-activity-image, #profile-network .profile-network-image, #profile-wall .profile-wall-image {
- width: 19%;
+#profile_activities .profile-activity-image, #profile-network .profile-network-image, #profile-wall .profile-wall-image {
+ width: 50px;
+ margin: 5px;
}
#profile-activity .profile-activity-description, #profile-network .profile-network-description, #profile-wall .profile-wall-description {
diff --git a/test/factories.rb b/test/factories.rb
index 53abbd0..fb24dcf 100644
--- a/test/factories.rb
+++ b/test/factories.rb
@@ -438,7 +438,7 @@ module Noosfero::Factory
def defaults_for_comment(params = {})
name = "comment_#{rand(1000)}"
- { :title => name, :body => "my own comment", :article_id => 1 }.merge(params)
+ { :title => name, :body => "my own comment", :source_id => 1 }.merge(params)
end
###############################################
diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb
index 675cd1b..e6a51df 100644
--- a/test/functional/profile_controller_test.rb
+++ b/test/functional/profile_controller_test.rb
@@ -714,21 +714,27 @@ class ProfileControllerTest < ActionController::TestCase
assert_no_tag :tag => 'p', :content => 'A scrap'
end
- should 'see all activities of the current profile' do
+ should 'see only actions of the current profile when he is not followed by the viewer' do
p1= Person.first
p2= fast_create(Person)
- assert !p1.is_a_friend?(p2)
p3= fast_create(Person)
- assert !p1.is_a_friend?(p3)
+
+# UserStampSweeper.any_instance.stubs(:current_user).returns(p1)
ActionTracker::Record.destroy_all
- Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p1))
+ scrap1 = Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p1))
+
+# UserStampSweeper.any_instance.stubs(:current_user).returns(p2)
+ scrap2 = Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => p3))
+# a2 = ActionTracker::Record.last
+
+# UserStampSweeper.any_instance.stubs(:current_user).returns(p3)
+ scrap3 = Scrap.create!(defaults_for_scrap(:sender => p3, :receiver => p1))
+# a3 = ActionTracker::Record.last
+
+ UserStampSweeper.any_instance.stubs(:current_user).returns(p1)
+ TinyMceArticle.create!(:profile => p1, :name => 'An article about free software')
a1 = ActionTracker::Record.last
- UserStampSweeper.any_instance.stubs(:current_user).returns(p2)
- Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => p3))
- a2 = ActionTracker::Record.last
- UserStampSweeper.any_instance.stubs(:current_user).returns(p3)
- Scrap.create!(defaults_for_scrap(:sender => p3, :receiver => p1))
- a3 = ActionTracker::Record.last
+
login_as(profile.identifier)
get :index, :profile => p1.identifier
assert_not_nil assigns(:activities)
@@ -744,7 +750,7 @@ class ProfileControllerTest < ActionController::TestCase
assert_equal 30, assigns(:activities).count
end
- should 'see not see the friends activities in the current profile activity' do
+ should 'not see the friends actions and scraps in the current profile activity' do
p1= Person.first
p2= fast_create(Person)
assert !p1.is_a_friend?(p2)
@@ -752,18 +758,23 @@ class ProfileControllerTest < ActionController::TestCase
p1.add_friend(p3)
assert p1.is_a_friend?(p3)
ActionTracker::Record.destroy_all
- Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p1))
+
+ scrap1 = Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p1))
+ scrap2 = Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => p3))
+ scrap3 = Scrap.create!(defaults_for_scrap(:sender => p3, :receiver => p1))
+
+ UserStampSweeper.any_instance.stubs(:current_user).returns(p3)
+ TinyMceArticle.create!(:profile => p3, :name => 'An article about free software')
a1 = ActionTracker::Record.last
- UserStampSweeper.any_instance.stubs(:current_user).returns(p2)
- Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => p3))
+
+ UserStampSweeper.any_instance.stubs(:current_user).returns(p1)
+ TinyMceArticle.create!(:profile => p1, :name => 'Another article about free software')
a2 = ActionTracker::Record.last
- UserStampSweeper.any_instance.stubs(:current_user).returns(p3)
- Scrap.create!(defaults_for_scrap(:sender => p3, :receiver => p1))
- a3 = ActionTracker::Record.last
+
login_as(profile.identifier)
get :index, :profile => p1.identifier
assert_not_nil assigns(:activities)
- assert_equal [a1], assigns(:activities)
+ assert_equal [a2], assigns(:activities)
end
should 'see all the activities in the current profile network' do
@@ -976,7 +987,7 @@ class ProfileControllerTest < ActionController::TestCase
should 'the wall_itens be paginated in people profiles' do
p1 = Person.first
- 40.times{fast_create(Scrap, :sender_id => p1.id)}
+ 40.times{fast_create(Scrap, :sender_id => p1.id, :created_at => Time.now)}
@controller.stubs(:logged_in?).returns(true)
user = mock()
@@ -1158,7 +1169,7 @@ class ProfileControllerTest < ActionController::TestCase
assert_equal 40, profile.tracked_actions.count
get :view_more_activities, :profile => profile.identifier, :page => 2
assert_response :success
- assert_template '_profile_activities'
+ assert_template '_profile_bla'
assert_equal 10, assigns(:activities).count
end
@@ -1247,4 +1258,34 @@ class ProfileControllerTest < ActionController::TestCase
post :register_report, :profile => reported.identifier, :abuse_report => {:reason => 'some reason'}
end
end
+
+ should 'display activities and scraps together' do
+ another_person = fast_create(Person)
+ Scrap.create!(defaults_for_scrap(:sender => another_person, :receiver => profile, :content => 'A scrap'))
+
+ UserStampSweeper.any_instance.stubs(:current_user).returns(profile)
+ ActionTracker::Record.destroy_all
+ TinyMceArticle.create!(:profile => profile, :name => 'An article about free software')
+
+ login_as(profile.identifier)
+ get :index, :profile => profile.identifier
+
+ assert_tag :tag => 'div', :attributes => { :id => 'profile-wall' }, :descendant => { :tag => 'p', :content => 'A scrap' }
+ assert_tag :tag => 'div', :attributes => { :id => 'profile-wall' }, :descendant => { :tag => 'a', :content => 'An article about free software' }
+ end
+
+ should 'have scraps and activities on activities' do
+ another_person = fast_create(Person)
+ scrap = Scrap.create!(defaults_for_scrap(:sender => another_person, :receiver => profile, :content => 'A scrap'))
+
+ UserStampSweeper.any_instance.stubs(:current_user).returns(profile)
+ ActionTracker::Record.destroy_all
+ TinyMceArticle.create!(:profile => profile, :name => 'An article about free software')
+ activity = ActionTracker::Record.last
+
+ login_as(profile.identifier)
+ get :index, :profile => profile.identifier
+
+ assert_equivalent [scrap,activity], assigns(:activities).map {|a| a.klass.constantize.find(a.id)}
+ end
end
diff --git a/test/unit/action_tracker_notification_test.rb b/test/unit/action_tracker_notification_test.rb
index 9c434c5..5784fc7 100644
--- a/test/unit/action_tracker_notification_test.rb
+++ b/test/unit/action_tracker_notification_test.rb
@@ -76,4 +76,12 @@ class ActionTrackerNotificationTest < ActiveSupport::TestCase
assert_equal [last_notification], at.action_tracker_notifications
end
+ should "have comments through action_tracker" do
+ action = fast_create(ActionTracker::Record)
+ notification = fast_create(ActionTrackerNotification, :action_tracker_id => action.id, :profile_id => 1)
+
+ comment = fast_create(Comment, :source_id => action.id)
+ assert_equal action.comments, notification.comments
+ end
+
end
diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb
index c05cb13..7fe35a3 100644
--- a/test/unit/article_test.rb
+++ b/test/unit/article_test.rb
@@ -1009,6 +1009,28 @@ class ArticleTest < ActiveSupport::TestCase
assert_equal ['a','b'], ta.get_name
end
+ should 'update action when article is updated' do
+ article = create(TinyMceArticle, :profile => profile)
+ action = ActionTracker::Record.last
+ time = action.updated_at
+
+ Time.stubs(:now).returns(time + 1.day)
+ article.name = 'New name'
+ article.save
+ assert_not_equal time, ActionTracker::Record.last.updated_at
+ end
+
+ should 'update action when comment is created' do
+ article = create(TinyMceArticle, :profile => profile)
+ action = ActionTracker::Record.last
+ time = action.updated_at
+
+ Time.stubs(:now).returns(time + 1.day)
+
+ article.comments << Comment.create(:name => 'Guest', :email => 'guest@example.com', :title => 'test comment', :body => 'hello!')
+ assert_not_equal time, ActionTracker::Record.last.updated_at
+ end
+
should 'notifiable is false by default' do
a = fast_create(Article)
assert !a.notifiable?
@@ -1638,4 +1660,23 @@ class ArticleTest < ActiveSupport::TestCase
assert_equal [c1,c2,c5], Article.text_articles
end
+ should 'filter articles by date of creation' do
+ from = Date.today - 2.days
+ to = Date.today - 1.day
+ article1 = fast_create(Article, :created_at => from - 1.day)
+ article2 = fast_create(Article, :created_at => from + 6.hours)
+ article3 = fast_create(Article, :created_at => to + 1.day)
+
+ assert_not_includes Article.created_between(from, nil), article1
+ assert_includes Article.created_between(from, nil), article2
+ assert_includes Article.created_between(from, nil), article3
+
+ assert_includes Article.created_between(nil, to), article1
+ assert_includes Article.created_between(nil, to), article2
+ assert_not_includes Article.created_between(nil, to), article3
+
+ assert_not_includes Article.created_between(from, to), article1
+ assert_includes Article.created_between(from, to), article2
+ assert_not_includes Article.created_between(from, to), article3
+ end
end
diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb
index 32a348f..a7a378a 100644
--- a/test/unit/comment_test.rb
+++ b/test/unit/comment_test.rb
@@ -13,13 +13,13 @@ class CommentTest < ActiveSupport::TestCase
assert_mandatory(Comment.new, :body)
end
- should 'belong to an article' do
+ should 'have a polymorphic relationship with source' do
c = Comment.new
- assert_raise ActiveRecord::AssociationTypeMismatch do
- c.article = 1
+ assert_nothing_raised do
+ c.source = Article.new
end
assert_nothing_raised do
- c.article = Article.new
+ c.source = ActionTracker::Record.new
end
end
@@ -69,8 +69,9 @@ class CommentTest < ActiveSupport::TestCase
cc = art.comments_count
art.comments.build(:title => 'test comment', :body => 'anything', :author => owner).save!
- art.reload
- assert_equal cc + 1, art.comments_count
+ art = Article.find(art.id)
+
+ assert_equal cc + 1, Article.find(art.id).comments_count
end
should 'provide author name for authenticated authors' do
@@ -217,30 +218,10 @@ class CommentTest < ActiveSupport::TestCase
assert File.exists?(File.join(Rails.root, 'public', image)), "#{image} does not exist."
end
- should 'track action when comment is created' do
- owner = create_user('testuser').person
- article = owner.articles.create!(:name => 'test', :body => '...')
- comment = article.comments.create!(:article => article, :name => 'foo', :title => 'bar', :body => 'my comment', :email => 'cracker@test.org')
- ta = ActionTracker::Record.last
- assert_equal 'bar', ta.get_title
- assert_equal 'my comment', ta.get_body
- assert_equal 'test', ta.get_article_title
- assert_equal article.url, ta.get_article_url
- assert_equal comment.url, ta.get_url
- end
-
should 'have the action_tracker_target defined' do
assert Comment.method_defined?(:action_tracker_target)
end
- should "have the action_tracker_target be the articles's profile" do
- owner = create_user('testuser').person
- article = owner.articles.create!(:name => 'test', :body => '...')
- comment = article.comments.create!(:article => article, :name => 'foo', :title => 'bar', :body => 'my comment', :email => 'cracker@test.org')
- ta = ActionTracker::Record.last
- assert_equal owner, ta.target
- end
-
should "get children of a comment" do
c = fast_create(Comment)
c1 = fast_create(Comment, :reply_of_id => c.id)
@@ -307,11 +288,11 @@ class CommentTest < ActiveSupport::TestCase
should "return comments as a thread" do
a = fast_create(Article)
- c0 = fast_create(Comment, :article_id => a.id)
- c1 = fast_create(Comment, :reply_of_id => c0.id, :article_id => a.id)
- c2 = fast_create(Comment, :reply_of_id => c1.id, :article_id => a.id)
- c3 = fast_create(Comment, :reply_of_id => c0.id, :article_id => a.id)
- c4 = fast_create(Comment, :article_id => a.id)
+ c0 = fast_create(Comment, :source_id => a.id)
+ c1 = fast_create(Comment, :reply_of_id => c0.id, :source_id => a.id)
+ c2 = fast_create(Comment, :reply_of_id => c1.id, :source_id => a.id)
+ c3 = fast_create(Comment, :reply_of_id => c0.id, :source_id => a.id)
+ c4 = fast_create(Comment, :source_id => a.id)
result = a.comments.as_thread
assert_equal c0.id, result[0].id
assert_equal [c1.id, c3.id], result[0].replies.map(&:id)
diff --git a/test/unit/community_test.rb b/test/unit/community_test.rb
index b070a6e..164b06a 100644
--- a/test/unit/community_test.rb
+++ b/test/unit/community_test.rb
@@ -341,4 +341,5 @@ class CommunityTest < ActiveSupport::TestCase
assert_equal false, community.receives_scrap_notification?
end
+ should 'return tracked_actions and scraps as activities'
end
diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb
index 3884f9c..6aa38d6 100644
--- a/test/unit/enterprise_test.rb
+++ b/test/unit/enterprise_test.rb
@@ -450,4 +450,6 @@ class EnterpriseTest < ActiveSupport::TestCase
e = fast_create(Enterprise)
assert_respond_to e, :production_costs
end
+
+ should 'return tracked_actions and scraps as activities'
end
diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb
index e1f3368..747b94d 100644
--- a/test/unit/person_test.rb
+++ b/test/unit/person_test.rb
@@ -1243,4 +1243,34 @@ class PersonTest < ActiveSupport::TestCase
assert !person.visible
assert_not_equal password, person.user.password
end
+
+ should 'return tracked_actions and scraps as activities' do
+ person = fast_create(Person)
+ another_person = fast_create(Person)
+
+ scrap = Scrap.create!(defaults_for_scrap(:sender => another_person, :receiver => person, :content => 'A scrap'))
+ UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once
+ TinyMceArticle.create!(:profile => person, :name => 'An article about free software')
+ activity = ActionTracker::Record.last
+
+ assert_equal 'An article about free software', activity.get_name.last
+ assert_equal [scrap,activity], person.activities.map { |a| a.klass.constantize.find(a.id) }
+ end
+
+ should 'not return tracked_actions and scraps from others as activities' do
+ person = fast_create(Person)
+ another_person = fast_create(Person)
+
+ person_scrap = Scrap.create!(defaults_for_scrap(:sender => person, :receiver => person, :content => 'A scrap from person'))
+ another_person_scrap = Scrap.create!(defaults_for_scrap(:sender => another_person, :receiver => another_person, :content => 'A scrap from another person'))
+
+ TinyMceArticle.create!(:profile => another_person, :name => 'An article about free software from another person')
+ another_person_activity = ActionTracker::Record.last
+
+ UserStampSweeper.any_instance.stubs(:current_user).returns(person)
+ TinyMceArticle.create!(:profile => person, :name => 'An article about free software')
+ person_activity = ActionTracker::Record.last
+
+ assert_equal [person_scrap,person_activity], person.activities.map { |a| a.klass.constantize.find(a.id) }
+ end
end
diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb
index 454aeb4..3c33e7b 100644
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -1704,6 +1704,7 @@ class ProfileTest < ActiveSupport::TestCase
assert profile.is_on_homepage?("/#{profile.identifier}/#{homepage.slug}", homepage)
end
+
should 'find profiles with image' do
env = fast_create(Environment)
2.times do |n|
@@ -1762,10 +1763,15 @@ class ProfileTest < ActiveSupport::TestCase
assert_raise NoMethodError do
Profile::Roles.invalid_role(env.id)
end
+
+ should 'return empty array as activities' do
+ profile = Profile.new
+ assert_equal [], profile.activities
end
private
+
def assert_invalid_identifier(id)
profile = Profile.new(:identifier => id)
assert !profile.valid?
diff --git a/vendor/plugins/active_record_counter_cache_on_polymorphic_association/init.rb b/vendor/plugins/active_record_counter_cache_on_polymorphic_association/init.rb
new file mode 100644
index 0000000..56dd001
--- /dev/null
+++ b/vendor/plugins/active_record_counter_cache_on_polymorphic_association/init.rb
@@ -0,0 +1,32 @@
+# monkey patch to fix ActiveRecord bug
+#
+# https://rails.lighthouseapp.com/projects/8994/tickets/2452-counter_cache-not-updated-when-an-item-updates-its-polymorphic-owner
+
+ActiveRecord::Associations::ClassMethods.module_eval do
+
+ def replace(record)
+ counter_cache_name = @reflection.counter_cache_column
+ if record.nil?
+ if counter_cache_name && !@owner.new_record?
+ record.class.base_class.decrement_counter(counter_cache_name, @owner[@reflection.primary_key_name]) if @owner[@reflection.primary_key_name]
+ end
+ @target = @owner[@reflection.primary_key_name] = @owner[@reflection.options[:foreign_type]] = nil
+ else
+ @target = (AssociationProxy === record ? record.target : record)
+
+ if counter_cache_name && !@owner.new_record?
+ record.class.base_class.increment_counter(counter_cache_name, record.id)
+ record.class.base_class.decrement_counter(counter_cache_name, @owner[@reflection.primary_key_name]) if @owner[@reflection.primary_key_name]
+ end
+
+ @owner[@reflection.primary_key_name] = record.id
+ @owner[@reflection.options[:foreign_type]] = record.class.base_class.name.to_s
+
+ @updated = true
+ end
+
+ loaded
+ record
+ end
+
+end
--
libgit2 0.21.2
<%= comment.title %>
+