inkwell 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +39 -0
- data/app/assets/javascripts/inkwell/application.js +9 -0
- data/app/assets/stylesheets/inkwell/application.css +7 -0
- data/app/controllers/inkwell/application_controller.rb +4 -0
- data/app/helpers/inkwell/application_helper.rb +4 -0
- data/app/models/inkwell/blog_item.rb +5 -0
- data/app/models/inkwell/comment.rb +125 -0
- data/app/models/inkwell/favorite_item.rb +5 -0
- data/app/models/inkwell/timeline_item.rb +5 -0
- data/app/views/layouts/inkwell/application.html.erb +14 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20121202140510_create_inkwell_timeline_items.rb +13 -0
- data/db/migrate/20121202140816_add_columns_to_posts.rb +7 -0
- data/db/migrate/20121209121955_create_inkwell_blog_items.rb +12 -0
- data/db/migrate/20121209123557_create_inkwell_favorite_items.rb +11 -0
- data/db/migrate/20121209124435_add_columns_to_users.rb +6 -0
- data/db/migrate/20121209124743_create_inkwell_comments.rb +16 -0
- data/lib/acts_as_inkwell_post/base.rb +79 -0
- data/lib/acts_as_inkwell_user/base.rb +286 -0
- data/lib/common/base.rb +16 -0
- data/lib/inkwell.rb +7 -0
- data/lib/inkwell/engine.rb +5 -0
- data/lib/inkwell/version.rb +3 -0
- data/lib/tasks/inkwell_tasks.rake +4 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +9 -0
- data/test/dummy/app/assets/stylesheets/application.css +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/post.rb +5 -0
- data/test/dummy/app/models/user.rb +6 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +45 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +30 -0
- data/test/dummy/config/environments/production.rb +60 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/inkwell.rb +6 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/db/migrate/20121202111750_create_posts.rb +11 -0
- data/test/dummy/db/migrate/20121202112556_create_users.rb +9 -0
- data/test/dummy/db/migrate/20130120124010_create_inkwell_timeline_items.rb +13 -0
- data/test/dummy/db/migrate/20130120124011_add_columns_to_posts.rb +7 -0
- data/test/dummy/db/migrate/20130120124012_create_inkwell_blog_items.rb +12 -0
- data/test/dummy/db/migrate/20130120124013_create_inkwell_favorite_items.rb +11 -0
- data/test/dummy/db/migrate/20130120124014_add_columns_to_users.rb +6 -0
- data/test/dummy/db/migrate/20130120124015_create_inkwell_comments.rb +16 -0
- data/test/dummy/db/schema.rb +75 -0
- data/test/dummy/db/seeds.rb +7 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/spec/functional/blogline_spec.rb +70 -0
- data/test/dummy/spec/functional/comments_spec.rb +396 -0
- data/test/dummy/spec/functional/favorite_spec.rb +236 -0
- data/test/dummy/spec/functional/following_spec.rb +120 -0
- data/test/dummy/spec/functional/reblog_spec.rb +153 -0
- data/test/dummy/spec/functional/timeline_spec.rb +68 -0
- data/test/dummy/spec/spec_helper.rb +52 -0
- metadata +229 -0
@@ -0,0 +1,236 @@
|
|
1
|
+
require "rspec"
|
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
|
+
from_favorite_item_id = ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@morozovm_comment2.id, true).id
|
163
|
+
fline = @salkar.favoriteline(from_favorite_item_id)
|
164
|
+
fline.size.should == 10
|
165
|
+
fline[0].id.should == @salkar_comment4.id
|
166
|
+
fline[0].class.to_s.should == 'Inkwell::Comment'
|
167
|
+
fline[0].item_id_in_line.should == ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@salkar_comment4.id, true).id
|
168
|
+
fline[9].id.should == @salkar_comment.id
|
169
|
+
fline[9].class.to_s.should == 'Inkwell::Comment'
|
170
|
+
fline[9].item_id_in_line.should == ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@salkar_comment.id, true).id
|
171
|
+
|
172
|
+
from_favorite_item_id = ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@morozovm_comment2.id, true).id
|
173
|
+
fline = @salkar.favoriteline(from_favorite_item_id, 5)
|
174
|
+
fline.size.should == 5
|
175
|
+
fline[0].id.should == @salkar_comment4.id
|
176
|
+
fline[0].class.to_s.should == 'Inkwell::Comment'
|
177
|
+
fline[0].item_id_in_line.should == ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@salkar_comment4.id, true).id
|
178
|
+
fline[4].id.should == @morozovm_post2.id
|
179
|
+
fline[4].class.to_s.should == 'Post'
|
180
|
+
fline[4].item_id_in_line.should == ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@morozovm_post2.id, false).id
|
181
|
+
end
|
182
|
+
|
183
|
+
it "Favoriteline should been return for for_user" do
|
184
|
+
@salkar_post = @salkar.posts.create :body => "salkar_post_test_body"
|
185
|
+
@salkar_comment = @salkar.comments.create :post_id => @salkar_post.id, :body => "salkar_comment_body"
|
186
|
+
@morozovm_post = @morozovm.posts.create :body => "salkar_post_test_body"
|
187
|
+
@morozovm_comment = @morozovm.comments.create :post_id => @morozovm_post.id, :body => "salkar_comment_body"
|
188
|
+
@salkar_comment1 = @salkar.comments.create :post_id => @morozovm_post.id, :body => "salkar_comment_body"
|
189
|
+
@morozovm_post1 = @morozovm.posts.create :body => "salkar_post_test_body"
|
190
|
+
@morozovm_post2 = @morozovm.posts.create :body => "salkar_post_test_body"
|
191
|
+
@morozovm_post3 = @morozovm.posts.create :body => "salkar_post_test_body"
|
192
|
+
@salkar_comment2 = @salkar.comments.create :post_id => @morozovm_post3.id, :body => "salkar_comment_body"
|
193
|
+
@salkar_comment3 = @salkar.comments.create :post_id => @morozovm_post3.id, :body => "salkar_comment_body"
|
194
|
+
@salkar_comment4 = @salkar.comments.create :post_id => @morozovm_post3.id, :body => "salkar_comment_body"
|
195
|
+
@morozovm_comment2 = @morozovm.comments.create :post_id => @morozovm_post3.id, :body => "salkar_comment_body"
|
196
|
+
@salkar_post1 = @salkar.posts.create :body => "salkar_post_test_body"
|
197
|
+
|
198
|
+
@salkar.favorite @salkar_post
|
199
|
+
@salkar.favorite @salkar_comment
|
200
|
+
@salkar.favorite @morozovm_post
|
201
|
+
@salkar.favorite @morozovm_comment
|
202
|
+
@salkar.favorite @salkar_comment1
|
203
|
+
@salkar.favorite @morozovm_post1
|
204
|
+
@salkar.favorite @morozovm_post2
|
205
|
+
@salkar.favorite @morozovm_post3
|
206
|
+
@salkar.favorite @salkar_comment2
|
207
|
+
@salkar.favorite @salkar_comment3
|
208
|
+
@salkar.favorite @salkar_comment4
|
209
|
+
@salkar.favorite @morozovm_comment2
|
210
|
+
@salkar.favorite @salkar_post1
|
211
|
+
@morozovm.favorite @salkar_post1
|
212
|
+
@morozovm.favorite @morozovm_comment
|
213
|
+
@morozovm.reblog @salkar_comment4
|
214
|
+
@morozovm.reblog @salkar_post1
|
215
|
+
|
216
|
+
|
217
|
+
fline = @salkar.favoriteline(nil,10,@morozovm)
|
218
|
+
fline.size.should == 10
|
219
|
+
fline[0].id.should == @salkar_post1.id
|
220
|
+
fline[0].class.to_s.should == 'Post'
|
221
|
+
fline[0].item_id_in_line.should == ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@salkar_post1.id, false).id
|
222
|
+
fline[0].is_favorited.should == true
|
223
|
+
fline[0].is_reblogged.should == true
|
224
|
+
fline[2].id.should == @salkar_comment4.id
|
225
|
+
fline[2].class.to_s.should == 'Inkwell::Comment'
|
226
|
+
fline[2].is_reblogged.should == true
|
227
|
+
fline[9].id.should == @morozovm_comment.id
|
228
|
+
fline[9].class.to_s.should == 'Inkwell::Comment'
|
229
|
+
fline[9].item_id_in_line.should == ::Inkwell::FavoriteItem.find_by_item_id_and_is_comment(@morozovm_comment.id, true).id
|
230
|
+
fline[9].is_favorited.should == true
|
231
|
+
for i in 1..8
|
232
|
+
fline[i].is_favorited.should == false
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require "rspec"
|
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,153 @@
|
|
1
|
+
require "rspec"
|
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.reblog @salkar_post
|
112
|
+
|
113
|
+
@talisman.timeline_items.where(:item_id => @salkar_post, :is_comment => false).size.should == 1
|
114
|
+
item = @talisman.timeline_items.first
|
115
|
+
item.has_many_sources.should == false
|
116
|
+
item.from_source.should == ActiveSupport::JSON.encode([{'user_id' => @morozovm.id, 'type' => 'reblog'}])
|
117
|
+
|
118
|
+
@morozovm.unreblog @salkar_post
|
119
|
+
@talisman.timeline_items.where(:item_id => @salkar_post, :is_comment => false).size.should == 0
|
120
|
+
end
|
121
|
+
|
122
|
+
it "timeline items should delete for followers when user unreblog comment" do
|
123
|
+
@talisman = User.create :nick => "Talisman"
|
124
|
+
@talisman.follow @morozovm
|
125
|
+
@morozovm.reblog @salkar_comment
|
126
|
+
|
127
|
+
@talisman.timeline_items.where(:item_id => @salkar_comment, :is_comment => true).size.should == 1
|
128
|
+
item = @talisman.timeline_items.first
|
129
|
+
item.has_many_sources.should == false
|
130
|
+
item.from_source.should == ActiveSupport::JSON.encode([{'user_id' => @morozovm.id, 'type' => 'reblog'}])
|
131
|
+
|
132
|
+
@morozovm.unreblog @salkar_comment
|
133
|
+
@talisman.timeline_items.where(:item_id => @salkar_comment, :is_comment => true).size.should == 0
|
134
|
+
end
|
135
|
+
|
136
|
+
it "timeline item should not been delete if post has many sources and unreblogged by following" do
|
137
|
+
@talisman = User.create :nick => "Talisman"
|
138
|
+
@talisman.reblog @salkar_post
|
139
|
+
@morozovm.follow @talisman
|
140
|
+
@morozovm.follow @salkar
|
141
|
+
@morozovm.timeline_items.where(:item_id => @salkar_post, :is_comment => false).size.should == 1
|
142
|
+
item = @morozovm.timeline_items.where(:item_id => @salkar_post, :is_comment => false).first
|
143
|
+
item.from_source.should == ActiveSupport::JSON.encode([{'user_id' => @talisman.id, 'type' => 'reblog'}, {'user_id' => @salkar.id, 'type' => 'following'}])
|
144
|
+
item.has_many_sources.should == true
|
145
|
+
|
146
|
+
@talisman.unreblog @salkar_post
|
147
|
+
@morozovm.timeline_items.where(:item_id => @salkar_post, :is_comment => false).size.should == 1
|
148
|
+
item = @morozovm.timeline_items.where(:item_id => @salkar_post, :is_comment => false).first
|
149
|
+
item.from_source.should == ActiveSupport::JSON.encode([{'user_id' => @salkar.id, 'type' => 'following'}])
|
150
|
+
item.has_many_sources.should == false
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|