Commit 16f70434a650efc21b1603f004670bf5faeded4d
Exists in
master
and in
9 other branches
Merge branch 'profile-activities' into noosfero
Showing
20 changed files
with
216 additions
and
66 deletions
Show diff stats
app/mailers/scrap_notifier.rb
1 | class ScrapNotifier < ActionMailer::Base | 1 | class ScrapNotifier < ActionMailer::Base |
2 | def notification(scrap) | 2 | def notification(scrap) |
3 | sender, receiver = scrap.sender, scrap.receiver | 3 | sender, receiver = scrap.sender, scrap.receiver |
4 | + # for tests | ||
5 | + return unless receiver.email | ||
6 | + | ||
4 | @recipient = receiver.name | 7 | @recipient = receiver.name |
5 | @sender = sender.name | 8 | @sender = sender.name |
6 | @sender_link = sender.url | 9 | @sender_link = sender.url |
app/models/community.rb
@@ -86,8 +86,8 @@ class Community < Organization | @@ -86,8 +86,8 @@ class Community < Organization | ||
86 | {:title => _('Community Info and settings'), :icon => 'edit-profile-group'} | 86 | {:title => _('Community Info and settings'), :icon => 'edit-profile-group'} |
87 | end | 87 | end |
88 | 88 | ||
89 | - def activities | ||
90 | - Scrap.find_by_sql("SELECT id, updated_at, '#{Scrap.to_s}' AS klass FROM #{Scrap.table_name} WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} WHERE action_tracker.target_id = #{self.id} and action_tracker.verb != 'join_community' and action_tracker.verb != 'leave_scrap' UNION SELECT at.id, at.updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} at INNER JOIN articles a ON at.target_id = a.id WHERE a.profile_id = #{self.id} AND at.target_type = 'Article' ORDER BY updated_at DESC") | 89 | + def exclude_verbs_on_activities |
90 | + %w[join_community leave_scrap] | ||
91 | end | 91 | end |
92 | 92 | ||
93 | end | 93 | end |
app/models/enterprise.rb
@@ -194,10 +194,6 @@ class Enterprise < Organization | @@ -194,10 +194,6 @@ class Enterprise < Organization | ||
194 | true | 194 | true |
195 | end | 195 | end |
196 | 196 | ||
197 | - def activities | ||
198 | - Scrap.find_by_sql("SELECT id, updated_at, 'Scrap' AS klass FROM scraps WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, 'ActionTracker::Record' AS klass FROM action_tracker WHERE action_tracker.target_id = #{self.id} UNION SELECT action_tracker.id, action_tracker.updated_at, 'ActionTracker::Record' AS klass FROM action_tracker INNER JOIN articles ON action_tracker.target_id = articles.id WHERE articles.profile_id = #{self.id} AND action_tracker.target_type = 'Article' ORDER BY updated_at DESC") | ||
199 | - end | ||
200 | - | ||
201 | def catalog_url | 197 | def catalog_url |
202 | { :profile => identifier, :controller => 'catalog'} | 198 | { :profile => identifier, :controller => 'catalog'} |
203 | end | 199 | end |
app/models/person.rb
@@ -496,8 +496,8 @@ roles] } | @@ -496,8 +496,8 @@ roles] } | ||
496 | user.save! | 496 | user.save! |
497 | end | 497 | end |
498 | 498 | ||
499 | - def activities | ||
500 | - Scrap.find_by_sql("SELECT id, updated_at, '#{Scrap.to_s}' AS klass FROM #{Scrap.table_name} WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} WHERE action_tracker.user_id = #{self.id} and action_tracker.verb != 'leave_scrap_to_self' and action_tracker.verb != 'add_member_in_community' and action_tracker.verb != 'reply_scrap_on_self' ORDER BY updated_at DESC") | 499 | + def exclude_verbs_on_activities |
500 | + %w[leave_scrap_to_self add_member_in_community reply_scrap_on_self] | ||
501 | end | 501 | end |
502 | 502 | ||
503 | # by default, all fields are private | 503 | # by default, all fields are private |
app/models/profile.rb
@@ -146,6 +146,7 @@ class Profile < ActiveRecord::Base | @@ -146,6 +146,7 @@ class Profile < ActiveRecord::Base | ||
146 | 146 | ||
147 | acts_as_trackable :dependent => :destroy | 147 | acts_as_trackable :dependent => :destroy |
148 | 148 | ||
149 | + has_many :profile_activities | ||
149 | has_many :action_tracker_notifications, :foreign_key => 'profile_id' | 150 | has_many :action_tracker_notifications, :foreign_key => 'profile_id' |
150 | has_many :tracked_notifications, :through => :action_tracker_notifications, :source => :action_tracker, :order => 'updated_at DESC' | 151 | has_many :tracked_notifications, :through => :action_tracker_notifications, :source => :action_tracker, :order => 'updated_at DESC' |
151 | has_many :scraps_received, :class_name => 'Scrap', :foreign_key => :receiver_id, :order => "updated_at DESC", :dependent => :destroy | 152 | has_many :scraps_received, :class_name => 'Scrap', :foreign_key => :receiver_id, :order => "updated_at DESC", :dependent => :destroy |
@@ -976,9 +977,13 @@ private :generate_url, :url_options | @@ -976,9 +977,13 @@ private :generate_url, :url_options | ||
976 | name | 977 | name |
977 | end | 978 | end |
978 | 979 | ||
979 | - # Override in your subclasses | 980 | + def exclude_verbs_on_activities |
981 | + %w[] | ||
982 | + end | ||
983 | + | ||
984 | + # Customize in subclasses | ||
980 | def activities | 985 | def activities |
981 | - [] | 986 | + self.profile_activities.includes(:activity).order('updated_at DESC') |
982 | end | 987 | end |
983 | 988 | ||
984 | def may_display_field_to? field, user = nil | 989 | def may_display_field_to? field, user = nil |
@@ -0,0 +1,31 @@ | @@ -0,0 +1,31 @@ | ||
1 | +class ProfileActivity < ActiveRecord::Base | ||
2 | + | ||
3 | + self.record_timestamps = false | ||
4 | + | ||
5 | + attr_accessible :profile_id, | ||
6 | + :profile, :activity | ||
7 | + | ||
8 | + belongs_to :profile | ||
9 | + belongs_to :activity, polymorphic: true | ||
10 | + | ||
11 | + # non polymorphic versions | ||
12 | + belongs_to :scrap, foreign_key: :activity_id, class_name: 'Scrap', conditions: {profile_activities: {activity_type: 'Scrap'}} | ||
13 | + belongs_to :action_tracker, foreign_key: :activity_id, class_name: 'ActionTracker::Record', conditions: {profile_activities: {activity_type: 'ActionTracker::Record'}} | ||
14 | + | ||
15 | + before_validation :copy_timestamps | ||
16 | + | ||
17 | + def self.update_activity activity | ||
18 | + profile_activity = ProfileActivity.where(activity_id: activity.id, activity_type: activity.class.base_class.name).first | ||
19 | + profile_activity.send :copy_timestamps | ||
20 | + profile_activity.save! | ||
21 | + profile_activity | ||
22 | + end | ||
23 | + | ||
24 | + protected | ||
25 | + | ||
26 | + def copy_timestamps | ||
27 | + self.created_at = self.activity.created_at | ||
28 | + self.updated_at = self.activity.updated_at | ||
29 | + end | ||
30 | + | ||
31 | +end |
app/models/scrap.rb
@@ -13,6 +13,11 @@ class Scrap < ActiveRecord::Base | @@ -13,6 +13,11 @@ class Scrap < ActiveRecord::Base | ||
13 | has_many :replies, :class_name => 'Scrap', :foreign_key => 'scrap_id', :dependent => :destroy | 13 | has_many :replies, :class_name => 'Scrap', :foreign_key => 'scrap_id', :dependent => :destroy |
14 | belongs_to :root, :class_name => 'Scrap', :foreign_key => 'scrap_id' | 14 | belongs_to :root, :class_name => 'Scrap', :foreign_key => 'scrap_id' |
15 | 15 | ||
16 | + has_many :profile_activities, foreign_key: :activity_id, conditions: {profile_activities: {activity_type: 'Scrap'}}, dependent: :destroy | ||
17 | + | ||
18 | + after_create :create_activity | ||
19 | + after_update :update_activity | ||
20 | + | ||
16 | scope :all_scraps, lambda {|profile| {:conditions => ["receiver_id = ? OR sender_id = ?", profile, profile], :limit => 30}} | 21 | scope :all_scraps, lambda {|profile| {:conditions => ["receiver_id = ? OR sender_id = ?", profile, profile], :limit => 30}} |
17 | 22 | ||
18 | scope :not_replies, :conditions => {:scrap_id => nil} | 23 | scope :not_replies, :conditions => {:scrap_id => nil} |
@@ -23,10 +28,7 @@ class Scrap < ActiveRecord::Base | @@ -23,10 +28,7 @@ class Scrap < ActiveRecord::Base | ||
23 | 28 | ||
24 | track_actions :reply_scrap_on_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.sender != s.receiver && s.sender == s.top_root.receiver} | 29 | track_actions :reply_scrap_on_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.sender != s.receiver && s.sender == s.top_root.receiver} |
25 | 30 | ||
26 | - after_create do |scrap| | ||
27 | - scrap.root.update_attribute('updated_at', DateTime.now) unless scrap.root.nil? | ||
28 | - ScrapNotifier.notification(scrap).deliver if scrap.send_notification? | ||
29 | - end | 31 | + after_create :send_notification |
30 | 32 | ||
31 | before_validation :strip_all_html_tags | 33 | before_validation :strip_all_html_tags |
32 | 34 | ||
@@ -57,4 +59,21 @@ class Scrap < ActiveRecord::Base | @@ -57,4 +59,21 @@ class Scrap < ActiveRecord::Base | ||
57 | sender != receiver && (is_root? ? root.receiver.receives_scrap_notification? : receiver.receives_scrap_notification?) | 59 | sender != receiver && (is_root? ? root.receiver.receives_scrap_notification? : receiver.receives_scrap_notification?) |
58 | end | 60 | end |
59 | 61 | ||
62 | + protected | ||
63 | + | ||
64 | + def create_activity | ||
65 | + # do not scrap replies (when scrap_id is not nil) | ||
66 | + return if self.scrap_id.present? | ||
67 | + ProfileActivity.create! profile_id: self.receiver_id, activity: self | ||
68 | + end | ||
69 | + | ||
70 | + def update_activity | ||
71 | + ProfileActivity.update_activity self | ||
72 | + end | ||
73 | + | ||
74 | + def send_notification | ||
75 | + self.root.update_attribute('updated_at', DateTime.now) unless self.root.nil? | ||
76 | + ScrapNotifier.notification(self).deliver if self.send_notification? | ||
77 | + end | ||
78 | + | ||
60 | end | 79 | end |
app/views/profile/_profile_activities_list.html.erb
1 | <% unless activities.nil? %> | 1 | <% unless activities.nil? %> |
2 | - <% activities.each do |a| %> | ||
3 | - <% activity = a.klass.constantize.find(a.id) %> | 2 | + <% activities.each do |profile_activity| %> |
3 | + <% activity = profile_activity.activity %> | ||
4 | <% if activity.kind_of?(ActionTracker::Record) %> | 4 | <% if activity.kind_of?(ActionTracker::Record) %> |
5 | <%= render :partial => 'profile_activity', :locals => { :activity => activity, :tab_action => 'wall' } if activity.visible? %> | 5 | <%= render :partial => 'profile_activity', :locals => { :activity => activity, :tab_action => 'wall' } if activity.visible? %> |
6 | <% else %> | 6 | <% else %> |
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +class CreateProfileActivity < ActiveRecord::Migration | ||
2 | + def up | ||
3 | + ActiveRecord::Base.transaction do | ||
4 | + create_table :profile_activities do |t| | ||
5 | + t.integer :profile_id | ||
6 | + t.integer :activity_id | ||
7 | + t.string :activity_type | ||
8 | + t.timestamps | ||
9 | + end | ||
10 | + add_index :profile_activities, :profile_id | ||
11 | + add_index :profile_activities, [:activity_id, :activity_type] | ||
12 | + add_index :profile_activities, :activity_type | ||
13 | + | ||
14 | + Scrap.find_each batch_size: 50 do |scrap| | ||
15 | + scrap.send :create_activity | ||
16 | + end | ||
17 | + ActionTracker::Record.find_each batch_size: 50 do |action_tracker| | ||
18 | + action_tracker.send :create_activity | ||
19 | + end | ||
20 | + end | ||
21 | + end | ||
22 | + | ||
23 | + def down | ||
24 | + drop_table :profile_activities | ||
25 | + end | ||
26 | +end |
db/schema.rb
@@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
11 | # | 11 | # |
12 | # It's strongly recommended to check this file into your version control system. | 12 | # It's strongly recommended to check this file into your version control system. |
13 | 13 | ||
14 | -ActiveRecord::Schema.define(:version => 20150625234824) do | 14 | +ActiveRecord::Schema.define(:version => 20150712130827) do |
15 | 15 | ||
16 | create_table "abuse_reports", :force => true do |t| | 16 | create_table "abuse_reports", :force => true do |t| |
17 | t.integer "reporter_id" | 17 | t.integer "reporter_id" |
@@ -489,6 +489,18 @@ ActiveRecord::Schema.define(:version => 20150625234824) do | @@ -489,6 +489,18 @@ ActiveRecord::Schema.define(:version => 20150625234824) do | ||
489 | add_index "products", ["product_category_id"], :name => "index_products_on_product_category_id" | 489 | add_index "products", ["product_category_id"], :name => "index_products_on_product_category_id" |
490 | add_index "products", ["profile_id"], :name => "index_products_on_profile_id" | 490 | add_index "products", ["profile_id"], :name => "index_products_on_profile_id" |
491 | 491 | ||
492 | + create_table "profile_activities", :force => true do |t| | ||
493 | + t.integer "profile_id" | ||
494 | + t.integer "activity_id" | ||
495 | + t.string "activity_type" | ||
496 | + t.datetime "created_at", :null => false | ||
497 | + t.datetime "updated_at", :null => false | ||
498 | + end | ||
499 | + | ||
500 | + add_index "profile_activities", ["activity_id", "activity_type"], :name => "index_profile_activities_on_activity_id_and_activity_type" | ||
501 | + add_index "profile_activities", ["activity_type"], :name => "index_profile_activities_on_activity_type" | ||
502 | + add_index "profile_activities", ["profile_id"], :name => "index_profile_activities_on_profile_id" | ||
503 | + | ||
492 | create_table "profile_suggestions", :force => true do |t| | 504 | create_table "profile_suggestions", :force => true do |t| |
493 | t.integer "person_id" | 505 | t.integer "person_id" |
494 | t.integer "suggestion_id" | 506 | t.integer "suggestion_id" |
@@ -555,6 +567,8 @@ ActiveRecord::Schema.define(:version => 20150625234824) do | @@ -555,6 +567,8 @@ ActiveRecord::Schema.define(:version => 20150625234824) do | ||
555 | add_index "profiles", ["identifier"], :name => "index_profiles_on_identifier" | 567 | add_index "profiles", ["identifier"], :name => "index_profiles_on_identifier" |
556 | add_index "profiles", ["members_count"], :name => "index_profiles_on_members_count" | 568 | add_index "profiles", ["members_count"], :name => "index_profiles_on_members_count" |
557 | add_index "profiles", ["region_id"], :name => "index_profiles_on_region_id" | 569 | add_index "profiles", ["region_id"], :name => "index_profiles_on_region_id" |
570 | + add_index "profiles", ["user_id", "type"], :name => "index_profiles_on_user_id_and_type" | ||
571 | + add_index "profiles", ["user_id"], :name => "index_profiles_on_user_id" | ||
558 | 572 | ||
559 | create_table "qualifier_certifiers", :force => true do |t| | 573 | create_table "qualifier_certifiers", :force => true do |t| |
560 | t.integer "qualifier_id" | 574 | t.integer "qualifier_id" |
lib/noosfero/action_tracker_ext.rb
1 | Rails.configuration.to_prepare do | 1 | Rails.configuration.to_prepare do |
2 | - ActionTracker::Record.module_eval do | 2 | + ActionTracker::Record.class_eval do |
3 | extend CacheCounterHelper | 3 | extend CacheCounterHelper |
4 | 4 | ||
5 | after_create do |record| | 5 | after_create do |record| |
@@ -9,6 +9,11 @@ Rails.configuration.to_prepare do | @@ -9,6 +9,11 @@ Rails.configuration.to_prepare do | ||
9 | end | 9 | end |
10 | end | 10 | end |
11 | 11 | ||
12 | + has_many :profile_activities, foreign_key: :activity_id, conditions: {profile_activities: {activity_type: 'ActionTracker::Record'}}, dependent: :destroy | ||
13 | + | ||
14 | + after_create :create_activity | ||
15 | + after_update :update_activity | ||
16 | + | ||
12 | after_destroy do |record| | 17 | after_destroy do |record| |
13 | if record.created_at >= ActionTracker::Record::RECENT_DELAY.days.ago | 18 | if record.created_at >= ActionTracker::Record::RECENT_DELAY.days.ago |
14 | ActionTracker::Record.update_cache_counter(:activities_count, record.user, -1) | 19 | ActionTracker::Record.update_cache_counter(:activities_count, record.user, -1) |
@@ -17,5 +22,17 @@ Rails.configuration.to_prepare do | @@ -17,5 +22,17 @@ Rails.configuration.to_prepare do | ||
17 | end | 22 | end |
18 | end | 23 | end |
19 | end | 24 | end |
25 | + | ||
26 | + protected | ||
27 | + | ||
28 | + def create_activity | ||
29 | + target = if self.target.is_a? Profile then self.target else self.target.profile rescue self.user end | ||
30 | + return if self.verb.in? target.exclude_verbs_on_activities | ||
31 | + ProfileActivity.create! profile: target, activity: self | ||
32 | + end | ||
33 | + def update_activity | ||
34 | + ProfileActivity.update_activity self | ||
35 | + end | ||
36 | + | ||
20 | end | 37 | end |
21 | end | 38 | end |
test/functional/profile_controller_test.rb
@@ -724,7 +724,7 @@ class ProfileControllerTest < ActionController::TestCase | @@ -724,7 +724,7 @@ class ProfileControllerTest < ActionController::TestCase | ||
724 | 40.times{create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p1))} | 724 | 40.times{create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p1))} |
725 | login_as(p1.identifier) | 725 | login_as(p1.identifier) |
726 | get :index, :profile => p1.identifier | 726 | get :index, :profile => p1.identifier |
727 | - assert_equal 15, assigns(:activities).count | 727 | + assert_equal 15, assigns(:activities).size |
728 | end | 728 | end |
729 | 729 | ||
730 | should 'not see the friends activities in the current profile' do | 730 | should 'not see the friends activities in the current profile' do |
@@ -747,7 +747,7 @@ class ProfileControllerTest < ActionController::TestCase | @@ -747,7 +747,7 @@ class ProfileControllerTest < ActionController::TestCase | ||
747 | login_as(profile.identifier) | 747 | login_as(profile.identifier) |
748 | get :index, :profile => p3.identifier | 748 | get :index, :profile => p3.identifier |
749 | assert_not_nil assigns(:activities) | 749 | assert_not_nil assigns(:activities) |
750 | - assert_equivalent [scrap1, article1.activity], assigns(:activities).map { |a| a.klass.constantize.find(a.id) } | 750 | + assert_equivalent [scrap1, article1.activity], assigns(:activities).map(&:activity) |
751 | end | 751 | end |
752 | 752 | ||
753 | should 'see all the activities in the current profile network' do | 753 | should 'see all the activities in the current profile network' do |
@@ -759,18 +759,17 @@ class ProfileControllerTest < ActionController::TestCase | @@ -759,18 +759,17 @@ class ProfileControllerTest < ActionController::TestCase | ||
759 | p3.add_friend(p1) | 759 | p3.add_friend(p1) |
760 | p1.add_friend(p3) | 760 | p1.add_friend(p3) |
761 | 761 | ||
762 | - ActionTracker::Record.delete_all | 762 | + ActionTracker::Record.destroy_all |
763 | 763 | ||
764 | User.current = p1.user | 764 | User.current = p1.user |
765 | - create(Scrap,defaults_for_scrap(:sender => p1, :receiver => p1)) | 765 | + create(Scrap, sender: p1, receiver: p1) |
766 | a1 = ActionTracker::Record.last | 766 | a1 = ActionTracker::Record.last |
767 | 767 | ||
768 | User.current = p2.user | 768 | User.current = p2.user |
769 | - create(Scrap, defaults_for_scrap(:sender => p2, :receiver => p3)) | ||
770 | - a2 = ActionTracker::Record.last | 769 | + create(Scrap, sender: p2, receiver: p3) |
771 | 770 | ||
772 | User.current = p3.user | 771 | User.current = p3.user |
773 | - create(Scrap, defaults_for_scrap(:sender => p3, :receiver => p1)) | 772 | + create(Scrap, sender: p3, receiver: p1) |
774 | a3 = ActionTracker::Record.last | 773 | a3 = ActionTracker::Record.last |
775 | 774 | ||
776 | process_delayed_job_queue | 775 | process_delayed_job_queue |
@@ -933,9 +932,9 @@ class ProfileControllerTest < ActionController::TestCase | @@ -933,9 +932,9 @@ class ProfileControllerTest < ActionController::TestCase | ||
933 | p1 = fast_create(Person) | 932 | p1 = fast_create(Person) |
934 | p2 = fast_create(Person) | 933 | p2 = fast_create(Person) |
935 | p3 = fast_create(Person) | 934 | p3 = fast_create(Person) |
936 | - s1 = fast_create(Scrap, :sender_id => p1.id, :receiver_id => p2.id) | ||
937 | - s2 = fast_create(Scrap, :sender_id => p2.id, :receiver_id => p1.id) | ||
938 | - s3 = fast_create(Scrap, :sender_id => p3.id, :receiver_id => p1.id) | 935 | + s1 = create(Scrap, :sender_id => p1.id, :receiver_id => p2.id) |
936 | + s2 = create(Scrap, :sender_id => p2.id, :receiver_id => p1.id) | ||
937 | + s3 = create(Scrap, :sender_id => p3.id, :receiver_id => p1.id) | ||
939 | 938 | ||
940 | @controller.stubs(:logged_in?).returns(true) | 939 | @controller.stubs(:logged_in?).returns(true) |
941 | user = mock() | 940 | user = mock() |
@@ -944,7 +943,7 @@ class ProfileControllerTest < ActionController::TestCase | @@ -944,7 +943,7 @@ class ProfileControllerTest < ActionController::TestCase | ||
944 | @controller.stubs(:current_user).returns(user) | 943 | @controller.stubs(:current_user).returns(user) |
945 | Person.any_instance.stubs(:follows?).returns(true) | 944 | Person.any_instance.stubs(:follows?).returns(true) |
946 | get :index, :profile => p1.identifier | 945 | get :index, :profile => p1.identifier |
947 | - assert_equal [s2,s3], assigns(:activities) | 946 | + assert_equal [s3,s2], assigns(:activities).map(&:activity) |
948 | end | 947 | end |
949 | 948 | ||
950 | should 'the activities be the received scraps in community profile' do | 949 | should 'the activities be the received scraps in community profile' do |
@@ -952,9 +951,9 @@ class ProfileControllerTest < ActionController::TestCase | @@ -952,9 +951,9 @@ class ProfileControllerTest < ActionController::TestCase | ||
952 | p1 = fast_create(Person) | 951 | p1 = fast_create(Person) |
953 | p2 = fast_create(Person) | 952 | p2 = fast_create(Person) |
954 | p3 = fast_create(Person) | 953 | p3 = fast_create(Person) |
955 | - s1 = fast_create(Scrap, :sender_id => p1.id, :receiver_id => p2.id) | ||
956 | - s2 = fast_create(Scrap, :sender_id => p2.id, :receiver_id => c.id) | ||
957 | - s3 = fast_create(Scrap, :sender_id => p3.id, :receiver_id => c.id) | 954 | + s1 = create(Scrap, :sender_id => p1.id, :receiver_id => p2.id) |
955 | + s2 = create(Scrap, :sender_id => p2.id, :receiver_id => c.id) | ||
956 | + s3 = create(Scrap, :sender_id => p3.id, :receiver_id => c.id) | ||
958 | 957 | ||
959 | @controller.stubs(:logged_in?).returns(true) | 958 | @controller.stubs(:logged_in?).returns(true) |
960 | user = mock() | 959 | user = mock() |
@@ -963,12 +962,12 @@ class ProfileControllerTest < ActionController::TestCase | @@ -963,12 +962,12 @@ class ProfileControllerTest < ActionController::TestCase | ||
963 | @controller.stubs(:current_user).returns(user) | 962 | @controller.stubs(:current_user).returns(user) |
964 | Person.any_instance.stubs(:follows?).returns(true) | 963 | Person.any_instance.stubs(:follows?).returns(true) |
965 | get :index, :profile => c.identifier | 964 | get :index, :profile => c.identifier |
966 | - assert_equivalent [s2,s3], assigns(:activities) | 965 | + assert_equivalent [s2,s3], assigns(:activities).map(&:activity) |
967 | end | 966 | end |
968 | 967 | ||
969 | should 'the activities be paginated in people profiles' do | 968 | should 'the activities be paginated in people profiles' do |
970 | p1= fast_create(Person) | 969 | p1= fast_create(Person) |
971 | - 40.times{fast_create(Scrap, :receiver_id => p1.id, :created_at => Time.now)} | 970 | + 40.times{create(Scrap, :receiver_id => p1.id, :created_at => Time.now)} |
972 | 971 | ||
973 | @controller.stubs(:logged_in?).returns(true) | 972 | @controller.stubs(:logged_in?).returns(true) |
974 | user = mock() | 973 | user = mock() |
@@ -978,13 +977,13 @@ class ProfileControllerTest < ActionController::TestCase | @@ -978,13 +977,13 @@ class ProfileControllerTest < ActionController::TestCase | ||
978 | Person.any_instance.stubs(:follows?).returns(true) | 977 | Person.any_instance.stubs(:follows?).returns(true) |
979 | assert_equal 40, p1.scraps_received.not_replies.count | 978 | assert_equal 40, p1.scraps_received.not_replies.count |
980 | get :index, :profile => p1.identifier | 979 | get :index, :profile => p1.identifier |
981 | - assert_equal 15, assigns(:activities).count | 980 | + assert_equal 15, assigns(:activities).size |
982 | end | 981 | end |
983 | 982 | ||
984 | should 'the activities be paginated in community profiles' do | 983 | should 'the activities be paginated in community profiles' do |
985 | p1= fast_create(Person) | 984 | p1= fast_create(Person) |
986 | c = fast_create(Community) | 985 | c = fast_create(Community) |
987 | - 40.times{fast_create(Scrap, :receiver_id => c.id)} | 986 | + 40.times{create(Scrap, :receiver_id => c.id)} |
988 | 987 | ||
989 | @controller.stubs(:logged_in?).returns(true) | 988 | @controller.stubs(:logged_in?).returns(true) |
990 | user = mock() | 989 | user = mock() |
@@ -994,7 +993,7 @@ class ProfileControllerTest < ActionController::TestCase | @@ -994,7 +993,7 @@ class ProfileControllerTest < ActionController::TestCase | ||
994 | Person.any_instance.stubs(:follows?).returns(true) | 993 | Person.any_instance.stubs(:follows?).returns(true) |
995 | assert_equal 40, c.scraps_received.not_replies.count | 994 | assert_equal 40, c.scraps_received.not_replies.count |
996 | get :index, :profile => c.identifier | 995 | get :index, :profile => c.identifier |
997 | - assert_equal 15, assigns(:activities).count | 996 | + assert_equal 15, assigns(:activities).size |
998 | end | 997 | end |
999 | 998 | ||
1000 | should "the owner of activity could remove it" do | 999 | should "the owner of activity could remove it" do |
@@ -1140,7 +1139,7 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1140,7 +1139,7 @@ class ProfileControllerTest < ActionController::TestCase | ||
1140 | get :view_more_activities, :profile => profile.identifier, :page => 2 | 1139 | get :view_more_activities, :profile => profile.identifier, :page => 2 |
1141 | assert_response :success | 1140 | assert_response :success |
1142 | assert_template '_profile_activities_list' | 1141 | assert_template '_profile_activities_list' |
1143 | - assert_equal 10, assigns(:activities).count | 1142 | + assert_equal 10, assigns(:activities).size |
1144 | end | 1143 | end |
1145 | 1144 | ||
1146 | should "be logged in to access the view_more_activities action" do | 1145 | should "be logged in to access the view_more_activities action" do |
@@ -1193,8 +1192,8 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1193,8 +1192,8 @@ class ProfileControllerTest < ActionController::TestCase | ||
1193 | should "not index display scraps replies" do | 1192 | should "not index display scraps replies" do |
1194 | login_as(profile.identifier) | 1193 | login_as(profile.identifier) |
1195 | Scrap.destroy_all | 1194 | Scrap.destroy_all |
1196 | - scrap = fast_create(Scrap, :sender_id => profile.id, :receiver_id => profile.id) | ||
1197 | - 20.times {fast_create(Scrap, :sender_id => profile.id, :receiver_id => profile.id, :scrap_id => scrap.id)} | 1195 | + scrap = create(Scrap, :sender_id => profile.id, :receiver_id => profile.id) |
1196 | + 20.times {create(Scrap, :sender_id => profile.id, :receiver_id => profile.id, :scrap_id => scrap.id)} | ||
1198 | profile.reload | 1197 | profile.reload |
1199 | get :index, :profile => profile.identifier | 1198 | get :index, :profile => profile.identifier |
1200 | assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments scrap-replies'}, :children => {:count => 0 } | 1199 | assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments scrap-replies'}, :children => {:count => 0 } |
@@ -1340,7 +1339,7 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1340,7 +1339,7 @@ class ProfileControllerTest < ActionController::TestCase | ||
1340 | login_as(profile.identifier) | 1339 | login_as(profile.identifier) |
1341 | get :index, :profile => profile.identifier | 1340 | get :index, :profile => profile.identifier |
1342 | 1341 | ||
1343 | - assert_equivalent [scrap,activity], assigns(:activities).map {|a| a.klass.constantize.find(a.id)} | 1342 | + assert_equivalent [scrap,activity], assigns(:activities).map(&:activity) |
1344 | end | 1343 | end |
1345 | 1344 | ||
1346 | should "be logged in to leave comment on an activity" do | 1345 | should "be logged in to leave comment on an activity" do |
test/unit/action_tracker_ext_test.rb
1 | require_relative "../test_helper" | 1 | require_relative "../test_helper" |
2 | 2 | ||
3 | class ActionTrackerExtTest < ActiveSupport::TestCase | 3 | class ActionTrackerExtTest < ActiveSupport::TestCase |
4 | + | ||
4 | should 'increase person activities_count on new activity' do | 5 | should 'increase person activities_count on new activity' do |
5 | person = fast_create(Person) | 6 | person = fast_create(Person) |
6 | assert_difference 'person.activities_count', 1 do | 7 | assert_difference 'person.activities_count', 1 do |
@@ -61,4 +62,12 @@ class ActionTrackerExtTest < ActiveSupport::TestCase | @@ -61,4 +62,12 @@ class ActionTrackerExtTest < ActiveSupport::TestCase | ||
61 | organization.reload | 62 | organization.reload |
62 | end | 63 | end |
63 | end | 64 | end |
65 | + | ||
66 | + should 'create profile activity' do | ||
67 | + person = fast_create(Profile) | ||
68 | + organization = fast_create(Enterprise) | ||
69 | + record = create ActionTracker::Record, :verb => :create_product, :user => person, :target => organization | ||
70 | + assert_equal record, organization.activities.first.activity | ||
71 | + end | ||
72 | + | ||
64 | end | 73 | end |
test/unit/community_test.rb
@@ -368,7 +368,7 @@ class CommunityTest < ActiveSupport::TestCase | @@ -368,7 +368,7 @@ class CommunityTest < ActiveSupport::TestCase | ||
368 | scrap = create(Scrap, defaults_for_scrap(:sender => person, :receiver => community, :content => 'A scrap')) | 368 | scrap = create(Scrap, defaults_for_scrap(:sender => person, :receiver => community, :content => 'A scrap')) |
369 | activity = ActionTracker::Record.last | 369 | activity = ActionTracker::Record.last |
370 | 370 | ||
371 | - assert_equal [scrap], community.activities.map { |a| a.klass.constantize.find(a.id) } | 371 | + assert_equal [scrap], community.activities.map(&:activity) |
372 | end | 372 | end |
373 | 373 | ||
374 | should 'return tracked_actions of community as activities' do | 374 | should 'return tracked_actions of community as activities' do |
@@ -378,7 +378,7 @@ class CommunityTest < ActiveSupport::TestCase | @@ -378,7 +378,7 @@ class CommunityTest < ActiveSupport::TestCase | ||
378 | User.current = person.user | 378 | User.current = person.user |
379 | assert_difference 'ActionTracker::Record.count', 1 do | 379 | assert_difference 'ActionTracker::Record.count', 1 do |
380 | article = create(TinyMceArticle, :profile => community, :name => 'An article about free software') | 380 | article = create(TinyMceArticle, :profile => community, :name => 'An article about free software') |
381 | - assert_equal [article.activity], community.activities.map { |a| a.klass.constantize.find(a.id) } | 381 | + assert_equal [article.activity], community.activities.map(&:activity) |
382 | end | 382 | end |
383 | end | 383 | end |
384 | 384 | ||
@@ -393,12 +393,12 @@ class CommunityTest < ActiveSupport::TestCase | @@ -393,12 +393,12 @@ class CommunityTest < ActiveSupport::TestCase | ||
393 | assert_not_includes community.activities.map { |a| a.klass.constantize.find(a.id) }, article.activity | 393 | assert_not_includes community.activities.map { |a| a.klass.constantize.find(a.id) }, article.activity |
394 | end | 394 | end |
395 | 395 | ||
396 | - | 396 | + |
397 | should 'check if a community admin user is really a community admin' do | 397 | should 'check if a community admin user is really a community admin' do |
398 | c = fast_create(Community, :name => 'my test profile', :identifier => 'mytestprofile') | 398 | c = fast_create(Community, :name => 'my test profile', :identifier => 'mytestprofile') |
399 | admin = create_user('adminuser').person | 399 | admin = create_user('adminuser').person |
400 | c.add_admin(admin) | 400 | c.add_admin(admin) |
401 | - | 401 | + |
402 | assert c.is_admin?(admin) | 402 | assert c.is_admin?(admin) |
403 | end | 403 | end |
404 | 404 |
test/unit/enterprise_test.rb
@@ -468,7 +468,7 @@ class EnterpriseTest < ActiveSupport::TestCase | @@ -468,7 +468,7 @@ class EnterpriseTest < ActiveSupport::TestCase | ||
468 | activity = ActionTracker::Record.last | 468 | activity = ActionTracker::Record.last |
469 | scrap = create(Scrap, defaults_for_scrap(:sender => person, :receiver => enterprise, :content => 'A scrap')) | 469 | scrap = create(Scrap, defaults_for_scrap(:sender => person, :receiver => enterprise, :content => 'A scrap')) |
470 | 470 | ||
471 | - assert_equal [scrap], enterprise.activities.map { |a| a.klass.constantize.find(a.id) } | 471 | + assert_equal [scrap], enterprise.activities.map(&:activity) |
472 | end | 472 | end |
473 | 473 | ||
474 | should 'return tracked_actions of community as activities' do | 474 | should 'return tracked_actions of community as activities' do |
@@ -478,7 +478,7 @@ class EnterpriseTest < ActiveSupport::TestCase | @@ -478,7 +478,7 @@ class EnterpriseTest < ActiveSupport::TestCase | ||
478 | User.current = person.user | 478 | User.current = person.user |
479 | article = create(TinyMceArticle, :profile => enterprise, :name => 'An article about free software') | 479 | article = create(TinyMceArticle, :profile => enterprise, :name => 'An article about free software') |
480 | 480 | ||
481 | - assert_equal [article.activity], enterprise.activities.map { |a| a.klass.constantize.find(a.id) } | 481 | + assert_equal [article.activity], enterprise.activities.map(&:activity) |
482 | end | 482 | end |
483 | 483 | ||
484 | should 'not return tracked_actions of other community as activities' do | 484 | should 'not return tracked_actions of other community as activities' do |
@@ -489,7 +489,7 @@ class EnterpriseTest < ActiveSupport::TestCase | @@ -489,7 +489,7 @@ class EnterpriseTest < ActiveSupport::TestCase | ||
489 | User.current = person.user | 489 | User.current = person.user |
490 | article = create(TinyMceArticle, :profile => enterprise2, :name => 'Another article about free software') | 490 | article = create(TinyMceArticle, :profile => enterprise2, :name => 'Another article about free software') |
491 | 491 | ||
492 | - assert_not_includes enterprise.activities.map { |a| a.klass.constantize.find(a.id) }, article.activity | 492 | + assert_not_includes enterprise.activities.map(&:activity), article.activity |
493 | end | 493 | end |
494 | 494 | ||
495 | should 'provide URL to catalog area' do | 495 | should 'provide URL to catalog area' do |
@@ -503,7 +503,7 @@ class EnterpriseTest < ActiveSupport::TestCase | @@ -503,7 +503,7 @@ class EnterpriseTest < ActiveSupport::TestCase | ||
503 | c = fast_create(Enterprise, :name => 'my test profile', :identifier => 'mytestprofile') | 503 | c = fast_create(Enterprise, :name => 'my test profile', :identifier => 'mytestprofile') |
504 | admin = create_user('adminuser').person | 504 | admin = create_user('adminuser').person |
505 | c.add_admin(admin) | 505 | c.add_admin(admin) |
506 | - | 506 | + |
507 | assert c.is_admin?(admin) | 507 | assert c.is_admin?(admin) |
508 | end | 508 | end |
509 | 509 |
test/unit/person_notifier_test.rb
@@ -168,7 +168,8 @@ class PersonNotifierTest < ActiveSupport::TestCase | @@ -168,7 +168,8 @@ class PersonNotifierTest < ActiveSupport::TestCase | ||
168 | a.verb = verb | 168 | a.verb = verb |
169 | a.user = @member | 169 | a.user = @member |
170 | a.created_at = @member.notifier.notify_from + 1.day | 170 | a.created_at = @member.notifier.notify_from + 1.day |
171 | - a.target = fast_create(Forum) | 171 | + profile = create(Community) |
172 | + a.target = create(Forum, profile: profile) | ||
172 | a.comments_count = 0 | 173 | a.comments_count = 0 |
173 | a.params = { | 174 | a.params = { |
174 | 'name' => 'home', 'url' => '/', 'lead' => '', | 175 | 'name' => 'home', 'url' => '/', 'lead' => '', |
test/unit/person_test.rb
@@ -916,7 +916,7 @@ class PersonTest < ActiveSupport::TestCase | @@ -916,7 +916,7 @@ class PersonTest < ActiveSupport::TestCase | ||
916 | refute p2.is_member_of?(community) | 916 | refute p2.is_member_of?(community) |
917 | process_delayed_job_queue | 917 | process_delayed_job_queue |
918 | 918 | ||
919 | - action_tracker = fast_create(ActionTracker::Record, :verb => 'create_article') | 919 | + action_tracker = create(ActionTracker::Record, user: p1, verb: 'create_article') |
920 | action_tracker.target = community | 920 | action_tracker.target = community |
921 | action_tracker.user = p4 | 921 | action_tracker.user = p4 |
922 | action_tracker.save! | 922 | action_tracker.save! |
@@ -1254,7 +1254,7 @@ class PersonTest < ActiveSupport::TestCase | @@ -1254,7 +1254,7 @@ class PersonTest < ActiveSupport::TestCase | ||
1254 | User.current = person.user | 1254 | User.current = person.user |
1255 | article = create(TinyMceArticle, :profile => person, :name => 'An article about free software') | 1255 | article = create(TinyMceArticle, :profile => person, :name => 'An article about free software') |
1256 | 1256 | ||
1257 | - assert_equivalent [scrap,article.activity], person.activities.map { |a| a.klass.constantize.find(a.id) } | 1257 | + assert_equivalent [scrap,article.activity], person.activities.map { |a| a.activity } |
1258 | end | 1258 | end |
1259 | 1259 | ||
1260 | should 'not return tracked_actions and scraps from others as activities' do | 1260 | should 'not return tracked_actions and scraps from others as activities' do |
@@ -1273,7 +1273,7 @@ class PersonTest < ActiveSupport::TestCase | @@ -1273,7 +1273,7 @@ class PersonTest < ActiveSupport::TestCase | ||
1273 | create(TinyMceArticle, :profile => person, :name => 'An article about free software') | 1273 | create(TinyMceArticle, :profile => person, :name => 'An article about free software') |
1274 | person_activity = ActionTracker::Record.last | 1274 | person_activity = ActionTracker::Record.last |
1275 | 1275 | ||
1276 | - assert_equivalent [person_scrap,person_activity], person.activities.map { |a| a.klass.constantize.find(a.id) } | 1276 | + assert_equivalent [person_scrap,person_activity], person.activities.map { |a| a.activity } |
1277 | end | 1277 | end |
1278 | 1278 | ||
1279 | should 'grant every permission over profile for its admin' do | 1279 | should 'grant every permission over profile for its admin' do |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +require_relative '../test_helper' | ||
2 | + | ||
3 | +class ProfileActivityTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + super | ||
7 | + end | ||
8 | + | ||
9 | + should 'use timestamps from activity' do | ||
10 | + profile = fast_create Person | ||
11 | + target = fast_create Person | ||
12 | + | ||
13 | + ActionTracker::Record.attr_accessible :created_at, :updated_at | ||
14 | + tracker = ActionTracker::Record.create! verb: :leave_scrap, user: profile, target: target, created_at: Time.now-2.days, updated_at: Time.now-1.day | ||
15 | + | ||
16 | + pa = ProfileActivity.create! profile: profile, activity: tracker | ||
17 | + assert_equal pa.created_at, pa.activity.created_at | ||
18 | + assert_equal pa.updated_at, pa.activity.updated_at | ||
19 | + end | ||
20 | + | ||
21 | +end |
test/unit/scrap_notifier_test.rb
@@ -58,7 +58,7 @@ class ScrapNotifierTest < ActiveSupport::TestCase | @@ -58,7 +58,7 @@ class ScrapNotifierTest < ActiveSupport::TestCase | ||
58 | should 'not deliver mail if is a reply on a community' do | 58 | should 'not deliver mail if is a reply on a community' do |
59 | community = fast_create(Community) | 59 | community = fast_create(Community) |
60 | person = create_user.person | 60 | person = create_user.person |
61 | - scrap = fast_create(Scrap, :receiver_id => community.id, :sender_id => @sender.id) | 61 | + scrap = create(Scrap, receiver_id: community.id, sender_id: @sender.id) |
62 | assert_no_difference 'ActionMailer::Base.deliveries.size' do | 62 | assert_no_difference 'ActionMailer::Base.deliveries.size' do |
63 | Scrap.create!(:sender_id => person.id, :receiver_id => @sender.id, :scrap_id => scrap.id, :content => 'Hi myself!') | 63 | Scrap.create!(:sender_id => person.id, :receiver_id => @sender.id, :scrap_id => scrap.id, :content => 'Hi myself!') |
64 | end | 64 | end |
test/unit/scrap_test.rb
@@ -3,8 +3,8 @@ require_relative "../test_helper" | @@ -3,8 +3,8 @@ require_relative "../test_helper" | ||
3 | class ScrapTest < ActiveSupport::TestCase | 3 | class ScrapTest < ActiveSupport::TestCase |
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | - Person.delete_all | ||
7 | - Scrap.delete_all | 6 | + Person.destroy_all |
7 | + Scrap.destroy_all | ||
8 | ActionTracker::Record.destroy_all | 8 | ActionTracker::Record.destroy_all |
9 | end | 9 | end |
10 | 10 | ||
@@ -126,16 +126,16 @@ class ScrapTest < ActiveSupport::TestCase | @@ -126,16 +126,16 @@ class ScrapTest < ActiveSupport::TestCase | ||
126 | p1 = create_user.person | 126 | p1 = create_user.person |
127 | p2 = create_user.person | 127 | p2 = create_user.person |
128 | p1.add_friend(p2) | 128 | p1.add_friend(p2) |
129 | - ActionTrackerNotification.delete_all | ||
130 | - Delayed::Job.delete_all | 129 | + process_delayed_job_queue |
131 | s = Scrap.new | 130 | s = Scrap.new |
132 | s.sender= p1 | 131 | s.sender= p1 |
133 | s.receiver= p2 | 132 | s.receiver= p2 |
134 | s.content = 'some content' | 133 | s.content = 'some content' |
135 | s.save! | 134 | s.save! |
136 | - process_delayed_job_queue | ||
137 | - assert_equal 2, ActionTrackerNotification.count | ||
138 | - ActionTrackerNotification.all.map{|a|a.profile}.map do |profile| | 135 | + assert_difference 'ActionTrackerNotification.count', 2 do |
136 | + process_delayed_job_queue | ||
137 | + end | ||
138 | + ActionTrackerNotification.all.map(&:profile).map do |profile| | ||
139 | assert [p1,p2].include?(profile) | 139 | assert [p1,p2].include?(profile) |
140 | end | 140 | end |
141 | end | 141 | end |
@@ -151,7 +151,9 @@ class ScrapTest < ActiveSupport::TestCase | @@ -151,7 +151,9 @@ class ScrapTest < ActiveSupport::TestCase | ||
151 | s.receiver= c | 151 | s.receiver= c |
152 | s.content = 'some content' | 152 | s.content = 'some content' |
153 | s.save! | 153 | s.save! |
154 | - process_delayed_job_queue | 154 | + assert_difference 'ActionTrackerNotification.count', 2 do |
155 | + process_delayed_job_queue | ||
156 | + end | ||
155 | assert_equal 2, ActionTrackerNotification.count | 157 | assert_equal 2, ActionTrackerNotification.count |
156 | ActionTrackerNotification.all.map{|a|a.profile}.map do |profile| | 158 | ActionTrackerNotification.all.map{|a|a.profile}.map do |profile| |
157 | assert [p,c].include?(profile) | 159 | assert [p,c].include?(profile) |
@@ -183,8 +185,9 @@ class ScrapTest < ActiveSupport::TestCase | @@ -183,8 +185,9 @@ class ScrapTest < ActiveSupport::TestCase | ||
183 | s.receiver= p1 | 185 | s.receiver= p1 |
184 | s.content = 'some content' | 186 | s.content = 'some content' |
185 | s.save! | 187 | s.save! |
186 | - process_delayed_job_queue | ||
187 | - assert_equal 2, ActionTrackerNotification.count | 188 | + assert_difference 'ActionTrackerNotification.count', 2 do |
189 | + process_delayed_job_queue | ||
190 | + end | ||
188 | ActionTrackerNotification.all.map{|a|a.profile}.map do |profile| | 191 | ActionTrackerNotification.all.map{|a|a.profile}.map do |profile| |
189 | assert [p1,p2].include?(profile) | 192 | assert [p1,p2].include?(profile) |
190 | end | 193 | end |
@@ -218,7 +221,7 @@ class ScrapTest < ActiveSupport::TestCase | @@ -218,7 +221,7 @@ class ScrapTest < ActiveSupport::TestCase | ||
218 | 221 | ||
219 | should "update the scrap on reply creation" do | 222 | should "update the scrap on reply creation" do |
220 | person = create_user.person | 223 | person = create_user.person |
221 | - s = fast_create(Scrap, :updated_at => DateTime.parse('2010-01-01')) | 224 | + s = create(Scrap, sender: person, receiver: person, updated_at: DateTime.parse('2010-01-01')) |
222 | assert_equal DateTime.parse('2010-01-01'), s.updated_at.strftime('%Y-%m-%d') | 225 | assert_equal DateTime.parse('2010-01-01'), s.updated_at.strftime('%Y-%m-%d') |
223 | DateTime.stubs(:now).returns(DateTime.parse('2010-09-07')) | 226 | DateTime.stubs(:now).returns(DateTime.parse('2010-09-07')) |
224 | s1 = create(Scrap, :content => 'some content', :sender => person, :receiver => person, :scrap_id => s.id) | 227 | s1 = create(Scrap, :content => 'some content', :sender => person, :receiver => person, :scrap_id => s.id) |
@@ -288,7 +291,7 @@ class ScrapTest < ActiveSupport::TestCase | @@ -288,7 +291,7 @@ class ScrapTest < ActiveSupport::TestCase | ||
288 | 291 | ||
289 | should 'create activity with reply_scrap_on_self when top_root scrap receiver is the same as sender' do | 292 | should 'create activity with reply_scrap_on_self when top_root scrap receiver is the same as sender' do |
290 | s, r = create_user.person, create_user.person | 293 | s, r = create_user.person, create_user.person |
291 | - root = fast_create(Scrap, :sender_id => s.id, :receiver_id => r.id) | 294 | + root = create(Scrap, :sender_id => s.id, :receiver_id => r.id) |
292 | assert_difference 'ActionTracker::Record.count', 1 do | 295 | assert_difference 'ActionTracker::Record.count', 1 do |
293 | reply = create(Scrap, :sender => r, :receiver => s, :scrap_id => root.id, :content => 'sample') | 296 | reply = create(Scrap, :sender => r, :receiver => s, :scrap_id => root.id, :content => 'sample') |
294 | end | 297 | end |
@@ -296,4 +299,10 @@ class ScrapTest < ActiveSupport::TestCase | @@ -296,4 +299,10 @@ class ScrapTest < ActiveSupport::TestCase | ||
296 | assert_equal 'reply_scrap_on_self', activity.verb.to_s | 299 | assert_equal 'reply_scrap_on_self', activity.verb.to_s |
297 | end | 300 | end |
298 | 301 | ||
302 | + should 'create profile activity' do | ||
303 | + p1, p2 = create_user.person, create_user.person | ||
304 | + s = create Scrap, :sender => p1, :receiver => p2, :content => "Hello!" | ||
305 | + assert_equal s, p2.activities.first.activity | ||
306 | + end | ||
307 | + | ||
299 | end | 308 | end |