refinerycms-blog 3.0.2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.gitignore +2 -0
- data/.travis.yml +1 -3
- data/Gemfile +8 -8
- data/app/controllers/refinery/blog/admin/categories_controller.rb +2 -2
- data/app/controllers/refinery/blog/admin/posts_controller.rb +15 -12
- data/app/controllers/refinery/blog/blog_controller.rb +1 -1
- data/app/controllers/refinery/blog/posts_controller.rb +15 -13
- data/app/helpers/refinery/blog/posts_helper.rb +4 -4
- data/app/models/refinery/blog/category.rb +3 -0
- data/app/models/refinery/blog/post.rb +43 -16
- data/app/views/refinery/blog/admin/categories/_category.html.erb +4 -10
- data/app/views/refinery/blog/admin/comments/_comment.html.erb +4 -14
- data/app/views/refinery/blog/admin/posts/_form.html.erb +5 -1
- data/app/views/refinery/blog/admin/posts/_post.html.erb +7 -12
- data/app/views/refinery/blog/posts/_comment.html.erb +3 -3
- data/app/views/refinery/blog/posts/_comments.html.erb +6 -6
- data/app/views/refinery/blog/posts/_post.html.erb +7 -7
- data/app/views/refinery/blog/posts/index.rss.builder +8 -2
- data/app/views/refinery/blog/shared/_categories.html.erb +2 -2
- data/app/views/refinery/blog/shared/_post.html.erb +9 -7
- data/app/views/refinery/blog/shared/_posts.html.erb +1 -1
- data/app/views/refinery/blog/shared/_tags.html.erb +1 -1
- data/bin/rails +9 -3
- data/certs/parndt.pem +25 -0
- data/config/locales/ru.yml +1 -1
- data/config/locales/uk.yml +172 -0
- data/db/migrate/20110803223522_create_blog_structure.rb +1 -1
- data/db/migrate/20110803223523_add_user_id_to_blog_posts.rb +1 -1
- data/db/migrate/20110803223524_acts_as_taggable_on_migration.rb +1 -1
- data/db/migrate/20110803223526_add_cached_slugs.rb +1 -1
- data/db/migrate/20110803223527_add_custom_url_field_to_blog_posts.rb +1 -1
- data/db/migrate/20110803223528_add_custom_teaser_field_to_blog_posts.rb +1 -1
- data/db/migrate/20110803223529_add_primary_key_to_categorizations.rb +1 -1
- data/db/migrate/20120103055909_add_source_url_to_blog_posts.rb +2 -2
- data/db/migrate/20120223022021_add_access_count_to_posts.rb +4 -4
- data/db/migrate/20120227022021_add_slug_to_posts_and_categories.rb +2 -2
- data/db/migrate/20120530102901_create_blog_translations.rb +1 -1
- data/db/migrate/20120531113632_delete_cached_slugs.rb +1 -1
- data/db/migrate/20120601151114_create_category_translations.rb +1 -1
- data/db/migrate/20140622132537_add_missing_unique_indices.acts_as_taggable_on_engine.rb +1 -1
- data/db/migrate/20140622132538_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +1 -1
- data/db/migrate/20160602042848_add_username_to_blog_posts.rb +5 -0
- data/db/migrate/20161223024527_create_multi_user_model.rb +13 -0
- data/db/migrate/20180420132008_remove_translated_columns_to_refinery_blog_categories.rb +5 -0
- data/lib/generators/refinery/blog/templates/config/initializers/refinery/blog.rb.erb +2 -1
- data/lib/refinery/blog.rb +2 -0
- data/lib/refinery/blog/configuration.rb +3 -3
- data/lib/refinery/blog/engine.rb +1 -0
- data/readme.md +2 -2
- data/refinerycms-blog.gemspec +15 -8
- data/spec/controllers/refinery/blog/admin/comments_controller_spec.rb +10 -14
- data/spec/controllers/refinery/blog/admin/posts_controller_spec.rb +5 -5
- data/spec/controllers/refinery/blog/posts_controller_spec.rb +4 -4
- data/spec/factories/blog_categories.rb +1 -1
- data/spec/factories/blog_comments.rb +1 -1
- data/spec/factories/blog_posts.rb +6 -2
- data/spec/factories/blog_test_users.rb +6 -0
- data/spec/features/refinery/blog/admin/categories_spec.rb +3 -3
- data/spec/features/refinery/blog/admin/comments_spec.rb +5 -5
- data/spec/features/refinery/blog/admin/menu_spec.rb +2 -2
- data/spec/features/refinery/blog/admin/posts_spec.rb +34 -20
- data/spec/features/refinery/blog/categories_spec.rb +2 -3
- data/spec/features/refinery/blog/posts_spec.rb +17 -30
- data/spec/models/refinery/blog/category_spec.rb +12 -13
- data/spec/models/refinery/blog/comment_spec.rb +1 -1
- data/spec/models/refinery/blog/post_spec.rb +38 -31
- data/spec/spec_helper.rb +1 -0
- data/spec/support/refinery_blog_test_user.rb +2 -0
- metadata +85 -33
- metadata.gz.sig +0 -0
- data/spec/factories/user.rb +0 -27
@@ -4,7 +4,7 @@ module Refinery
|
|
4
4
|
module Blog
|
5
5
|
module Admin
|
6
6
|
describe Menu, type: :feature do
|
7
|
-
|
7
|
+
refinery_login
|
8
8
|
|
9
9
|
it "is highlighted when managing the blog" do
|
10
10
|
visit refinery.admin_root_path
|
@@ -16,4 +16,4 @@ module Refinery
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
-
end
|
19
|
+
end
|
@@ -1,14 +1,27 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "spec_helper"
|
3
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
|
+
|
4
17
|
module Refinery
|
5
18
|
module Blog
|
6
19
|
module Admin
|
7
20
|
describe Post, type: :feature do
|
8
|
-
|
21
|
+
refinery_login
|
9
22
|
|
10
23
|
let!(:blog_category) do
|
11
|
-
Globalize.with_locale(:en) {
|
24
|
+
Globalize.with_locale(:en) { FactoryBot.create(:blog_category) }
|
12
25
|
end
|
13
26
|
|
14
27
|
context "when no blog posts" do
|
@@ -39,8 +52,9 @@ module Refinery
|
|
39
52
|
describe "create blog post" do
|
40
53
|
before do
|
41
54
|
expect(subject.class.count).to eq(0)
|
42
|
-
fill_in "post_title", :
|
55
|
+
fill_in "post_title", with: "This is my blog post"
|
43
56
|
fill_in "post_body", with: "<p>And I love it</p>"
|
57
|
+
fill_in "post_user_id", with: "John Doe"
|
44
58
|
|
45
59
|
expect(page).to have_css '.blog_categories'
|
46
60
|
expect(page).to have_css "#post_category_ids_#{blog_category.id}"
|
@@ -57,10 +71,6 @@ module Refinery
|
|
57
71
|
expect(subject.class.count).to eq(1)
|
58
72
|
end
|
59
73
|
|
60
|
-
it "should belong to me" do
|
61
|
-
expect(subject.class.first.author).to eq(::Refinery::Blog.user_class.last)
|
62
|
-
end
|
63
|
-
|
64
74
|
it "should save categories" do
|
65
75
|
expect(subject.class.last.categories.count).to eq(1)
|
66
76
|
expect(subject.class.last.categories.first.title).to eq(blog_category.title)
|
@@ -70,9 +80,10 @@ module Refinery
|
|
70
80
|
describe "create blog post with tags" do
|
71
81
|
let(:tag_list) { "chicago, bikes, beers, babes" }
|
72
82
|
before do
|
73
|
-
fill_in "Title", :
|
83
|
+
fill_in "Title", with: "This is a tagged blog post"
|
74
84
|
fill_in "post_body", with: "<p>And I also love it</p>"
|
75
|
-
fill_in "
|
85
|
+
fill_in "post_user_id", with: "John Doe"
|
86
|
+
fill_in "Tags", with: tag_list
|
76
87
|
click_button "Save"
|
77
88
|
end
|
78
89
|
|
@@ -93,7 +104,7 @@ module Refinery
|
|
93
104
|
|
94
105
|
context "when has blog posts" do
|
95
106
|
let!(:blog_post) do
|
96
|
-
Globalize.with_locale(:en) {
|
107
|
+
Globalize.with_locale(:en) { FactoryBot.create(:blog_post) }
|
97
108
|
end
|
98
109
|
|
99
110
|
describe "blog post listing" do
|
@@ -153,7 +164,9 @@ module Refinery
|
|
153
164
|
end
|
154
165
|
|
155
166
|
context "with multiple users" do
|
156
|
-
|
167
|
+
include_context "with_user_class"
|
168
|
+
|
169
|
+
let!(:other_guy) { FactoryBot.create(:blog_test_user, :username => "Other Guy") }
|
157
170
|
|
158
171
|
describe "create blog post with alternate author" do
|
159
172
|
before do
|
@@ -164,7 +177,7 @@ module Refinery
|
|
164
177
|
fill_in "post_body", with: "<p>I totally did not write it.</p>"
|
165
178
|
|
166
179
|
expect(page).to have_content("Author")
|
167
|
-
select other_guy.username, :
|
180
|
+
select other_guy.username, from: "Author"
|
168
181
|
|
169
182
|
click_button "Save"
|
170
183
|
expect(page).to have_content("was successfully added.")
|
@@ -180,7 +193,7 @@ module Refinery
|
|
180
193
|
before do
|
181
194
|
Globalize.locale = :en
|
182
195
|
allow(Refinery::I18n).to receive(:frontend_locales).and_return([:en, :ru])
|
183
|
-
blog_page =
|
196
|
+
blog_page = FactoryBot.create(:page, :link_url => "/blog", :title => "Blog")
|
184
197
|
Globalize.with_locale(:ru) do
|
185
198
|
blog_page.title = 'блог'
|
186
199
|
blog_page.save
|
@@ -191,8 +204,9 @@ module Refinery
|
|
191
204
|
describe "add a blog post with title for default locale" do
|
192
205
|
before do
|
193
206
|
click_link "Create new post"
|
194
|
-
fill_in "Title", :
|
195
|
-
fill_in "post_body", :
|
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"
|
196
210
|
click_button "Save"
|
197
211
|
@p = Refinery::Blog::Post.by_title("Post")
|
198
212
|
end
|
@@ -237,8 +251,9 @@ module Refinery
|
|
237
251
|
within "#switch_locale_picker" do
|
238
252
|
click_link "RU"
|
239
253
|
end
|
240
|
-
fill_in "Title", :
|
241
|
-
fill_in "post_body", :
|
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"
|
242
257
|
click_button "Save"
|
243
258
|
@p = Refinery::Blog::Post.by_title(ru_page_title)
|
244
259
|
end
|
@@ -282,7 +297,7 @@ module Refinery
|
|
282
297
|
context "with a blog post in both locales" do
|
283
298
|
|
284
299
|
let!(:blog_post) do
|
285
|
-
_blog_post = Globalize.with_locale(:en) {
|
300
|
+
_blog_post = Globalize.with_locale(:en) { FactoryBot.create(:blog_post, :title => 'First Post') }
|
286
301
|
Globalize.with_locale(:ru) do
|
287
302
|
_blog_post.title = 'Домашняя страница'
|
288
303
|
_blog_post.save
|
@@ -325,7 +340,6 @@ module Refinery
|
|
325
340
|
fill_in "Title", :with => "Нов"
|
326
341
|
click_button "Save"
|
327
342
|
|
328
|
-
expect(page).not_to have_content(blog_post.title)
|
329
343
|
expect(page).to have_content("'Нов' was successfully updated.")
|
330
344
|
end
|
331
345
|
end
|
@@ -338,7 +352,7 @@ module Refinery
|
|
338
352
|
|
339
353
|
click_link "Remove this translation"
|
340
354
|
|
341
|
-
expect(page).not_to have_content(
|
355
|
+
expect(page).not_to have_content('RU')
|
342
356
|
expect(page).to have_content("The translation was successfully removed.")
|
343
357
|
end
|
344
358
|
end
|
@@ -3,15 +3,14 @@ require "spec_helper"
|
|
3
3
|
module Refinery
|
4
4
|
module Blog
|
5
5
|
describe Category, type: :feature do
|
6
|
-
refinery_login_with_devise :authentication_devise_refinery_user
|
7
6
|
|
8
7
|
context "has one category and post" do
|
9
8
|
before do
|
10
9
|
post = Globalize.with_locale(:en) do
|
11
|
-
|
10
|
+
FactoryBot.create(:blog_post, :title => "Refinery CMS blog post")
|
12
11
|
end
|
13
12
|
@category = Globalize.with_locale(:en) do
|
14
|
-
|
13
|
+
FactoryBot.create(:blog_category, :title => "Video Games")
|
15
14
|
end
|
16
15
|
post.categories << @category
|
17
16
|
post.save!
|
@@ -3,11 +3,9 @@ require "spec_helper"
|
|
3
3
|
module Refinery
|
4
4
|
module Blog
|
5
5
|
describe Post, type: :feature do
|
6
|
-
refinery_login_with_devise :authentication_devise_refinery_user
|
7
|
-
|
8
6
|
context "when has blog posts" do
|
9
7
|
let!(:blog_post) do
|
10
|
-
Globalize.with_locale(:en) {
|
8
|
+
Globalize.with_locale(:en) { FactoryBot.create(:blog_post, :title => "Refinery CMS blog post") }
|
11
9
|
end
|
12
10
|
|
13
11
|
it "should display blog post" do
|
@@ -19,8 +17,8 @@ module Refinery
|
|
19
17
|
describe "visit blog" do
|
20
18
|
|
21
19
|
before do
|
22
|
-
|
23
|
-
|
20
|
+
FactoryBot.create(:page, :link_url => "/")
|
21
|
+
FactoryBot.create(:page, :link_url => "/blog", :title => "Blog")
|
24
22
|
end
|
25
23
|
|
26
24
|
it "shows blog link in menu" do
|
@@ -44,7 +42,7 @@ module Refinery
|
|
44
42
|
context "when has tagged blog posts" do
|
45
43
|
let!(:tag_name) { "chicago" }
|
46
44
|
let!(:post) {
|
47
|
-
|
45
|
+
FactoryBot.create(:blog_post,
|
48
46
|
:title => "I Love my city",
|
49
47
|
:tag_list => tag_name
|
50
48
|
)
|
@@ -62,7 +60,7 @@ module Refinery
|
|
62
60
|
|
63
61
|
describe "#show" do
|
64
62
|
context "when has no comments" do
|
65
|
-
let!(:blog_post) {
|
63
|
+
let!(:blog_post) { FactoryBot.create(:blog_post) }
|
66
64
|
|
67
65
|
it "should display the blog post" do
|
68
66
|
visit refinery.blog_post_path(blog_post)
|
@@ -71,7 +69,7 @@ module Refinery
|
|
71
69
|
end
|
72
70
|
end
|
73
71
|
context "when has approved comments" do
|
74
|
-
let!(:approved_comment) {
|
72
|
+
let!(:approved_comment) { FactoryBot.create(:approved_comment) }
|
75
73
|
|
76
74
|
it "should display the comments" do
|
77
75
|
visit refinery.blog_post_path(approved_comment.post)
|
@@ -81,7 +79,7 @@ module Refinery
|
|
81
79
|
end
|
82
80
|
end
|
83
81
|
context "when has rejected comments" do
|
84
|
-
let!(:rejected_comment) {
|
82
|
+
let!(:rejected_comment) { FactoryBot.create(:rejected_comment) }
|
85
83
|
|
86
84
|
it "should not display the comments" do
|
87
85
|
visit refinery.blog_post_path(rejected_comment.post)
|
@@ -90,7 +88,7 @@ module Refinery
|
|
90
88
|
end
|
91
89
|
end
|
92
90
|
context "when has new comments" do
|
93
|
-
let!(:blog_comment) {
|
91
|
+
let!(:blog_comment) { FactoryBot.create(:blog_comment) }
|
94
92
|
|
95
93
|
it "should not display the comments" do
|
96
94
|
visit refinery.blog_post_path(blog_comment.post)
|
@@ -100,7 +98,7 @@ module Refinery
|
|
100
98
|
end
|
101
99
|
|
102
100
|
context "when posting comments" do
|
103
|
-
let!(:blog_post) {
|
101
|
+
let!(:blog_post) { FactoryBot.create(:blog_post) }
|
104
102
|
let(:name) { "pete" }
|
105
103
|
let(:email) { "pete@mcawesome.com" }
|
106
104
|
let(:body) { "Witty comment." }
|
@@ -124,8 +122,8 @@ module Refinery
|
|
124
122
|
end
|
125
123
|
|
126
124
|
context "post popular" do
|
127
|
-
let!(:blog_post) {
|
128
|
-
let!(:blog_post2) {
|
125
|
+
let!(:blog_post) { FactoryBot.create(:blog_post) }
|
126
|
+
let!(:blog_post2) { FactoryBot.create(:blog_post) }
|
129
127
|
|
130
128
|
before do
|
131
129
|
visit refinery.blog_post_path(blog_post)
|
@@ -133,8 +131,11 @@ module Refinery
|
|
133
131
|
|
134
132
|
it "should increment access count" do
|
135
133
|
expect(blog_post.reload.access_count).to eq(1)
|
134
|
+
last_updated = blog_post.reload.updated_at
|
135
|
+
|
136
136
|
visit refinery.blog_post_path(blog_post)
|
137
137
|
expect(blog_post.reload.access_count).to eq(2)
|
138
|
+
expect(blog_post.reload.updated_at).to eq(last_updated)
|
138
139
|
end
|
139
140
|
|
140
141
|
it "should be most popular" do
|
@@ -143,8 +144,8 @@ module Refinery
|
|
143
144
|
end
|
144
145
|
|
145
146
|
context "post recent" do
|
146
|
-
let!(:blog_post) {
|
147
|
-
let!(:blog_post2) {
|
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) }
|
148
149
|
|
149
150
|
it "should be the most recent" do
|
150
151
|
expect(Refinery::Blog::Post.recent(2).first.id).to eq(blog_post2.id)
|
@@ -154,7 +155,7 @@ module Refinery
|
|
154
155
|
end
|
155
156
|
|
156
157
|
describe "#show draft preview" do
|
157
|
-
let!(:blog_post) {
|
158
|
+
let!(:blog_post) { FactoryBot.create(:blog_post_draft) }
|
158
159
|
|
159
160
|
context "when logged in as admin" do
|
160
161
|
it "should display the draft notification" do
|
@@ -164,20 +165,6 @@ module Refinery
|
|
164
165
|
end
|
165
166
|
end
|
166
167
|
|
167
|
-
context "when not logged in as an admin" do
|
168
|
-
before do
|
169
|
-
# TODO: remove Refinery::Pages::Engine.load_seed dependency.
|
170
|
-
# It's here to temporary fix the issue with 404 after visiting logout path.
|
171
|
-
Refinery::Pages::Engine.load_seed
|
172
|
-
visit refinery.logout_path
|
173
|
-
end
|
174
|
-
|
175
|
-
it "should not display the blog post" do
|
176
|
-
visit refinery.blog_post_path(blog_post)
|
177
|
-
|
178
|
-
expect(page).to have_content("The page you requested was not found.")
|
179
|
-
end
|
180
|
-
end
|
181
168
|
end
|
182
169
|
end
|
183
170
|
end
|
@@ -3,16 +3,15 @@ require 'spec_helper'
|
|
3
3
|
module Refinery
|
4
4
|
module Blog
|
5
5
|
describe Category, type: :model do
|
6
|
-
let(:category) {
|
7
|
-
let(:author) { FactoryGirl.create(:authentication_devise_refinery_user) }
|
6
|
+
let(:category) { FactoryBot.create(:blog_category) }
|
8
7
|
|
9
8
|
describe "validations" do
|
10
9
|
it "requires title" do
|
11
|
-
expect(
|
10
|
+
expect(FactoryBot.build(:blog_category, :title => "")).not_to be_valid
|
12
11
|
end
|
13
12
|
|
14
13
|
it "won't allow duplicate titles" do
|
15
|
-
expect(
|
14
|
+
expect(FactoryBot.build(:blog_category, :title => category.title)).not_to be_valid
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
@@ -22,15 +21,15 @@ module Refinery
|
|
22
21
|
end
|
23
22
|
|
24
23
|
it "returns posts by published_at date in descending order" do
|
25
|
-
first_post = category.posts.create!({ :
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
24
|
+
first_post = category.posts.create!({ title: "Breaking News: Joe Sak is hot stuff you guys!!",
|
25
|
+
body: "True story.",
|
26
|
+
published_at: Time.now.yesterday,
|
27
|
+
username: "John Doe" })
|
29
28
|
|
30
|
-
latest_post = category.posts.create!({ :
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
29
|
+
latest_post = category.posts.create!({ title: "parndt is p. okay",
|
30
|
+
body: "For a Kiwi.",
|
31
|
+
published_at: Time.now,
|
32
|
+
username: "John Doe" })
|
34
33
|
|
35
34
|
expect(category.posts.newest_first.first).to eq(latest_post)
|
36
35
|
end
|
@@ -40,7 +39,7 @@ module Refinery
|
|
40
39
|
describe "#post_count" do
|
41
40
|
it "returns post count in category" do
|
42
41
|
2.times do
|
43
|
-
category.posts <<
|
42
|
+
category.posts << FactoryBot.create(:blog_post)
|
44
43
|
end
|
45
44
|
expect(category.post_count).to eq(2)
|
46
45
|
end
|
@@ -3,19 +3,19 @@ require 'spec_helper'
|
|
3
3
|
module Refinery
|
4
4
|
module Blog
|
5
5
|
describe Post, type: :model do
|
6
|
-
let(:post) {
|
6
|
+
let(:post) { FactoryBot.create(:blog_post) }
|
7
7
|
|
8
8
|
describe "validations" do
|
9
9
|
it "requires title" do
|
10
|
-
expect(
|
10
|
+
expect(FactoryBot.build(:blog_post, :title => "")).not_to be_valid
|
11
11
|
end
|
12
12
|
|
13
13
|
it "won't allow duplicate titles" do
|
14
|
-
expect(
|
14
|
+
expect(FactoryBot.build(:blog_post, :title => post.title)).not_to be_valid
|
15
15
|
end
|
16
16
|
|
17
17
|
it "requires body" do
|
18
|
-
expect(
|
18
|
+
expect(FactoryBot.build(:blog_post, :body => nil)).not_to be_valid
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -26,7 +26,7 @@ module Refinery
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it "destroys associated comments" do
|
29
|
-
|
29
|
+
FactoryBot.create(:blog_comment, :blog_post_id => post.id)
|
30
30
|
post.destroy
|
31
31
|
expect(Blog::Comment.where(:blog_post_id => post.id)).to be_empty
|
32
32
|
end
|
@@ -50,6 +50,13 @@ module Refinery
|
|
50
50
|
end
|
51
51
|
|
52
52
|
describe "authors" do
|
53
|
+
before do
|
54
|
+
allow(Refinery::Blog).to receive(:user_class).and_return("Refinery::Authentication::Devise::User")
|
55
|
+
end
|
56
|
+
|
57
|
+
let(:author) { mock_model(::Refinery::Blog.user_class, id: 1) }
|
58
|
+
let(:blog_post) { FactoryBot.create(:blog_post, author: author) }
|
59
|
+
|
53
60
|
it "are authored" do
|
54
61
|
expect(described_class.instance_methods.map(&:to_sym)).to include(:author)
|
55
62
|
end
|
@@ -57,11 +64,11 @@ module Refinery
|
|
57
64
|
|
58
65
|
describe "by_month" do
|
59
66
|
before do
|
60
|
-
@post1 =
|
61
|
-
@post2 =
|
67
|
+
@post1 = FactoryBot.create(:blog_post, :published_at => Date.new(2011, 3, 11))
|
68
|
+
@post2 = FactoryBot.create(:blog_post, :published_at => Date.new(2011, 3, 12))
|
62
69
|
|
63
70
|
#2 months before
|
64
|
-
|
71
|
+
FactoryBot.create(:blog_post, :published_at => Date.new(2011, 1, 10))
|
65
72
|
end
|
66
73
|
|
67
74
|
it "returns all posts from specified month" do
|
@@ -74,9 +81,9 @@ module Refinery
|
|
74
81
|
|
75
82
|
describe ".published_dates_older_than" do
|
76
83
|
before do
|
77
|
-
@post1 =
|
78
|
-
@post2 =
|
79
|
-
|
84
|
+
@post1 = FactoryBot.create(:blog_post, :published_at => Time.utc(2012, 05, 01, 15, 20))
|
85
|
+
@post2 = FactoryBot.create(:blog_post, :published_at => Time.utc(2012, 05, 01, 15, 30))
|
86
|
+
FactoryBot.create(:blog_post, :published_at => Time.now)
|
80
87
|
end
|
81
88
|
|
82
89
|
it "returns all published dates older than the argument" do
|
@@ -88,10 +95,10 @@ module Refinery
|
|
88
95
|
|
89
96
|
describe "live" do
|
90
97
|
before do
|
91
|
-
@post1 =
|
92
|
-
@post2 =
|
93
|
-
|
94
|
-
|
98
|
+
@post1 = FactoryBot.create(:blog_post, :published_at => Time.now.advance(:minutes => -2))
|
99
|
+
@post2 = FactoryBot.create(:blog_post, :published_at => Time.now.advance(:minutes => -1))
|
100
|
+
FactoryBot.create(:blog_post, :draft => true)
|
101
|
+
FactoryBot.create(:blog_post, :published_at => Time.now + 1.minute)
|
95
102
|
end
|
96
103
|
|
97
104
|
it "returns all posts which aren't in draft and pub date isn't in future" do
|
@@ -104,10 +111,10 @@ module Refinery
|
|
104
111
|
|
105
112
|
describe "uncategorized" do
|
106
113
|
before do
|
107
|
-
@uncategorized_post =
|
108
|
-
@categorized_post =
|
114
|
+
@uncategorized_post = FactoryBot.create(:blog_post)
|
115
|
+
@categorized_post = FactoryBot.create(:blog_post)
|
109
116
|
|
110
|
-
@categorized_post.categories <<
|
117
|
+
@categorized_post.categories << FactoryBot.create(:blog_category)
|
111
118
|
end
|
112
119
|
|
113
120
|
it "returns uncategorized posts if they exist" do
|
@@ -118,22 +125,22 @@ module Refinery
|
|
118
125
|
|
119
126
|
describe "#live?" do
|
120
127
|
it "returns true if post is not in draft and it's published" do
|
121
|
-
expect(
|
128
|
+
expect(FactoryBot.build(:blog_post)).to be_live
|
122
129
|
end
|
123
130
|
|
124
131
|
it "returns false if post is in draft" do
|
125
|
-
expect(
|
132
|
+
expect(FactoryBot.build(:blog_post, :draft => true)).not_to be_live
|
126
133
|
end
|
127
134
|
|
128
135
|
it "returns false if post pub date is in future" do
|
129
|
-
expect(
|
136
|
+
expect(FactoryBot.build(:blog_post, :published_at => Time.now.advance(:minutes => 1))).not_to be_live
|
130
137
|
end
|
131
138
|
end
|
132
139
|
|
133
140
|
describe "#next" do
|
134
141
|
before do
|
135
|
-
|
136
|
-
@post =
|
142
|
+
FactoryBot.create(:blog_post, :published_at => Time.now.advance(:days => -1))
|
143
|
+
@post = FactoryBot.create(:blog_post)
|
137
144
|
end
|
138
145
|
|
139
146
|
it "returns next article when called on current article" do
|
@@ -143,8 +150,8 @@ module Refinery
|
|
143
150
|
|
144
151
|
describe "#prev" do
|
145
152
|
before do
|
146
|
-
|
147
|
-
@post =
|
153
|
+
FactoryBot.create(:blog_post)
|
154
|
+
@post = FactoryBot.create(:blog_post, :published_at => Time.now.advance(:days => -1))
|
148
155
|
end
|
149
156
|
|
150
157
|
it "returns previous article when called on current article" do
|
@@ -176,7 +183,7 @@ module Refinery
|
|
176
183
|
|
177
184
|
describe "custom teasers" do
|
178
185
|
it "should allow a custom teaser" do
|
179
|
-
expect(
|
186
|
+
expect(FactoryBot.create(:blog_post, :custom_teaser => 'This is some custom content')).to be_valid
|
180
187
|
end
|
181
188
|
end
|
182
189
|
|
@@ -204,7 +211,7 @@ module Refinery
|
|
204
211
|
|
205
212
|
describe "source url" do
|
206
213
|
it "should allow a source url and title" do
|
207
|
-
p =
|
214
|
+
p = FactoryBot.create(:blog_post, :source_url => 'google.com', :source_url_title => 'author')
|
208
215
|
expect(p).to be_valid
|
209
216
|
expect(p.source_url).to include('google')
|
210
217
|
expect(p.source_url_title).to include('author')
|
@@ -219,7 +226,7 @@ module Refinery
|
|
219
226
|
it "should have canonical url" do
|
220
227
|
expect_any_instance_of(UrlValidator).to receive(:resolve_redirects_verify_url).
|
221
228
|
and_return('http://www.google.com')
|
222
|
-
p =
|
229
|
+
p = FactoryBot.create(:blog_post, :source_url => 'google.com', :source_url_title => 'google')
|
223
230
|
expect(p.source_url).to include('www')
|
224
231
|
end
|
225
232
|
end
|
@@ -228,7 +235,7 @@ module Refinery
|
|
228
235
|
Refinery::Blog.validate_source_url = false
|
229
236
|
end
|
230
237
|
it "should have original url" do
|
231
|
-
p =
|
238
|
+
p = FactoryBot.create(:blog_post, :source_url => 'google.com', :source_url_title => 'google')
|
232
239
|
expect(p.source_url).not_to include('www')
|
233
240
|
end
|
234
241
|
end
|
@@ -237,7 +244,7 @@ module Refinery
|
|
237
244
|
describe "#should_generate_new_friendly_id?" do
|
238
245
|
context "when custom_url changes" do
|
239
246
|
it "regenerates slug upon save" do
|
240
|
-
post =
|
247
|
+
post = FactoryBot.create(:blog_post, :custom_url => "Test Url")
|
241
248
|
|
242
249
|
post.custom_url = "Test Url 2"
|
243
250
|
post.save!
|
@@ -248,7 +255,7 @@ module Refinery
|
|
248
255
|
|
249
256
|
context "when title changes" do
|
250
257
|
it "regenerates slug upon save" do
|
251
|
-
post =
|
258
|
+
post = FactoryBot.create(:blog_post, :title => "Test Title")
|
252
259
|
|
253
260
|
post.title = "Test Title 2"
|
254
261
|
post.save!
|