inkwell 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/Rakefile +39 -0
  2. data/app/assets/javascripts/inkwell/application.js +9 -0
  3. data/app/assets/stylesheets/inkwell/application.css +7 -0
  4. data/app/controllers/inkwell/application_controller.rb +4 -0
  5. data/app/helpers/inkwell/application_helper.rb +4 -0
  6. data/app/models/inkwell/blog_item.rb +5 -0
  7. data/app/models/inkwell/comment.rb +125 -0
  8. data/app/models/inkwell/favorite_item.rb +5 -0
  9. data/app/models/inkwell/timeline_item.rb +5 -0
  10. data/app/views/layouts/inkwell/application.html.erb +14 -0
  11. data/config/routes.rb +3 -0
  12. data/db/migrate/20121202140510_create_inkwell_timeline_items.rb +13 -0
  13. data/db/migrate/20121202140816_add_columns_to_posts.rb +7 -0
  14. data/db/migrate/20121209121955_create_inkwell_blog_items.rb +12 -0
  15. data/db/migrate/20121209123557_create_inkwell_favorite_items.rb +11 -0
  16. data/db/migrate/20121209124435_add_columns_to_users.rb +6 -0
  17. data/db/migrate/20121209124743_create_inkwell_comments.rb +16 -0
  18. data/lib/acts_as_inkwell_post/base.rb +79 -0
  19. data/lib/acts_as_inkwell_user/base.rb +286 -0
  20. data/lib/common/base.rb +16 -0
  21. data/lib/inkwell.rb +7 -0
  22. data/lib/inkwell/engine.rb +5 -0
  23. data/lib/inkwell/version.rb +3 -0
  24. data/lib/tasks/inkwell_tasks.rake +4 -0
  25. data/test/dummy/Rakefile +7 -0
  26. data/test/dummy/app/assets/javascripts/application.js +9 -0
  27. data/test/dummy/app/assets/stylesheets/application.css +7 -0
  28. data/test/dummy/app/controllers/application_controller.rb +3 -0
  29. data/test/dummy/app/helpers/application_helper.rb +2 -0
  30. data/test/dummy/app/models/post.rb +5 -0
  31. data/test/dummy/app/models/user.rb +6 -0
  32. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  33. data/test/dummy/config.ru +4 -0
  34. data/test/dummy/config/application.rb +45 -0
  35. data/test/dummy/config/boot.rb +10 -0
  36. data/test/dummy/config/database.yml +25 -0
  37. data/test/dummy/config/environment.rb +5 -0
  38. data/test/dummy/config/environments/development.rb +30 -0
  39. data/test/dummy/config/environments/production.rb +60 -0
  40. data/test/dummy/config/environments/test.rb +39 -0
  41. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  42. data/test/dummy/config/initializers/inflections.rb +10 -0
  43. data/test/dummy/config/initializers/inkwell.rb +6 -0
  44. data/test/dummy/config/initializers/mime_types.rb +5 -0
  45. data/test/dummy/config/initializers/secret_token.rb +7 -0
  46. data/test/dummy/config/initializers/session_store.rb +8 -0
  47. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  48. data/test/dummy/config/locales/en.yml +5 -0
  49. data/test/dummy/config/routes.rb +4 -0
  50. data/test/dummy/db/migrate/20121202111750_create_posts.rb +11 -0
  51. data/test/dummy/db/migrate/20121202112556_create_users.rb +9 -0
  52. data/test/dummy/db/migrate/20130120124010_create_inkwell_timeline_items.rb +13 -0
  53. data/test/dummy/db/migrate/20130120124011_add_columns_to_posts.rb +7 -0
  54. data/test/dummy/db/migrate/20130120124012_create_inkwell_blog_items.rb +12 -0
  55. data/test/dummy/db/migrate/20130120124013_create_inkwell_favorite_items.rb +11 -0
  56. data/test/dummy/db/migrate/20130120124014_add_columns_to_users.rb +6 -0
  57. data/test/dummy/db/migrate/20130120124015_create_inkwell_comments.rb +16 -0
  58. data/test/dummy/db/schema.rb +75 -0
  59. data/test/dummy/db/seeds.rb +7 -0
  60. data/test/dummy/public/404.html +26 -0
  61. data/test/dummy/public/422.html +26 -0
  62. data/test/dummy/public/500.html +26 -0
  63. data/test/dummy/public/favicon.ico +0 -0
  64. data/test/dummy/script/rails +6 -0
  65. data/test/dummy/spec/functional/blogline_spec.rb +70 -0
  66. data/test/dummy/spec/functional/comments_spec.rb +396 -0
  67. data/test/dummy/spec/functional/favorite_spec.rb +236 -0
  68. data/test/dummy/spec/functional/following_spec.rb +120 -0
  69. data/test/dummy/spec/functional/reblog_spec.rb +153 -0
  70. data/test/dummy/spec/functional/timeline_spec.rb +68 -0
  71. data/test/dummy/spec/spec_helper.rb +52 -0
  72. metadata +229 -0
@@ -0,0 +1,9 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :nick
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ class CreateInkwellTimelineItems < ActiveRecord::Migration
2
+ def change
3
+ create_table :inkwell_timeline_items do |t|
4
+ t.integer :item_id
5
+ t.integer "#{::Inkwell::Engine::config.user_table.to_s.singularize}_id"
6
+ t.string :from_source
7
+ t.boolean :has_many_sources, :default => false
8
+ t.boolean :is_comment
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ class AddColumnsToPosts < ActiveRecord::Migration
2
+ def change
3
+ add_column ::Inkwell::Engine::config.post_table, :users_ids_who_favorite_it, :text, :default => '[]'
4
+ add_column ::Inkwell::Engine::config.post_table, :users_ids_who_comment_it, :text, :default => '[]'
5
+ add_column ::Inkwell::Engine::config.post_table, :users_ids_who_reblog_it, :text, :default => '[]'
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ class CreateInkwellBlogItems < ActiveRecord::Migration
2
+ def change
3
+ create_table :inkwell_blog_items do |t|
4
+ t.integer :item_id
5
+ t.integer "#{::Inkwell::Engine::config.user_table.to_s.singularize}_id"
6
+ t.boolean :is_reblog
7
+ t.boolean :is_comment
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ class CreateInkwellFavoriteItems < ActiveRecord::Migration
2
+ def change
3
+ create_table :inkwell_favorite_items do |t|
4
+ t.integer "item_id"
5
+ t.integer "#{::Inkwell::Engine::config.user_table.to_s.singularize}_id"
6
+ t.boolean "is_comment"
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ class AddColumnsToUsers < ActiveRecord::Migration
2
+ def change
3
+ add_column ::Inkwell::Engine::config.user_table, :followers_ids, :text, :default => '[]'
4
+ add_column ::Inkwell::Engine::config.user_table, :followings_ids, :text, :default => '[]'
5
+ end
6
+ end
@@ -0,0 +1,16 @@
1
+ class CreateInkwellComments < ActiveRecord::Migration
2
+ def change
3
+ create_table :inkwell_comments do |t|
4
+ t.integer "#{::Inkwell::Engine::config.user_table.to_s.singularize}_id"
5
+ t.text :body
6
+ t.integer :parent_id
7
+ t.integer "#{::Inkwell::Engine::config.post_table.to_s.singularize}_id"
8
+ t.text :upper_comments_tree
9
+ t.text :users_ids_who_favorite_it
10
+ t.text :users_ids_who_comment_it
11
+ t.text :users_ids_who_reblog_it
12
+
13
+ t.timestamps
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,75 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20130120124015) do
15
+
16
+ create_table "inkwell_blog_items", :force => true do |t|
17
+ t.integer "item_id"
18
+ t.integer "user_id"
19
+ t.boolean "is_reblog"
20
+ t.boolean "is_comment"
21
+ t.datetime "created_at"
22
+ t.datetime "updated_at"
23
+ end
24
+
25
+ create_table "inkwell_comments", :force => true do |t|
26
+ t.integer "user_id"
27
+ t.text "body"
28
+ t.integer "parent_id"
29
+ t.integer "post_id"
30
+ t.text "upper_comments_tree"
31
+ t.text "users_ids_who_favorite_it"
32
+ t.text "users_ids_who_comment_it"
33
+ t.text "users_ids_who_reblog_it"
34
+ t.datetime "created_at"
35
+ t.datetime "updated_at"
36
+ end
37
+
38
+ create_table "inkwell_favorite_items", :force => true do |t|
39
+ t.integer "item_id"
40
+ t.integer "user_id"
41
+ t.boolean "is_comment"
42
+ t.datetime "created_at"
43
+ t.datetime "updated_at"
44
+ end
45
+
46
+ create_table "inkwell_timeline_items", :force => true do |t|
47
+ t.integer "item_id"
48
+ t.integer "user_id"
49
+ t.string "from_source"
50
+ t.boolean "has_many_sources", :default => false
51
+ t.boolean "is_comment"
52
+ t.datetime "created_at"
53
+ t.datetime "updated_at"
54
+ end
55
+
56
+ create_table "posts", :force => true do |t|
57
+ t.string "title"
58
+ t.text "body"
59
+ t.integer "user_id"
60
+ t.datetime "created_at"
61
+ t.datetime "updated_at"
62
+ t.text "users_ids_who_favorite_it", :default => "[]"
63
+ t.text "users_ids_who_comment_it", :default => "[]"
64
+ t.text "users_ids_who_reblog_it", :default => "[]"
65
+ end
66
+
67
+ create_table "users", :force => true do |t|
68
+ t.string "nick"
69
+ t.datetime "created_at"
70
+ t.datetime "updated_at"
71
+ t.text "followers_ids", :default => "[]"
72
+ t.text "followings_ids", :default => "[]"
73
+ end
74
+
75
+ end
@@ -0,0 +1,7 @@
1
+ salkar = User.create :nick => "Salkar"
2
+ morozovm = User.create :nick => "Morozovm"
3
+
4
+ salkar_post1 = salkar.posts.create :title => "salkar_post1"
5
+ salkar_post2 = salkar.posts.create :title => "salkar_post2"
6
+ morozovm_post1 = morozovm.posts.create :title => "morozovm_post1"
7
+ morozovm_post2 = morozovm.posts.create :title => "morozovm_post2"
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
+ </div>
25
+ </body>
26
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,70 @@
1
+ require "rspec"
2
+
3
+ describe "BlogLine" do
4
+
5
+ before(:each) do
6
+ @salkar = User.create :nick => "Salkar"
7
+ @morozovm = User.create :nick => "Morozovm"
8
+ @salkar_post = @salkar.posts.create :body => "salkar_post_test_body"
9
+ end
10
+
11
+ it "blogitem record should been created for new post" do
12
+ @salkar.blog_items.size.should == 1
13
+ item = @salkar.blog_items.first
14
+ item.user_id.should == @salkar.id
15
+ item.item_id.should == @salkar_post.id
16
+ item.is_reblog.should == false
17
+ item.is_comment.should == false
18
+ end
19
+
20
+ it "timeline items should been created for followers for new post" do
21
+ @talisman = User.create :nick => "Talisman"
22
+ @morozovm.follow @salkar
23
+ @talisman.follow @salkar
24
+ @salkar_post1 = @salkar.posts.create :body => "salkar_post_test_body"
25
+ ::Inkwell::TimelineItem.where(:user_id => @morozovm.id, :is_comment => false, :item_id => @salkar_post1.id).size.should == 1
26
+ ::Inkwell::TimelineItem.where(:user_id => @talisman.id, :is_comment => false, :item_id => @salkar_post1.id).size.should == 1
27
+ end
28
+
29
+ it "user should have blogline with reblogs and his posts" do
30
+ @salkar_post1 = @salkar.posts.create :body => "salkar_post_test_body_1"
31
+ @salkar_post2 = @salkar.posts.create :body => "salkar_post_test_body_2"
32
+ @salkar_post3 = @salkar.posts.create :body => "salkar_post_test_body_3"
33
+ @morozovm_post = @morozovm.posts.create :body => "morozovm_post_test_body"
34
+ @salkar_post4 = @salkar.posts.create :body => "salkar_post_test_body_4"
35
+ @salkar_post5 = @salkar.posts.create :body => "salkar_post_test_body_5"
36
+ @salkar.reblog @morozovm_post
37
+ @morozovm_post1 = @morozovm.posts.create :body => "morozovm_post_test_body_1"
38
+ @salkar_post6 = @salkar.posts.create :body => "salkar_post_test_body_6"
39
+ @salkar_post7 = @salkar.posts.create :body => "salkar_post_test_body_7"
40
+ @salkar_post8 = @salkar.posts.create :body => "salkar_post_test_body_8"
41
+ @morozovm_post2 = @morozovm.posts.create :body => "morozovm_post_test_body_2"
42
+ @salkar_post9 = @salkar.posts.create :body => "salkar_post_test_body_9"
43
+ @morozovm_post3 = @morozovm.posts.create :body => "morozovm_post_test_body_3"
44
+ @salkar.reblog @morozovm_post1
45
+ @salkar.reblog @morozovm_post2
46
+
47
+ @morozovm.reblog @salkar_post9
48
+ @morozovm.favorite @salkar_post9
49
+
50
+ bline = @salkar.blogline(nil, 10, @morozovm)
51
+ bline.size.should == 10
52
+ bline[0].should == @morozovm_post2
53
+ bline[0].is_reblog_in_blogline.should == true
54
+ bline[1].should == @morozovm_post1
55
+ bline[1].is_reblog_in_blogline.should == true
56
+ bline[2].should == @salkar_post9
57
+ bline[2].is_reblogged.should == true
58
+ bline[2].is_favorited.should == true
59
+ bline[2].is_reblog_in_blogline.should == false
60
+ bline[2].item_id_in_line.should == ::Inkwell::BlogItem.where(:item_id => @salkar_post9.id, :is_comment => false).first.id
61
+ bline[3].should == @salkar_post8
62
+ bline[4].should == @salkar_post7
63
+ bline[5].should == @salkar_post6
64
+ bline[6].should == @morozovm_post
65
+ bline[6].is_reblog_in_blogline.should == true
66
+ bline[7].should == @salkar_post5
67
+ bline[8].should == @salkar_post4
68
+ bline[9].should == @salkar_post3
69
+ end
70
+ end
@@ -0,0 +1,396 @@
1
+ require "rspec"
2
+ require "spec_helper"
3
+
4
+ describe "Comments" do
5
+
6
+ before(:each) do
7
+ @salkar = User.create :nick => "Salkar"
8
+ @morozovm = User.create :nick => "Morozovm"
9
+ @salkar_post = @salkar.posts.create :body => "salkar_post_test_body"
10
+ end
11
+
12
+ it "comments should be available for user and post" do
13
+ @salkar.comments.should == []
14
+ @salkar_post.comments.should == []
15
+ end
16
+
17
+ it "comment should been created" do
18
+ @salkar.comments.size.should == 0
19
+ comment = @salkar.comments.create :post_id => @salkar_post.id, :body => "salkar_comment_body"
20
+ @salkar.comments.size.should == 1
21
+ @salkar_post.comments.size.should == 1
22
+ @salkar.comments.should == @salkar_post.comments
23
+ comment.id.should be
24
+ comment.body.should be
25
+ comment.user.should == @salkar
26
+ comment.post.should == @salkar_post
27
+ comment.users_ids_who_favorite_it.should == "[]"
28
+ comment.users_ids_who_comment_it.should == "[]"
29
+ comment.users_ids_who_reblog_it.should == "[]"
30
+
31
+ @salkar_post = Post.find @salkar_post
32
+ ActiveSupport::JSON.decode(@salkar_post.users_ids_who_comment_it).should == [{"user_id"=>@salkar.id, "comment_id"=>comment.id}]
33
+ end
34
+
35
+ it "comment should not been created" do
36
+ post = @salkar.comments.create :post_id => @salkar_post.id
37
+ post.id.should == nil
38
+ post = @salkar.comments.create :body => "salkar_comment_body"
39
+ post.id.should == nil
40
+ post = @salkar_post.comments.create :body => "salkar_comment_body"
41
+ post.id.should == nil
42
+ end
43
+
44
+ it "10 comments for main post should been received" do
45
+ @comment = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
46
+ @comment1 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
47
+ @comment2 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
48
+ @comment3 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
49
+ @comment4 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
50
+ @comment5 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
51
+ @comment6 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
52
+ @comment7 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
53
+ @comment8 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
54
+ @comment9 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
55
+ @comment10 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
56
+ @comment11 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
57
+
58
+ commentline = @salkar_post.commentline
59
+ commentline.size.should == 10
60
+ commentline[0].id.should == @comment2.id
61
+ commentline[9].id.should == @comment11.id
62
+
63
+ commentline = @salkar_post.commentline @comment10.id
64
+ commentline.size.should == 10
65
+ commentline[0].id.should == @comment.id
66
+ commentline[9].id.should == @comment9.id
67
+
68
+ end
69
+
70
+ it "5 comments for main post should been received" do
71
+ @comment = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
72
+ @comment1 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
73
+ @comment2 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
74
+ @comment3 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment1.id)
75
+ @comment4 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
76
+ @comment5 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
77
+ @comment6 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
78
+ @comment7 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
79
+ @comment8 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
80
+ @comment9 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
81
+ @comment10 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
82
+ @comment11 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
83
+
84
+ commentline = @salkar_post.commentline nil, 5
85
+ commentline.size.should == 5
86
+ commentline[0].id.should == @comment7.id
87
+ commentline[4].id.should == @comment11.id
88
+
89
+ commentline = @salkar_post.commentline @comment10.id, 5
90
+ commentline.size.should == 5
91
+ commentline[0].id.should == @comment5.id
92
+ commentline[4].id.should == @comment9.id
93
+
94
+ commentline = @salkar_post.commentline @comment5.id, 7
95
+ commentline.size.should == 5
96
+ commentline[0].id.should == @comment.id
97
+ commentline[4].id.should == @comment4.id
98
+ end
99
+
100
+ it "comments should been deleted when parent post destroyed" do
101
+ @salkar_comment = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
102
+ @morozovm_comment = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
103
+ @salkar_post.comments.size.should == 2
104
+ ::Inkwell::Comment.all.size.should == 2
105
+ @salkar_post.destroy
106
+ ::Inkwell::Comment.all.size.should == 0
107
+ end
108
+
109
+ it "2 comments with parent_id should been created" do
110
+ @salkar_comment = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
111
+ @morozovm_comment = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @salkar_comment.id)
112
+ @salkar_comment = ::Inkwell::Comment.find @salkar_comment
113
+ @morozovm_comment = ::Inkwell::Comment.find @morozovm_comment
114
+ @salkar_post.reload
115
+ ActiveSupport::JSON.decode(@salkar_comment.users_ids_who_comment_it).should == [{"user_id"=>@morozovm.id, "comment_id"=>@morozovm_comment.id}]
116
+ ActiveSupport::JSON.decode(@morozovm_comment.upper_comments_tree).should == [@salkar_comment.id]
117
+ ActiveSupport::JSON.decode(@salkar_post.users_ids_who_comment_it).should == [{"user_id"=>@salkar.id, "comment_id"=>@salkar_comment.id}, {"user_id"=>@morozovm.id, "comment_id"=>@morozovm_comment.id}]
118
+
119
+
120
+ ActiveSupport::JSON.decode(@morozovm_comment.users_ids_who_comment_it).should == []
121
+ ActiveSupport::JSON.decode(@salkar_comment.upper_comments_tree).should == []
122
+ end
123
+
124
+ it "7 comments should been created" do
125
+ @salkar_comment = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
126
+ @morozovm_comment = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @salkar_comment.id)
127
+ @salkar_comment1 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
128
+ @morozovm_comment1 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @salkar_comment.id)
129
+ @salkar_comment2 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
130
+ @morozovm_comment2 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @salkar_comment.id)
131
+ @salkar_comment3 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
132
+ @salkar_post.reload
133
+ users_ids_who_comment_it = ActiveSupport::JSON.decode(@salkar_post.users_ids_who_comment_it)
134
+ users_ids_who_comment_it.size.should == 7
135
+ users_ids_who_comment_it[0].should == {"user_id"=>@salkar.id, "comment_id"=>@salkar_comment.id}
136
+ users_ids_who_comment_it[6].should == {"user_id"=>@salkar.id, "comment_id"=>@salkar_comment3.id}
137
+
138
+ @salkar_comment.reload
139
+ users_ids_who_comment_it = ActiveSupport::JSON.decode(@salkar_comment.users_ids_who_comment_it)
140
+ users_ids_who_comment_it.size.should == 3
141
+ users_ids_who_comment_it[0].should == {"user_id"=>@morozovm.id, "comment_id"=>@morozovm_comment.id}
142
+ users_ids_who_comment_it[2].should == {"user_id"=>@morozovm.id, "comment_id"=>@morozovm_comment2.id}
143
+
144
+ @salkar_comment1.reload
145
+ users_ids_who_comment_it = ActiveSupport::JSON.decode(@salkar_comment1.users_ids_who_comment_it)
146
+ users_ids_who_comment_it.size.should == 0
147
+
148
+ @salkar_comment3.reload
149
+ users_ids_who_comment_it = ActiveSupport::JSON.decode(@salkar_comment3.users_ids_who_comment_it)
150
+ users_ids_who_comment_it.size.should == 0
151
+ end
152
+
153
+ it "1 comments should been deleted from post" do
154
+ @comment = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
155
+ @salkar_post.reload
156
+ users_ids_who_comment_it = ActiveSupport::JSON.decode(@salkar_post.users_ids_who_comment_it)
157
+ users_ids_who_comment_it.should == [{"user_id"=>@salkar.id, "comment_id"=>@comment.id}]
158
+ ::Inkwell::TimelineItem.create :item_id => @comment.id, :user_id => @morozovm.id, :is_comment => true
159
+ ::Inkwell::FavoriteItem.create :item_id => @comment.id, :user_id => @salkar.id, :is_comment => true
160
+ ::Inkwell::BlogItem.create :item_id => @comment.id, :user_id => @morozovm.id, :is_comment => true
161
+ ::Inkwell::BlogItem.create :item_id => @comment.id, :user_id => @salkar.id, :is_comment => true
162
+ ::Inkwell::FavoriteItem.all.size.should == 1
163
+ ::Inkwell::TimelineItem.all.size.should == 1
164
+ ::Inkwell::BlogItem.all.size.should == 3
165
+ ::Inkwell::Comment.all.size.should == 1
166
+
167
+ @comment.destroy
168
+ @salkar_post.reload
169
+ users_ids_who_comment_it = ActiveSupport::JSON.decode(@salkar_post.users_ids_who_comment_it)
170
+ users_ids_who_comment_it.should == []
171
+ ::Inkwell::FavoriteItem.all.size.should == 0
172
+ ::Inkwell::TimelineItem.all.size.should == 0
173
+ ::Inkwell::BlogItem.all.size.should == 1
174
+ ::Inkwell::Comment.all.size.should == 0
175
+ end
176
+
177
+ it "1 comments should been deleted from post with parent comment" do
178
+ @comment = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
179
+ @comment_to_delete = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
180
+ @salkar_post.reload
181
+ users_ids_who_comment_it = ActiveSupport::JSON.decode(@salkar_post.users_ids_who_comment_it)
182
+ users_ids_who_comment_it.should == [{"user_id" => @salkar.id, "comment_id" => @comment.id}, {"user_id" => @morozovm.id, "comment_id" => @comment_to_delete.id}]
183
+ ::Inkwell::TimelineItem.create :item_id => @comment_to_delete.id, :user_id => @morozovm.id, :is_comment => true
184
+ ::Inkwell::FavoriteItem.create :item_id => @comment_to_delete.id, :user_id => @salkar.id, :is_comment => true
185
+ ::Inkwell::TimelineItem.create :item_id => @comment.id, :user_id => @morozovm.id, :is_comment => true
186
+ ::Inkwell::FavoriteItem.create :item_id => @comment.id, :user_id => @salkar.id, :is_comment => true
187
+ ::Inkwell::BlogItem.create :item_id => @comment_to_delete.id, :user_id => @morozovm.id, :is_comment => true
188
+ ::Inkwell::BlogItem.create :item_id => @comment_to_delete.id, :user_id => @salkar.id, :is_comment => true
189
+ ::Inkwell::BlogItem.create :item_id => @comment.id, :user_id => @salkar.id, :is_comment => true
190
+ ::Inkwell::FavoriteItem.all.size.should == 2
191
+ ::Inkwell::TimelineItem.all.size.should == 2
192
+ ::Inkwell::BlogItem.all.size.should == 4
193
+ ::Inkwell::Comment.all.size.should == 2
194
+
195
+ @comment_to_delete.destroy
196
+ @salkar_post.reload
197
+ users_ids_who_comment_it = ActiveSupport::JSON.decode(@salkar_post.users_ids_who_comment_it)
198
+ users_ids_who_comment_it.should == [{"user_id" => @salkar.id, "comment_id" => @comment.id}]
199
+ ::Inkwell::FavoriteItem.all.size.should == 1
200
+ ::Inkwell::TimelineItem.all.size.should == 1
201
+ ::Inkwell::BlogItem.all.size.should == 2
202
+ ::Inkwell::Comment.all.size.should == 1
203
+ @comment.reload
204
+ users_ids_who_comment_it = ActiveSupport::JSON.decode(@comment.users_ids_who_comment_it)
205
+ users_ids_who_comment_it.should == []
206
+ end
207
+
208
+ it "2 comments should been deleted from post with parent comment" do
209
+ @comment = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
210
+ @comment2 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
211
+ @salkar_post.reload
212
+ users_ids_who_comment_it = ActiveSupport::JSON.decode(@salkar_post.users_ids_who_comment_it)
213
+ users_ids_who_comment_it.should == [{"user_id" => @salkar.id, "comment_id" => @comment.id}, {"user_id" => @morozovm.id, "comment_id" => @comment2.id}]
214
+ ::Inkwell::TimelineItem.create :item_id => @comment2.id, :user_id => @morozovm.id, :is_comment => true
215
+ ::Inkwell::FavoriteItem.create :item_id => @comment2.id, :user_id => @salkar.id, :is_comment => true
216
+ ::Inkwell::TimelineItem.create :item_id => @comment.id, :user_id => @morozovm.id, :is_comment => true
217
+ ::Inkwell::FavoriteItem.create :item_id => @comment.id, :user_id => @salkar.id, :is_comment => true
218
+ ::Inkwell::BlogItem.create :item_id => @comment2.id, :user_id => @morozovm.id, :is_comment => true
219
+ ::Inkwell::BlogItem.create :item_id => @comment2.id, :user_id => @salkar.id, :is_comment => true
220
+ ::Inkwell::BlogItem.create :item_id => @comment.id, :user_id => @salkar.id, :is_comment => true
221
+ ::Inkwell::FavoriteItem.all.size.should == 2
222
+ ::Inkwell::TimelineItem.all.size.should == 2
223
+ ::Inkwell::BlogItem.all.size.should == 4
224
+ ::Inkwell::Comment.all.size.should == 2
225
+ @comment.reload
226
+
227
+ @comment.destroy
228
+ @salkar_post.reload
229
+ users_ids_who_comment_it = ActiveSupport::JSON.decode(@salkar_post.users_ids_who_comment_it)
230
+ users_ids_who_comment_it.should == []
231
+ ::Inkwell::FavoriteItem.all.size.should == 0
232
+ ::Inkwell::TimelineItem.all.size.should == 0
233
+ ::Inkwell::BlogItem.all.size.should == 1
234
+ ::Inkwell::Comment.all.size.should == 0
235
+ end
236
+
237
+ it "4 comments should been deleted from post with parent comment" do
238
+ @comment = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
239
+ @comment2 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
240
+ @comment2 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment2.id)
241
+ @comment3 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
242
+ @salkar_post.reload
243
+ users_ids_who_comment_it = ActiveSupport::JSON.decode(@salkar_post.users_ids_who_comment_it)
244
+ users_ids_who_comment_it.size.should == 4
245
+ ::Inkwell::TimelineItem.create :item_id => @comment2.id, :user_id => @morozovm.id, :is_comment => true
246
+ ::Inkwell::FavoriteItem.create :item_id => @comment2.id, :user_id => @salkar.id, :is_comment => true
247
+ ::Inkwell::TimelineItem.create :item_id => @comment.id, :user_id => @morozovm.id, :is_comment => true
248
+ ::Inkwell::FavoriteItem.create :item_id => @comment.id, :user_id => @salkar.id, :is_comment => true
249
+ ::Inkwell::BlogItem.create :item_id => @comment2.id, :user_id => @morozovm.id, :is_comment => true
250
+ ::Inkwell::BlogItem.create :item_id => @comment2.id, :user_id => @salkar.id, :is_comment => true
251
+ ::Inkwell::BlogItem.create :item_id => @comment.id, :user_id => @salkar.id, :is_comment => true
252
+ ::Inkwell::FavoriteItem.all.size.should == 2
253
+ ::Inkwell::TimelineItem.all.size.should == 2
254
+ ::Inkwell::BlogItem.all.size.should == 4
255
+ ::Inkwell::Comment.all.size.should == 4
256
+ @comment.reload
257
+
258
+ @comment.destroy
259
+ @salkar_post.reload
260
+ users_ids_who_comment_it = ActiveSupport::JSON.decode(@salkar_post.users_ids_who_comment_it)
261
+ users_ids_who_comment_it.should == []
262
+ ::Inkwell::FavoriteItem.all.size.should == 0
263
+ ::Inkwell::TimelineItem.all.size.should == 0
264
+ ::Inkwell::BlogItem.all.size.should == 1
265
+ ::Inkwell::Comment.all.size.should == 0
266
+ end
267
+
268
+ it "commentline for comment should been returned (comments for 1 comment)" do
269
+ @comment = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
270
+ @comment1 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
271
+ @comment2 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
272
+ @comment3 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
273
+ @comment4 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
274
+ @comment5 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
275
+ @comment6 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
276
+ @comment7 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
277
+ @comment8 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
278
+ @comment9 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
279
+ @comment10 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
280
+ @comment11 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
281
+
282
+ @comment.reload
283
+ commentline = @comment.commentline
284
+ commentline.size.should == 10
285
+ commentline[0].id.should == @comment2.id
286
+ commentline[9].id.should == @comment11.id
287
+
288
+ commentline = @salkar_post.commentline @comment10.id
289
+ commentline.size.should == 10
290
+ commentline[0].id.should == @comment.id
291
+ commentline[9].id.should == @comment9.id
292
+ end
293
+
294
+ it "commentline for comment should been returned (comments for several comments)" do
295
+ @comment = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
296
+ @comment1 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
297
+ @comment2 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
298
+ @comment3 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment1.id)
299
+ @comment4 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment2.id)
300
+ @comment5 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
301
+ @comment6 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment3.id)
302
+ @comment7 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment2.id)
303
+ @comment8 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
304
+ @comment9 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment5.id)
305
+ @comment10 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment4.id)
306
+ @comment11 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
307
+
308
+ @comment.reload
309
+ commentline = @comment.commentline
310
+ commentline.size.should == 10
311
+ commentline[0].id.should == @comment2.id
312
+ commentline[9].id.should == @comment11.id
313
+
314
+ commentline = @salkar_post.commentline @comment10.id
315
+ commentline.size.should == 10
316
+ commentline[0].id.should == @comment.id
317
+ commentline[9].id.should == @comment9.id
318
+ end
319
+
320
+ it "5 comments for comment should been received" do
321
+ @comment = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
322
+ @comment1 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
323
+ @comment2 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
324
+ @comment3 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment1.id)
325
+ @comment4 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment2.id)
326
+ @comment5 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
327
+ @comment6 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment3.id)
328
+ @comment7 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment2.id)
329
+ @comment8 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
330
+ @comment9 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment5.id)
331
+ @comment10 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment4.id)
332
+ @comment11 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
333
+
334
+ @comment.reload
335
+ commentline = @comment.commentline nil, 5
336
+ commentline.size.should == 5
337
+ commentline[0].id.should == @comment7.id
338
+ commentline[4].id.should == @comment11.id
339
+
340
+ @comment.reload
341
+ commentline = @comment.commentline @comment10.id, 5
342
+ commentline.size.should == 5
343
+ commentline[0].id.should == @comment5.id
344
+ commentline[4].id.should == @comment9.id
345
+
346
+ @comment.reload
347
+ commentline = @comment.commentline @comment5.id, 7
348
+ commentline.size.should == 4
349
+ commentline[0].id.should == @comment1.id
350
+ commentline[3].id.should == @comment4.id
351
+ end
352
+
353
+ it "is_favorited should been returned in commentline for comment for for_user" do
354
+ @comment = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
355
+ @comment1 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
356
+ @comment2 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
357
+ @salkar.favorite @comment1
358
+ @morozovm.favorite @comment2
359
+
360
+ @comment.reload
361
+ commentline = @comment.commentline nil, 10, @salkar
362
+ commentline[0].id.should == @comment1.id
363
+ commentline[0].is_favorited.should == true
364
+ commentline[1].id.should == @comment2.id
365
+ commentline[1].is_favorited.should == false
366
+
367
+ commentline = @comment.commentline nil, 10, @morozovm
368
+ commentline[0].id.should == @comment1.id
369
+ commentline[0].is_favorited.should == false
370
+ commentline[1].id.should == @comment2.id
371
+ commentline[1].is_favorited.should == true
372
+ end
373
+
374
+ it "is_favorited should been returned in commentline for post for for_user" do
375
+ @comment = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id)
376
+ @comment1 = @morozovm.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
377
+ @comment2 = @salkar.comments.create(:body => 'Lets You Party Like a Facebook User', :post_id => @salkar_post.id, :parent_id => @comment.id)
378
+ @salkar.favorite @comment1
379
+ @morozovm.favorite @comment2
380
+
381
+ @salkar_post.reload
382
+ commentline = @salkar_post.commentline nil, 10, @salkar
383
+ commentline[1].id.should == @comment1.id
384
+ commentline[1].is_favorited.should == true
385
+ commentline[2].id.should == @comment2.id
386
+ commentline[2].is_favorited.should == false
387
+
388
+ commentline = @salkar_post.commentline nil, 10, @morozovm
389
+ commentline[1].id.should == @comment1.id
390
+ commentline[1].is_favorited.should == false
391
+ commentline[2].id.should == @comment2.id
392
+ commentline[2].is_favorited.should == true
393
+ end
394
+
395
+
396
+ end