refinerycms-blog 2.0.4 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.gitignore +6 -1
  5. data/.travis.yml +10 -14
  6. data/Gemfile +30 -50
  7. data/Rakefile +2 -1
  8. data/app/assets/javascripts/refinery/blog/backend.js +18 -59
  9. data/app/assets/stylesheets/refinery/blog/backend.css.scss +10 -61
  10. data/app/assets/stylesheets/refinery/blog/frontend.css.scss +87 -76
  11. data/app/controllers/refinery/blog/admin/categories_controller.rb +7 -1
  12. data/app/controllers/refinery/blog/admin/comments_controller.rb +19 -21
  13. data/app/controllers/refinery/blog/admin/posts_controller.rb +43 -15
  14. data/app/controllers/refinery/blog/blog_controller.rb +31 -5
  15. data/app/controllers/refinery/blog/categories_controller.rb +10 -3
  16. data/app/controllers/refinery/blog/posts_controller.rb +40 -26
  17. data/app/helpers/refinery/blog/controller_helper.rb +1 -22
  18. data/app/helpers/refinery/blog/posts_helper.rb +9 -4
  19. data/app/models/refinery/blog/categorization.rb +11 -0
  20. data/app/models/refinery/blog/category.rb +15 -5
  21. data/app/models/refinery/blog/comment.rb +17 -28
  22. data/app/models/refinery/blog/post.rb +100 -30
  23. data/app/views/refinery/blog/admin/_submenu.html.erb +1 -6
  24. data/app/views/refinery/blog/admin/categories/_category.html.erb +23 -10
  25. data/app/views/refinery/blog/admin/categories/_form.html.erb +10 -11
  26. data/app/views/refinery/blog/admin/categories/_sortable_list.html.erb +2 -4
  27. data/app/views/refinery/blog/admin/categories/edit.html.erb +1 -1
  28. data/app/views/refinery/blog/admin/categories/index.html.erb +9 -15
  29. data/app/views/refinery/blog/admin/categories/new.html.erb +1 -1
  30. data/app/views/refinery/blog/admin/comments/_comment.html.erb +4 -12
  31. data/app/views/refinery/blog/admin/comments/_sortable_list.html.erb +2 -4
  32. data/app/views/refinery/blog/admin/comments/index.html.erb +14 -23
  33. data/app/views/refinery/blog/admin/comments/show.html.erb +6 -4
  34. data/app/views/refinery/blog/admin/posts/_form.html.erb +31 -28
  35. data/app/views/refinery/blog/admin/posts/_form_part.html.erb +1 -1
  36. data/app/views/refinery/blog/admin/posts/_post.html.erb +28 -11
  37. data/app/views/refinery/blog/admin/posts/_sortable_list.html.erb +2 -4
  38. data/app/views/refinery/blog/admin/posts/_teaser_part.html.erb +1 -1
  39. data/app/views/refinery/blog/admin/posts/edit.html.erb +1 -1
  40. data/app/views/refinery/blog/admin/posts/index.html.erb +9 -15
  41. data/app/views/refinery/blog/admin/posts/new.html.erb +1 -1
  42. data/app/views/refinery/blog/admin/posts/uncategorized.html.erb +2 -2
  43. data/app/views/refinery/blog/admin/settings/notification_recipients.html.erb +5 -7
  44. data/app/views/refinery/blog/categories/show.html.erb +4 -4
  45. data/app/views/refinery/blog/comment_mailer/notification.html.erb +5 -0
  46. data/app/views/refinery/blog/posts/_comment.html.erb +4 -4
  47. data/app/views/refinery/blog/posts/_comments.html.erb +28 -31
  48. data/app/views/refinery/blog/posts/_nav.html.erb +6 -6
  49. data/app/views/refinery/blog/posts/_post.html.erb +9 -9
  50. data/app/views/refinery/blog/posts/archive.html.erb +7 -6
  51. data/app/views/refinery/blog/posts/index.html.erb +6 -6
  52. data/app/views/refinery/blog/posts/index.rss.builder +8 -2
  53. data/app/views/refinery/blog/posts/show.html.erb +5 -7
  54. data/app/views/refinery/blog/posts/tagged.html.erb +5 -5
  55. data/app/views/refinery/blog/shared/_body_content_right.html.erb +7 -7
  56. data/app/views/refinery/blog/shared/_categories.html.erb +4 -4
  57. data/app/views/refinery/blog/shared/_post.html.erb +18 -18
  58. data/app/views/refinery/blog/shared/_posts.html.erb +1 -1
  59. data/app/views/refinery/blog/shared/_rss_feed.html.erb +2 -0
  60. data/app/views/refinery/blog/shared/_tags.html.erb +1 -1
  61. data/app/views/refinery/shared/admin/_autocomplete.html.erb +44 -3
  62. data/bin/rails +11 -0
  63. data/bin/refinerycms +62 -0
  64. data/certs/parndt.pem +25 -0
  65. data/changelog.md +4 -1
  66. data/config/initializers/url_validator.rb +15 -11
  67. data/config/locales/bg.yml +8 -10
  68. data/config/locales/cs.yml +7 -9
  69. data/config/locales/de.yml +27 -8
  70. data/config/locales/en.yml +18 -12
  71. data/config/locales/es.yml +2 -4
  72. data/config/locales/fr.yml +34 -16
  73. data/config/locales/it.yml +8 -10
  74. data/config/locales/ja.yml +22 -11
  75. data/config/locales/nb.yml +154 -16
  76. data/config/locales/nl.yml +42 -7
  77. data/config/locales/pl.yml +6 -8
  78. data/config/locales/pt-BR.yml +39 -8
  79. data/config/locales/ru.yml +49 -5
  80. data/config/locales/sk.yml +59 -20
  81. data/config/locales/sv.yml +165 -0
  82. data/config/locales/uk.yml +172 -0
  83. data/config/locales/zh-CN.yml +34 -5
  84. data/config/locales/zh-TW.yml +160 -0
  85. data/config/routes.rb +11 -8
  86. data/db/migrate/20110803223522_create_blog_structure.rb +16 -15
  87. data/db/migrate/20110803223523_add_user_id_to_blog_posts.rb +3 -3
  88. data/db/migrate/20110803223524_acts_as_taggable_on_migration.rb +1 -1
  89. data/db/migrate/20110803223526_add_cached_slugs.rb +3 -3
  90. data/db/migrate/20110803223527_add_custom_url_field_to_blog_posts.rb +2 -2
  91. data/db/migrate/20110803223528_add_custom_teaser_field_to_blog_posts.rb +2 -2
  92. data/db/migrate/20110803223529_add_primary_key_to_categorizations.rb +5 -5
  93. data/db/migrate/20120103055909_add_source_url_to_blog_posts.rb +2 -2
  94. data/db/migrate/20120223022021_add_access_count_to_posts.rb +4 -4
  95. data/db/migrate/20120227022021_add_slug_to_posts_and_categories.rb +2 -2
  96. data/db/migrate/20120530102901_create_blog_translations.rb +17 -0
  97. data/db/migrate/20120531113632_delete_cached_slugs.rb +6 -0
  98. data/db/migrate/20120601151114_create_category_translations.rb +14 -0
  99. data/db/migrate/20140622132537_add_missing_unique_indices.acts_as_taggable_on_engine.rb +20 -0
  100. data/db/migrate/20140622132538_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +15 -0
  101. data/db/migrate/20160602042848_add_username_to_blog_posts.rb +5 -0
  102. data/db/migrate/20161223024527_create_multi_user_model.rb +13 -0
  103. data/db/migrate/20180420132008_remove_translated_columns_to_refinery_blog_categories.rb +5 -0
  104. data/db/seeds.rb +5 -5
  105. data/lib/generators/refinery/blog/templates/config/initializers/refinery/blog.rb.erb +6 -0
  106. data/lib/refinery/blog.rb +4 -1
  107. data/lib/refinery/blog/configuration.rb +25 -1
  108. data/lib/refinery/blog/engine.rb +9 -3
  109. data/readme.md +31 -5
  110. data/refinerycms-blog.gemspec +19 -15
  111. data/script/rails +1 -3
  112. data/spec/controllers/refinery/blog/admin/comments_controller_spec.rb +84 -0
  113. data/spec/controllers/refinery/blog/admin/posts_controller_spec.rb +35 -0
  114. data/spec/controllers/refinery/blog/posts_controller_spec.rb +24 -0
  115. data/spec/factories/blog_categories.rb +1 -1
  116. data/spec/factories/blog_comments.rb +1 -1
  117. data/spec/factories/blog_posts.rb +7 -3
  118. data/spec/factories/blog_test_users.rb +6 -0
  119. data/spec/features/refinery/blog/admin/categories_spec.rb +121 -0
  120. data/spec/{requests → features}/refinery/blog/admin/comments_spec.rb +30 -30
  121. data/spec/features/refinery/blog/admin/menu_spec.rb +19 -0
  122. data/spec/features/refinery/blog/admin/posts_spec.rb +365 -0
  123. data/spec/features/refinery/blog/categories_spec.rb +29 -0
  124. data/spec/features/refinery/blog/posts_spec.rb +171 -0
  125. data/spec/helpers/refinery/blog/posts_helper_spec.rb +23 -11
  126. data/spec/lib/refinery/blog/engine_spec.rb +1 -11
  127. data/spec/models/refinery/blog/category_spec.rb +18 -11
  128. data/spec/models/refinery/blog/comment_spec.rb +4 -4
  129. data/spec/models/refinery/blog/post_spec.rb +97 -60
  130. data/spec/spec_helper.rb +20 -46
  131. data/spec/support/refinery_blog_test_user.rb +2 -0
  132. metadata +168 -95
  133. metadata.gz.sig +0 -0
  134. data/Guardfile +0 -20
  135. data/app/assets/images/refinery/blog/icons/cog.png +0 -0
  136. data/app/assets/images/refinery/blog/icons/comment.png +0 -0
  137. data/app/assets/images/refinery/blog/icons/comment_cross.png +0 -0
  138. data/app/assets/images/refinery/blog/icons/comment_tick.png +0 -0
  139. data/app/assets/images/refinery/blog/icons/comments.png +0 -0
  140. data/app/assets/images/refinery/blog/icons/down.gif +0 -0
  141. data/app/assets/images/refinery/blog/icons/folder.png +0 -0
  142. data/app/assets/images/refinery/blog/icons/folder_add.png +0 -0
  143. data/app/assets/images/refinery/blog/icons/folder_edit.png +0 -0
  144. data/app/assets/images/refinery/blog/icons/page.png +0 -0
  145. data/app/assets/images/refinery/blog/icons/page_add.png +0 -0
  146. data/app/assets/images/refinery/blog/icons/page_copy.png +0 -0
  147. data/app/assets/images/refinery/blog/icons/up.gif +0 -0
  148. data/app/assets/images/refinerycms-blog/.gitkeep +0 -0
  149. data/app/assets/javascripts/refinerycms-blog/.gitkeep +0 -0
  150. data/app/assets/stylesheets/refinerycms-blog/.gitkeep +0 -0
  151. data/app/models/refinery/blog/comment_mailer.rb +0 -1
  152. data/app/models/refinery/categorization.rb +0 -10
  153. data/app/sweepers/refinery/blog_sweeper.rb +0 -26
  154. data/lib/refinery/blog/version.rb +0 -17
  155. data/spec/requests/refinery/blog/admin/categories_spec.rb +0 -20
  156. data/spec/requests/refinery/blog/admin/menu_spec.rb +0 -13
  157. data/spec/requests/refinery/blog/admin/posts_spec.rb +0 -175
  158. data/spec/requests/refinery/blog/categories_spec.rb +0 -24
  159. data/spec/requests/refinery/blog/posts_spec.rb +0 -160
  160. data/todo.md +0 -5
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ module Refinery
4
+ module Blog
5
+ module Admin
6
+ describe Menu, type: :feature do
7
+ refinery_login
8
+
9
+ it "is highlighted when managing the blog" do
10
+ visit refinery.admin_root_path
11
+
12
+ within("#menu") { click_link "Blog" }
13
+
14
+ expect(page).to have_css("a.active", :text => "Blog")
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,365 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+
4
+ shared_context "with_user_class" do
5
+ # This context changes the user class and updates the author association on Post.
6
+ before :each do
7
+ @old_user_class = Refinery::Blog.user_class
8
+ allow(Refinery::Blog).to receive(:user_class).and_return(Refinery::Blog::TestUser)
9
+ Refinery::Blog::Post.reflections['author'].instance_variable_set(:@class_name, Refinery::Blog.user_class.to_s)
10
+ end
11
+
12
+ after :each do
13
+ Refinery::Blog::Post.reflections['author'].instance_variable_set(:@class_name, @old_user_class.to_s)
14
+ end
15
+ end
16
+
17
+ module Refinery
18
+ module Blog
19
+ module Admin
20
+ describe Post, type: :feature do
21
+ refinery_login
22
+
23
+ let!(:blog_category) do
24
+ Globalize.with_locale(:en) { FactoryBot.create(:blog_category) }
25
+ end
26
+
27
+ context "when no blog posts" do
28
+ before { subject.class.destroy_all }
29
+
30
+ describe "blog post listing" do
31
+ before { visit refinery.blog_admin_posts_path }
32
+
33
+ it "invites to create new post" do
34
+ expect(page).to have_content("There are no Blog Posts yet. Click \"Create new post\" to add your first blog post.")
35
+ end
36
+ end
37
+
38
+ describe "new blog post form" do
39
+ before do
40
+ visit refinery.blog_admin_posts_path
41
+ click_link "Create new post"
42
+ end
43
+
44
+ it "should have Tags" do
45
+ expect(page).to have_content("Tags")
46
+ end
47
+
48
+ it "should have category title" do
49
+ expect(page).to have_content(blog_category.title)
50
+ end
51
+
52
+ describe "create blog post" do
53
+ before do
54
+ expect(subject.class.count).to eq(0)
55
+ fill_in "post_title", with: "This is my blog post"
56
+ fill_in "post_body", with: "<p>And I love it</p>"
57
+ fill_in "post_user_id", with: "John Doe"
58
+
59
+ expect(page).to have_css '.blog_categories'
60
+ expect(page).to have_css "#post_category_ids_#{blog_category.id}"
61
+ expect { check(blog_category.title) }.to change {
62
+ !!page.find("#post_category_ids_#{blog_category.id}").checked?
63
+ }.from(false).to(true)
64
+
65
+ click_button "Save"
66
+
67
+ expect(page).to have_content("was successfully added.")
68
+ end
69
+
70
+ it "should be the only blog post" do
71
+ expect(subject.class.count).to eq(1)
72
+ end
73
+
74
+ it "should save categories" do
75
+ expect(subject.class.last.categories.count).to eq(1)
76
+ expect(subject.class.last.categories.first.title).to eq(blog_category.title)
77
+ end
78
+ end
79
+
80
+ describe "create blog post with tags" do
81
+ let(:tag_list) { "chicago, bikes, beers, babes" }
82
+ before do
83
+ fill_in "Title", with: "This is a tagged blog post"
84
+ fill_in "post_body", with: "<p>And I also love it</p>"
85
+ fill_in "post_user_id", with: "John Doe"
86
+ fill_in "Tags", with: tag_list
87
+ click_button "Save"
88
+ end
89
+
90
+ it "should succeed" do
91
+ expect(page).to have_content("was successfully added.")
92
+ end
93
+
94
+ it "should be the only blog post" do
95
+ expect(subject.class.count).to eq(1)
96
+ end
97
+
98
+ it "should have the specified tags" do
99
+ expect(subject.class.last.tag_list.sort).to eq(tag_list.split(', ').sort)
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ context "when has blog posts" do
106
+ let!(:blog_post) do
107
+ Globalize.with_locale(:en) { FactoryBot.create(:blog_post) }
108
+ end
109
+
110
+ describe "blog post listing" do
111
+ before { visit refinery.blog_admin_posts_path }
112
+
113
+ describe "edit blog post" do
114
+ it "should succeed" do
115
+ expect(page).to have_content(blog_post.title)
116
+
117
+ click_link("Edit this blog post")
118
+ expect(current_path).to eq(refinery.edit_blog_admin_post_path(blog_post))
119
+
120
+ fill_in "post_title", :with => "hax0r"
121
+ click_button "Save"
122
+
123
+ expect(page).not_to have_content(blog_post.title)
124
+ expect(page).to have_content("'hax0r' was successfully updated.")
125
+ end
126
+ end
127
+
128
+ describe "deleting blog post" do
129
+ it "should succeed" do
130
+ expect(page).to have_content(blog_post.title)
131
+
132
+ click_link "Remove this blog post forever"
133
+
134
+ expect(page).to have_content("'#{blog_post.title}' was successfully removed.")
135
+ end
136
+ end
137
+
138
+ describe "view live" do
139
+ it "redirects to blog post in the frontend" do
140
+ click_link "View this blog post live"
141
+
142
+ expect(current_path).to eq(refinery.blog_post_path(blog_post))
143
+ expect(page).to have_content(blog_post.title)
144
+ end
145
+ end
146
+ end
147
+
148
+ context "when uncategorized post" do
149
+ it "shows up in the list" do
150
+ visit refinery.uncategorized_blog_admin_posts_path
151
+ expect(page).to have_content(blog_post.title)
152
+ end
153
+ end
154
+
155
+ context "when categorized post" do
156
+ it "won't show up in the list" do
157
+ blog_post.categories << blog_category
158
+ blog_post.save!
159
+
160
+ visit refinery.uncategorized_blog_admin_posts_path
161
+ expect(page).not_to have_content(blog_post.title)
162
+ end
163
+ end
164
+ end
165
+
166
+ context "with multiple users" do
167
+ include_context "with_user_class"
168
+
169
+ let!(:other_guy) { FactoryBot.create(:blog_test_user, :username => "Other Guy") }
170
+
171
+ describe "create blog post with alternate author" do
172
+ before do
173
+ visit refinery.blog_admin_posts_path
174
+ click_link "Create new post"
175
+
176
+ fill_in "post_title", :with => "This is some other guy's blog post"
177
+ fill_in "post_body", with: "<p>I totally did not write it.</p>"
178
+
179
+ expect(page).to have_content("Author")
180
+ select other_guy.username, from: "Author"
181
+
182
+ click_button "Save"
183
+ expect(page).to have_content("was successfully added.")
184
+ end
185
+
186
+ it "belongs to another user" do
187
+ expect(subject.class.last.author).to eq(other_guy)
188
+ end
189
+ end
190
+ end
191
+
192
+ context "with translations" do
193
+ before do
194
+ Globalize.locale = :en
195
+ allow(Refinery::I18n).to receive(:frontend_locales).and_return([:en, :ru])
196
+ blog_page = FactoryBot.create(:page, :link_url => "/blog", :title => "Blog")
197
+ Globalize.with_locale(:ru) do
198
+ blog_page.title = 'блог'
199
+ blog_page.save
200
+ end
201
+ visit refinery.blog_admin_posts_path
202
+ end
203
+
204
+ describe "add a blog post with title for default locale" do
205
+ before do
206
+ click_link "Create new post"
207
+ fill_in "Title", with: "Post"
208
+ fill_in "post_body", with: "One post in my blog"
209
+ fill_in "post_user_id", with: "John Doe"
210
+ click_button "Save"
211
+ @p = Refinery::Blog::Post.by_title("Post")
212
+ end
213
+
214
+ it "succeeds" do
215
+ expect(page).to have_content("'Post' was successfully added.")
216
+ expect(Refinery::Blog::Post.count).to eq(1)
217
+ end
218
+
219
+ it "shows locale for post" do
220
+
221
+ within "#post_#{@p.id}" do
222
+ expect(page).to have_css(".locale .en")
223
+ end
224
+ end
225
+
226
+ it "shows up in blog page for default locale" do
227
+ visit refinery.blog_admin_root_path
228
+ expect(page).to have_selector("#post_#{@p.id}")
229
+ end
230
+
231
+ it "does show locale for default locale" do
232
+ within "#post_#{@p.id}" do
233
+ expect(page).to have_css(".locale .en")
234
+ end
235
+ end
236
+
237
+ it "does not show locale for secondary locale" do
238
+ within "#post_#{@p.id}" do
239
+ expect(page).not_to have_css(".locale .ru")
240
+ end
241
+ end
242
+
243
+ end
244
+
245
+ describe "add a blog post with title only for secondary locale" do
246
+
247
+ let(:ru_page_title) { 'Новости' }
248
+
249
+ before do
250
+ click_link "Create new post"
251
+ within "#switch_locale_picker" do
252
+ click_link "RU"
253
+ end
254
+ fill_in "Title", with: ru_page_title
255
+ fill_in "post_body", with: "One post in my blog"
256
+ fill_in "post_user_id", with: "John Doe"
257
+ click_button "Save"
258
+ @p = Refinery::Blog::Post.by_title(ru_page_title)
259
+ end
260
+
261
+ it "succeeds" do
262
+ expect(page).to have_content("was successfully added.")
263
+ expect(Refinery::Blog::Post.count).to eq(1)
264
+ end
265
+
266
+ it "shows title in secondary locale" do
267
+ within "#post_#{@p.id}" do
268
+ expect(page).to have_content(ru_page_title)
269
+ end
270
+ end
271
+
272
+ it "shows locale for post" do
273
+ within "#post_#{@p.id}" do
274
+ expect(page).to have_css(".locale .ru")
275
+ end
276
+ end
277
+
278
+ it "does not show locale for primary locale" do
279
+ within "#post_#{@p.id}" do
280
+ expect(page).not_to have_css(".locale .en")
281
+ end
282
+ end
283
+
284
+ it "does show locale for secondary locale" do
285
+ within "#post_#{@p.id}" do
286
+ expect(page).to have_css(".locale .ru")
287
+ end
288
+ end
289
+
290
+ it "shows up in blog page for secondary locale" do
291
+ visit refinery.blog_admin_root_path(:locale => :ru)
292
+ expect(page).to have_selector("#post_#{@p.id}")
293
+ end
294
+
295
+ end
296
+
297
+ context "with a blog post in both locales" do
298
+
299
+ let!(:blog_post) do
300
+ _blog_post = Globalize.with_locale(:en) { FactoryBot.create(:blog_post, :title => 'First Post') }
301
+ Globalize.with_locale(:ru) do
302
+ _blog_post.title = 'Домашняя страница'
303
+ _blog_post.save
304
+ end
305
+ _blog_post
306
+ end
307
+
308
+ before do
309
+ visit refinery.blog_admin_posts_path
310
+ end
311
+
312
+ it "shows both locales for post" do
313
+ within "#post_#{blog_post.id}" do
314
+ expect(page).to have_css(".locale .en")
315
+ expect(page).to have_css(".locale .ru")
316
+ end
317
+ end
318
+
319
+ describe "edit the post in english" do
320
+ it "succeeds" do
321
+
322
+ within "#post_#{blog_post.id}" do
323
+ click_link("EN")
324
+ end
325
+ expect(current_path).to eq(refinery.edit_blog_admin_post_path(blog_post))
326
+ fill_in "Title", :with => "New Post Title"
327
+ click_button "Save"
328
+
329
+ expect(page).not_to have_content(blog_post.title)
330
+ expect(page).to have_content("'New Post Title' was successfully updated.")
331
+ end
332
+ end
333
+
334
+ describe "edit the post in secondary locale" do
335
+ it "succeeds" do
336
+ within "#post_#{blog_post.id}" do
337
+ click_link("RU")
338
+ end
339
+
340
+ fill_in "Title", :with => "Нов"
341
+ click_button "Save"
342
+
343
+ expect(page).to have_content("'Нов' was successfully updated.")
344
+ end
345
+ end
346
+
347
+ describe "delete the post translation in secondary locale" do
348
+ it "succeeds" do
349
+ within "#post_#{blog_post.id}" do
350
+ click_link("RU")
351
+ end
352
+
353
+ click_link "Remove this translation"
354
+
355
+ expect(page).not_to have_content('RU')
356
+ expect(page).to have_content("The translation was successfully removed.")
357
+ end
358
+ end
359
+ end
360
+ end
361
+
362
+ end
363
+ end
364
+ end
365
+ end
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+
3
+ module Refinery
4
+ module Blog
5
+ describe Category, type: :feature do
6
+
7
+ context "has one category and post" do
8
+ before do
9
+ post = Globalize.with_locale(:en) do
10
+ FactoryBot.create(:blog_post, :title => "Refinery CMS blog post")
11
+ end
12
+ @category = Globalize.with_locale(:en) do
13
+ FactoryBot.create(:blog_category, :title => "Video Games")
14
+ end
15
+ post.categories << @category
16
+ post.save!
17
+ end
18
+
19
+ describe "show categories blog posts" do
20
+ it "should displays categories blog posts" do
21
+ visit refinery.blog_category_path(@category)
22
+ expect(page).to have_content("Refinery CMS blog post")
23
+ expect(page).to have_content("Video Games")
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,171 @@
1
+ require "spec_helper"
2
+
3
+ module Refinery
4
+ module Blog
5
+ describe Post, type: :feature do
6
+ context "when has blog posts" do
7
+ let!(:blog_post) do
8
+ Globalize.with_locale(:en) { FactoryBot.create(:blog_post, :title => "Refinery CMS blog post") }
9
+ end
10
+
11
+ it "should display blog post" do
12
+ visit refinery.blog_post_path(blog_post)
13
+
14
+ expect(page).to have_content(blog_post.title)
15
+ end
16
+
17
+ describe "visit blog" do
18
+
19
+ before do
20
+ FactoryBot.create(:page, :link_url => "/")
21
+ FactoryBot.create(:page, :link_url => "/blog", :title => "Blog")
22
+ end
23
+
24
+ it "shows blog link in menu" do
25
+ visit "/"
26
+ within "#menu" do
27
+ expect(page).to have_content("Blog")
28
+ expect(page).to have_selector("a[href='/blog']")
29
+ end
30
+ end
31
+
32
+ it "shows blog posts" do
33
+ visit refinery.blog_root_path
34
+ expect(page).to have_content blog_post.title
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ describe "list tagged posts" do
42
+ context "when has tagged blog posts" do
43
+ let!(:tag_name) { "chicago" }
44
+ let!(:post) {
45
+ FactoryBot.create(:blog_post,
46
+ :title => "I Love my city",
47
+ :tag_list => tag_name
48
+ )
49
+ }
50
+ let!(:tag) { ::Refinery::Blog::Post.tag_counts_on(:tags).first }
51
+
52
+ it "should have one tagged post" do
53
+ visit refinery.blog_tagged_posts_path(tag.id, tag_name.parameterize)
54
+
55
+ expect(page).to have_content(tag_name)
56
+ expect(page).to have_content(post.title)
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "#show" do
62
+ context "when has no comments" do
63
+ let!(:blog_post) { FactoryBot.create(:blog_post) }
64
+
65
+ it "should display the blog post" do
66
+ visit refinery.blog_post_path(blog_post)
67
+ expect(page).to have_content(blog_post.title)
68
+ expect(page).to have_content(blog_post.body)
69
+ end
70
+ end
71
+ context "when has approved comments" do
72
+ let!(:approved_comment) { FactoryBot.create(:approved_comment) }
73
+
74
+ it "should display the comments" do
75
+ visit refinery.blog_post_path(approved_comment.post)
76
+
77
+ expect(page).to have_content(approved_comment.body)
78
+ expect(page).to have_content("Posted by #{approved_comment.name}")
79
+ end
80
+ end
81
+ context "when has rejected comments" do
82
+ let!(:rejected_comment) { FactoryBot.create(:rejected_comment) }
83
+
84
+ it "should not display the comments" do
85
+ visit refinery.blog_post_path(rejected_comment.post)
86
+
87
+ expect(page).not_to have_content(rejected_comment.body)
88
+ end
89
+ end
90
+ context "when has new comments" do
91
+ let!(:blog_comment) { FactoryBot.create(:blog_comment) }
92
+
93
+ it "should not display the comments" do
94
+ visit refinery.blog_post_path(blog_comment.post)
95
+
96
+ expect(page).not_to have_content(blog_comment.body)
97
+ end
98
+ end
99
+
100
+ context "when posting comments" do
101
+ let!(:blog_post) { FactoryBot.create(:blog_post) }
102
+ let(:name) { "pete" }
103
+ let(:email) { "pete@mcawesome.com" }
104
+ let(:body) { "Witty comment." }
105
+
106
+ before do
107
+ visit refinery.blog_post_path(blog_post)
108
+
109
+ fill_in "Name", :with => name
110
+ fill_in "Email", :with => email
111
+ fill_in "Message", :with => body
112
+ click_button "Send comment"
113
+ end
114
+
115
+ it "creates the comment" do
116
+ comment = blog_post.reload.comments.last
117
+
118
+ expect(comment.name).to eq(name)
119
+ expect(comment.email).to eq(email)
120
+ expect(comment.body).to eq(body)
121
+ end
122
+ end
123
+
124
+ context "post popular" do
125
+ let!(:blog_post) { FactoryBot.create(:blog_post) }
126
+ let!(:blog_post2) { FactoryBot.create(:blog_post) }
127
+
128
+ before do
129
+ visit refinery.blog_post_path(blog_post)
130
+ end
131
+
132
+ it "should increment access count" do
133
+ expect(blog_post.reload.access_count).to eq(1)
134
+ last_updated = blog_post.reload.updated_at
135
+
136
+ visit refinery.blog_post_path(blog_post)
137
+ expect(blog_post.reload.access_count).to eq(2)
138
+ expect(blog_post.reload.updated_at).to eq(last_updated)
139
+ end
140
+
141
+ it "should be most popular" do
142
+ expect(Refinery::Blog::Post.popular(2).first).to eq(blog_post)
143
+ end
144
+ end
145
+
146
+ context "post recent" do
147
+ let!(:blog_post) { FactoryBot.create(:blog_post, :published_at => Time.now - 5.minutes) }
148
+ let!(:blog_post2) { FactoryBot.create(:blog_post, :published_at => Time.now - 2.minutes) }
149
+
150
+ it "should be the most recent" do
151
+ expect(Refinery::Blog::Post.recent(2).first.id).to eq(blog_post2.id)
152
+ end
153
+ end
154
+
155
+ end
156
+
157
+ describe "#show draft preview" do
158
+ let!(:blog_post) { FactoryBot.create(:blog_post_draft) }
159
+
160
+ context "when logged in as admin" do
161
+ it "should display the draft notification" do
162
+ visit refinery.blog_post_path(blog_post)
163
+
164
+ expect(page).to have_content('This page is NOT live for public viewing.')
165
+ end
166
+ end
167
+
168
+ end
169
+ end
170
+ end
171
+ end