fuel 0.3.28 → 0.3.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/fuel/admin/authors_controller.rb +1 -1
  3. data/app/controllers/fuel/admin/posts_controller.rb +1 -0
  4. data/app/controllers/fuel/posts_controller.rb +1 -1
  5. data/app/models/fuel/author.rb +1 -0
  6. data/app/models/fuel/post.rb +6 -5
  7. data/lib/fuel/version.rb +1 -1
  8. data/spec/codeclimate_env.rb +1 -0
  9. data/spec/controllers/fuel/admin/authors_controller_spec.rb +148 -0
  10. data/spec/controllers/fuel/admin/posts_controller_spec.rb +38 -22
  11. data/spec/controllers/fuel/posts_controller_spec.rb +17 -12
  12. data/spec/dummy/config/environments/test.rb +2 -0
  13. data/spec/factories.rb +19 -5
  14. data/spec/models/fuel/author_spec.rb +15 -0
  15. data/spec/models/fuel/post_spec.rb +82 -27
  16. data/spec/spec_helper.rb +18 -5
  17. metadata +105 -100
  18. data/app/assets/images/fuel/icons/application-icons.svg +0 -1
  19. data/app/assets/images/fuel/icons/calendar-icon.svg +0 -1
  20. data/app/assets/images/fuel/icons/dropdown-arrow-icon.svg +0 -10
  21. data/app/assets/images/fuel/icons/navigation-icons.svg +0 -1
  22. data/app/controllers/fuel/admin/settings_controller.rb +0 -7
  23. data/spec/dummy/db/development.sqlite3 +0 -0
  24. data/spec/dummy/db/test.sqlite3 +0 -0
  25. data/spec/dummy/log/test.log +0 -5441
  26. data/spec/dummy/public/404.html +0 -58
  27. data/spec/dummy/public/422.html +0 -58
  28. data/spec/dummy/public/500.html +0 -57
  29. data/spec/dummy/public/favicon.ico +0 -0
  30. data/spec/dummy/tmp/cache/assets/development/sass/4105e5a1347506aa0bdf1d045b6c437eeeaa8594/admin.css.sassc +0 -0
  31. data/spec/dummy/tmp/cache/assets/development/sass/4105e5a1347506aa0bdf1d045b6c437eeeaa8594/application.css.scssc +0 -0
  32. data/spec/dummy/tmp/cache/assets/development/sass/4105e5a1347506aa0bdf1d045b6c437eeeaa8594/posts.css.sassc +0 -0
  33. data/spec/dummy/tmp/cache/assets/development/sass/4105e5a1347506aa0bdf1d045b6c437eeeaa8594/posts.css.scssc +0 -0
  34. data/spec/dummy/tmp/cache/assets/development/sprockets/014dac3985653ba3455824e5bdaf93bd +0 -0
  35. data/spec/dummy/tmp/cache/assets/development/sprockets/03ac2f751ed77389257433b768f934c3 +0 -0
  36. data/spec/dummy/tmp/cache/assets/development/sprockets/05c5819ebb446d33153d21337d3a20ad +0 -0
  37. data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  38. data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  39. data/spec/dummy/tmp/cache/assets/development/sprockets/308795da63b7e95bd0f55cecedd62d94 +0 -0
  40. data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  41. data/spec/dummy/tmp/cache/assets/development/sprockets/3865b2b2d5132e0ea4ed29815b482dce +0 -0
  42. data/spec/dummy/tmp/cache/assets/development/sprockets/3a8a9a4ef7dd450b1cf686b461bb5245 +0 -0
  43. data/spec/dummy/tmp/cache/assets/development/sprockets/3ebee12608c20315d8de4675220e3d04 +0 -0
  44. data/spec/dummy/tmp/cache/assets/development/sprockets/4498ae7c9df269c897e3280835f07167 +0 -0
  45. data/spec/dummy/tmp/cache/assets/development/sprockets/5191f0a9c44f6502f1b23c4e717ea384 +0 -0
  46. data/spec/dummy/tmp/cache/assets/development/sprockets/5562fe0dd779e67464c82bf5f677b926 +0 -0
  47. data/spec/dummy/tmp/cache/assets/development/sprockets/70c9660e2c4d5e5a677d36620d59df7c +0 -0
  48. data/spec/dummy/tmp/cache/assets/development/sprockets/741e06bd7a3e5bc32d44a86b156237b4 +0 -0
  49. data/spec/dummy/tmp/cache/assets/development/sprockets/78148fb54f92bb724386c0cbf866bf8b +0 -0
  50. data/spec/dummy/tmp/cache/assets/development/sprockets/7cb8cf7fca54a9d0c860db5e7a874fa9 +0 -0
  51. data/spec/dummy/tmp/cache/assets/development/sprockets/89c5e5ef520aeb480b2c370cd95e4aa3 +0 -0
  52. data/spec/dummy/tmp/cache/assets/development/sprockets/9501761eef62112c4a992aa52331b52f +0 -0
  53. data/spec/dummy/tmp/cache/assets/development/sprockets/970522fbbd63cf689683466c5196857f +0 -0
  54. data/spec/dummy/tmp/cache/assets/development/sprockets/9e6bbc6ad4182b36488ed894b2cf25af +0 -0
  55. data/spec/dummy/tmp/cache/assets/development/sprockets/9f4599bbfc23ec621d87974b1cb749e3 +0 -0
  56. data/spec/dummy/tmp/cache/assets/development/sprockets/9f6c8d6fbf570cfe1a06179461b0de2d +0 -0
  57. data/spec/dummy/tmp/cache/assets/development/sprockets/a97bc057d70e3604312a80f169e9e6e9 +0 -0
  58. data/spec/dummy/tmp/cache/assets/development/sprockets/bc12f5ee1ab1f3f41620171e56218d6f +0 -0
  59. data/spec/dummy/tmp/cache/assets/development/sprockets/bfa298bb2836528bc682672f2a549707 +0 -0
  60. data/spec/dummy/tmp/cache/assets/development/sprockets/c0b400cdc41be57879274baf7d92b911 +0 -0
  61. data/spec/dummy/tmp/cache/assets/development/sprockets/c21e7a5dd39166b6f02a10131e7b60a5 +0 -0
  62. data/spec/dummy/tmp/cache/assets/development/sprockets/c78d634ffc32ae4fadbe52ac7ca08aac +0 -0
  63. data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  64. data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  65. data/spec/dummy/tmp/cache/assets/development/sprockets/d7fb93600298f6787c9defd51a75aeb5 +0 -0
  66. data/spec/dummy/tmp/cache/assets/development/sprockets/d85f307de0f4da9bd598243e1f505804 +0 -0
  67. data/spec/dummy/tmp/cache/assets/development/sprockets/d9ff247d231468f7dc28844500bc20aa +0 -0
  68. data/spec/dummy/tmp/cache/assets/development/sprockets/f089ae120c22843da39b636bfc4b8e01 +0 -0
  69. 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: 0505ce01882eba5d7556e4523d72a4ca3d638660
4
- data.tar.gz: cfc3cf2c44738d67d15876691ba8429fdfb7f97e
3
+ metadata.gz: 119ebf4f62cc4f134697c9a3163400ef4d1d0503
4
+ data.tar.gz: 89e4b2c53f79bf21e32e5d08522785122894c93d
5
5
  SHA512:
6
- metadata.gz: 9bd796cc21130dec9b5436d38837350f14698119f17bc81df628976b0d7a6b7776208697be2b15a0ce085a80c0737c23aa96330fbfe16ab6cfc88c62c3f2faeb
7
- data.tar.gz: b6c13a46b70585a82abd1fdb8628b85db257956dfdb120ecfa836b8708e12ac48c052bbc5d188a092faf6d6ca46bac31bca2b03894c35537c38892d6c3b5fa1a
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.admin_authors_path, notice: "Author was updated and #{@message}"
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
@@ -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}
@@ -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, -> { where(published: true).order("created_at DESC") }
25
- scope :recent, -> { order("created_at DESC") }
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("created_at <= ? AND id != ?", created_at, id).first
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("created_at >= ? AND id != ?", created_at, id).last
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
@@ -1,3 +1,3 @@
1
1
  module Fuel
2
- VERSION = "0.3.28"
2
+ VERSION = "0.3.29"
3
3
  end
@@ -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(Post.count)
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, post: attributes_for(:post)
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 show page" do
60
- expect(response).to redirect_to(fuel.admin_posts_path)
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, post: attributes_for(:invalid_post)
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
- @post = create(:post)
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: @post, post: attributes_for(:post, title: test_title)
86
- @post.reload
87
- expect(@post.title).to eq(test_title)
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: @post, post: attributes_for(:post)
91
- expect(response).to redirect_to(fuel.admin_posts_path)
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
- author = "Tom Cullen"
97
- put :update, id: @post, post: attributes_for(:post, title: nil, author: author)
98
- @post.reload
99
- expect(@post.author).to_not eq(author)
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: @post, post: attributes_for(:post, title: nil)
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
- @post = create(:post)
125
+ post
111
126
  end
127
+
112
128
  it "deletes the posts" do
113
129
  original_count = Post.count
114
- delete :destroy, id: @post
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: @post
120
- expect(response).to redirect_to(fuel.admin_posts_path)
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
- @num_published_posts = 10
10
- @num_published_posts.times do |post|
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
- @post = create(:post)
37
+ post
33
38
  end
34
39
 
35
40
  it "assigns the requested post to @post using slug" do
36
- get :show, id: @post.slug
37
- expect(assigns(:post)).to eq @post
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: @post.id
42
- expect(assigns(:post)).to eq @post
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: @post.slug
51
+ get :show, id: post.slug
47
52
  title_length = assigns(:title).length
48
53
  expect(title_length).to be < 70
49
54
  end
@@ -33,4 +33,6 @@ Dummy::Application.configure do
33
33
 
34
34
  # Print deprecation notices to the stderr.
35
35
  config.active_support.deprecation = :stderr
36
+ config.active_record.maintain_test_schema = false
37
+
36
38
  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
- title "This is a title"
5
- author "Ryan Francis"
6
- tag "Coding"
7
- content "Some content for a blog post"
8
- published true
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
- it "is valid with a title, author, tag, content, and published" do
6
- post = build(:post)
7
- expect(post).to be_valid
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
- required_attributes = [:title, :author, :content]
11
- required_attributes.each do |attr|
12
- it "is invalid without a #{attr}" do
13
- post = build(:post, attr => nil)
14
- expect(post).to have(1).errors_on(attr)
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
- describe "Scope recent published posts" do
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
- @num_published_posts = 3
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
- it "returns an array of posts" do
32
- expect(@posts.count).to be > (0)
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
- it "only displays published posts" do
35
- expect(@posts.count).to eq(@num_published_posts)
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
- it "sorts the posts by created_at datetime" do
38
- is_ordered = @posts[0].created_at > @posts[1].created_at && @posts[1].created_at > @posts[2].created_at
39
- expect(is_ordered).to be_true
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
- # require 'codeclimate_env.rb'
2
- # require 'codeclimate-test-reporter'
3
- # CodeClimate::TestReporter.start
4
- # This file is copied to spec/ when you run 'rails generate rspec:install'
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: