acts_as_messenger 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts_as_messenger}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mike Nelson"]
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  "generators/acts_as_messenger/templates/models/message_thread.rb",
31
31
  "generators/acts_as_messenger/templates/models/recipient.rb",
32
32
  "lib/acts_as_messenger.rb",
33
+ "lib/acts_as_messenger/message.rb",
33
34
  "lib/acts_as_messenger/thread.rb",
34
35
  "spec/acts_as_messenger_spec.rb",
35
36
  "spec/database.yml",
@@ -1,50 +1,2 @@
1
- module SocialButterfly
2
- module Message
3
- def self.included(model)
4
- model.extend(SocialButterfly::Message::ClassMethods)
5
- model.send(:include, SocialButterfly::Message::InstanceMethods)
6
- end
7
-
8
- module ClassMethods
9
- def acts_as_messenger
10
- has_many :recipients, :as => :receiver
11
- has_many :unread_recipients, :source => :recipients, :class_name => 'Recipient', :as => :receiver, :conditions => {:read => false}
12
- has_many :read_recipients, :source => :recipients, :class_name => 'Recipient', :as => :receiver, :conditions => {:read => true}
13
-
14
- has_many :sent_messages, :class_name => 'MessageThread', :foreign_key => :author_id
15
- has_many :unread_messages, :through => :unread_recipients, :source => :message_thread
16
- has_many :read_messages, :through => :read_recipients, :source => :message_thread
17
- end
18
- end
19
-
20
- module InstanceMethods
21
- def send_message(title, body, recips)
22
- thread = ::MessageThread.create(:author => self, :title => title, :body => body, :private_thread => true)
23
- thread.recipients = [recips].flatten.uniq.collect{|r| rdata = recipient_data(r); thread.recipients.create(:receiver_id => rdata[0], :receiver_type => rdata[1])}
24
- thread
25
- end
26
- def recipient_for(message)
27
- self.recipients.find(:first, :conditions => ['message_thread_id = ?', message.id])
28
- end
29
-
30
- def comment_on(message, body)
31
- if message && body
32
- message.comments.create(:author => self, :body => body)
33
- recip = recipient_for(message)
34
- (message.recipients - [recip].compact).each{|r| r.unread!}
35
- true
36
- else
37
- false
38
- end
39
- end
40
-
41
- private
42
-
43
- def recipient_data(given)
44
- given.is_a?(Fixnum) && [given, self.class.name] || [given.id, given.class.name]
45
- end
46
- end
47
- end
48
- end
49
-
50
- ::ActiveRecord::Base.send :include, SocialButterfly::Message
1
+ require File.dirname(__FILE__) + '/acts_as_messenger/thread.rb'
2
+ require File.dirname(__FILE__) + '/acts_as_messenger/message.rb'
@@ -0,0 +1,50 @@
1
+ module SocialButterfly
2
+ module Message
3
+ def self.included(model)
4
+ model.extend(SocialButterfly::Message::ClassMethods)
5
+ model.send(:include, SocialButterfly::Message::InstanceMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ def acts_as_messenger
10
+ has_many :recipients, :as => :receiver
11
+ has_many :unread_recipients, :source => :recipients, :class_name => 'Recipient', :as => :receiver, :conditions => {:read => false}
12
+ has_many :read_recipients, :source => :recipients, :class_name => 'Recipient', :as => :receiver, :conditions => {:read => true}
13
+
14
+ has_many :sent_messages, :class_name => 'MessageThread', :foreign_key => :author_id
15
+ has_many :unread_messages, :through => :unread_recipients, :source => :message_thread
16
+ has_many :read_messages, :through => :read_recipients, :source => :message_thread
17
+ end
18
+ end
19
+
20
+ module InstanceMethods
21
+ def send_message(title, body, recips)
22
+ thread = ::MessageThread.create(:author => self, :title => title, :body => body, :private_thread => true)
23
+ thread.recipients = [recips].flatten.uniq.collect{|r| rdata = recipient_data(r); thread.recipients.create(:receiver_id => rdata[0], :receiver_type => rdata[1])}
24
+ thread
25
+ end
26
+ def recipient_for(message)
27
+ self.recipients.find(:first, :conditions => ['message_thread_id = ?', message.id])
28
+ end
29
+
30
+ def comment_on(message, body)
31
+ if message && body
32
+ message.comments.create(:author => self, :body => body)
33
+ recip = recipient_for(message)
34
+ (message.recipients - [recip].compact).each{|r| r.unread!}
35
+ true
36
+ else
37
+ false
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def recipient_data(given)
44
+ given.is_a?(Fixnum) && [given, self.class.name] || [given.id, given.class.name]
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ ::ActiveRecord::Base.send :include, SocialButterfly::Message
@@ -2517,3 +2517,236 @@
2517
2517
  User Load (0.5ms) SELECT * FROM `users` WHERE (`users`.`id` IN (20,21)) 
2518
2518
  Recipient Load (0.3ms) SELECT * FROM `recipients` WHERE (`recipients`.message_thread_id = 7) ORDER BY has_read ASC, created_at DESC
2519
2519
  User Load (0.2ms) SELECT * FROM `users` WHERE (`users`.`id` IN (20,21)) 
2520
+ SQL (0.1ms) SET NAMES 'utf8'
2521
+ SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
2522
+ SQL (72.5ms) SHOW TABLES
2523
+ SQL (44.3ms) DROP TABLE `comments`
2524
+ SQL (81.9ms) CREATE TABLE `comments` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `commentable_id` int(11), `commentable_type` varchar(255), `author_id` int(11), `body` text, `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
2525
+ SQL (0.6ms) SHOW TABLES
2526
+ SQL (2.5ms) DROP TABLE `message_threads`
2527
+ SQL (333.6ms) CREATE TABLE `message_threads` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `author_id` int(11), `title` varchar(255), `body` text, `private_thread` tinyint(1) DEFAULT 1, `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
2528
+ SQL (1.2ms) SHOW TABLES
2529
+ SQL (5.9ms) DROP TABLE `recipients`
2530
+ SQL (113.4ms) CREATE TABLE `recipients` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `receiver_id` int(11), `receiver_type` varchar(255), `message_thread_id` int(11), `has_read` tinyint(1), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
2531
+ SQL (0.7ms) SHOW TABLES
2532
+ SQL (3.1ms) DROP TABLE `users`
2533
+ SQL (141.2ms) CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
2534
+ SQL (0.9ms) SHOW TABLES
2535
+ SQL (0.9ms) SELECT version FROM `schema_migrations`
2536
+ User Columns (1.7ms) SHOW FIELDS FROM `users`
2537
+ SQL (0.1ms) BEGIN
2538
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-02 01:10:39', '2010-02-02 01:10:39')
2539
+ SQL (0.6ms) COMMIT
2540
+ SQL (0.1ms) BEGIN
2541
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('John', '2010-02-02 01:10:39', '2010-02-02 01:10:39')
2542
+ SQL (0.5ms) COMMIT
2543
+ SQL (0.2ms) BEGIN
2544
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Sky', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2545
+ SQL (18.9ms) COMMIT
2546
+ SQL (0.2ms) BEGIN
2547
+ User Create (0.3ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2548
+ SQL (0.7ms) COMMIT
2549
+ SQL (0.1ms) BEGIN
2550
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('John', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2551
+ SQL (0.6ms) COMMIT
2552
+ SQL (0.1ms) BEGIN
2553
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Sky', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2554
+ SQL (0.6ms) COMMIT
2555
+ MessageThread Columns (1.6ms) SHOW FIELDS FROM `message_threads`
2556
+ SQL (0.1ms) BEGIN
2557
+ MessageThread Create (0.2ms) INSERT INTO `message_threads` (`created_at`, `title`, `body`, `updated_at`, `private_thread`, `author_id`) VALUES('2010-02-02 01:10:40', 'Title', 'Body', '2010-02-02 01:10:40', 1, 4)
2558
+ SQL (0.6ms) COMMIT
2559
+ Recipient Columns (1.3ms) SHOW FIELDS FROM `recipients`
2560
+ SQL (0.1ms) BEGIN
2561
+ Recipient Create (0.2ms) INSERT INTO `recipients` (`receiver_type`, `created_at`, `receiver_id`, `updated_at`, `has_read`, `message_thread_id`) VALUES('User', '2010-02-02 01:10:40', 5, '2010-02-02 01:10:40', NULL, 1)
2562
+ SQL (0.5ms) COMMIT
2563
+ Recipient Load (0.3ms) SELECT * FROM `recipients` WHERE (`recipients`.message_thread_id = 1) ORDER BY has_read ASC, created_at DESC
2564
+ SQL (0.1ms) BEGIN
2565
+ SQL (0.1ms) COMMIT
2566
+ SQL (0.1ms) BEGIN
2567
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2568
+ SQL (0.6ms) COMMIT
2569
+ SQL (0.1ms) BEGIN
2570
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('John', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2571
+ SQL (8.1ms) COMMIT
2572
+ SQL (0.1ms) BEGIN
2573
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Sky', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2574
+ SQL (0.5ms) COMMIT
2575
+ SQL (0.1ms) BEGIN
2576
+ MessageThread Create (0.2ms) INSERT INTO `message_threads` (`created_at`, `title`, `body`, `updated_at`, `private_thread`, `author_id`) VALUES('2010-02-02 01:10:40', 'Title 1', 'Body 1', '2010-02-02 01:10:40', 1, 7)
2577
+ SQL (0.5ms) COMMIT
2578
+ SQL (0.1ms) BEGIN
2579
+ Recipient Create (0.3ms) INSERT INTO `recipients` (`receiver_type`, `created_at`, `receiver_id`, `updated_at`, `has_read`, `message_thread_id`) VALUES('User', '2010-02-02 01:10:40', 8, '2010-02-02 01:10:40', NULL, 2)
2580
+ SQL (0.5ms) COMMIT
2581
+ Recipient Load (0.3ms) SELECT * FROM `recipients` WHERE (`recipients`.message_thread_id = 2) ORDER BY has_read ASC, created_at DESC
2582
+ SQL (0.1ms) BEGIN
2583
+ SQL (0.1ms) COMMIT
2584
+ SQL (0.3ms) SELECT count(*) AS count_all FROM `recipients` WHERE (`recipients`.receiver_id = 8 AND `recipients`.receiver_type = 'User') 
2585
+ SQL (0.2ms) SELECT count(*) AS count_all FROM `recipients` WHERE (`recipients`.receiver_id = 7 AND `recipients`.receiver_type = 'User') 
2586
+ SQL (0.1ms) BEGIN
2587
+ MessageThread Create (0.2ms) INSERT INTO `message_threads` (`created_at`, `title`, `body`, `updated_at`, `private_thread`, `author_id`) VALUES('2010-02-02 01:10:40', 'Title 2', 'Body 2', '2010-02-02 01:10:40', 1, 8)
2588
+ SQL (0.5ms) COMMIT
2589
+ SQL (0.1ms) BEGIN
2590
+ Recipient Create (0.2ms) INSERT INTO `recipients` (`receiver_type`, `created_at`, `receiver_id`, `updated_at`, `has_read`, `message_thread_id`) VALUES('User', '2010-02-02 01:10:40', 7, '2010-02-02 01:10:40', NULL, 3)
2591
+ SQL (0.5ms) COMMIT
2592
+ SQL (0.1ms) BEGIN
2593
+ Recipient Create (0.1ms) INSERT INTO `recipients` (`receiver_type`, `created_at`, `receiver_id`, `updated_at`, `has_read`, `message_thread_id`) VALUES('User', '2010-02-02 01:10:40', 9, '2010-02-02 01:10:40', NULL, 3)
2594
+ SQL (0.5ms) COMMIT
2595
+ Recipient Load (0.3ms) SELECT * FROM `recipients` WHERE (`recipients`.message_thread_id = 3) ORDER BY has_read ASC, created_at DESC
2596
+ SQL (0.1ms) BEGIN
2597
+ SQL (0.1ms) COMMIT
2598
+ User Load (0.2ms) SELECT * FROM `users` WHERE (`users`.`id` = 7) 
2599
+ User Load (0.1ms) SELECT * FROM `users` WHERE (`users`.`id` = 8) 
2600
+ User Load (0.1ms) SELECT * FROM `users` WHERE (`users`.`id` = 9) 
2601
+ SQL (0.2ms) SELECT count(*) AS count_all FROM `recipients` WHERE (`recipients`.receiver_id = 7 AND `recipients`.receiver_type = 'User') 
2602
+ SQL (0.2ms) SELECT count(*) AS count_all FROM `recipients` WHERE (`recipients`.receiver_id = 8 AND `recipients`.receiver_type = 'User') 
2603
+ SQL (0.2ms) SELECT count(*) AS count_all FROM `recipients` WHERE (`recipients`.receiver_id = 9 AND `recipients`.receiver_type = 'User') 
2604
+ SQL (0.1ms) BEGIN
2605
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2606
+ SQL (0.6ms) COMMIT
2607
+ SQL (0.1ms) BEGIN
2608
+ User Create (0.1ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('John', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2609
+ SQL (1.0ms) COMMIT
2610
+ SQL (0.1ms) BEGIN
2611
+ User Create (0.1ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Sky', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2612
+ SQL (0.5ms) COMMIT
2613
+ SQL (0.1ms) BEGIN
2614
+ MessageThread Create (0.2ms) INSERT INTO `message_threads` (`created_at`, `title`, `body`, `updated_at`, `private_thread`, `author_id`) VALUES('2010-02-02 01:10:40', 'Title 3', 'Body 3', '2010-02-02 01:10:40', 1, 10)
2615
+ SQL (0.6ms) COMMIT
2616
+ SQL (0.1ms) BEGIN
2617
+ Recipient Create (0.2ms) INSERT INTO `recipients` (`receiver_type`, `created_at`, `receiver_id`, `updated_at`, `has_read`, `message_thread_id`) VALUES('User', '2010-02-02 01:10:40', 11, '2010-02-02 01:10:40', NULL, 4)
2618
+ SQL (0.5ms) COMMIT
2619
+ SQL (0.1ms) BEGIN
2620
+ Recipient Create (0.1ms) INSERT INTO `recipients` (`receiver_type`, `created_at`, `receiver_id`, `updated_at`, `has_read`, `message_thread_id`) VALUES('User', '2010-02-02 01:10:40', 12, '2010-02-02 01:10:40', NULL, 4)
2621
+ SQL (0.5ms) COMMIT
2622
+ Recipient Load (0.3ms) SELECT * FROM `recipients` WHERE (`recipients`.message_thread_id = 4) ORDER BY has_read ASC, created_at DESC
2623
+ SQL (0.1ms) BEGIN
2624
+ SQL (0.1ms) COMMIT
2625
+ Recipient Load (0.2ms) SELECT * FROM `recipients` WHERE (`recipients`.receiver_id = 11 AND `recipients`.receiver_type = 'User') ORDER BY has_read ASC, created_at DESC LIMIT 1
2626
+ SQL (0.1ms) BEGIN
2627
+ Recipient Update (0.2ms) UPDATE `recipients` SET `updated_at` = '2010-02-02 01:10:40', `has_read` = 1 WHERE `id` = 5
2628
+ SQL (0.6ms) COMMIT
2629
+ SQL (0.4ms) SELECT count(*) AS count_all FROM `recipients` WHERE (((has_read = 1) AND (`recipients`.receiver_id = 11 AND `recipients`.receiver_type = 'User')) AND (`recipients`.receiver_id = 11 AND `recipients`.receiver_type = 'User')) 
2630
+ SQL (0.3ms) SELECT count(*) AS count_all FROM `recipients` WHERE (((has_read = 0) AND (`recipients`.receiver_id = 11 AND `recipients`.receiver_type = 'User')) AND (`recipients`.receiver_id = 11 AND `recipients`.receiver_type = 'User')) 
2631
+ Comment Columns (1.4ms) SHOW FIELDS FROM `comments`
2632
+ SQL (0.1ms) BEGIN
2633
+ Comment Create (0.2ms) INSERT INTO `comments` (`created_at`, `commentable_type`, `body`, `commentable_id`, `updated_at`, `author_id`) VALUES('2010-02-02 01:10:40', 'MessageThread', 'This is totally awesome', 4, '2010-02-02 01:10:40', 12)
2634
+ SQL (0.5ms) COMMIT
2635
+ Recipient Load (0.3ms) SELECT * FROM `recipients` WHERE (`recipients`.receiver_id = 12 AND `recipients`.receiver_type = 'User' AND (message_thread_id = 4)) ORDER BY has_read ASC, created_at DESC LIMIT 1
2636
+ SQL (0.1ms) BEGIN
2637
+ Recipient Update (0.2ms) UPDATE `recipients` SET `updated_at` = '2010-02-02 01:10:40', `has_read` = 0 WHERE `id` = 5
2638
+ SQL (0.5ms) COMMIT
2639
+ SQL (0.2ms) SELECT count(*) AS count_all FROM `recipients` WHERE (((has_read = 0) AND (`recipients`.receiver_id = 11 AND `recipients`.receiver_type = 'User')) AND (`recipients`.receiver_id = 11 AND `recipients`.receiver_type = 'User')) 
2640
+ SQL (0.7ms) SELECT count(*) AS count_all FROM `recipients` WHERE (((has_read = 1) AND (`recipients`.receiver_id = 11 AND `recipients`.receiver_type = 'User')) AND (`recipients`.receiver_id = 11 AND `recipients`.receiver_type = 'User')) 
2641
+ Recipient Load (0.3ms) SELECT * FROM `recipients` WHERE (`recipients`.receiver_id = 11 AND `recipients`.receiver_type = 'User') ORDER BY has_read ASC, created_at DESC LIMIT 1
2642
+ SQL (0.1ms) BEGIN
2643
+ Recipient Destroy (0.2ms) DELETE FROM `recipients` WHERE `id` = 5
2644
+ SQL (0.7ms) COMMIT
2645
+ SQL (0.1ms) BEGIN
2646
+ Comment Create (0.2ms) INSERT INTO `comments` (`created_at`, `commentable_type`, `body`, `commentable_id`, `updated_at`, `author_id`) VALUES('2010-02-02 01:10:40', 'MessageThread', 'Seriously, i love this', 4, '2010-02-02 01:10:40', 12)
2647
+ SQL (0.6ms) COMMIT
2648
+ Recipient Load (0.3ms) SELECT * FROM `recipients` WHERE (`recipients`.receiver_id = 12 AND `recipients`.receiver_type = 'User' AND (message_thread_id = 4)) ORDER BY has_read ASC, created_at DESC LIMIT 1
2649
+ SQL (0.1ms) BEGIN
2650
+ SQL (0.1ms) COMMIT
2651
+ SQL (0.2ms) SELECT count(*) AS count_all FROM `recipients` WHERE (`recipients`.receiver_id = 11 AND `recipients`.receiver_type = 'User') 
2652
+ SQL (0.1ms) BEGIN
2653
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2654
+ SQL (0.7ms) COMMIT
2655
+ SQL (0.1ms) BEGIN
2656
+ User Create (0.1ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('John', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2657
+ SQL (0.6ms) COMMIT
2658
+ SQL (0.1ms) BEGIN
2659
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Sky', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2660
+ SQL (0.7ms) COMMIT
2661
+ SQL (0.1ms) BEGIN
2662
+ MessageThread Create (0.2ms) INSERT INTO `message_threads` (`created_at`, `title`, `body`, `updated_at`, `private_thread`, `author_id`) VALUES('2010-02-02 01:10:40', 'Title 4', 'Body 4', '2010-02-02 01:10:40', 1, 13)
2663
+ SQL (0.6ms) COMMIT
2664
+ SQL (0.1ms) BEGIN
2665
+ Recipient Create (0.2ms) INSERT INTO `recipients` (`receiver_type`, `created_at`, `receiver_id`, `updated_at`, `has_read`, `message_thread_id`) VALUES('User', '2010-02-02 01:10:40', 14, '2010-02-02 01:10:40', NULL, 5)
2666
+ SQL (0.5ms) COMMIT
2667
+ SQL (0.1ms) BEGIN
2668
+ Recipient Create (0.2ms) INSERT INTO `recipients` (`receiver_type`, `created_at`, `receiver_id`, `updated_at`, `has_read`, `message_thread_id`) VALUES('User', '2010-02-02 01:10:40', 15, '2010-02-02 01:10:40', NULL, 5)
2669
+ SQL (0.7ms) COMMIT
2670
+ Recipient Load (0.3ms) SELECT * FROM `recipients` WHERE (`recipients`.message_thread_id = 5) ORDER BY has_read ASC, created_at DESC
2671
+ SQL (0.1ms) BEGIN
2672
+ SQL (0.1ms) COMMIT
2673
+ SQL (0.2ms) SELECT count(*) AS count_all FROM `recipients` WHERE (`recipients`.receiver_id = 14 AND `recipients`.receiver_type = 'User') 
2674
+ SQL (0.1ms) BEGIN
2675
+ Comment Load (0.2ms) SELECT * FROM `comments` WHERE (`comments`.commentable_id = 5 AND `comments`.commentable_type = 'MessageThread') ORDER BY created_at asc
2676
+ Recipient Destroy (0.2ms) DELETE FROM `recipients` WHERE `id` = 7
2677
+ Recipient Destroy (0.1ms) DELETE FROM `recipients` WHERE `id` = 8
2678
+ MessageThread Destroy (0.1ms) DELETE FROM `message_threads` WHERE `id` = 5
2679
+ SQL (0.6ms) COMMIT
2680
+ SQL (0.2ms) SELECT count(*) AS count_all FROM `recipients` WHERE (`recipients`.receiver_id = 14 AND `recipients`.receiver_type = 'User') 
2681
+ SQL (0.2ms) SELECT count(*) AS count_all FROM `recipients` WHERE (`recipients`.receiver_id = 15 AND `recipients`.receiver_type = 'User') 
2682
+ SQL (0.1ms) BEGIN
2683
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2684
+ SQL (0.6ms) COMMIT
2685
+ SQL (0.1ms) BEGIN
2686
+ User Create (0.1ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('John', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2687
+ SQL (0.6ms) COMMIT
2688
+ SQL (0.1ms) BEGIN
2689
+ User Create (0.1ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Sky', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2690
+ SQL (0.6ms) COMMIT
2691
+ SQL (0.1ms) BEGIN
2692
+ MessageThread Create (0.2ms) INSERT INTO `message_threads` (`created_at`, `title`, `body`, `updated_at`, `private_thread`, `author_id`) VALUES('2010-02-02 01:10:40', 'Title 5', 'Body 5', '2010-02-02 01:10:40', 1, 16)
2693
+ SQL (0.6ms) COMMIT
2694
+ SQL (0.1ms) BEGIN
2695
+ Recipient Create (0.2ms) INSERT INTO `recipients` (`receiver_type`, `created_at`, `receiver_id`, `updated_at`, `has_read`, `message_thread_id`) VALUES('User', '2010-02-02 01:10:40', 17, '2010-02-02 01:10:40', NULL, 6)
2696
+ SQL (0.6ms) COMMIT
2697
+ SQL (0.1ms) BEGIN
2698
+ Recipient Create (0.1ms) INSERT INTO `recipients` (`receiver_type`, `created_at`, `receiver_id`, `updated_at`, `has_read`, `message_thread_id`) VALUES('User', '2010-02-02 01:10:40', 18, '2010-02-02 01:10:40', NULL, 6)
2699
+ SQL (0.5ms) COMMIT
2700
+ Recipient Load (0.3ms) SELECT * FROM `recipients` WHERE (`recipients`.message_thread_id = 6) ORDER BY has_read ASC, created_at DESC
2701
+ SQL (0.1ms) BEGIN
2702
+ SQL (0.1ms) COMMIT
2703
+ User Load (0.3ms) SELECT DISTINCT `users`.* FROM `users` INNER JOIN `comments` ON `users`.id = `comments`.author_id WHERE ((`comments`.commentable_type = 'MessageThread') AND (`comments`.commentable_id = 6)) 
2704
+ SQL (0.1ms) BEGIN
2705
+ Comment Create (0.2ms) INSERT INTO `comments` (`created_at`, `commentable_type`, `body`, `commentable_id`, `updated_at`, `author_id`) VALUES('2010-02-02 01:10:40', 'MessageThread', 'Test', 6, '2010-02-02 01:10:40', 17)
2706
+ SQL (0.6ms) COMMIT
2707
+ Recipient Load (0.3ms) SELECT * FROM `recipients` WHERE (`recipients`.receiver_id = 17 AND `recipients`.receiver_type = 'User' AND (message_thread_id = 6)) ORDER BY has_read ASC, created_at DESC LIMIT 1
2708
+ SQL (0.1ms) BEGIN
2709
+ Recipient Update (0.2ms) UPDATE `recipients` SET `updated_at` = '2010-02-02 01:10:40', `has_read` = 0 WHERE `id` = 10
2710
+ SQL (0.7ms) COMMIT
2711
+ MessageThread Load (0.2ms) SELECT * FROM `message_threads` WHERE (`message_threads`.`id` = 6) 
2712
+ User Load (0.2ms) SELECT * FROM `users` WHERE (`users`.`id` = 16) 
2713
+ User Load (0.3ms) SELECT DISTINCT `users`.* FROM `users` INNER JOIN `comments` ON `users`.id = `comments`.author_id WHERE ((`comments`.commentable_type = 'MessageThread') AND (`comments`.commentable_id = 6)) 
2714
+ SQL (0.1ms) BEGIN
2715
+ Comment Create (0.2ms) INSERT INTO `comments` (`created_at`, `commentable_type`, `body`, `commentable_id`, `updated_at`, `author_id`) VALUES('2010-02-02 01:10:40', 'MessageThread', 'Tester', 6, '2010-02-02 01:10:40', 18)
2716
+ SQL (0.5ms) COMMIT
2717
+ Recipient Load (0.3ms) SELECT * FROM `recipients` WHERE (`recipients`.receiver_id = 18 AND `recipients`.receiver_type = 'User' AND (message_thread_id = 6)) ORDER BY has_read ASC, created_at DESC LIMIT 1
2718
+ Recipient Load (0.2ms) SELECT * FROM `recipients` WHERE (`recipients`.message_thread_id = 6) ORDER BY has_read ASC, created_at DESC
2719
+ SQL (0.1ms) BEGIN
2720
+ Recipient Update (0.2ms) UPDATE `recipients` SET `updated_at` = '2010-02-02 01:10:40', `has_read` = 0 WHERE `id` = 9
2721
+ SQL (0.5ms) COMMIT
2722
+ MessageThread Load (0.2ms) SELECT * FROM `message_threads` WHERE (`message_threads`.`id` = 6) 
2723
+ User Load (0.1ms) SELECT * FROM `users` WHERE (`users`.`id` = 16) 
2724
+ User Load (0.2ms) SELECT DISTINCT `users`.* FROM `users` INNER JOIN `comments` ON `users`.id = `comments`.author_id WHERE ((`comments`.commentable_type = 'MessageThread') AND (`comments`.commentable_id = 6)) 
2725
+ SQL (0.1ms) BEGIN
2726
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Mike', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2727
+ SQL (0.5ms) COMMIT
2728
+ SQL (0.1ms) BEGIN
2729
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('John', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2730
+ SQL (0.6ms) COMMIT
2731
+ SQL (0.1ms) BEGIN
2732
+ User Create (0.1ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES('Sky', '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2733
+ SQL (0.6ms) COMMIT
2734
+ SQL (0.1ms) BEGIN
2735
+ MessageThread Create (0.2ms) INSERT INTO `message_threads` (`created_at`, `title`, `body`, `updated_at`, `private_thread`, `author_id`) VALUES('2010-02-02 01:10:40', 'Title 6', 'Body 6', '2010-02-02 01:10:40', 1, 19)
2736
+ SQL (0.5ms) COMMIT
2737
+ SQL (0.1ms) BEGIN
2738
+ Recipient Create (0.2ms) INSERT INTO `recipients` (`receiver_type`, `created_at`, `receiver_id`, `updated_at`, `has_read`, `message_thread_id`) VALUES('User', '2010-02-02 01:10:40', 20, '2010-02-02 01:10:40', NULL, 7)
2739
+ SQL (0.6ms) COMMIT
2740
+ SQL (0.1ms) BEGIN
2741
+ Recipient Create (0.2ms) INSERT INTO `recipients` (`receiver_type`, `created_at`, `receiver_id`, `updated_at`, `has_read`, `message_thread_id`) VALUES('User', '2010-02-02 01:10:40', 21, '2010-02-02 01:10:40', NULL, 7)
2742
+ SQL (0.9ms) COMMIT
2743
+ Recipient Load (0.3ms) SELECT * FROM `recipients` WHERE (`recipients`.message_thread_id = 7) ORDER BY has_read ASC, created_at DESC
2744
+ SQL (0.1ms) BEGIN
2745
+ SQL (0.1ms) COMMIT
2746
+ SQL (0.1ms) BEGIN
2747
+ User Create (0.2ms) INSERT INTO `users` (`name`, `created_at`, `updated_at`) VALUES(NULL, '2010-02-02 01:10:40', '2010-02-02 01:10:40')
2748
+ SQL (0.7ms) COMMIT
2749
+ Recipient Load (0.2ms) SELECT * FROM `recipients` WHERE (`recipients`.message_thread_id = 7) ORDER BY has_read ASC, created_at DESC
2750
+ User Load (0.2ms) SELECT * FROM `users` WHERE (`users`.`id` IN (20,21)) 
2751
+ Recipient Load (0.2ms) SELECT * FROM `recipients` WHERE (`recipients`.message_thread_id = 7) ORDER BY has_read ASC, created_at DESC
2752
+ User Load (0.2ms) SELECT * FROM `users` WHERE (`users`.`id` IN (20,21)) 
@@ -9,7 +9,7 @@ require 'spec/autorun'
9
9
  require 'models/user.rb'
10
10
  require File.dirname(__FILE__) + "/../lib/acts_as_messenger/thread"
11
11
  %w(comment message_thread recipient).each do |model|
12
- require File.dirname(__FILE__) + "/../generators/acts_as_messenger/models/#{model}.rb"
12
+ require File.dirname(__FILE__) + "/../generators/acts_as_messenger/templates/models/#{model}.rb"
13
13
  end
14
14
 
15
15
  ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_messenger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson
@@ -55,6 +55,7 @@ files:
55
55
  - generators/acts_as_messenger/templates/models/message_thread.rb
56
56
  - generators/acts_as_messenger/templates/models/recipient.rb
57
57
  - lib/acts_as_messenger.rb
58
+ - lib/acts_as_messenger/message.rb
58
59
  - lib/acts_as_messenger/thread.rb
59
60
  - spec/acts_as_messenger_spec.rb
60
61
  - spec/database.yml