kawara 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/kawara/categories_controller.rb +14 -0
  3. data/app/controllers/kawara/home_controller.rb +9 -0
  4. data/app/controllers/kawara/tags_controller.rb +14 -0
  5. data/app/models/kawara/article.rb +6 -1
  6. data/app/models/kawara/category.rb +5 -0
  7. data/app/models/kawara/tag.rb +4 -0
  8. data/app/views/kawara/articles/_list.html.erb +6 -0
  9. data/app/views/kawara/categories/index.html.erb +5 -0
  10. data/app/views/kawara/categories/show.html.erb +1 -0
  11. data/app/views/kawara/home/index.html.erb +1 -0
  12. data/app/views/kawara/tags/index.html.erb +5 -0
  13. data/app/views/kawara/tags/show.html.erb +1 -0
  14. data/config/initializers/friendly_id.rb +88 -0
  15. data/config/routes.rb +5 -1
  16. data/db/migrate/20160310230220_create_kawara_categories.rb +2 -0
  17. data/db/migrate/20160311072058_create_kawara_articles.rb +4 -1
  18. data/db/migrate/20160315075716_create_kawara_tags.rb +3 -1
  19. data/db/migrate/20160324062743_create_friendly_id_slugs.rb +15 -0
  20. data/lib/kawara.rb +1 -0
  21. data/lib/kawara/version.rb +1 -1
  22. data/spec/controllers/kawara/categories_controller_spec.rb +53 -0
  23. data/spec/controllers/kawara/home_controller_spec.rb +30 -0
  24. data/spec/controllers/kawara/tags_controller_spec.rb +54 -0
  25. data/spec/dummy/db/development.sqlite3 +0 -0
  26. data/spec/dummy/db/fixtures/development/articles.rb +33 -0
  27. data/spec/dummy/db/fixtures/development/categories.rb +15 -0
  28. data/spec/dummy/db/fixtures/development/tags.rb +20 -0
  29. data/spec/dummy/db/schema.rb +22 -2
  30. data/spec/dummy/db/test.sqlite3 +0 -0
  31. data/spec/dummy/log/development.log +12767 -0
  32. data/spec/dummy/log/test.log +21376 -0
  33. data/spec/dummy/tmp/uploads/store/01c5dd5642a687eb5249a2c46f0381215db48d307940775d478f892b7d93 +1 -0
  34. data/spec/dummy/tmp/uploads/store/0778585f4752ba5e3ab81e3a953eb3483bad28bf385692e1eee9f56278c0 +1 -0
  35. data/spec/dummy/tmp/uploads/store/0a8f59b5f851c1cd6bc7413ab4460c1ad024a1de51bfb971bef318d98fa2 +1 -0
  36. data/spec/dummy/tmp/uploads/store/0da9099f8e35a8bab7db0f52174d518608fadc52b1aac56c07c0ac335cf1 +1 -0
  37. data/spec/dummy/tmp/uploads/store/146c75ff6f9313b39bafabf203fd451745ad06415990b5af5f7dffc86691 +1 -0
  38. data/spec/dummy/tmp/uploads/store/1f1207b54c3e8ee021b334fb3129b423f6d97b18626de135d7def3dee22f +1 -0
  39. data/spec/dummy/tmp/uploads/store/2b3e012d7906b4d273d18be41b1423fc61c258f6a1cc6cffcc51917e83ef +1 -0
  40. data/spec/dummy/tmp/uploads/store/2d1e897f147f93e2d28fae9d3333154e04bb3cc0228b95694927c81603ce +1 -0
  41. data/spec/dummy/tmp/uploads/store/3254d9bfc999010b076bea2bf9d39fe4c4ba7b5167a8edfb379b59b30ad4 +1 -0
  42. data/spec/dummy/tmp/uploads/store/375c9c1a88e11de2198353ebbe8cf610910eea14e2eec175d0a82e613105 +1 -0
  43. data/spec/dummy/tmp/uploads/store/3ad77ebaccd5efeb9441238ed32b984b7128827429ca36b1b995e04af89a +1 -0
  44. data/spec/dummy/tmp/uploads/store/3f46c2fa4f8988393cd22e2fe023d76e41ef640fee642b15b75750d765d0 +1 -0
  45. data/spec/dummy/tmp/uploads/store/3ff2c87c1873add39ec1464731f5192f8e8e2a696d6624823317ad14cffa +1 -0
  46. data/spec/dummy/tmp/uploads/store/4352a16779490e14e5903e4bc1a4ff42d990047bbc8ae83d2a76582e3ae2 +1 -0
  47. data/spec/dummy/tmp/uploads/store/45492195be7ee2c3d38e63b897e6a795245a6abac9e0312dca59b8f9431a +1 -0
  48. data/spec/dummy/tmp/uploads/store/46b9dd648bc0419e12aefdfd3ef53e1403b72ea1d7c121a73beeddf26d74 +1 -0
  49. data/spec/dummy/tmp/uploads/store/47017513e5a2468deaed6083cecc2bde91fa765d050e491f13964e14d57f +1 -0
  50. data/spec/dummy/tmp/uploads/store/4e9fa292ea8755f30b85ac474451be905e0b3d0f2b91152f9e5e5aac308b +1 -0
  51. data/spec/dummy/tmp/uploads/store/5c9f10ad783509bceaa8913050f69d68a0c9353e9207aeab9d05b5e4ec2f +1 -0
  52. data/spec/dummy/tmp/uploads/store/5efe5b7bc4aeff3964b6981588dd55bd23135e32db133c80548b1d51d487 +1 -0
  53. data/spec/dummy/tmp/uploads/store/5f92364277a557bc3b1028604d15031232cceed2bb3060b61c2c848345df +1 -0
  54. data/spec/dummy/tmp/uploads/store/67a80828e8c652b961d5e1fdcb147be475e8c3f3d9145dfe43daf6707deb +1 -0
  55. data/spec/dummy/tmp/uploads/store/6b5f2381320815551cd8c24eb1a9efe91a7023655bf736e255737700fce6 +1 -0
  56. data/spec/dummy/tmp/uploads/store/748136a2a6b4ef63096c93c3c5f8f33df57566c1700feb3697d5edd943be +1 -0
  57. data/spec/dummy/tmp/uploads/store/787754b597751020a2f6847d8464eda5b8c76b6f52f1dc3fcc19ad5d3896 +1 -0
  58. data/spec/dummy/tmp/uploads/store/7d4b5435d971c9074b0953d9f6daf3fc4e101ea45620d958af7173527d51 +1 -0
  59. data/spec/dummy/tmp/uploads/store/86d20a826e4b2ca3411f4825b0132c4ba498085ac83da170495dcec8a752 +1 -0
  60. data/spec/dummy/tmp/uploads/store/8751451f21431bb4dee028bf021bd9e3a02b3baa08d05049bc0d2d27d82f +1 -0
  61. data/spec/dummy/tmp/uploads/store/88f98d4811f93b41a43773f986bab80ee54af37a52f25ae5e8164a52e7bb +1 -0
  62. data/spec/dummy/tmp/uploads/store/912f96b779102ae9aa55d77fc1e945152a518c332911bd51d326c5bc5bac +1 -0
  63. data/spec/dummy/tmp/uploads/store/92f99a38e9192ae1fb4936ea3fd3f0055557b3963fde34679236b47dac7c +1 -0
  64. data/spec/dummy/tmp/uploads/store/940822fd30221ce4e54bd40e7a2e73b1f5f6f6dd88b734cae3313ee6de84 +1 -0
  65. data/spec/dummy/tmp/uploads/store/95f42a8f29d6e56a8690a1c7812e2281b0ab2043f826feead0fd12aeb621 +1 -0
  66. data/spec/dummy/tmp/uploads/store/a5ca4b846e137f06672dc618288a2a35fca573c64415afadcdab0d58c71f +1 -0
  67. data/spec/dummy/tmp/uploads/store/b30d89171efb4663031af2788a7caf726b4d4861e650ed64558356cf2638 +1 -0
  68. data/spec/dummy/tmp/uploads/store/b400ad8a9a4fa260719bb197f5ee1cd10077ea70b22ed4c39cf710477be6 +1 -0
  69. data/spec/dummy/tmp/uploads/store/b53cd13166e01c58cc30c6754d09c5dfeec92c662cec9e3806621130a370 +1 -0
  70. data/spec/dummy/tmp/uploads/store/b6ab99cd97d8fb8dffb9ba1c3c0c93667078652b4b7c4218d31e73b56a52 +1 -0
  71. data/spec/dummy/tmp/uploads/store/b89f0387a1cdb1f9d590892f3906a61808c26f2be3c13dc3533443cc4b88 +1 -0
  72. data/spec/dummy/tmp/uploads/store/ba1871376fd3bfc54bf781e24310729f3c21b8c4413fc41780428e732ef6 +1 -0
  73. data/spec/dummy/tmp/uploads/store/bb2ff75b19e8f6d1a5b6985927deb0d8f6836e5282b6ece81b6855049efe +1 -0
  74. data/spec/dummy/tmp/uploads/store/c01700f5e147843a5443e5ae5ef57b5458d00f029e11e2b6b565868b1622 +1 -0
  75. data/spec/dummy/tmp/uploads/store/c63e12a8335aa1fa05b477e0934208c8b38b64d2308cd1e1b9da2d6274e1 +1 -0
  76. data/spec/dummy/tmp/uploads/store/cf92a6fefe2e493d1f25ceb838fb5df63e3c4b45bcd9d8dfb2693e3f312d +1 -0
  77. data/spec/dummy/tmp/uploads/store/d64917757ebcb7e68e431081f98a7f215d9b684255c684054331a01f09ac +1 -0
  78. data/spec/dummy/tmp/uploads/store/d778b760ca8435d9b07c13dac3f9adb47af14790bc970f753ba9d9ba66ec +1 -0
  79. data/spec/dummy/tmp/uploads/store/dd802a13fc27db4b7c6072ad3c87def9fd9bc1dca0282e182e9431fd390a +1 -0
  80. data/spec/dummy/tmp/uploads/store/df3f6885911ad7985c3f55b6b58e45e91e49c1dc7b26382c9fe200d51f69 +1 -0
  81. data/spec/dummy/tmp/uploads/store/e7ee9da6eafe018b1a5342e091e416b72988d973d5953a18e5214537bf02 +1 -0
  82. data/spec/dummy/tmp/uploads/store/ee4593837bd2a9bba0e58378eb0a525ecd646e8f5856b3a09e9b0ed5f523 +1 -0
  83. data/spec/dummy/tmp/uploads/store/f429accb14006b2ceb2fb42049cb2357ccd0fd4c9c90379761123eb84421 +1 -0
  84. data/spec/dummy/tmp/uploads/store/fac6420448d7d01fc432b667d46db7d171ab62f699078e07014e9819da29 +1 -0
  85. data/spec/dummy/tmp/uploads/store/faeb9711776d0be95261291bbc9eee47fd3d48ef5d814e227dee3dae1080 +1 -0
  86. data/spec/factories/kawara_categories.rb +10 -0
  87. data/spec/factories/kawara_tags.rb +10 -1
  88. data/spec/models/kawara/article_spec.rb +38 -1
  89. data/spec/models/kawara/category_spec.rb +4 -0
  90. data/spec/models/kawara/tag_spec.rb +4 -0
  91. metadata +191 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3853c2184ebf23b4ef108a7a12fcf923eb06d24a
4
- data.tar.gz: a37595e7369bb006c8f940a38b8b74c5b347fc12
3
+ metadata.gz: 9dd79233c86b1fb2004cf9a94a94dbfcaace57e3
4
+ data.tar.gz: 791d8b14926050fe927d31ba8feb30892c9cea07
5
5
  SHA512:
6
- metadata.gz: b9c909aa15ea77f61007116d4b41836920c171cec74ab0144eefa1aac8ca8083f1fbbe963535d0a815dd15a8460924e8cb2c534c295546b2c956effa8d9136c7
7
- data.tar.gz: 5c404413c3519cb15c74dbd2ea63b58ef3cd4468563b6f60abe473bd48390cdce862a7eb618ac7b2201403bde5ad9faa056c746384c5ee58f3135f9cc185d048
6
+ metadata.gz: d3f0512b6b731b5131ee41bf275fc9af50699072da57a42348a24752ece221e16a1be8945ed1818674ad8b705b208f9ba2d2723c3275c33ea64a9eef107d2559
7
+ data.tar.gz: de555d3b47a189bc31b5320ec3badce51f08d14c3d481a2b6ce866f4dad9c27c2e10b6d03c538fa02dce0456f753f2700b6d22895587c51f09aad724f153898a
@@ -0,0 +1,14 @@
1
+ require_dependency "kawara/application_controller"
2
+
3
+ module Kawara
4
+ class CategoriesController < ApplicationController
5
+ def index
6
+ @categories = Kawara::Category.all
7
+ end
8
+
9
+ def show
10
+ category = Kawara::Category.friendly.find(params[:id])
11
+ @articles = category.articles_latest
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ require_dependency "kawara/application_controller"
2
+
3
+ module Kawara
4
+ class HomeController < ApplicationController
5
+ def index
6
+ @articles = Article.latest
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require_dependency "kawara/application_controller"
2
+
3
+ module Kawara
4
+ class TagsController < ApplicationController
5
+ def index
6
+ @tags = Kawara::Tag.all
7
+ end
8
+
9
+ def show
10
+ tag= Kawara::Tag.friendly.find(params[:id])
11
+ @articles = tag.articles_latest
12
+ end
13
+ end
14
+ end
@@ -3,6 +3,9 @@ require 'kramdown'
3
3
  module Kawara
4
4
  class Article < ActiveRecord::Base
5
5
 
6
+ extend FriendlyId
7
+ friendly_id :title, use: :slugged
8
+
6
9
  belongs_to :category
7
10
  has_many :images, class_name: 'ArticleImage', dependent: :destroy
8
11
  has_many :articles_tags, dependent: :destroy
@@ -14,8 +17,10 @@ module Kawara
14
17
 
15
18
  accepts_attachments_for :images
16
19
 
20
+ scope :latest, -> (limit=10) { published.last(limit).reverse }
21
+
17
22
  def self.find_from_published(id)
18
- published.find(id)
23
+ friendly.published.find(id)
19
24
  end
20
25
 
21
26
  def html_content(auto_ids: true)
@@ -2,10 +2,15 @@ require 'awesome_nested_set'
2
2
 
3
3
  module Kawara
4
4
  class Category < ActiveRecord::Base
5
+ extend FriendlyId
6
+ friendly_id :name, use: :slugged
7
+
5
8
  acts_as_nested_set
6
9
 
7
10
  has_many :articles
8
11
 
9
12
  validates :name, presence: true
13
+
14
+ delegate :latest, to: :articles, prefix: true
10
15
  end
11
16
  end
@@ -1,9 +1,13 @@
1
1
  module Kawara
2
2
  class Tag < ActiveRecord::Base
3
+ extend FriendlyId
4
+ friendly_id :name, use: :slugged
3
5
 
4
6
  has_many :articles_tags, dependent: :destroy
5
7
  has_many :articles, through: :articles_tags
6
8
 
7
9
  validates :name, presence: true, uniqueness: true
10
+
11
+ delegate :latest, to: :articles, prefix: true
8
12
  end
9
13
  end
@@ -0,0 +1,6 @@
1
+ <% articles.each do |article| %>
2
+ <div>
3
+ <h1><%= article.title %></h1>
4
+ <p><%= article.subtitle %></p>
5
+ </div>
6
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <% @categories.each do |category| %>
2
+ <p>
3
+ <%= link_to category.name, category %>
4
+ </p>
5
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= render 'kawara/articles/list', articles: @articles %>
@@ -0,0 +1 @@
1
+ <%= render 'kawara/articles/list', articles: @articles %>
@@ -0,0 +1,5 @@
1
+ <% @tags.each do |tag| %>
2
+ <p>
3
+ <%= link_to tag.name, tag %>
4
+ </p>
5
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= render 'kawara/articles/list', articles: @articles %>
@@ -0,0 +1,88 @@
1
+ # FriendlyId Global Configuration
2
+ #
3
+ # Use this to set up shared configuration options for your entire application.
4
+ # Any of the configuration options shown here can also be applied to single
5
+ # models by passing arguments to the `friendly_id` class method or defining
6
+ # methods in your model.
7
+ #
8
+ # To learn more, check out the guide:
9
+ #
10
+ # http://norman.github.io/friendly_id/file.Guide.html
11
+
12
+ FriendlyId.defaults do |config|
13
+ # ## Reserved Words
14
+ #
15
+ # Some words could conflict with Rails's routes when used as slugs, or are
16
+ # undesirable to allow as slugs. Edit this list as needed for your app.
17
+ config.use :reserved
18
+
19
+ config.reserved_words = %w(new edit index session login logout users admin
20
+ stylesheets assets javascripts images)
21
+
22
+ # ## Friendly Finders
23
+ #
24
+ # Uncomment this to use friendly finders in all models. By default, if
25
+ # you wish to find a record by its friendly id, you must do:
26
+ #
27
+ # MyModel.friendly.find('foo')
28
+ #
29
+ # If you uncomment this, you can do:
30
+ #
31
+ # MyModel.find('foo')
32
+ #
33
+ # This is significantly more convenient but may not be appropriate for
34
+ # all applications, so you must explicity opt-in to this behavior. You can
35
+ # always also configure it on a per-model basis if you prefer.
36
+ #
37
+ # Something else to consider is that using the :finders addon boosts
38
+ # performance because it will avoid Rails-internal code that makes runtime
39
+ # calls to `Module.extend`.
40
+ #
41
+ # config.use :finders
42
+ #
43
+ # ## Slugs
44
+ #
45
+ # Most applications will use the :slugged module everywhere. If you wish
46
+ # to do so, uncomment the following line.
47
+ #
48
+ # config.use :slugged
49
+ #
50
+ # By default, FriendlyId's :slugged addon expects the slug column to be named
51
+ # 'slug', but you can change it if you wish.
52
+ #
53
+ # config.slug_column = 'slug'
54
+ #
55
+ # When FriendlyId can not generate a unique ID from your base method, it appends
56
+ # a UUID, separated by a single dash. You can configure the character used as the
57
+ # separator. If you're upgrading from FriendlyId 4, you may wish to replace this
58
+ # with two dashes.
59
+ #
60
+ # config.sequence_separator = '-'
61
+ #
62
+ # ## Tips and Tricks
63
+ #
64
+ # ### Controlling when slugs are generated
65
+ #
66
+ # As of FriendlyId 5.0, new slugs are generated only when the slug field is
67
+ # nil, but if you're using a column as your base method can change this
68
+ # behavior by overriding the `should_generate_new_friendly_id` method that
69
+ # FriendlyId adds to your model. The change below makes FriendlyId 5.0 behave
70
+ # more like 4.0.
71
+ #
72
+ # config.use Module.new {
73
+ # def should_generate_new_friendly_id?
74
+ # slug.blank? || <your_column_name_here>_changed?
75
+ # end
76
+ # }
77
+ #
78
+ # FriendlyId uses Rails's `parameterize` method to generate slugs, but for
79
+ # languages that don't use the Roman alphabet, that's not usually sufficient.
80
+ # Here we use the Babosa library to transliterate Russian Cyrillic slugs to
81
+ # ASCII. If you use this, don't forget to add "babosa" to your Gemfile.
82
+ #
83
+ # config.use Module.new {
84
+ # def normalize_friendly_id(text)
85
+ # text.to_slug.normalize! :transliterations => [:russian, :latin]
86
+ # end
87
+ # }
88
+ end
@@ -1,3 +1,7 @@
1
1
  Kawara::Engine.routes.draw do
2
- resources :articles, only: %w(show)
2
+
3
+ resources :categories, only: %w(index show)
4
+ resources :articles, only: %w(show)
5
+ resources :tags, only: %w(index show)
6
+ root 'home#index'
3
7
  end
@@ -1,6 +1,7 @@
1
1
  class CreateKawaraCategories < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :kawara_categories do |t|
4
+ t.string :slug
4
5
  t.string :name, null: false
5
6
  t.integer :parent_id
6
7
  t.integer :lft, null: false
@@ -11,6 +12,7 @@ class CreateKawaraCategories < ActiveRecord::Migration
11
12
  t.timestamps null: false
12
13
  end
13
14
 
15
+ add_index :kawara_categories, :slug, unique: true
14
16
  add_index :kawara_categories, :parent_id
15
17
  add_index :kawara_categories, :lft
16
18
  add_index :kawara_categories, :rgt
@@ -2,6 +2,7 @@ class CreateKawaraArticles < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :kawara_articles do |t|
4
4
  t.integer :category_id
5
+ t.string :slug
5
6
  t.string :title
6
7
  t.string :subtitle
7
8
  t.text :content
@@ -10,8 +11,10 @@ class CreateKawaraArticles < ActiveRecord::Migration
10
11
  t.timestamps null: false
11
12
  end
12
13
 
14
+ add_index :kawara_articles, :slug, unique: true
15
+ add_index :kawara_articles, [:status, :slug]
13
16
  add_index :kawara_articles, [:status, :id]
14
17
  add_index :kawara_articles, :category_id
15
- add_index :kawara_articles, [:status, :category_id]
18
+ add_index :kawara_articles, [:category_id, :status]
16
19
  end
17
20
  end
@@ -1,12 +1,14 @@
1
1
  class CreateKawaraTags < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :kawara_tags do |t|
4
- t.string :name, null: false
4
+ t.string :slug
5
+ t.string :name, null: false
5
6
  t.integer :articles_count
6
7
 
7
8
  t.timestamps null: false
8
9
  end
9
10
 
11
+ add_index :kawara_tags, :slug, unique: true
10
12
  add_index :kawara_tags, :name, unique: true
11
13
  end
12
14
  end
@@ -0,0 +1,15 @@
1
+ class CreateFriendlyIdSlugs < ActiveRecord::Migration
2
+ def change
3
+ create_table :friendly_id_slugs do |t|
4
+ t.string :slug, :null => false
5
+ t.integer :sluggable_id, :null => false
6
+ t.string :sluggable_type, :limit => 50
7
+ t.string :scope
8
+ t.datetime :created_at
9
+ end
10
+ add_index :friendly_id_slugs, :sluggable_id
11
+ add_index :friendly_id_slugs, [:slug, :sluggable_type]
12
+ add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], :unique => true
13
+ add_index :friendly_id_slugs, :sluggable_type
14
+ end
15
+ end
@@ -1,6 +1,7 @@
1
1
  require 'kawara/engine'
2
2
  require 'kawara/config'
3
3
 
4
+ require 'friendly_id'
4
5
  require 'refile/rails'
5
6
  require 'refile/mini_magick'
6
7
  require "refile/s3"
@@ -1,3 +1,3 @@
1
1
  module Kawara
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,53 @@
1
+ require 'rails_helper'
2
+
3
+ module Kawara
4
+ RSpec.describe CategoriesController, type: :controller do
5
+
6
+ routes { Kawara::Engine.routes }
7
+
8
+ describe 'GET #index' do
9
+ subject { get :index }
10
+
11
+ before { subject }
12
+
13
+ context 'when there is no tag' do
14
+ it { expect(response).to render_template(:index) }
15
+ it { expect(response).to have_http_status(:success) }
16
+ it { expect(assigns(:categories)).to match_array(Kawara::Category.none) }
17
+ end
18
+ end
19
+
20
+ describe 'GET #show' do
21
+ subject { get :show, id: id }
22
+
23
+ let(:category) { create :kawara_category }
24
+ let(:category_with_published_articles) { create :kawara_category_with_published_articles }
25
+
26
+ context 'when there are related articles' do
27
+ let(:id) { category_with_published_articles.id }
28
+
29
+ before { subject }
30
+
31
+ it { expect(response).to render_template(:show) }
32
+ it { expect(response).to have_http_status(:success) }
33
+ it { expect(assigns(:articles)).to match(category_with_published_articles.articles_latest) }
34
+ end
35
+
36
+ context 'when there are no related articles' do
37
+ let(:id) { category.id }
38
+
39
+ before { subject }
40
+
41
+ it { expect(response).to render_template(:show) }
42
+ it { expect(response).to have_http_status(:success) }
43
+ it { expect(assigns(:articles)).to match Kawara::Category.none }
44
+ end
45
+
46
+ context 'when there are no articles' do
47
+ let(:id) { 1 }
48
+ it { expect{subject}.to raise_error(ActiveRecord::RecordNotFound) }
49
+ end
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,30 @@
1
+ require 'rails_helper'
2
+
3
+ module Kawara
4
+ RSpec.describe HomeController, type: :controller do
5
+
6
+ routes { Kawara::Engine.routes }
7
+
8
+ describe 'GET #index' do
9
+ subject { get :index }
10
+
11
+ let(:draft_article) { create :draft_article }
12
+ let(:published_article) { create :published_article }
13
+
14
+ context 'when there is a published article' do
15
+ before { published_article; subject }
16
+ it { expect(response).to render_template(:index) }
17
+ it { expect(response).to have_http_status(:success) }
18
+ it { expect(assigns(:articles)).to match_array published_article }
19
+ end
20
+
21
+ context 'when there are no published articles' do
22
+ before { draft_article; subject }
23
+
24
+ it { expect(response).to render_template(:index) }
25
+ it { expect(response).to have_http_status(:success) }
26
+ it { expect(assigns(:articles)).to match Kawara::Article.none }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,54 @@
1
+ require 'rails_helper'
2
+
3
+ module Kawara
4
+ RSpec.describe TagsController, type: :controller do
5
+
6
+ routes { Kawara::Engine.routes }
7
+
8
+ describe 'GET #index' do
9
+ subject { get :index }
10
+
11
+ before { subject }
12
+
13
+ context 'when there is no tag' do
14
+ it { expect(response).to render_template(:index) }
15
+ it { expect(response).to have_http_status(:success) }
16
+ it { expect(assigns(:tags)).to match_array(Kawara::Tag.none) }
17
+ end
18
+
19
+ end
20
+
21
+ describe 'GET #show' do
22
+ subject { get :show, id: id }
23
+
24
+ let(:tag) { create :kawara_tag }
25
+ let(:tag_with_published_articles) { create :kawara_tag_with_published_articles }
26
+
27
+ context 'when there are related articles' do
28
+ let(:id) { tag_with_published_articles.id }
29
+
30
+ before { subject }
31
+
32
+ it { expect(response).to render_template(:show) }
33
+ it { expect(response).to have_http_status(:success) }
34
+ it { expect(assigns(:articles)).to match(tag_with_published_articles.articles_latest) }
35
+ end
36
+
37
+ context 'when there are no related articles' do
38
+ let(:id) { tag.id }
39
+
40
+ before { subject }
41
+
42
+ it { expect(response).to render_template(:show) }
43
+ it { expect(response).to have_http_status(:success) }
44
+ it { expect(assigns(:articles)).to match Kawara::Article.none }
45
+ end
46
+
47
+ context 'when there are no tags' do
48
+ let(:id) { 1 }
49
+ it { expect{subject}.to raise_error(ActiveRecord::RecordNotFound) }
50
+ end
51
+ end
52
+
53
+ end
54
+ end