refinerycms-blog 2.0.5 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -1
  3. data/.travis.yml +3 -9
  4. data/Gemfile +10 -11
  5. data/app/assets/images/refinery/blog/icons/add.png +0 -0
  6. data/app/assets/stylesheets/refinery/blog/backend.css.scss +25 -25
  7. data/app/assets/stylesheets/refinery/blog/frontend.css.scss +87 -76
  8. data/app/controllers/refinery/blog/admin/comments_controller.rb +19 -19
  9. data/app/controllers/refinery/blog/admin/posts_controller.rb +9 -4
  10. data/app/controllers/refinery/blog/categories_controller.rb +1 -1
  11. data/app/controllers/refinery/blog/posts_controller.rb +12 -11
  12. data/app/helpers/refinery/blog/controller_helper.rb +7 -7
  13. data/app/helpers/refinery/blog/posts_helper.rb +5 -0
  14. data/app/models/refinery/blog/categorization.rb +12 -0
  15. data/app/models/refinery/blog/category.rb +14 -4
  16. data/app/models/refinery/blog/comment.rb +0 -9
  17. data/app/models/refinery/blog/post.rb +55 -13
  18. data/app/views/refinery/blog/admin/_submenu.html.erb +1 -4
  19. data/app/views/refinery/blog/admin/categories/_category.html.erb +11 -3
  20. data/app/views/refinery/blog/admin/categories/_form.html.erb +10 -11
  21. data/app/views/refinery/blog/admin/categories/_sortable_list.html.erb +2 -4
  22. data/app/views/refinery/blog/admin/categories/edit.html.erb +1 -1
  23. data/app/views/refinery/blog/admin/categories/index.html.erb +9 -15
  24. data/app/views/refinery/blog/admin/categories/new.html.erb +1 -1
  25. data/app/views/refinery/blog/admin/comments/_comment.html.erb +4 -2
  26. data/app/views/refinery/blog/admin/comments/_sortable_list.html.erb +2 -4
  27. data/app/views/refinery/blog/admin/comments/index.html.erb +14 -23
  28. data/app/views/refinery/blog/admin/comments/show.html.erb +6 -4
  29. data/app/views/refinery/blog/admin/posts/_form.html.erb +18 -26
  30. data/app/views/refinery/blog/admin/posts/_post.html.erb +14 -1
  31. data/app/views/refinery/blog/admin/posts/_sortable_list.html.erb +2 -4
  32. data/app/views/refinery/blog/admin/posts/edit.html.erb +1 -1
  33. data/app/views/refinery/blog/admin/posts/index.html.erb +9 -15
  34. data/app/views/refinery/blog/admin/posts/new.html.erb +1 -1
  35. data/app/views/refinery/blog/admin/posts/uncategorized.html.erb +2 -2
  36. data/app/views/refinery/blog/admin/settings/notification_recipients.html.erb +5 -7
  37. data/app/views/refinery/blog/categories/show.html.erb +2 -2
  38. data/app/views/refinery/blog/comment_mailer/notification.html.erb +5 -0
  39. data/app/views/refinery/blog/posts/_comment.html.erb +1 -1
  40. data/app/views/refinery/blog/posts/_comments.html.erb +28 -31
  41. data/app/views/refinery/blog/posts/_post.html.erb +3 -3
  42. data/app/views/refinery/blog/posts/archive.html.erb +6 -5
  43. data/app/views/refinery/blog/posts/index.html.erb +3 -3
  44. data/app/views/refinery/blog/posts/show.html.erb +4 -6
  45. data/app/views/refinery/blog/posts/tagged.html.erb +4 -4
  46. data/app/views/refinery/blog/shared/_body_content_right.html.erb +6 -6
  47. data/app/views/refinery/blog/shared/_post.html.erb +11 -13
  48. data/app/views/refinery/blog/shared/_rss_feed.html.erb +2 -0
  49. data/config/initializers/url_validator.rb +15 -11
  50. data/config/locales/bg.yml +2 -4
  51. data/config/locales/cs.yml +6 -8
  52. data/config/locales/de.yml +27 -8
  53. data/config/locales/en.yml +9 -6
  54. data/config/locales/es.yml +2 -4
  55. data/config/locales/fr.yml +23 -7
  56. data/config/locales/it.yml +2 -4
  57. data/config/locales/ja.yml +16 -5
  58. data/config/locales/nb.yml +0 -2
  59. data/config/locales/nl.yml +21 -7
  60. data/config/locales/pl.yml +3 -5
  61. data/config/locales/pt-BR.yml +38 -7
  62. data/config/locales/ru.yml +35 -2
  63. data/config/locales/sk.yml +4 -6
  64. data/config/locales/sv.yml +2 -4
  65. data/config/locales/zh-CN.yml +2 -4
  66. data/config/routes.rb +3 -3
  67. data/db/migrate/20110803223522_create_blog_structure.rb +15 -14
  68. data/db/migrate/20110803223523_add_user_id_to_blog_posts.rb +2 -2
  69. data/db/migrate/20110803223526_add_cached_slugs.rb +2 -2
  70. data/db/migrate/20110803223527_add_custom_url_field_to_blog_posts.rb +1 -1
  71. data/db/migrate/20110803223528_add_custom_teaser_field_to_blog_posts.rb +1 -1
  72. data/db/migrate/20110803223529_add_primary_key_to_categorizations.rb +4 -4
  73. data/db/migrate/20120530102901_create_blog_translations.rb +17 -0
  74. data/db/migrate/20120531113632_delete_cached_slugs.rb +6 -0
  75. data/db/migrate/20120601151114_create_category_translations.rb +14 -0
  76. data/db/seeds.rb +2 -2
  77. data/lib/generators/refinery/blog/templates/config/initializers/refinery/blog.rb.erb +3 -0
  78. data/lib/refinery/blog.rb +1 -0
  79. data/lib/refinery/blog/configuration.rb +23 -0
  80. data/readme.md +3 -3
  81. data/refinerycms-blog.gemspec +8 -14
  82. data/spec/controllers/refinery/blog/admin/comments_controller_spec.rb +84 -0
  83. data/spec/controllers/refinery/blog/posts_controller_spec.rb +0 -2
  84. data/spec/factories/blog_posts.rb +2 -2
  85. data/spec/features/refinery/blog/admin/categories_spec.rb +119 -0
  86. data/spec/{requests → features}/refinery/blog/admin/comments_spec.rb +9 -9
  87. data/spec/{requests → features}/refinery/blog/admin/menu_spec.rb +2 -2
  88. data/spec/features/refinery/blog/admin/posts_spec.rb +338 -0
  89. data/spec/features/refinery/blog/categories_spec.rb +28 -0
  90. data/spec/{requests → features}/refinery/blog/posts_spec.rb +62 -42
  91. data/spec/helpers/refinery/blog/controller_helper_spec.rb +27 -0
  92. data/spec/helpers/refinery/blog/posts_helper_spec.rb +12 -0
  93. data/spec/models/refinery/blog/category_spec.rb +10 -2
  94. data/spec/models/refinery/blog/post_spec.rb +21 -17
  95. data/spec/spec_helper.rb +20 -46
  96. metadata +41 -38
  97. data/Guardfile +0 -20
  98. data/app/assets/images/refinerycms-blog/.gitkeep +0 -0
  99. data/app/assets/javascripts/refinerycms-blog/.gitkeep +0 -0
  100. data/app/assets/stylesheets/refinerycms-blog/.gitkeep +0 -0
  101. data/app/models/refinery/categorization.rb +0 -10
  102. data/app/views/refinery/blog/admin/comments/approve.html.erb +0 -0
  103. data/lib/refinery/blog/version.rb +0 -17
  104. data/spec/requests/refinery/blog/admin/categories_spec.rb +0 -20
  105. data/spec/requests/refinery/blog/admin/posts_spec.rb +0 -175
  106. data/spec/requests/refinery/blog/categories_spec.rb +0 -24
@@ -4,11 +4,11 @@ module Refinery
4
4
  module Blog
5
5
  module Admin
6
6
  describe Comment do
7
- login_refinery_user
7
+ refinery_login_with :refinery_user
8
8
 
9
9
  describe "#index" do
10
10
  context "when has no new unapproved comments" do
11
- before(:each) do
11
+ before do
12
12
  subject.class.delete_all
13
13
  visit refinery.blog_admin_comments_path
14
14
  end
@@ -21,7 +21,7 @@ module Refinery
21
21
  end
22
22
  context "when has new unapproved comments" do
23
23
  let!(:blog_comment) { FactoryGirl.create(:blog_comment) }
24
- before(:each) { visit refinery.blog_admin_comments_path }
24
+ before { visit refinery.blog_admin_comments_path }
25
25
 
26
26
  it "should list comments" do
27
27
  page.should have_content(blog_comment.body)
@@ -44,7 +44,7 @@ module Refinery
44
44
 
45
45
  describe "#approved" do
46
46
  context "when has no approved comments" do
47
- before(:each) do
47
+ before do
48
48
  subject.class.delete_all
49
49
  visit refinery.approved_blog_admin_comments_path
50
50
  end
@@ -57,7 +57,7 @@ module Refinery
57
57
  let!(:blog_comment) do
58
58
  FactoryGirl.create(:blog_comment, :state => 'approved')
59
59
  end
60
- before(:each) { visit refinery.approved_blog_admin_comments_path }
60
+ before { visit refinery.approved_blog_admin_comments_path }
61
61
 
62
62
  it "should list comments" do
63
63
  page.should have_content(blog_comment.body)
@@ -74,7 +74,7 @@ module Refinery
74
74
 
75
75
  describe "#rejected" do
76
76
  context "when has no rejected comments" do
77
- before(:each) do
77
+ before do
78
78
  subject.class.delete_all
79
79
  visit refinery.rejected_blog_admin_comments_path
80
80
  end
@@ -87,7 +87,7 @@ module Refinery
87
87
  let!(:blog_comment) do
88
88
  FactoryGirl.create(:blog_comment, :state => 'rejected')
89
89
  end
90
- before(:each) { visit refinery.rejected_blog_admin_comments_path }
90
+ before { visit refinery.rejected_blog_admin_comments_path }
91
91
 
92
92
  it "should list comments" do
93
93
  page.should have_content(blog_comment.body)
@@ -104,7 +104,7 @@ module Refinery
104
104
 
105
105
  describe "#show" do
106
106
  let!(:blog_comment) { FactoryGirl.create(:blog_comment) }
107
- before(:each) { visit refinery.blog_admin_comment_path(blog_comment) }
107
+ before { visit refinery.blog_admin_comment_path(blog_comment) }
108
108
  it "should display the comment" do
109
109
  page.should have_content(blog_comment.body)
110
110
  page.should have_content(blog_comment.name)
@@ -118,4 +118,4 @@ module Refinery
118
118
  end
119
119
  end
120
120
  end
121
- end
121
+ end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Blog menu entry" do
4
- login_refinery_user
5
-
4
+ refinery_login_with :refinery_user
5
+
6
6
  it "is highlighted when managing the blog" do
7
7
  visit refinery.admin_root_path
8
8
 
@@ -0,0 +1,338 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+
4
+ module Refinery
5
+ module Blog
6
+ module Admin
7
+ describe Post do
8
+ refinery_login_with :refinery_user
9
+
10
+ let!(:blog_category) do
11
+ Globalize.with_locale(:en) { FactoryGirl.create(:blog_category) }
12
+ end
13
+
14
+ context "when no blog posts" do
15
+ before { subject.class.destroy_all }
16
+
17
+ describe "blog post listing" do
18
+ before { visit refinery.blog_admin_posts_path }
19
+
20
+ it "invites to create new post" do
21
+ page.should have_content("There are no Blog Posts yet. Click \"Create new post\" to add your first blog post.")
22
+ end
23
+ end
24
+
25
+ describe "new blog post form" do
26
+ before do
27
+ visit refinery.blog_admin_posts_path
28
+ click_link "Create new post"
29
+ end
30
+
31
+ it "should have Tags" do
32
+ page.should have_content("Tags")
33
+ end
34
+
35
+ it "should have category title", :js => true do
36
+ click_link "toggle_advanced_options"
37
+ page.should have_content(blog_category.title)
38
+ end
39
+
40
+ describe "create blog post", :js => true do
41
+ before do
42
+ fill_in "post_title", :with => "This is my blog post"
43
+ # this is a dirty hack but textarea that needs to be filled is
44
+ # hidden and capybara refuses to fill in elements it can't see
45
+ page.evaluate_script("WYMeditor.INSTANCES[0].html('<p>And I love it</p>')")
46
+ click_link "toggle_advanced_options"
47
+ check blog_category.title
48
+ click_button "Save"
49
+ end
50
+
51
+ it "should succeed" do
52
+ page.should have_content("was successfully added.")
53
+ end
54
+
55
+ it "should be the only blog post" do
56
+ subject.class.count.should eq(1)
57
+ end
58
+
59
+ it "should belong to me" do
60
+ subject.class.first.author.should eq(::Refinery::User.last)
61
+ end
62
+
63
+ it "should save categories" do
64
+ subject.class.last.categories.count.should eq(1)
65
+ subject.class.last.categories.first.title.should eq(blog_category.title)
66
+ end
67
+ end
68
+
69
+ describe "create blog post with tags", :js => true do
70
+ before do
71
+ @tag_list = "chicago, bikes, beers, babes"
72
+ fill_in "Title", :with => "This is a tagged blog post"
73
+ # this is a dirty hack but textarea that needs to be filled is
74
+ # hidden and capybara refuses to fill in elements it can't see
75
+ page.evaluate_script("WYMeditor.INSTANCES[0].html('<p>And I also love it</p>')")
76
+ fill_in "Tags", :with => @tag_list
77
+ click_button "Save"
78
+ end
79
+
80
+ it "should succeed" do
81
+ page.should have_content("was successfully added.")
82
+ end
83
+
84
+ it "should be the only blog post" do
85
+ subject.class.count.should eq(1)
86
+ end
87
+
88
+ it "should have the specified tags" do
89
+ subject.class.last.tag_list.sort.should eq(@tag_list.split(', ').sort)
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ context "when has blog posts" do
96
+ let!(:blog_post) do
97
+ Globalize.with_locale(:en) { FactoryGirl.create(:blog_post) }
98
+ end
99
+
100
+ describe "blog post listing" do
101
+ before { visit refinery.blog_admin_posts_path }
102
+
103
+ describe "edit blog post" do
104
+ it "should succeed" do
105
+ page.should have_content(blog_post.title)
106
+
107
+ click_link("Edit this blog post")
108
+ current_path.should == refinery.edit_blog_admin_post_path(blog_post)
109
+
110
+ fill_in "post_title", :with => "hax0r"
111
+ click_button "Save"
112
+
113
+ page.should_not have_content(blog_post.title)
114
+ page.should have_content("'hax0r' was successfully updated.")
115
+ end
116
+ end
117
+
118
+ describe "deleting blog post" do
119
+ it "should succeed" do
120
+ page.should have_content(blog_post.title)
121
+
122
+ click_link "Remove this blog post forever"
123
+
124
+ page.should have_content("'#{blog_post.title}' was successfully removed.")
125
+ end
126
+ end
127
+
128
+ describe "view live" do
129
+ it "redirects to blog post in the frontend" do
130
+ click_link "View this blog post live"
131
+
132
+ current_path.should == refinery.blog_post_path(blog_post)
133
+ page.should have_content(blog_post.title)
134
+ end
135
+ end
136
+ end
137
+
138
+ context "when uncategorized post" do
139
+ it "shows up in the list" do
140
+ visit refinery.uncategorized_blog_admin_posts_path
141
+ page.should have_content(blog_post.title)
142
+ end
143
+ end
144
+
145
+ context "when categorized post" do
146
+ it "won't show up in the list" do
147
+ blog_post.categories << blog_category
148
+ blog_post.save!
149
+
150
+ visit refinery.uncategorized_blog_admin_posts_path
151
+ page.should_not have_content(blog_post.title)
152
+ end
153
+ end
154
+ end
155
+
156
+ context "with multiple users" do
157
+ let!(:other_guy) { FactoryGirl.create(:refinery_user, :username => "Other Guy") }
158
+
159
+ describe "create blog post with alternate author", :js => true do
160
+ before do
161
+ visit refinery.blog_admin_posts_path
162
+ click_link "Create new post"
163
+
164
+ fill_in "post_title", :with => "This is some other guy's blog post"
165
+ # this is a dpage_titleirty hack but textarea that needs to be filled is
166
+ # hidden and capybara refuses to fill in elements it can't see
167
+ page.evaluate_script("WYMeditor.INSTANCES[0].html('<p>I totally did not write it.</p>')")
168
+
169
+ click_link "toggle_advanced_options"
170
+
171
+ select other_guy.username, :from => "Author"
172
+
173
+ click_button "Save"
174
+ end
175
+
176
+ it "should succeed" do
177
+ page.should have_content("was successfully added.")
178
+ end
179
+
180
+ it "belongs to another user" do
181
+ subject.class.last.author.should eq(other_guy)
182
+ end
183
+ end
184
+ end
185
+
186
+ context "with translations" do
187
+ before do
188
+ Globalize.locale = :en
189
+ Refinery::I18n.stub(:frontend_locales).and_return([:en, :ru])
190
+ blog_page = FactoryGirl.create(:page, :link_url => "/blog", :title => "Blog")
191
+ Globalize.with_locale(:ru) do
192
+ blog_page.title = 'блог'
193
+ blog_page.save
194
+ end
195
+ visit refinery.blog_admin_posts_path
196
+ end
197
+
198
+ describe "add a blog post with title for default locale" do
199
+ before do
200
+ click_link "Create new post"
201
+ fill_in "Title", :with => "Post"
202
+ fill_in "post_body", :with => "One post in my blog"
203
+ click_button "Save"
204
+ @p = Refinery::Blog::Post.find_by_title("Post")
205
+ end
206
+
207
+ it "succeeds" do
208
+ page.should have_content("'Post' was successfully added.")
209
+ Refinery::Blog::Post.count.should eq(1)
210
+ end
211
+
212
+ it "shows locale flag for post" do
213
+
214
+ within "#post_#{@p.id}" do
215
+ page.should have_css("img[src='/assets/refinery/icons/flags/en.png']")
216
+ end
217
+ end
218
+
219
+ it "shows up in blog page for default locale" do
220
+ visit refinery.blog_root_path
221
+ page.should have_selector("#post_#{@p.id}")
222
+ end
223
+
224
+ it "does not show up in blog page for secondary locale" do
225
+ visit refinery.blog_root_path(:locale => :ru)
226
+ page.should_not have_selector("#post_#{@p.id}")
227
+ end
228
+
229
+ end
230
+
231
+ describe "add a blog post with title only for secondary locale" do
232
+
233
+ let(:ru_page_title) { 'Новости' }
234
+
235
+ before do
236
+ click_link "Create new post"
237
+ within "#switch_locale_picker" do
238
+ click_link "Ru"
239
+ end
240
+ fill_in "Title", :with => ru_page_title
241
+ fill_in "post_body", :with => "One post in my blog"
242
+ click_button "Save"
243
+ @p = Refinery::Blog::Post.find_by_title("Новости")
244
+ end
245
+
246
+ it "succeeds" do
247
+ page.should have_content("was successfully added.")
248
+ Refinery::Blog::Post.count.should eq(1)
249
+ end
250
+
251
+ it "shows title in secondary locale" do
252
+ within "#post_#{@p.id}" do
253
+ page.should have_content(ru_page_title)
254
+ end
255
+ end
256
+
257
+ it "shows locale flag for post" do
258
+ within "#post_#{@p.id}" do
259
+ page.should have_css("img[src='/assets/refinery/icons/flags/ru.png']")
260
+ end
261
+ end
262
+
263
+ it "does not show locale flag for primary locale" do
264
+ within "#post_#{@p.id}" do
265
+ page.should_not have_css("img[src='/assets/refinery/icons/flags/en.png']")
266
+ end
267
+ end
268
+
269
+ it "does not show up in blog page for default locale" do
270
+ visit refinery.blog_root_path
271
+ page.should_not have_selector("#post_#{@p.id}")
272
+ end
273
+
274
+ it "shows up in blog page for secondary locale" do
275
+ visit refinery.blog_root_path(:locale => :ru)
276
+ page.should have_selector("#post_#{@p.id}")
277
+ end
278
+
279
+ end
280
+
281
+ context "with a blog post in both locales" do
282
+
283
+ let!(:blog_post) do
284
+ _blog_post = Globalize.with_locale(:en) { FactoryGirl.create(:blog_post, :title => 'First Post') }
285
+ Globalize.with_locale(:ru) do
286
+ _blog_post.title = 'Домашняя страница'
287
+ _blog_post.save
288
+ end
289
+ _blog_post
290
+ end
291
+
292
+ before do
293
+ visit refinery.blog_admin_posts_path
294
+ end
295
+
296
+ it "shows both locale flags for post" do
297
+ within "#post_#{blog_post.id}" do
298
+ page.should have_css("img[src='/assets/refinery/icons/flags/en.png']")
299
+ page.should have_css("img[src='/assets/refinery/icons/flags/ru.png']")
300
+ end
301
+ end
302
+
303
+ describe "edit the post in english" do
304
+ it "succeeds" do
305
+
306
+ within "#post_#{blog_post.id}" do
307
+ click_link("En")
308
+ end
309
+ current_path.should == refinery.edit_blog_admin_post_path(blog_post)
310
+ fill_in "Title", :with => "New Post Title"
311
+ click_button "Save"
312
+
313
+ page.should_not have_content(blog_post.title)
314
+ page.should have_content("'New Post Title' was successfully updated.")
315
+ end
316
+ end
317
+
318
+ describe "edit the post in secondary locale" do
319
+ it "succeeds" do
320
+ within "#post_#{blog_post.id}" do
321
+ click_link("Ru")
322
+ end
323
+
324
+ fill_in "Title", :with => "Нов"
325
+ click_button "Save"
326
+
327
+ page.should_not have_content(blog_post.title)
328
+ page.should have_content("'Нов' was successfully updated.")
329
+ end
330
+ end
331
+
332
+ end
333
+ end
334
+
335
+ end
336
+ end
337
+ end
338
+ end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ module Refinery
4
+ describe "BlogCategories" do
5
+ refinery_login_with :refinery_user
6
+
7
+ context "has one category and post" do
8
+ before do
9
+ post = Globalize.with_locale(:en) do
10
+ FactoryGirl.create(:blog_post, :title => "Refinery CMS blog post")
11
+ end
12
+ @category = Globalize.with_locale(:en) do
13
+ FactoryGirl.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
+ page.should have_content("Refinery CMS blog post")
23
+ page.should have_content("Video Games")
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -2,47 +2,65 @@ require "spec_helper"
2
2
 
3
3
  module Refinery
4
4
  describe "Blog::Posts" do
5
- login_refinery_user
6
-
7
- context "when has blog posts" do
8
- let!(:blog_post) { FactoryGirl.create(:blog_post, :title => "Refinery CMS blog post") }
9
-
5
+ refinery_login_with :refinery_user
6
+
7
+ context "when has blog posts" do
8
+ let!(:blog_post) do
9
+ Globalize.with_locale(:en) { FactoryGirl.create(:blog_post, :title => "Refinery CMS blog post") }
10
+ end
11
+
10
12
  it "should display blog post" do
11
13
  visit refinery.blog_post_path(blog_post)
12
-
14
+
13
15
  page.should have_content(blog_post.title)
14
16
  end
15
-
16
- it "should display the blog rss feed" do
17
- get refinery.blog_rss_feed_path
18
-
19
- response.should be_success
20
- response.content_type.should eq("application/rss+xml")
17
+
18
+ describe "visit blog" do
19
+
20
+ before do
21
+ FactoryGirl.create(:page, :link_url => "/")
22
+ FactoryGirl.create(:page, :link_url => "/blog", :title => "Blog")
23
+ end
24
+
25
+ it "shows blog link in menu" do
26
+ visit "/"
27
+ within "#menu" do
28
+ page.should have_content("Blog")
29
+ page.should have_selector("a[href='/blog']")
30
+ end
31
+ end
32
+
33
+ it "shows blog posts" do
34
+ visit refinery.blog_root_path
35
+ page.should have_content blog_post.title
36
+ end
37
+
21
38
  end
39
+
22
40
  end
23
-
24
- describe "list tagged posts" do
25
- context "when has tagged blog posts" do
26
- before(:each) do
41
+
42
+ describe "list tagged posts" do
43
+ context "when has tagged blog posts" do
44
+ before do
27
45
  @tag_name = "chicago"
28
46
  @post = FactoryGirl.create(:blog_post,
29
47
  :title => "I Love my city",
30
48
  :tag_list => @tag_name)
31
- @tag = ::Refinery::Blog::Post.tag_counts_on(:tags).first
49
+ @tag = ::Refinery::Blog::Post.tag_counts_on(:tags).first
32
50
  end
33
51
  it "should have one tagged post" do
34
52
  visit refinery.blog_tagged_posts_path(@tag.id, @tag_name.parameterize)
35
-
53
+
36
54
  page.should have_content(@tag_name)
37
55
  page.should have_content(@post.title)
38
56
  end
39
57
  end
40
58
  end
41
-
59
+
42
60
  describe "#show" do
43
61
  context "when has no comments" do
44
62
  let(:blog_post) { FactoryGirl.create(:blog_post) }
45
-
63
+
46
64
  it "should display the blog post" do
47
65
  visit refinery.blog_post_path(blog_post)
48
66
  page.should have_content(blog_post.title)
@@ -51,35 +69,35 @@ module Refinery
51
69
  end
52
70
  context "when has approved comments" do
53
71
  let(:approved_comment) { FactoryGirl.create(:approved_comment) }
54
-
72
+
55
73
  it "should display the comments" do
56
74
  visit refinery.blog_post_path(approved_comment.post)
57
-
75
+
58
76
  page.should have_content(approved_comment.body)
59
77
  page.should have_content("Posted by #{approved_comment.name}")
60
78
  end
61
79
  end
62
80
  context "when has rejected comments" do
63
81
  let(:rejected_comment) { FactoryGirl.create(:rejected_comment) }
64
-
65
- it "should not display the comments" do
82
+
83
+ it "should not display the comments" do
66
84
  visit refinery.blog_post_path(rejected_comment.post)
67
-
85
+
68
86
  page.should_not have_content(rejected_comment.body)
69
87
  end
70
88
  end
71
89
  context "when has new comments" do
72
90
  let(:blog_comment) { FactoryGirl.create(:blog_comment) }
73
-
91
+
74
92
  it "should not display the comments" do
75
93
  visit refinery.blog_post_path(blog_comment.post)
76
-
94
+
77
95
  page.should_not have_content(blog_comment.body)
78
96
  end
79
97
  end
80
98
 
81
99
  context "when posting comments" do
82
- let(:blog_post) { Factory(:blog_post) }
100
+ let(:blog_post) { FactoryGirl.create(:blog_post) }
83
101
  let(:name) { "pete" }
84
102
  let(:email) { "pete@mcawesome.com" }
85
103
  let(:body) { "Witty comment." }
@@ -122,16 +140,11 @@ module Refinery
122
140
  end
123
141
 
124
142
  context "post recent" do
125
- let(:blog_post) { FactoryGirl.create(:blog_post) }
126
- let(:blog_post2) { FactoryGirl.create(:blog_post) }
127
-
128
- before do
129
- visit refinery.blog_post_path(blog_post2)
130
- visit refinery.blog_post_path(blog_post)
131
- end
143
+ let!(:blog_post) { FactoryGirl.create(:blog_post, :published_at => Time.now - 5.minutes) }
144
+ let!(:blog_post2) { FactoryGirl.create(:blog_post, :published_at => Time.now - 2.minutes) }
132
145
 
133
146
  it "should be the most recent" do
134
- Refinery::Blog::Post.recent(2).first.should eq(blog_post2)
147
+ Refinery::Blog::Post.recent(2).first.id.should eq(blog_post2.id)
135
148
  end
136
149
  end
137
150
 
@@ -139,20 +152,27 @@ module Refinery
139
152
 
140
153
  describe "#show draft preview" do
141
154
  let(:blog_post) { FactoryGirl.create(:blog_post_draft) }
142
- context "when logged in as admin" do
155
+
156
+ context "when logged in as admin" do
143
157
  it "should display the draft notification" do
144
158
  visit refinery.blog_post_path(blog_post)
145
-
159
+
146
160
  page.should have_content('This page is NOT live for public viewing.')
147
161
  end
148
162
  end
163
+
149
164
  context "when not logged in as an admin" do
150
- before(:each) { visit refinery.destroy_refinery_user_session_path }
151
-
165
+ before do
166
+ # TODO: remove Refinery::Pages::Engine.load_seed dependency.
167
+ # It's here to temporary fix the issue with 404 after visiting logout path.
168
+ Refinery::Pages::Engine.load_seed
169
+ visit refinery.logout_path
170
+ end
171
+
152
172
  it "should not display the blog post" do
153
173
  visit refinery.blog_post_path(blog_post)
154
-
155
- page.should have_content("The page you were looking for doesn't exist (404)")
174
+
175
+ page.should have_content("The page you requested was not found.")
156
176
  end
157
177
  end
158
178
  end