fuel 0.3.28 → 0.3.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/fuel/admin/authors_controller.rb +1 -1
- data/app/controllers/fuel/admin/posts_controller.rb +1 -0
- data/app/controllers/fuel/posts_controller.rb +1 -1
- data/app/models/fuel/author.rb +1 -0
- data/app/models/fuel/post.rb +6 -5
- data/lib/fuel/version.rb +1 -1
- data/spec/codeclimate_env.rb +1 -0
- data/spec/controllers/fuel/admin/authors_controller_spec.rb +148 -0
- data/spec/controllers/fuel/admin/posts_controller_spec.rb +38 -22
- data/spec/controllers/fuel/posts_controller_spec.rb +17 -12
- data/spec/dummy/config/environments/test.rb +2 -0
- data/spec/factories.rb +19 -5
- data/spec/models/fuel/author_spec.rb +15 -0
- data/spec/models/fuel/post_spec.rb +82 -27
- data/spec/spec_helper.rb +18 -5
- metadata +105 -100
- data/app/assets/images/fuel/icons/application-icons.svg +0 -1
- data/app/assets/images/fuel/icons/calendar-icon.svg +0 -1
- data/app/assets/images/fuel/icons/dropdown-arrow-icon.svg +0 -10
- data/app/assets/images/fuel/icons/navigation-icons.svg +0 -1
- data/app/controllers/fuel/admin/settings_controller.rb +0 -7
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +0 -5441
- data/spec/dummy/public/404.html +0 -58
- data/spec/dummy/public/422.html +0 -58
- data/spec/dummy/public/500.html +0 -57
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/cache/assets/development/sass/4105e5a1347506aa0bdf1d045b6c437eeeaa8594/admin.css.sassc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sass/4105e5a1347506aa0bdf1d045b6c437eeeaa8594/application.css.scssc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sass/4105e5a1347506aa0bdf1d045b6c437eeeaa8594/posts.css.sassc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sass/4105e5a1347506aa0bdf1d045b6c437eeeaa8594/posts.css.scssc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/014dac3985653ba3455824e5bdaf93bd +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/03ac2f751ed77389257433b768f934c3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/05c5819ebb446d33153d21337d3a20ad +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/308795da63b7e95bd0f55cecedd62d94 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3865b2b2d5132e0ea4ed29815b482dce +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3a8a9a4ef7dd450b1cf686b461bb5245 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3ebee12608c20315d8de4675220e3d04 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4498ae7c9df269c897e3280835f07167 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5191f0a9c44f6502f1b23c4e717ea384 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5562fe0dd779e67464c82bf5f677b926 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/70c9660e2c4d5e5a677d36620d59df7c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/741e06bd7a3e5bc32d44a86b156237b4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/78148fb54f92bb724386c0cbf866bf8b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7cb8cf7fca54a9d0c860db5e7a874fa9 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/89c5e5ef520aeb480b2c370cd95e4aa3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/9501761eef62112c4a992aa52331b52f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/970522fbbd63cf689683466c5196857f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/9e6bbc6ad4182b36488ed894b2cf25af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/9f4599bbfc23ec621d87974b1cb749e3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/9f6c8d6fbf570cfe1a06179461b0de2d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a97bc057d70e3604312a80f169e9e6e9 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/bc12f5ee1ab1f3f41620171e56218d6f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/bfa298bb2836528bc682672f2a549707 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c0b400cdc41be57879274baf7d92b911 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c21e7a5dd39166b6f02a10131e7b60a5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c78d634ffc32ae4fadbe52ac7ca08aac +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d7fb93600298f6787c9defd51a75aeb5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d85f307de0f4da9bd598243e1f505804 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d9ff247d231468f7dc28844500bc20aa +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f089ae120c22843da39b636bfc4b8e01 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 119ebf4f62cc4f134697c9a3163400ef4d1d0503
|
4
|
+
data.tar.gz: 89e4b2c53f79bf21e32e5d08522785122894c93d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18e51a26135a038f6969cce6c1fbb8fed62000e404b095ccdf24d33da1217f6b668d30e51658210243124163512bfbb4463eff97f85d19314164ed761f128171
|
7
|
+
data.tar.gz: 6da165c5c109ea23f78834880018e9e2bd30506418ded8e6f2a4c06de07ecfc06e92e31ccb42c72948dbaa41f96ece0c7722f6f22e647d7ee34643fab03b4170
|
@@ -35,7 +35,7 @@ module Fuel
|
|
35
35
|
@author.attributes = @params_hash
|
36
36
|
|
37
37
|
if @author.save
|
38
|
-
redirect_to fuel.
|
38
|
+
redirect_to fuel.edit_admin_author_path(@author), notice: "Author was updated and #{@message}"
|
39
39
|
else
|
40
40
|
render action: "edit"
|
41
41
|
end
|
@@ -67,6 +67,7 @@ module Fuel
|
|
67
67
|
|
68
68
|
def update_published_at
|
69
69
|
published_at_string = @params_hash[:published_at]
|
70
|
+
return unless published_at_string.present?
|
70
71
|
published_at_datetime = DateTime.strptime(published_at_string, "%m/%d/%Y")
|
71
72
|
@params_hash[:published_at] = published_at_datetime
|
72
73
|
end
|
@@ -16,7 +16,7 @@ module Fuel
|
|
16
16
|
|
17
17
|
def show
|
18
18
|
@post = Fuel::Post.find_by_slug(params[:id]) || Fuel::Post.find_by_id(params[:id]) || not_found
|
19
|
-
@title = truncate_on_space(@post.seo_title, 70)
|
19
|
+
@title = truncate_on_space(@post.seo_title || @post.title, 70)
|
20
20
|
@description = @post.seo_description
|
21
21
|
@disqus_name = Fuel.configuration.disqus_name
|
22
22
|
end
|
data/app/models/fuel/author.rb
CHANGED
@@ -18,6 +18,7 @@ module Fuel
|
|
18
18
|
end
|
19
19
|
|
20
20
|
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
|
21
|
+
validates :first_name, :last_name, :title, presence: true
|
21
22
|
|
22
23
|
def s3_credentials
|
23
24
|
{:bucket => Fuel.configuration.aws_bucket, :access_key_id => Fuel.configuration.aws_access_key, :secret_access_key => Fuel.configuration.aws_secret_access_key}
|
data/app/models/fuel/post.rb
CHANGED
@@ -18,22 +18,23 @@ module Fuel
|
|
18
18
|
end
|
19
19
|
validates_attachment_content_type :featured_image, :content_type => /\Aimage\/.*\Z/
|
20
20
|
|
21
|
-
validates_presence_of :title, :content, :author_id, if: :is_published
|
21
|
+
validates_presence_of :title, :content, :author_id, :published_at, if: :is_published
|
22
22
|
paginates_per Fuel.configuration.paginates_per.to_i
|
23
23
|
|
24
|
-
scope :recent_published_posts, -> {
|
25
|
-
scope :
|
24
|
+
scope :recent_published_posts, -> { published.recent }
|
25
|
+
scope :published, -> { where(published: true) }
|
26
|
+
scope :recent, -> { order("published_at DESC").order("created_at DESC") }
|
26
27
|
|
27
28
|
def s3_credentials
|
28
29
|
{:bucket => Fuel.configuration.aws_bucket, :access_key_id => Fuel.configuration.aws_access_key, :secret_access_key => Fuel.configuration.aws_secret_access_key}
|
29
30
|
end
|
30
31
|
|
31
32
|
def next
|
32
|
-
self.class.recent.where("
|
33
|
+
self.class.recent.where("published_at <= ? AND id != ?", published_at, id).first
|
33
34
|
end
|
34
35
|
|
35
36
|
def previous
|
36
|
-
self.class.recent.where("
|
37
|
+
self.class.recent.where("published_at >= ? AND id != ?", published_at, id).last
|
37
38
|
end
|
38
39
|
|
39
40
|
def should_generate_new_friendly_id?
|
data/lib/fuel/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
ENV["CODECLIMATE_REPO_TOKEN"] = "a18d4ae96dd06db174789c3819d6347347232494f24a2c6f536e85f3455f6890"
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fuel::Admin::AuthorsController, type: :controller do
|
4
|
+
|
5
|
+
routes { Fuel::Engine.routes }
|
6
|
+
|
7
|
+
let(:authors) { create_list(:author, number_authors) }
|
8
|
+
let(:number_authors) { 5 }
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
credentials = ActionController::HttpAuthentication::Basic.encode_credentials Fuel.configuration.username, Fuel.configuration.password
|
12
|
+
request.env['HTTP_AUTHORIZATION'] = credentials
|
13
|
+
authors
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'GET #index' do
|
17
|
+
it "populates an array of authors" do
|
18
|
+
get :index
|
19
|
+
expect(assigns(:authors).count).to eq(number_authors)
|
20
|
+
end
|
21
|
+
it "renders the :index view" do
|
22
|
+
get :index
|
23
|
+
expect(response).to render_template(:index)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'GET #new' do
|
28
|
+
it "it assigns a new Author to @author" do
|
29
|
+
get :new
|
30
|
+
expect(assigns(:author)).to be_a_new(Author)
|
31
|
+
end
|
32
|
+
it "renders the :new view" do
|
33
|
+
get :new
|
34
|
+
expect(response).to render_template(:new)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'GET #edit' do
|
39
|
+
|
40
|
+
let(:author) { create(:author) }
|
41
|
+
|
42
|
+
it "assigns the requested author to @author" do
|
43
|
+
get :edit, id: author
|
44
|
+
expect(assigns(:author)).to eq(author)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "renders the :edit template" do
|
48
|
+
get :edit, id: author
|
49
|
+
expect(response).to render_template(:edit)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'POST #create' do
|
54
|
+
|
55
|
+
let(:original_count) { Author.count }
|
56
|
+
|
57
|
+
before(:each) do
|
58
|
+
original_count
|
59
|
+
post :create, fuel_author: author_hash
|
60
|
+
end
|
61
|
+
|
62
|
+
context "with valid attributes" do
|
63
|
+
|
64
|
+
let(:author_hash) { attributes_for(:author) }
|
65
|
+
|
66
|
+
it "saves the new author in the database" do
|
67
|
+
new_count = Author.count
|
68
|
+
expect(new_count - original_count).to eq(1)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "redirects to the index page" do
|
72
|
+
expect(response).to redirect_to(admin_authors_path)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "with invalid attributes" do
|
77
|
+
let(:author_hash) { attributes_for(:author, first_name: nil) }
|
78
|
+
|
79
|
+
it "does not save the new author in the database" do
|
80
|
+
new_count = Author.count
|
81
|
+
expect(new_count - original_count).to eq(0)
|
82
|
+
end
|
83
|
+
it "re-renders the :new template" do
|
84
|
+
expect(response).to render_template(:new)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'PUT #update' do
|
90
|
+
|
91
|
+
let(:author) { create(:author) }
|
92
|
+
let(:author_hash) { attributes_for(:author) }
|
93
|
+
|
94
|
+
before(:each) do
|
95
|
+
author_hash
|
96
|
+
end
|
97
|
+
|
98
|
+
context "with valid attributes" do
|
99
|
+
it "updates the author in the database" do
|
100
|
+
test_first_name = "UniqueString123"
|
101
|
+
put :update, id: author, fuel_author: author_hash.merge(first_name: test_first_name)
|
102
|
+
author.reload
|
103
|
+
expect(author.first_name).to eq(test_first_name)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "redirects to the author edit page" do
|
107
|
+
put :update, id: author, fuel_author: author_hash
|
108
|
+
expect(response).to redirect_to(edit_admin_author_path(author))
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context "with invalid attributes" do
|
113
|
+
it "does not update the author" do
|
114
|
+
first_name = "Hopefully I don't persist"
|
115
|
+
put :update, id: author, fuel_author: author_hash.merge(first_name: first_name, last_name: nil)
|
116
|
+
author.reload
|
117
|
+
expect(author.first_name).to_not eq(first_name)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "re-renders the #edit template" do
|
121
|
+
put :update, id: author, fuel_author: author_hash.merge(first_name: nil)
|
122
|
+
expect(response).to render_template(:edit)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe 'DELETE #destroy' do
|
128
|
+
|
129
|
+
subject(:author) { create(:author) }
|
130
|
+
|
131
|
+
before(:each) do
|
132
|
+
author
|
133
|
+
end
|
134
|
+
|
135
|
+
it "deletes the authors" do
|
136
|
+
original_count = Author.count
|
137
|
+
delete :destroy, id: author
|
138
|
+
new_count = Author.count
|
139
|
+
expect(original_count - new_count).to eq(1)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "redirects to admin/authors#index" do
|
143
|
+
delete :destroy, id: author
|
144
|
+
expect(response).to redirect_to(admin_authors_path)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
@@ -1,18 +1,22 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Fuel::Admin::PostsController do
|
3
|
+
describe Fuel::Admin::PostsController, type: :controller do
|
4
4
|
|
5
5
|
routes { Fuel::Engine.routes }
|
6
6
|
|
7
|
+
let(:posts) { create_list(:post, number_posts) }
|
8
|
+
let(:number_posts) { 5 }
|
9
|
+
|
7
10
|
before(:each) do
|
8
11
|
credentials = ActionController::HttpAuthentication::Basic.encode_credentials Fuel.configuration.username, Fuel.configuration.password
|
9
12
|
request.env['HTTP_AUTHORIZATION'] = credentials
|
13
|
+
posts
|
10
14
|
end
|
11
15
|
|
12
16
|
describe 'GET #index' do
|
13
17
|
it "populates an array of posts" do
|
14
18
|
get :index
|
15
|
-
expect(assigns(:posts).count).to eq(
|
19
|
+
expect(assigns(:posts).count).to eq(number_posts)
|
16
20
|
end
|
17
21
|
it "renders the :index view" do
|
18
22
|
get :index
|
@@ -50,20 +54,20 @@ describe Fuel::Admin::PostsController do
|
|
50
54
|
context "with valid attributes" do
|
51
55
|
before(:each) do
|
52
56
|
@original_count = Post.count
|
53
|
-
post :create,
|
57
|
+
post :create, fuel_post: attributes_for(:post)
|
54
58
|
end
|
55
59
|
it "saves the new post in the database" do
|
56
60
|
new_count = Post.count
|
57
61
|
expect(new_count - @original_count).to eq(1)
|
58
62
|
end
|
59
|
-
it "redirects to the
|
60
|
-
expect(response).to redirect_to(
|
63
|
+
it "redirects to the index page" do
|
64
|
+
expect(response).to redirect_to(admin_posts_path)
|
61
65
|
end
|
62
66
|
end
|
63
67
|
context "with invalid attributes" do
|
64
68
|
before(:each) do
|
65
69
|
@original_count = Post.count
|
66
|
-
post :create,
|
70
|
+
post :create, fuel_post: attributes_for(:invalid_post)
|
67
71
|
end
|
68
72
|
it "does not save the new post in the database" do
|
69
73
|
new_count = Post.count
|
@@ -76,48 +80,60 @@ describe Fuel::Admin::PostsController do
|
|
76
80
|
end
|
77
81
|
|
78
82
|
describe 'PUT #update' do
|
83
|
+
|
84
|
+
let(:post) { create(:post) }
|
85
|
+
let(:published_post) { create(:published_post) }
|
86
|
+
let(:post_hash) { attributes_for(:post) }
|
87
|
+
let(:published_post_hash) { attributes_for(:published_post, published_at: DateTime.now.strftime("%m/%d/%Y")) }
|
88
|
+
|
79
89
|
before(:each) do
|
80
|
-
|
90
|
+
post_hash
|
91
|
+
published_post_hash
|
81
92
|
end
|
93
|
+
|
82
94
|
context "with valid attributes" do
|
83
95
|
it "updates the post in the database" do
|
84
96
|
test_title = "Is this thing on?"
|
85
|
-
put :update, id:
|
86
|
-
|
87
|
-
expect(
|
97
|
+
put :update, id: post, fuel_post: post_hash.merge(title: test_title)
|
98
|
+
post.reload
|
99
|
+
expect(post.title).to eq(test_title)
|
88
100
|
end
|
89
|
-
it "redirects to the post" do
|
90
|
-
put :update, id:
|
91
|
-
expect(response).to redirect_to(
|
101
|
+
it "redirects to the post edit page" do
|
102
|
+
put :update, id: post, fuel_post: post_hash
|
103
|
+
expect(response).to redirect_to(edit_admin_post_path(post))
|
92
104
|
end
|
93
105
|
end
|
94
106
|
context "with invalid attributes" do
|
95
107
|
it "does not update the post" do
|
96
|
-
|
97
|
-
put :update, id:
|
98
|
-
|
99
|
-
expect(
|
108
|
+
content = "Hopefully I don't persist"
|
109
|
+
put :update, id: post, fuel_post: published_post_hash.merge(content: content, title: nil)
|
110
|
+
post.reload
|
111
|
+
expect(post.content).to_not eq(content)
|
100
112
|
end
|
101
113
|
it "re-renders the #edit template" do
|
102
|
-
put :update, id:
|
114
|
+
put :update, id: post, fuel_post: published_post_hash.merge(title: nil)
|
103
115
|
expect(response).to render_template(:edit)
|
104
116
|
end
|
105
117
|
end
|
106
118
|
end
|
107
119
|
|
108
120
|
describe 'DELETE #destroy' do
|
121
|
+
|
122
|
+
subject(:post) { create(:post) }
|
123
|
+
|
109
124
|
before(:each) do
|
110
|
-
|
125
|
+
post
|
111
126
|
end
|
127
|
+
|
112
128
|
it "deletes the posts" do
|
113
129
|
original_count = Post.count
|
114
|
-
delete :destroy, id:
|
130
|
+
delete :destroy, id: post
|
115
131
|
new_count = Post.count
|
116
132
|
expect(original_count - new_count).to eq(1)
|
117
133
|
end
|
118
134
|
it "redirects to admin/posts#index" do
|
119
|
-
delete :destroy, id:
|
120
|
-
expect(response).to redirect_to(
|
135
|
+
delete :destroy, id: post
|
136
|
+
expect(response).to redirect_to(admin_posts_path)
|
121
137
|
end
|
122
138
|
end
|
123
139
|
|
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Fuel::PostsController do
|
3
|
+
describe Fuel::PostsController, type: :controller do
|
4
4
|
|
5
5
|
routes { Fuel::Engine.routes }
|
6
6
|
|
7
7
|
describe 'GET #index' do
|
8
|
+
|
9
|
+
let(:number_posts) { 10 }
|
10
|
+
let(:posts) { create_list(:published_post, number_posts) }
|
11
|
+
let(:unpublished_post) { create(:post) }
|
12
|
+
|
8
13
|
before(:each) do
|
9
|
-
|
10
|
-
|
11
|
-
create(:post)
|
12
|
-
end
|
13
|
-
create(:unpublished_post)
|
14
|
+
posts
|
15
|
+
unpublished_post
|
14
16
|
end
|
15
17
|
|
16
18
|
it "populates an array of posts" do
|
@@ -28,22 +30,25 @@ describe Fuel::PostsController do
|
|
28
30
|
end
|
29
31
|
|
30
32
|
describe 'GET #show' do
|
33
|
+
|
34
|
+
let(:post) { create(:published_post) }
|
35
|
+
|
31
36
|
before :each do
|
32
|
-
|
37
|
+
post
|
33
38
|
end
|
34
39
|
|
35
40
|
it "assigns the requested post to @post using slug" do
|
36
|
-
get :show, id:
|
37
|
-
expect(assigns(:post)).to eq
|
41
|
+
get :show, id: post.slug
|
42
|
+
expect(assigns(:post)).to eq post
|
38
43
|
end
|
39
44
|
|
40
45
|
it "assigns the requested post to @post using ID" do
|
41
|
-
get :show, id:
|
42
|
-
expect(assigns(:post)).to eq
|
46
|
+
get :show, id: post.id
|
47
|
+
expect(assigns(:post)).to eq post
|
43
48
|
end
|
44
49
|
|
45
50
|
it "truncates title to 70 characters or less" do
|
46
|
-
get :show, id:
|
51
|
+
get :show, id: post.slug
|
47
52
|
title_length = assigns(:title).length
|
48
53
|
expect(title_length).to be < 70
|
49
54
|
end
|
data/spec/factories.rb
CHANGED
@@ -1,18 +1,32 @@
|
|
1
|
+
require 'faker'
|
2
|
+
|
1
3
|
FactoryGirl.define do
|
2
4
|
|
3
5
|
factory :post, class: Fuel::Post do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
published false
|
7
|
+
|
8
|
+
factory :published_post do
|
9
|
+
author
|
10
|
+
title Faker::Lorem.sentence
|
11
|
+
content "<p>Some content for a blog post</p>"
|
12
|
+
published true
|
13
|
+
published_at { DateTime.now - rand(1..100).days }
|
14
|
+
end
|
9
15
|
|
10
16
|
factory :invalid_post do
|
17
|
+
published true
|
11
18
|
title nil
|
12
19
|
end
|
20
|
+
|
13
21
|
factory :unpublished_post do
|
14
22
|
published false
|
15
23
|
end
|
16
24
|
end
|
17
25
|
|
26
|
+
factory :author, class: Fuel::Author do
|
27
|
+
first_name Faker::Name.first_name
|
28
|
+
last_name Faker::Name.last_name
|
29
|
+
title Faker::Name.title
|
30
|
+
end
|
31
|
+
|
18
32
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Fuel
|
4
|
+
describe Author, type: :model do
|
5
|
+
|
6
|
+
subject { build(:author) }
|
7
|
+
|
8
|
+
it { is_expected.to be_valid }
|
9
|
+
it { is_expected.to validate_presence_of(:first_name) }
|
10
|
+
it { is_expected.to validate_presence_of(:last_name) }
|
11
|
+
it { is_expected.to validate_presence_of(:title) }
|
12
|
+
it { is_expected.to have_many(:posts) }
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -1,43 +1,98 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Fuel
|
4
|
-
describe Post do
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
describe Post, type: :model do
|
5
|
+
|
6
|
+
context "draft" do
|
7
|
+
subject { build(:post) }
|
8
|
+
it { is_expected.to be_valid }
|
8
9
|
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
expect(
|
15
|
-
end
|
16
|
-
it "is valid without a #{attr} when not published (i.e. saved as a draft)" do
|
17
|
-
post = build(:post, attr => nil, published: false)
|
18
|
-
expect(post).to have(0).errors_on(attr)
|
11
|
+
context "slug" do
|
12
|
+
subject { create(:post) }
|
13
|
+
|
14
|
+
it "is expected to generate a slug" do
|
15
|
+
expect(subject.slug.length).to be > 0
|
19
16
|
end
|
20
17
|
end
|
21
18
|
|
22
|
-
|
19
|
+
context "published" do
|
20
|
+
subject { build(:published_post) }
|
21
|
+
|
22
|
+
it { is_expected.to be_valid }
|
23
|
+
it { is_expected.to validate_presence_of(:title) }
|
24
|
+
it { is_expected.to validate_presence_of(:content) }
|
25
|
+
it { is_expected.to validate_presence_of(:author_id) }
|
26
|
+
it { is_expected.to validate_presence_of(:published_at) }
|
27
|
+
it { is_expected.to belong_to(:author) }
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
describe "scopes" do
|
32
|
+
|
33
|
+
let(:published_posts) { create_list(:published_post, number_posts) }
|
34
|
+
let(:number_posts) { 10 }
|
35
|
+
let(:draft) { create(:post) }
|
36
|
+
|
23
37
|
before(:each) do
|
24
|
-
|
25
|
-
@num_published_posts.times do |post|
|
26
|
-
create(:post)
|
27
|
-
end
|
28
|
-
create(:unpublished_post)
|
29
|
-
@posts = Fuel::Post.recent_published_posts
|
38
|
+
published_posts
|
30
39
|
end
|
31
|
-
|
32
|
-
|
40
|
+
|
41
|
+
context "published" do
|
42
|
+
subject(:published) { Fuel::Post.published }
|
43
|
+
|
44
|
+
it "returns an array of posts" do
|
45
|
+
expect(published.count).to be > (0)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "only displays published posts" do
|
49
|
+
expect(published.count).to eq(number_posts)
|
50
|
+
end
|
33
51
|
end
|
34
|
-
|
35
|
-
|
52
|
+
|
53
|
+
context "recent" do
|
54
|
+
subject(:recent) { Fuel::Post.recent }
|
55
|
+
|
56
|
+
it "sorts the posts by published_at datetime" do
|
57
|
+
is_ordered = recent[0].published_at > recent[1].published_at && recent[1].published_at > recent[2].published_at
|
58
|
+
expect(is_ordered).to be_truthy
|
59
|
+
end
|
36
60
|
end
|
37
|
-
|
38
|
-
|
39
|
-
|
61
|
+
|
62
|
+
context "next" do
|
63
|
+
let(:post) { Fuel::Post.published.recent.first }
|
64
|
+
subject(:next_post) { post.next }
|
65
|
+
|
66
|
+
before(:each) do
|
67
|
+
post
|
68
|
+
next_post
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should have a published_at date less than or equal to the current posts' published_at date" do
|
72
|
+
expect(next_post.published_at).to be <= post.published_at
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should not be the same post as the current post" do
|
76
|
+
expect(next_post.id).to_not eq(post.id)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "there should be no other posts with a published_at date less than the current post's published_at date yet greater than the next posts' published_at date" do
|
80
|
+
all_posts = Fuel::Post.published
|
81
|
+
better_option = all_posts.detect do |p|
|
82
|
+
[post.id, next_post.id].exclude?(p.id) && p.published_at < post.published_at && p.published_at > next_post.published_at
|
83
|
+
end
|
84
|
+
expect(better_option).to be_blank
|
85
|
+
end
|
86
|
+
|
40
87
|
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "instance methods" do
|
92
|
+
|
93
|
+
let(:post) { create(:post) }
|
94
|
+
|
95
|
+
|
41
96
|
end
|
42
97
|
|
43
98
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
if File.exist?('codeclimate_env.rb')
|
2
|
+
require 'codeclimate_env.rb'
|
3
|
+
require 'codeclimate-test-reporter'
|
4
|
+
CodeClimate::TestReporter.start
|
5
|
+
end
|
6
|
+
|
5
7
|
ENV["RAILS_ENV"] ||= 'test'
|
6
8
|
require File.expand_path('../dummy/config/environment', __FILE__)
|
7
9
|
require 'rspec/rails'
|
@@ -9,10 +11,21 @@ require 'factory_girl'
|
|
9
11
|
require 'factories'
|
10
12
|
require 'database_cleaner'
|
11
13
|
require 'rspec/autorun'
|
14
|
+
require 'pry-nav'
|
15
|
+
require 'pry-rails'
|
16
|
+
require 'pry-stack_explorer'
|
17
|
+
require 'pry-theme'
|
18
|
+
require 'shoulda-matchers'
|
19
|
+
require 'rspec/collection_matchers'
|
20
|
+
|
12
21
|
include Fuel
|
13
|
-
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
|
22
|
+
# ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
|
14
23
|
|
15
24
|
RSpec.configure do |config|
|
25
|
+
|
26
|
+
config.before :each, type: :controller do
|
27
|
+
controller.class.include Fuel::Engine.routes.url_helpers
|
28
|
+
end
|
16
29
|
# ## Mock Framework
|
17
30
|
#
|
18
31
|
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|