inkwell 0.0.3 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/app/models/inkwell/comment.rb +23 -3
  2. data/lib/acts_as_inkwell_post/base.rb +23 -3
  3. data/lib/acts_as_inkwell_user/base.rb +26 -15
  4. data/lib/inkwell/version.rb +1 -1
  5. data/test/dummy/db/test.sqlite3 +0 -0
  6. data/test/dummy/log/development.log +5 -0
  7. data/test/dummy/log/test.log +28689 -0
  8. data/test/dummy/spec/functional/blogline_spec.rb +1 -1
  9. data/test/dummy/spec/functional/comments_spec.rb +34 -13
  10. data/test/dummy/spec/functional/favorite_spec.rb +26 -3
  11. data/test/dummy/spec/functional/reblog_spec.rb +27 -1
  12. data/test/dummy/spec/functional/timeline_spec.rb +2 -2
  13. data/test/dummy_without_community/Rakefile +7 -0
  14. data/test/dummy_without_community/app/assets/javascripts/application.js +9 -0
  15. data/test/dummy_without_community/app/assets/stylesheets/application.css +7 -0
  16. data/test/dummy_without_community/app/controllers/application_controller.rb +3 -0
  17. data/test/dummy_without_community/app/helpers/application_helper.rb +2 -0
  18. data/test/dummy_without_community/app/models/post.rb +6 -0
  19. data/test/dummy_without_community/app/models/user.rb +7 -0
  20. data/test/dummy_without_community/app/views/layouts/application.html.erb +14 -0
  21. data/test/dummy_without_community/config.ru +4 -0
  22. data/test/dummy_without_community/config/application.rb +51 -0
  23. data/test/dummy_without_community/config/boot.rb +10 -0
  24. data/test/dummy_without_community/config/database.yml +25 -0
  25. data/test/dummy_without_community/config/environment.rb +5 -0
  26. data/test/dummy_without_community/config/environments/development.rb +30 -0
  27. data/test/dummy_without_community/config/environments/production.rb +60 -0
  28. data/test/dummy_without_community/config/environments/test.rb +42 -0
  29. data/test/dummy_without_community/config/initializers/backtrace_silencers.rb +7 -0
  30. data/test/dummy_without_community/config/initializers/inflections.rb +10 -0
  31. data/test/dummy_without_community/config/initializers/inkwell.rb +6 -0
  32. data/test/dummy_without_community/config/initializers/mime_types.rb +5 -0
  33. data/test/dummy_without_community/config/initializers/secret_token.rb +7 -0
  34. data/test/dummy_without_community/config/initializers/session_store.rb +8 -0
  35. data/test/dummy_without_community/config/initializers/wrap_parameters.rb +14 -0
  36. data/test/dummy_without_community/config/locales/en.yml +5 -0
  37. data/test/dummy_without_community/config/routes.rb +4 -0
  38. data/test/dummy_without_community/db/migrate/20121202111750_create_posts.rb +11 -0
  39. data/test/dummy_without_community/db/migrate/20121202112556_create_users.rb +9 -0
  40. data/test/dummy_without_community/db/migrate/20130120124010_create_inkwell_timeline_items.rb +13 -0
  41. data/test/dummy_without_community/db/migrate/20130120124011_add_columns_to_posts.rb +7 -0
  42. data/test/dummy_without_community/db/migrate/20130120124012_create_inkwell_blog_items.rb +12 -0
  43. data/test/dummy_without_community/db/migrate/20130120124013_create_inkwell_favorite_items.rb +11 -0
  44. data/test/dummy_without_community/db/migrate/20130120124014_add_columns_to_users.rb +6 -0
  45. data/test/dummy_without_community/db/migrate/20130120124015_create_inkwell_comments.rb +16 -0
  46. data/test/dummy_without_community/db/schema.rb +75 -0
  47. data/test/dummy_without_community/db/seeds.rb +7 -0
  48. data/test/dummy_without_community/public/404.html +26 -0
  49. data/test/dummy_without_community/public/422.html +26 -0
  50. data/test/dummy_without_community/public/500.html +26 -0
  51. data/test/dummy_without_community/public/favicon.ico +0 -0
  52. data/test/dummy_without_community/script/rails +6 -0
  53. data/test/dummy_without_community/spec/functional/blogline_spec.rb +70 -0
  54. data/test/dummy_without_community/spec/functional/comments_spec.rb +416 -0
  55. data/test/dummy_without_community/spec/functional/favorite_spec.rb +259 -0
  56. data/test/dummy_without_community/spec/functional/following_spec.rb +120 -0
  57. data/test/dummy_without_community/spec/functional/reblog_spec.rb +179 -0
  58. data/test/dummy_without_community/spec/functional/timeline_spec.rb +68 -0
  59. data/test/dummy_without_community/spec/spec_helper.rb +52 -0
  60. metadata +96 -2
@@ -0,0 +1,259 @@
1
+ require "spec_helper"
2
+
3
+ describe "Favorites" 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
+ @salkar_comment = @salkar.comments.create :post_id => @salkar_post.id, :body => "salkar_comment_body"
10
+ end
11
+
12
+ it "Post should been favorited" do
13
+ @salkar.favorite @salkar_post
14
+ end
15
+
16
+ it "Comment should been favorited" do
17
+ @salkar.favorite @salkar_comment
18
+ end
19
+
20
+ it "String should not been favorited" do
21
+ expect{@salkar.favorite "string"}.to raise_error
22
+ end
23
+
24
+ it "Post should been favorited" do
25
+ ::Inkwell::FavoriteItem.create :item_id => @salkar_post.id, :user_id => @salkar.id, :is_comment => false
26
+ ::Inkwell::FavoriteItem.all.size.should == 1
27
+ @salkar.favorite?(@salkar_post).should == true
28
+ end
29
+
30
+ it "Post should not been favorited" do
31
+ ::Inkwell::FavoriteItem.all.size.should == 0
32
+ @salkar.favorite?(@salkar_post).should == false
33
+ end
34
+
35
+ it "Comment should been favorited" do
36
+ ::Inkwell::FavoriteItem.create :item_id => @salkar_comment.id, :user_id => @salkar.id, :is_comment => true
37
+ ::Inkwell::FavoriteItem.all.size.should == 1
38
+ @salkar.favorite?(@salkar_comment).should == true
39
+ end
40
+
41
+ it "Comment should not been favorited" do
42
+ ::Inkwell::FavoriteItem.all.size.should == 0
43
+ @salkar.favorite?(@salkar_comment).should == false
44
+ end
45
+
46
+ it "User should favorite post" do
47
+ @salkar.favorite @salkar_post
48
+ @salkar.favorite?(@salkar_post).should == true
49
+ ::Inkwell::FavoriteItem.all.size.should == 1
50
+ @salkar_post.reload
51
+ users_ids_who_favorite_it = ActiveSupport::JSON.decode(@salkar_post.users_ids_who_favorite_it)
52
+ users_ids_who_favorite_it.should == [@salkar.id]
53
+ @morozovm.favorite @salkar_post
54
+ @morozovm.favorite?(@salkar_post).should == true
55
+ ::Inkwell::FavoriteItem.all.size.should == 2
56
+ @salkar_post.reload
57
+ users_ids_who_favorite_it = ActiveSupport::JSON.decode(@salkar_post.users_ids_who_favorite_it)
58
+ users_ids_who_favorite_it.should == [@salkar.id, @morozovm.id]
59
+ end
60
+
61
+ it "User should favorite comment" do
62
+ @salkar.favorite @salkar_comment
63
+ @salkar.favorite?(@salkar_comment).should == true
64
+ ::Inkwell::FavoriteItem.all.size.should == 1
65
+ @salkar_comment.reload
66
+ users_ids_who_favorite_it = ActiveSupport::JSON.decode(@salkar_comment.users_ids_who_favorite_it)
67
+ users_ids_who_favorite_it.should == [@salkar.id]
68
+ @morozovm.favorite @salkar_comment
69
+ @morozovm.favorite?(@salkar_comment).should == true
70
+ ::Inkwell::FavoriteItem.all.size.should == 2
71
+ @salkar_comment.reload
72
+ users_ids_who_favorite_it = ActiveSupport::JSON.decode(@salkar_comment.users_ids_who_favorite_it)
73
+ users_ids_who_favorite_it.should == [@salkar.id, @morozovm.id]
74
+ end
75
+
76
+ it "User should unfavorite post" do
77
+ @salkar.favorite @salkar_post
78
+ @salkar_post.reload
79
+ @salkar.unfavorite @salkar_post
80
+ @salkar_post.reload
81
+ ::Inkwell::FavoriteItem.all.size.should == 0
82
+ users_ids_who_favorite_it = ActiveSupport::JSON.decode(@salkar_post.users_ids_who_favorite_it)
83
+ users_ids_who_favorite_it.should == []
84
+
85
+ @salkar.favorite @salkar_post
86
+ @morozovm.favorite @salkar_post
87
+ ::Inkwell::FavoriteItem.all.size.should == 2
88
+ @salkar_post.reload
89
+ @salkar.unfavorite @salkar_post
90
+ @salkar_post.reload
91
+ ::Inkwell::FavoriteItem.all.size.should == 1
92
+ users_ids_who_favorite_it = ActiveSupport::JSON.decode(@salkar_post.users_ids_who_favorite_it)
93
+ users_ids_who_favorite_it.should == [@morozovm.id]
94
+ end
95
+
96
+ it "User should unfavorite comment" do
97
+ @salkar.favorite @salkar_comment
98
+ @salkar_comment.reload
99
+ ::Inkwell::FavoriteItem.all.size.should == 1
100
+ @salkar.unfavorite @salkar_comment
101
+ @salkar_comment.reload
102
+ ::Inkwell::FavoriteItem.all.size.should == 0
103
+ users_ids_who_favorite_it = ActiveSupport::JSON.decode(@salkar_comment.users_ids_who_favorite_it)
104
+ users_ids_who_favorite_it.should == []
105
+
106
+ @salkar.favorite @salkar_comment
107
+ @morozovm.favorite @salkar_comment
108
+ ::Inkwell::FavoriteItem.all.size.should == 2
109
+ @salkar_comment.reload
110
+ @morozovm.unfavorite @salkar_comment
111
+ @salkar_comment.reload
112
+ ::Inkwell::FavoriteItem.all.size.should == 1
113
+ users_ids_who_favorite_it = ActiveSupport::JSON.decode(@salkar_comment.users_ids_who_favorite_it)
114
+ users_ids_who_favorite_it.should == [@salkar.id]
115
+ end
116
+
117
+ it "Unfavorite not favorited obj should not return error" do
118
+ @salkar.favorite?(@salkar_comment).should == false
119
+ @salkar.favorite?(@salkar_post).should == false
120
+ @salkar.unfavorite @salkar_comment
121
+ @salkar.unfavorite @salkar_post
122
+ end
123
+
124
+ it "Favoriteline should been return" do
125
+ @salkar_post = @salkar.posts.create :body => "salkar_post_test_body"
126
+ @salkar_comment = @salkar.comments.create :post_id => @salkar_post.id, :body => "salkar_comment_body"
127
+ @morozovm_post = @morozovm.posts.create :body => "salkar_post_test_body"
128
+ @morozovm_comment = @morozovm.comments.create :post_id => @morozovm_post.id, :body => "salkar_comment_body"
129
+ @salkar_comment1 = @salkar.comments.create :post_id => @morozovm_post.id, :body => "salkar_comment_body"
130
+ @morozovm_post1 = @morozovm.posts.create :body => "salkar_post_test_body"
131
+ @morozovm_post2 = @morozovm.posts.create :body => "salkar_post_test_body"
132
+ @morozovm_post3 = @morozovm.posts.create :body => "salkar_post_test_body"
133
+ @salkar_comment2 = @salkar.comments.create :post_id => @morozovm_post3.id, :body => "salkar_comment_body"
134
+ @salkar_comment3 = @salkar.comments.create :post_id => @morozovm_post3.id, :body => "salkar_comment_body"
135
+ @salkar_comment4 = @salkar.comments.create :post_id => @morozovm_post3.id, :body => "salkar_comment_body"
136
+ @morozovm_comment2 = @morozovm.comments.create :post_id => @morozovm_post3.id, :body => "salkar_comment_body"
137
+ @salkar_post1 = @salkar.posts.create :body => "salkar_post_test_body"
138
+
139
+ @salkar.favorite @salkar_post
140
+ @salkar.favorite @salkar_comment
141
+ @salkar.favorite @morozovm_post
142
+ @salkar.favorite @morozovm_comment
143
+ @salkar.favorite @salkar_comment1
144
+ @salkar.favorite @morozovm_post1
145
+ @salkar.favorite @morozovm_post2
146
+ @salkar.favorite @morozovm_post3
147
+ @salkar.favorite @salkar_comment2
148
+ @salkar.favorite @salkar_comment3
149
+ @salkar.favorite @salkar_comment4
150
+ @salkar.favorite @morozovm_comment2
151
+ @salkar.favorite @salkar_post1
152
+
153
+ fline = @salkar.favoriteline
154
+ fline.size.should == 10
155
+ fline[0].id.should == @salkar_post1.id
156
+ fline[0].class.to_s.should == 'Post'
157
+ fline[0].item_id_in_line.should == ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@salkar_post1.id, false).id
158
+ fline[9].id.should == @morozovm_comment.id
159
+ fline[9].class.to_s.should == 'Inkwell::Comment'
160
+ fline[9].item_id_in_line.should == ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@morozovm_comment.id, true).id
161
+
162
+ fline_same = @salkar.favoriteline :last_shown_obj_id => nil, :limit => 10, :for_user => nil
163
+ fline_same.should == fline
164
+
165
+ from_favorite_item_id = ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@morozovm_comment2.id, true).id
166
+ fline = @salkar.favoriteline(:last_shown_obj_id => from_favorite_item_id)
167
+ fline.size.should == 10
168
+ fline[0].id.should == @salkar_comment4.id
169
+ fline[0].class.to_s.should == 'Inkwell::Comment'
170
+ fline[0].item_id_in_line.should == ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@salkar_comment4.id, true).id
171
+ fline[9].id.should == @salkar_comment.id
172
+ fline[9].class.to_s.should == 'Inkwell::Comment'
173
+ fline[9].item_id_in_line.should == ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@salkar_comment.id, true).id
174
+
175
+ from_favorite_item_id = ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@morozovm_comment2.id, true).id
176
+ fline = @salkar.favoriteline(:last_shown_obj_id => from_favorite_item_id, :limit => 5)
177
+ fline.size.should == 5
178
+ fline[0].id.should == @salkar_comment4.id
179
+ fline[0].class.to_s.should == 'Inkwell::Comment'
180
+ fline[0].item_id_in_line.should == ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@salkar_comment4.id, true).id
181
+ fline[4].id.should == @morozovm_post2.id
182
+ fline[4].class.to_s.should == 'Post'
183
+ fline[4].item_id_in_line.should == ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@morozovm_post2.id, false).id
184
+ end
185
+
186
+ it "Favoriteline should been return for for_user" do
187
+ @salkar_post = @salkar.posts.create :body => "salkar_post_test_body"
188
+ @salkar_comment = @salkar.comments.create :post_id => @salkar_post.id, :body => "salkar_comment_body"
189
+ @morozovm_post = @morozovm.posts.create :body => "salkar_post_test_body"
190
+ @morozovm_comment = @morozovm.comments.create :post_id => @morozovm_post.id, :body => "salkar_comment_body"
191
+ @salkar_comment1 = @salkar.comments.create :post_id => @morozovm_post.id, :body => "salkar_comment_body"
192
+ @morozovm_post1 = @morozovm.posts.create :body => "salkar_post_test_body"
193
+ @morozovm_post2 = @morozovm.posts.create :body => "salkar_post_test_body"
194
+ @morozovm_post3 = @morozovm.posts.create :body => "salkar_post_test_body"
195
+ @salkar_comment2 = @salkar.comments.create :post_id => @morozovm_post3.id, :body => "salkar_comment_body"
196
+ @salkar_comment3 = @salkar.comments.create :post_id => @morozovm_post3.id, :body => "salkar_comment_body"
197
+ @salkar_comment4 = @salkar.comments.create :post_id => @morozovm_post3.id, :body => "salkar_comment_body"
198
+ @morozovm_comment2 = @morozovm.comments.create :post_id => @morozovm_post3.id, :body => "salkar_comment_body"
199
+ @salkar_post1 = @salkar.posts.create :body => "salkar_post_test_body"
200
+
201
+ @salkar.favorite @salkar_post
202
+ @salkar.favorite @salkar_comment
203
+ @salkar.favorite @morozovm_post
204
+ @salkar.favorite @morozovm_comment
205
+ @salkar.favorite @salkar_comment1
206
+ @salkar.favorite @morozovm_post1
207
+ @salkar.favorite @morozovm_post2
208
+ @salkar.favorite @morozovm_post3
209
+ @salkar.favorite @salkar_comment2
210
+ @salkar.favorite @salkar_comment3
211
+ @salkar.favorite @salkar_comment4
212
+ @salkar.favorite @morozovm_comment2
213
+ @salkar.favorite @salkar_post1
214
+ @morozovm.favorite @salkar_post1
215
+ @morozovm.favorite @morozovm_comment
216
+ @morozovm.reblog @salkar_comment4
217
+ @morozovm.reblog @salkar_post1
218
+
219
+
220
+ fline = @salkar.favoriteline(:for_user => @morozovm)
221
+ fline.size.should == 10
222
+ fline[0].id.should == @salkar_post1.id
223
+ fline[0].class.to_s.should == 'Post'
224
+ fline[0].item_id_in_line.should == ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@salkar_post1.id, false).id
225
+ fline[0].is_favorited.should == true
226
+ fline[0].is_reblogged.should == true
227
+ fline[2].id.should == @salkar_comment4.id
228
+ fline[2].class.to_s.should == 'Inkwell::Comment'
229
+ fline[2].is_reblogged.should == true
230
+ fline[9].id.should == @morozovm_comment.id
231
+ fline[9].class.to_s.should == 'Inkwell::Comment'
232
+ fline[9].item_id_in_line.should == ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@morozovm_comment.id, true).id
233
+ fline[9].is_favorited.should == true
234
+ for i in 1..8
235
+ fline[i].is_favorited.should == false
236
+ end
237
+ end
238
+
239
+ it "favorite count should been received for post" do
240
+ @talisman = User.create :nick => "Talisman"
241
+ @salkar_post.reload
242
+ @salkar_post.favorite_count.should == 0
243
+ @morozovm.favorite @salkar_post
244
+ @talisman.favorite @salkar_post
245
+ @salkar_post.reload
246
+ @salkar_post.favorite_count.should == 2
247
+ end
248
+
249
+ it "favorite count should been received for post" do
250
+ @talisman = User.create :nick => "Talisman"
251
+ @salkar_comment.reload
252
+ @salkar_comment.favorite_count.should == 0
253
+ @morozovm.favorite @salkar_comment
254
+ @talisman.favorite @salkar_comment
255
+ @salkar_comment.reload
256
+ @salkar_comment.favorite_count.should == 2
257
+ end
258
+
259
+ end
@@ -0,0 +1,120 @@
1
+ require "spec_helper"
2
+
3
+ describe "Following" 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
+ @salkar_comment = @salkar.comments.create :post_id => @salkar_post.id, :body => "salkar_comment_body"
10
+ @salkar_post1 = @salkar.posts.create :body => "salkar_post_test_body"
11
+ @salkar_post2 = @salkar.posts.create :body => "salkar_post_test_body"
12
+ @salkar_post3 = @salkar.posts.create :body => "salkar_post_test_body"
13
+ @morozovm_post = @morozovm.posts.create :body => "salkar_post_test_body"
14
+ @morozovm_post1 = @morozovm.posts.create :body => "salkar_post_test_body"
15
+ @morozovm_post2 = @morozovm.posts.create :body => "salkar_post_test_body"
16
+ @morozovm_post3 = @morozovm.posts.create :body => "salkar_post_test_body"
17
+ @morozovm_comment = @morozovm.comments.create :post_id => @salkar_post.id, :body => "salkar_comment_body"
18
+ end
19
+
20
+ it "user should follow another user" do
21
+ @salkar.follow @morozovm
22
+ @salkar.reload
23
+ @morozovm.reload
24
+ @salkar.followings_ids.should == "[#{@morozovm.id}]"
25
+ @salkar.followings_row.should == [@morozovm.id]
26
+ @salkar.followers_ids.should == "[]"
27
+ @salkar.followers_row.should == []
28
+
29
+ @salkar.timeline_items.size.should == 4
30
+ @salkar.timeline_items.find_by_item_id_and_is_comment(@morozovm_post.id, false).should be
31
+ @salkar.timeline_items.find_by_item_id_and_is_comment(@morozovm_post1.id, false).should be
32
+ @salkar.timeline_items.find_by_item_id_and_is_comment(@morozovm_post2.id, false).should be
33
+ @salkar.timeline_items.find_by_item_id_and_is_comment(@morozovm_post3.id, false).should be
34
+ @salkar.timeline_items.find_by_item_id_and_is_comment(@morozovm_comment.id, true).should == nil
35
+ @salkar.timeline_items.each do |item|
36
+ item.has_many_sources.should == false
37
+ ActiveSupport::JSON.decode(item.from_source).should == [Hash['user_id' => @morozovm.id, 'type' => 'following']]
38
+ end
39
+
40
+ @morozovm.timeline_items.size.should == 0
41
+ @morozovm.followers_ids.should == "[#{@salkar.id}]"
42
+ @morozovm.followers_row.should == [@salkar.id]
43
+ @morozovm.followings_ids.should == "[]"
44
+ @morozovm.followings_row.should == []
45
+ end
46
+
47
+ it "created_at from blog_item should transferred to timeline_item for follower when he follow this user" do
48
+ @salkar.follow @morozovm
49
+ @salkar.timeline_items.find_by_item_id_and_is_comment(@morozovm_post.id, false).created_at.to_s.should == @morozovm_post.created_at.to_s
50
+ @salkar.timeline_items.find_by_item_id_and_is_comment(@morozovm_post1.id, false).created_at.to_s.should == @morozovm_post1.created_at.to_s
51
+ @salkar.timeline_items.find_by_item_id_and_is_comment(@morozovm_post2.id, false).created_at.to_s.should == @morozovm_post2.created_at.to_s
52
+ @salkar.timeline_items.find_by_item_id_and_is_comment(@morozovm_post3.id, false).created_at.to_s.should == @morozovm_post3.created_at.to_s
53
+ end
54
+
55
+ it "user should follow another user (follow?)" do
56
+ @salkar.follow?(@morozovm).should == false
57
+ @salkar.follow @morozovm
58
+ @salkar.reload
59
+ @morozovm.reload
60
+ @salkar.follow?(@morozovm).should be
61
+ @morozovm.follow?(@salkar).should == false
62
+ @salkar.follow @morozovm
63
+ @salkar.follow?(@morozovm).should be
64
+ end
65
+
66
+ it "user should not follow himself" do
67
+ expect{@salkar.follow @salkar}.to raise_error
68
+ end
69
+
70
+ it "user should unfollow another user" do
71
+ @salkar.follow @morozovm
72
+ @salkar.reload
73
+ @salkar.timeline_items.size.should == 4
74
+ @salkar.unfollow @morozovm
75
+ @salkar.reload
76
+ @salkar.timeline_items.size.should == 0
77
+
78
+ end
79
+
80
+ it "reblog should added to followers timeline when follow" do
81
+ @talisman = User.create :nick => "Talisman"
82
+ @talisman.reblog @salkar_post
83
+ @morozovm.follow @talisman
84
+ @morozovm.timeline_items.size.should == 1
85
+ item = @morozovm.timeline_items.first
86
+ item.from_source.should == ActiveSupport::JSON.encode([{'user_id' => @talisman.id, 'type' => 'reblog'}])
87
+ item.item_id.should == @salkar_post.id
88
+ item.is_comment.should == false
89
+ end
90
+
91
+ it "timeline item should not delete if has many sources when unfollow" do
92
+ @talisman = User.create :nick => "Talisman"
93
+ @talisman.reblog @salkar_post
94
+ @morozovm.follow @talisman
95
+ @morozovm.follow @salkar
96
+ @morozovm.timeline_items.where(:item_id => @salkar_post, :is_comment => false).size.should == 1
97
+ item = @morozovm.timeline_items.where(:item_id => @salkar_post, :is_comment => false).first
98
+ item.from_source.should == ActiveSupport::JSON.encode([{'user_id' => @talisman.id, 'type' => 'reblog'},{'user_id' => @salkar.id, 'type' => 'following'}])
99
+ item.has_many_sources.should == true
100
+
101
+ @morozovm.unfollow @salkar
102
+ @morozovm.timeline_items.where(:item_id => @salkar_post, :is_comment => false).size.should == 1
103
+ item = @morozovm.timeline_items.where(:item_id => @salkar_post, :is_comment => false).first
104
+ item.from_source.should == ActiveSupport::JSON.encode([{'user_id' => @talisman.id, 'type' => 'reblog'}])
105
+ item.has_many_sources.should == false
106
+
107
+ @morozovm.follow @salkar
108
+ item = @morozovm.timeline_items.where(:item_id => @salkar_post, :is_comment => false).first
109
+ item.from_source.should == ActiveSupport::JSON.encode([{'user_id' => @talisman.id, 'type' => 'reblog'},{'user_id' => @salkar.id, 'type' => 'following'}])
110
+ item.has_many_sources.should == true
111
+
112
+ @morozovm.unfollow @talisman
113
+ @morozovm.timeline_items.where(:item_id => @salkar_post, :is_comment => false).size.should == 1
114
+ item = @morozovm.timeline_items.where(:item_id => @salkar_post, :is_comment => false).first
115
+ item.from_source.should == ActiveSupport::JSON.encode([{'user_id' => @salkar.id, 'type' => 'following'}])
116
+ item.has_many_sources.should == false
117
+ end
118
+
119
+
120
+ end
@@ -0,0 +1,179 @@
1
+ require "spec_helper"
2
+
3
+ describe "Reblog" do
4
+
5
+ before(:each) do
6
+ @salkar = User.create :nick => "Salkar"
7
+ @morozovm = User.create :nick => "Morozovm"
8
+ @talisman = User.create :nick => "Talisman"
9
+ @salkar_post = @salkar.posts.create :body => "salkar_post_test_body"
10
+ @salkar_comment = @salkar.comments.create :post_id => @salkar_post.id, :body => "salkar_comment_body"
11
+ end
12
+
13
+ it "user should reblog post" do
14
+ @morozovm.reblog @salkar_post
15
+ ::Inkwell::BlogItem.where(:item_id => @salkar_post.id, :is_comment => false).size.should == 2
16
+ ::Inkwell::BlogItem.where(:item_id => @salkar_post.id, :is_comment => false, :user_id => @morozovm.id, :is_reblog => true).size.should == 1
17
+ @salkar_post.reload
18
+ @salkar_post.users_ids_who_reblog_it.should == "[#{@morozovm.id}]"
19
+ end
20
+
21
+ it "user should reblog comment" do
22
+ @morozovm.reblog @salkar_comment
23
+ ::Inkwell::BlogItem.where(:item_id => @salkar_comment.id, :is_comment => true, :user_id => @morozovm.id, :is_reblog => true).size.should == 1
24
+ @salkar_comment.reload
25
+ @salkar_comment.users_ids_who_reblog_it.should == "[#{@morozovm.id}]"
26
+ end
27
+
28
+ it "timeline item should been created for followers when user reblog post" do
29
+ @talisman.follow @morozovm
30
+ @morozovm.reblog @salkar_post
31
+ @talisman.timeline_items.size.should == 1
32
+ item = @talisman.timeline_items.first
33
+ item.item_id.should == @salkar_post.id
34
+ item.created_at.to_i.should == @salkar_post.created_at.to_i
35
+ item.from_source.should == ActiveSupport::JSON.encode([{'user_id' => @morozovm.id, 'type' => 'reblog'}])
36
+ item.is_comment.should == false
37
+ end
38
+
39
+ it "timeline item should been created for followers when user reblog comment" do
40
+ @talisman.follow @morozovm
41
+ @morozovm.reblog @salkar_comment
42
+ @talisman.timeline_items.size.should == 1
43
+ item = @talisman.timeline_items.first
44
+ item.item_id.should == @salkar_comment.id
45
+ item.created_at.to_i.should == @salkar_comment.created_at.to_i
46
+ item.from_source.should == ActiveSupport::JSON.encode([{'user_id' => @morozovm.id, 'type' => 'reblog'}])
47
+ item.is_comment.should == true
48
+ end
49
+
50
+ it "timeline item should not been created for follower's post/comment" do
51
+ @salkar.follow @morozovm
52
+ @morozovm.reblog @salkar_post
53
+ @morozovm.reblog @salkar_comment
54
+ @salkar.timeline_items.size.should == 0
55
+ end
56
+
57
+ it "one timeline item should created for one post with two sources" do
58
+ @talisman.follow @morozovm
59
+ @morozovm.reblog @salkar_post
60
+ @talisman.follow @salkar
61
+ @talisman.timeline_items.where(:item_id => @salkar_post, :is_comment => false).size.should == 1
62
+ item = @talisman.timeline_items.first
63
+ item.has_many_sources.should == true
64
+ item.from_source.should == ActiveSupport::JSON.encode([{'user_id' => @morozovm.id, 'type' => 'reblog'},{'user_id' => @salkar.id, 'type' => 'following'}])
65
+ end
66
+
67
+ it "one timeline item should created for one post with two sources (reblog after follow)" do
68
+ @talisman.follow @morozovm
69
+ @talisman.follow @salkar
70
+ @morozovm.reblog @salkar_post
71
+ @talisman.timeline_items.where(:item_id => @salkar_post, :is_comment => false).size.should == 1
72
+ item = @talisman.timeline_items.first
73
+ item.has_many_sources.should == true
74
+ item.from_source.should == ActiveSupport::JSON.encode([{'user_id' => @salkar.id, 'type' => 'following'}, {'user_id' => @morozovm.id, 'type' => 'reblog'}])
75
+ end
76
+
77
+ it "object should not been relogged" do
78
+ expect{@salkar.reblog("String")}.to raise_error
79
+ expect{@salkar.reblog(@salkar_post)}.to raise_error
80
+ end
81
+
82
+ it "object should been reblogged (reblog?)" do
83
+ @morozovm.reblog?(@salkar_post).should == false
84
+ @morozovm.reblog?(@salkar_comment).should == false
85
+ @morozovm.reblog @salkar_post
86
+ @morozovm.reblog @salkar_comment
87
+ @morozovm.reblog?(@salkar_post).should == true
88
+ @morozovm.reblog?(@salkar_comment).should == true
89
+ end
90
+
91
+ it "user should unreblog post" do
92
+ @morozovm.reblog @salkar_post
93
+ @morozovm.unreblog @salkar_post
94
+ ::Inkwell::BlogItem.where(:item_id => @salkar_post.id, :is_comment => false).size.should == 1
95
+ ::Inkwell::BlogItem.where(:item_id => @salkar_post.id, :is_comment => false, :user_id => @morozovm.id, :is_reblog => true).size.should == 0
96
+ @salkar_post.reload
97
+ @salkar_post.users_ids_who_reblog_it.should == "[]"
98
+ end
99
+
100
+ it "user should unreblog comment" do
101
+ @morozovm.reblog @salkar_comment
102
+ @morozovm.unreblog @salkar_comment
103
+ ::Inkwell::BlogItem.where(:item_id => @salkar_comment.id, :is_comment => true, :user_id => @morozovm.id, :is_reblog => true).size.should == 0
104
+ @salkar_comment.reload
105
+ @salkar_comment.users_ids_who_reblog_it.should == "[]"
106
+ end
107
+
108
+ it "timeline items should delete for followers when user unreblog post" do
109
+ @talisman = User.create :nick => "Talisman"
110
+ @talisman.follow @morozovm
111
+ @morozovm_post = @morozovm.posts.create :body => "morozovm_post_test_body"
112
+ @morozovm.reblog @salkar_post
113
+
114
+ @talisman.timeline_items.size.should == 2
115
+ @talisman.timeline_items.where(:item_id => @salkar_post, :is_comment => false).size.should == 1
116
+ item = @talisman.timeline_items.where(:item_id => @salkar_post, :is_comment => false).first
117
+ item.has_many_sources.should == false
118
+ item.from_source.should == ActiveSupport::JSON.encode([{'user_id' => @morozovm.id, 'type' => 'reblog'}])
119
+
120
+ @morozovm.unreblog @salkar_post
121
+ @talisman.timeline_items.where(:item_id => @salkar_post, :is_comment => false).size.should == 0
122
+ @talisman.timeline_items.size.should == 1
123
+ end
124
+
125
+ it "timeline items should delete for followers when user unreblog comment" do
126
+ @talisman = User.create :nick => "Talisman"
127
+ @talisman.follow @morozovm
128
+ @morozovm.reblog @salkar_comment
129
+
130
+ @talisman.timeline_items.where(:item_id => @salkar_comment, :is_comment => true).size.should == 1
131
+ item = @talisman.timeline_items.first
132
+ item.has_many_sources.should == false
133
+ item.from_source.should == ActiveSupport::JSON.encode([{'user_id' => @morozovm.id, 'type' => 'reblog'}])
134
+
135
+ @morozovm.unreblog @salkar_comment
136
+ @talisman.timeline_items.where(:item_id => @salkar_comment, :is_comment => true).size.should == 0
137
+ end
138
+
139
+ it "timeline item should not been delete if post has many sources and unreblogged by following" do
140
+ @talisman = User.create :nick => "Talisman"
141
+ @talisman.reblog @salkar_post
142
+ @morozovm.follow @talisman
143
+ @morozovm.follow @salkar
144
+ @talisman_post = @talisman.posts.create :body => "talisman_post_test_body"
145
+ @morozovm.timeline_items.size == 2
146
+ @morozovm.timeline_items.where(:item_id => @salkar_post, :is_comment => false).size.should == 1
147
+ item = @morozovm.timeline_items.where(:item_id => @salkar_post, :is_comment => false).first
148
+ item.from_source.should == ActiveSupport::JSON.encode([{'user_id' => @talisman.id, 'type' => 'reblog'}, {'user_id' => @salkar.id, 'type' => 'following'}])
149
+ item.has_many_sources.should == true
150
+
151
+ @talisman.unreblog @salkar_post
152
+ @morozovm.timeline_items.where(:item_id => @salkar_post, :is_comment => false).size.should == 1
153
+ item = @morozovm.timeline_items.where(:item_id => @salkar_post, :is_comment => false).first
154
+ item.from_source.should == ActiveSupport::JSON.encode([{'user_id' => @salkar.id, 'type' => 'following'}])
155
+ item.has_many_sources.should == false
156
+ @morozovm.timeline_items.size == 2
157
+ end
158
+
159
+ it "reblog count should been received for post" do
160
+ @talisman = User.create :nick => "Talisman"
161
+ @salkar_post.reload
162
+ @salkar_post.reblog_count.should == 0
163
+ @morozovm.reblog @salkar_post
164
+ @talisman.reblog @salkar_post
165
+ @salkar_post.reload
166
+ @salkar_post.reblog_count.should == 2
167
+ end
168
+
169
+ it "reblog count should been received for post" do
170
+ @talisman = User.create :nick => "Talisman"
171
+ @salkar_comment.reload
172
+ @salkar_comment.reblog_count.should == 0
173
+ @morozovm.reblog @salkar_comment
174
+ @talisman.reblog @salkar_comment
175
+ @salkar_comment.reload
176
+ @salkar_comment.reblog_count.should == 2
177
+ end
178
+
179
+ end