homesteading_publisher 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/homesteading_publisher/posts_controller.rb +94 -0
  3. data/app/views/homesteading_publisher/posts/_audio.html.erb +3 -0
  4. data/app/views/homesteading_publisher/posts/_flickr.html.erb +16 -0
  5. data/app/views/homesteading_publisher/posts/_form.html.erb +87 -0
  6. data/app/views/homesteading_publisher/posts/_image.html.erb +3 -0
  7. data/app/views/homesteading_publisher/posts/_instagram.html.erb +3 -0
  8. data/app/views/homesteading_publisher/posts/_post.html.erb +132 -0
  9. data/app/views/homesteading_publisher/posts/_thisismyjam.html.erb +13 -0
  10. data/app/views/homesteading_publisher/posts/_twitter.html.erb +1 -0
  11. data/app/views/homesteading_publisher/posts/_video.html.erb +3 -0
  12. data/app/views/homesteading_publisher/posts/_vimeo.html.erb +3 -0
  13. data/app/views/homesteading_publisher/posts/_vine.html.erb +3 -0
  14. data/app/views/homesteading_publisher/posts/_youtube.html.erb +8 -0
  15. data/app/views/homesteading_publisher/posts/edit.html.erb +3 -0
  16. data/app/views/homesteading_publisher/posts/index.atom.erb +53 -0
  17. data/app/views/homesteading_publisher/posts/index.html.erb +5 -0
  18. data/app/views/homesteading_publisher/posts/new.html.erb +3 -0
  19. data/app/views/homesteading_publisher/posts/show.html.erb +1 -0
  20. data/config/routes.rb +38 -0
  21. data/lib/homesteading_publisher/version.rb +1 -1
  22. data/spec/controllers/homesteading_publisher/posts_controllers_spec.rb +141 -0
  23. data/spec/dummy/db/development.sqlite3 +0 -0
  24. data/spec/dummy/log/development.log +118 -0
  25. data/spec/dummy/log/test.log +8496 -0
  26. metadata +39 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 740e2d338a07606406a8592a62920ab582039fc6
4
- data.tar.gz: cef009818b421c2a365c32bf22c2c6a4e1c6c35b
3
+ metadata.gz: f264cb16a4de82c7e2119d05f2c3035cdd5a40cd
4
+ data.tar.gz: d9b0e604f7ebcb5ef0dec0c0787128b6fda4b622
5
5
  SHA512:
6
- metadata.gz: efa7fb022c20e8b0f82ae27a4ec337de6fcad806b8bfe978d22bbf195747619f682b4a444ee003863956c580aa9142c4512f17e9628f5e61a4bbe4b995f4e090
7
- data.tar.gz: 3eb74e2388795029adfcabb2b89439a99a198bbb6932b0c632ca4f0f5dd751504c4b0dff1dee98f7c9be23d9ef8f677fa380b88ec7bf427217a3e7f5fed90fdd
6
+ metadata.gz: 884d374439b0815b18af60cf565d4912dd5db317485f6870905a76e67a7d0ce943abe78ff6e414389e929471c1f6bf2a302aafb1dc8c7afa3e39f00bb74daf8c
7
+ data.tar.gz: 7c0d6eab7fba6e94c48c57dc0a7acfbe84c6168d1db4cc602f3de88678af5da5ee9c5c5f929c62580fc29b2e769d07b63054dadeb7eecb17824d30d5d50eb79a
@@ -0,0 +1,94 @@
1
+ module HomesteadingPublisher
2
+ class PostsController < ApplicationController
3
+ before_action :set_post, only: [:edit, :update, :show, :destroy]
4
+
5
+ def index
6
+ @page_title = "Posts"
7
+
8
+ @posts = Post.paginate(per_page: 5, page: params[:page])
9
+
10
+ @posts = @posts.where(year: params[:year]) if params[:year]
11
+ @posts = @posts.where(month: params[:month]) if params[:month]
12
+ @posts = @posts.where(day: params[:day]) if params[:day]
13
+ end
14
+
15
+ def show
16
+ @page_title = @post.name
17
+ end
18
+
19
+ # require auth
20
+ def new
21
+ @page_title = "New Post"
22
+ @post = Post.new
23
+ end
24
+
25
+ # require auth
26
+ def edit
27
+ @page_title = "Editing Post - #{@post.name}"
28
+ end
29
+
30
+ # require auth
31
+ def create
32
+ @post = Post.new(post_params)
33
+ if @post.save
34
+ headers["Location"] = post_url(@post.params)
35
+ redirect_to post_url(@post.params), notice: "Post was successfully created."
36
+ else
37
+ render action: "new"
38
+ end
39
+ end
40
+
41
+ # require auth
42
+ def update
43
+ if @post.update(post_params)
44
+ redirect_to post_url(@post.params), notice: "Post was successfully updated."
45
+ else
46
+ render action: "edit"
47
+ end
48
+ end
49
+
50
+ # require auth
51
+ def destroy
52
+ @post.destroy
53
+ redirect_to root_url
54
+ end
55
+
56
+
57
+ private
58
+
59
+ def set_post
60
+ # get all posts that match the slug from the URL: yyyy/mm/dd/SLUG
61
+ posts = Post.where(slug: params[:slug]).load
62
+
63
+ # just one match, use it!
64
+ if posts.length == 1
65
+ @post = posts.first
66
+
67
+ # mulitple posts on that day with that slug, use the right nth one
68
+ elsif posts.length > 1
69
+ @post = Post.where(year: params[:year] || @post.year
70
+ ).where(month: params[:month] || @post.month
71
+ ).where(day: params[:day] || @post.day
72
+ ).where(slug: params[:slug] || @post.slug).load.first
73
+
74
+ # no posts that match slug, go to /posts feed
75
+ else posts.length.zero?
76
+ return redirect_to root_url
77
+ end
78
+ end
79
+
80
+ def post_params
81
+ params.permit(:content,
82
+ :in_reply_to,
83
+ :location_altitude,
84
+ :location_latitude,
85
+ :location_longitude,
86
+ :location_name,
87
+ :private,
88
+ :published_at,
89
+ :slug,
90
+ :syndication,
91
+ :tags)
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,3 @@
1
+ <div class="embed-audio">
2
+ <audio controls src="<%= audio[:url] %>" class="u-audio" />
3
+ </div>
@@ -0,0 +1,16 @@
1
+ <div class="embed-flickr">
2
+ <%= link_to flickr[:page_url],
3
+ title: "#{flickr[:title]} by #{flickr[:photographer_name]}, on Flickr" do %>
4
+ <%= image_tag flickr[:image_url], alt: flickr[:title] %>
5
+ <% end %>
6
+
7
+ <br />
8
+ <%= small_word_tag "By" %>
9
+
10
+ <%= link_to flickr[:photographer_name],
11
+ flickr[:photographer_url],
12
+ title: "#{flickr[:photographer_name]} on Flickr" %>
13
+
14
+ <%= small_word_tag "on" %>
15
+ <%= link_to "Flickr", "http://flickr.com" %>
16
+ </div>
@@ -0,0 +1,87 @@
1
+ <% if editing? %>
2
+ <h4 class="alert alert-info">Editing <%= link_to @post.name, @post.path %></h4>
3
+ <% end %>
4
+
5
+ <main role="main">
6
+ <% if @post.errors.any? %>
7
+ <div class="alert alert-danger">
8
+ <h4><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h4>
9
+
10
+ <ul>
11
+ <% @post.errors.full_messages.each do |msg| %>
12
+ <li><%= msg %></li>
13
+ <% end %>
14
+ </ul>
15
+ </div>
16
+ <% end %>
17
+
18
+ <fieldset class="content-container">
19
+ <%= f.label :content, class: "screen-reader-only" %>
20
+ <%= f.text_area :content, class: "e-content p-name", placeholder: "Content...", autofocus: autofocus_value, name: "content" %>
21
+
22
+ <span id="content-count" class="p-hs-content-count"></span>
23
+ </fieldset>
24
+
25
+ <fieldset class="meta">
26
+ <%= f.label :tags, class: "screen-reader-only" %>
27
+ <%= f.text_field :tags, class: "p-hs-tags", placeholder: "#tags" %>
28
+
29
+ <%= f.label :in_reply_to, class: "screen-reader-only" %>
30
+ <%= f.text_field :in_reply_to, class: "u-in-reply-to", placeholder: "In Reply To URLs" %>
31
+ </fieldset>
32
+
33
+ <fieldset class="actions">
34
+ <% if action_name == "edit" %>
35
+ <%= link_to "Delete", @post.path, class: "action-delete", method: :delete, data: { confirm: "This post will be immediately deleted. There is NO UNDO. Are you sure you want to delete it?" } %>
36
+ <%= link_to "Cancel", @post.path, class: "action", data: { confirm: "All changes made since you last published this post will be immediately lost. There is NO UNDO. Are you sure you want to discard your changes?" } %>
37
+ <% end %>
38
+
39
+
40
+ <%= f.button "Publish", class: "action-save" %>
41
+
42
+ <span>
43
+ <%= f.check_box :private %>
44
+ <%= f.label :private %>
45
+ </span>
46
+
47
+ <!-- TODO: make this work -->
48
+ <time datetime="2013-09-15T11:34:53-0700" class="dt-updated">Saved 2 minutes ago</time>
49
+ </fieldset>
50
+ </main>
51
+
52
+ <aside>
53
+ <fieldset class="syndication">
54
+ <legend>Syndication</legend>
55
+
56
+ <%= f.label :syndication, class: "screen-reader-only" %>
57
+ <%= f.text_area :syndication, class: "screen-reader-only" %>
58
+
59
+ <ul>
60
+ <li><input type="checkbox" name="appdotnet" id="appdotnet" /><label for="appdotnet">App.net </label></li>
61
+ <li><input type="checkbox" name="facebook" id="facebook" /><label for="facebook"> Facebook </label></li>
62
+ <li><input type="checkbox" name="medium" id="medium" /><label for="medium"> Medium </label></li>
63
+ <li><input type="checkbox" name="tumblr" id="tumblr" /><label for="tumblr"> Tumblr </label></li>
64
+ <li><input type="checkbox" name="twitter" id="twitter" /><label for="twitter"> Twitter </label></li>
65
+ <li><input type="checkbox" name="wordpress" id="wordpress" /><label for="wordpress">WordPress</label></li>
66
+ </ul>
67
+ </fieldset>
68
+
69
+ <fieldset class="meta">
70
+ <%= f.label :published_at, "Published Date", class: "screen-reader-only" %>
71
+ <%= f.datetime_field :published_at, class: "dt-published", placeholder: "YYYY-MM-DDTHH:MM-ZZ:ZZ" %>
72
+ </fieldset>
73
+
74
+ <fieldset class="p-location h-card">
75
+ <%= f.label :location_name, class: "screen-reader-only" %>
76
+ <%= f.text_field :location_name, class: "p-name", placeholder: "Location" %>
77
+
78
+ <%= f.label :location_latitude, class: "screen-reader-only" %>
79
+ <%= f.text_field :location_latitude, class: "p-latitude", placeholder: "Latitude" %>
80
+
81
+ <%= f.label :location_longitude, class: "screen-reader-only" %>
82
+ <%= f.text_field :location_longitude, class: "p-longitude", placeholder: "Longitude" %>
83
+
84
+ <%= f.label :location_altitude, class: "screen-reader-only" %>
85
+ <%= f.text_field :location_altitude, class: "p-altitude", placeholder: "Altitude" %>
86
+ </fieldset>
87
+ </aside>
@@ -0,0 +1,3 @@
1
+ <div class="embed-image">
2
+ <%= image_tag image[:url], class: "u-photo" %>
3
+ </div>
@@ -0,0 +1,3 @@
1
+ <div class="embed-instagram">
2
+ <blockquote class="instagram-media" data-instgrm-version="2" style=" background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width:658px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);"><div style="padding:8px;"><div style=" background:#F8F8F8; line-height:0; margin-top:40px; padding-bottom:55%; padding-top:45%; text-align:center; width:100%;"><div style="position:relative;"><div style=" -webkit-animation:dkaXkpbBxI 1s ease-out infinite; animation:dkaXkpbBxI 1s ease-out infinite; background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAsCAMAAAApWqozAAAAGFBMVEUiIiI9PT0eHh4gIB4hIBkcHBwcHBwcHBydr+JQAAAACHRSTlMABA4YHyQsM5jtaMwAAADfSURBVDjL7ZVBEgMhCAQBAf//42xcNbpAqakcM0ftUmFAAIBE81IqBJdS3lS6zs3bIpB9WED3YYXFPmHRfT8sgyrCP1x8uEUxLMzNWElFOYCV6mHWWwMzdPEKHlhLw7NWJqkHc4uIZphavDzA2JPzUDsBZziNae2S6owH8xPmX8G7zzgKEOPUoYHvGz1TBCxMkd3kwNVbU0gKHkx+iZILf77IofhrY1nYFnB/lQPb79drWOyJVa/DAvg9B/rLB4cC+Nqgdz/TvBbBnr6GBReqn/nRmDgaQEej7WhonozjF+Y2I/fZou/qAAAAAElFTkSuQmCC); display:block; height:44px; margin:0 auto -44px; position:relative; top:-44px; width:44px;"></div><span style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:12px; font-style:normal; font-weight:bold; position:relative; top:15px;">Loading</span></div></div><p style=" line-height:32px; margin-bottom:0; margin-top:8px; padding:0; text-align:center;"> <a href="https://instagram.com/p/<%= instagram[:photo_id] %>/" style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; text-decoration:none;" target="_top"> View on Instagram</a></p></div><style>@-webkit-keyframes"dkaXkpbBxI"{ 0%{opacity:0.5;} 50%{opacity:1;} 100%{opacity:0.5;} } @keyframes"dkaXkpbBxI"{ 0%{opacity:0.5;} 50%{opacity:1;} 100%{opacity:0.5;} }</style></blockquote><script async defer src="//platform.instagram.com/en_US/embeds.js"></script>
3
+ </div>
@@ -0,0 +1,132 @@
1
+ <% if post.public? || logged_in? %>
2
+ <% if action_name == "index" %><li><% end %>
3
+
4
+ <article id="post-<%= post.id %>" class="h-entry as-post">
5
+ <header>
6
+
7
+ <% if is_a_reply?(post) %>
8
+ <p class="post-meta reply-context">
9
+ <b>In Reply To</b>
10
+ <%= link_to in_reply_to_urls(post) %>
11
+ </p>
12
+ <% end %>
13
+
14
+ <h1 class="p-name">
15
+ <%= link_to "Edit", edit_post_url(post.params), class: "edit" if logged_in? %>
16
+ </h1>
17
+ </header>
18
+
19
+ <div class="e-content p-name">
20
+
21
+ <%= simple_format post.linked_content %>
22
+
23
+ <div class="embedded-media">
24
+ <% unless post.images.blank? %>
25
+ <% post.images.each do |image| %>
26
+ <%= render "image", image: image %>
27
+ <% end %>
28
+ <% end %>
29
+
30
+ <% unless post.videos.blank? %>
31
+ <% post.videos.each do |video| %>
32
+ <%= render "video", video: video %>
33
+ <% end %>
34
+ <% end %>
35
+
36
+ <% unless post.audios.blank? %>
37
+ <% post.audios.each do |audio| %>
38
+ <%= render "audio", audio: audio %>
39
+ <% end %>
40
+ <% end %>
41
+
42
+ <% unless post.youtubes.blank? %>
43
+ <% post.youtubes.each do |youtube| %>
44
+ <%= render "youtube", youtube: youtube %>
45
+ <% end %>
46
+ <% end %>
47
+
48
+ <% unless post.vimeos.blank? %>
49
+ <% post.vimeos.each do |vimeo| %>
50
+ <%= render "vimeo", vimeo: vimeo %>
51
+ <% end %>
52
+ <% end %>
53
+
54
+ <% unless post.vines.blank? %>
55
+ <% post.vines.each do |vine| %>
56
+ <%= render "vine", vine: vine %>
57
+ <% end %>
58
+ <% end %>
59
+
60
+ <% unless post.instagrams.blank? %>
61
+ <% post.instagrams.each do |instagram| %>
62
+ <%= render "instagram", instagram: instagram %>
63
+ <% end %>
64
+ <% end %>
65
+
66
+ <% unless post.flickrs.blank? %>
67
+ <% post.flickrs.each do |flickr| %>
68
+ <%= render "flickr", flickr: flickr %>
69
+ <% end %>
70
+ <% end %>
71
+
72
+ <% unless post.twitters.blank? %>
73
+ <% post.twitters.each do |twitter| %>
74
+ <%= render "twitter", twitter: twitter %>
75
+ <% end %>
76
+ <% end %>
77
+
78
+ <% unless post.thisismyjams.blank? %>
79
+ <% post.thisismyjams.each do |thisismyjam| %>
80
+ <%= render "thisismyjam", thisismyjam: thisismyjam %>
81
+ <% end %>
82
+ <% end %>
83
+ </div>
84
+
85
+ </div>
86
+
87
+ <footer class="post-meta">
88
+ <p>
89
+ <%= link_to "Published", post.path, class: "u-url u-uid p-as-verb" %>
90
+
91
+ <span class="screen-reader-only">
92
+ this
93
+ <span class="p-as-object"><%= setting :post_type %></span>
94
+ </span>
95
+
96
+ <%= time_tag post.published_at, class: "dt-published" do %>
97
+ <%= small_word_tag "on" %>
98
+ <%= human_readable_date post.published_at %>
99
+
100
+ <%= small_word_tag "at" %>
101
+ <%= human_readable_time post.published_at %>
102
+ <% end %>
103
+
104
+ <%= small_word_tag "by" %>
105
+
106
+ <span class="p-author p-as-actor h-card">
107
+ <%= link_to setting(:author_name), setting(:author_url), rel: "me", class: "u-url p-name" %>
108
+ </span>
109
+
110
+ <% unless post.source_name.blank? %>
111
+ using
112
+ <%= link_to post.source_name, post.source_url, class: "p-source-name u-source-id" %>
113
+ <% end %>
114
+ </p>
115
+
116
+ <% unless index_action? %>
117
+ <p class="short-url">
118
+ <b>URL</b>
119
+ <%= link_to short_url(post).gsub(/https?:\/\//, ""), short_url(post), class: "u-shortlink" %>
120
+ </p>
121
+ <% end %>
122
+
123
+ <% unless post.twitter_url.blank? %>
124
+ <div class="syndication">
125
+ <%= link_to_syndication(post).html_safe %>
126
+ </div> <!-- .syndication -->
127
+ <% end %>
128
+ </footer>
129
+ </article>
130
+
131
+ <% if action_name == "index" %></li><% end %>
132
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <div class="embed-thisismyjam">
2
+ <%= image_tag thisismyjam[:image_url],
3
+ alt: thisismyjam[:title] + " by " + thisismyjam[:artist],
4
+ class: "u-photo" %>
5
+
6
+ <p>
7
+ &ldquo;<%= thisismyjam[:title] %>&rdquo;
8
+ <%= small_word_tag "by" %>
9
+ <%= thisismyjam[:artist] %>
10
+ </p>
11
+
12
+ <%= link_to thisismyjam[:embed_url], thisismyjam[:embed_url] %>
13
+ </div>
@@ -0,0 +1 @@
1
+ <blockquote class="twitter-tweet"><a href="<%= twitter[:tweet_url] %>"><%= twitter[:tweet_url] %></a></blockquote> <script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
@@ -0,0 +1,3 @@
1
+ <div class="embed-video">
2
+ <video controls src="<%= video[:url] %>" class="u-video" />
3
+ </div>
@@ -0,0 +1,3 @@
1
+ <div class="embed-vimeo">
2
+ <iframe src="//player.vimeo.com/video/<%= vimeo[:video_id] %>?portrait=0&amp;color=ffffff" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
3
+ </div>
@@ -0,0 +1,3 @@
1
+ <div class="embed-vine">
2
+ <iframe class="vine-embed" src="https://vine.co/v/<%= vine[:video_id] %>/embed/simple" width="600" height="600" frameborder="0"></iframe><script async src="//platform.vine.co/static/scripts/embed.js" charset="utf-8"></script>
3
+ </div>
@@ -0,0 +1,8 @@
1
+ <div class="embed-youtube">
2
+ <iframe width="560"
3
+ height="315"
4
+ src="//www.youtube.com/embed/<%= youtube[:video_id] %>"
5
+ frameborder="0"
6
+ allowfullscreen>
7
+ </iframe>
8
+ </div>
@@ -0,0 +1,3 @@
1
+ <%= form_for @post, url: @post.path, html: { class: "h-entry" } do |f| %>
2
+ <%= render "form", f: f %>
3
+ <% end %>
@@ -0,0 +1,53 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <feed xmlns="http://www.w3.org/2005/Atom"
3
+ xmlns:thr="http://purl.org/syndication/thread/1.0"
4
+ xml:base="<%= feed_url %>"
5
+ xml:lang="en-us">
6
+
7
+ <id><%= site_url %></id>
8
+ <link rel="alternate" type="text/html" href="<%= site_url %>" />
9
+ <link rel="self" type="application/atom+xml" href="<%= feed_url %>" />
10
+
11
+ <title> <%= setting :site_title %></title>
12
+ <subtitle><%= setting :site_description %></subtitle>
13
+
14
+ <link href="./" />
15
+ <link rel="self" href="" />
16
+
17
+ <logo>/images/apple-touch-icon-144-precomposed.png</logo>
18
+ <icon>/images/favicon.ico</icon>
19
+
20
+ <updated><%= @posts.first.updated_at.xmlschema %></updated>
21
+
22
+ <author><name><%= setting :author_name %></name></author>
23
+
24
+
25
+ <rights>
26
+ All site content is copyright (c) <%= Time.now.year %>
27
+ <%= setting :author_name %> unless explicity stated otherwise
28
+ </rights>
29
+
30
+ <generator uri="http://homesteading.io">Generated by Homesteading.</generator>
31
+
32
+
33
+ <% @posts.each do |post| %>
34
+ <entry>
35
+ <id><%= canonical_url post %></id>
36
+ <published><%= post.published_at.xmlschema %></published>
37
+ <updated><%= post.updated_at.xmlschema %></updated>
38
+ <link rel="alternate" type="text/html" href="<%= canonical_url post %>"/>
39
+ <title><%= post.name %></title>
40
+
41
+ <% post.tags.split.each do |tag| %>
42
+ <category scheme="<%= tag %>" term="<%= tag %>" />
43
+ <% end %>
44
+
45
+ <content type="html">
46
+ <%= post.content %>
47
+ </content>
48
+ <author>
49
+ <name><%= setting :author_name %></name>
50
+ </author>
51
+ </entry>
52
+ <% end %>
53
+ </feed>
@@ -0,0 +1,5 @@
1
+ <ol class="h-feed hfeed">
2
+ <%= render @posts %>
3
+ </ol>
4
+
5
+ <%= will_paginate @posts %>
@@ -0,0 +1,3 @@
1
+ <%= form_for @post, html: { class: "h-entry" } do |f| %>
2
+ <%= render "form", f: f %>
3
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= render @post %>
data/config/routes.rb CHANGED
@@ -1,2 +1,40 @@
1
1
  HomesteadingPublisher::Engine.routes.draw do
2
+ get "/posts/new",
3
+ to: "posts#new",
4
+ as: "new_post"
5
+
6
+ post "/posts",
7
+ to: "posts#create",
8
+ as: "posts"
9
+
10
+ post "/posts/:year/:month/:day",
11
+ to: "posts#create",
12
+ constraints: { year: /\d{4}/, month: /\d{1,2}/, day: /\d{1,2}/ }
13
+
14
+ get "/posts/:year/:month/:day/:slug",
15
+ to: "posts#show",
16
+ constraints: { year: /\d{4}/, month: /\d{1,2}/, day: /\d{1,2}/ },
17
+ as: "post"
18
+
19
+ get "/posts/:year/:month/:day/:slug/edit",
20
+ to: "posts#edit",
21
+ constraints: { year: /\d{4}/, month: /\d{1,2}/, day: /\d{1,2}/ },
22
+ as: "edit_post"
23
+
24
+ patch "/posts/:year/:month/:day/:slug",
25
+ to: "posts#update",
26
+ constraints: { year: /\d{4}/, month: /\d{1,2}/, day: /\d{1,2}/ }
27
+
28
+ delete "/posts/:year/:month/:day/:slug",
29
+ to: "posts#destroy",
30
+ constraints: { year: /\d{4}/, month: /\d{1,2}/, day: /\d{1,2}/ }
31
+
32
+ # atom feed
33
+ get "/posts/feed", to: "posts#index", defaults: { format: "atom" }, as: :feed
34
+
35
+ # Pagination
36
+ get "/posts/page/1", to: redirect("/")
37
+ get "/posts/page", to: redirect("/")
38
+ get "/posts/page/:page", to: "posts#index"
39
+ get "(/posts)(/:year)(/:month)(/:day)", to: "posts#index"
2
40
  end
@@ -1,3 +1,3 @@
1
1
  module HomesteadingPublisher
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -0,0 +1,141 @@
1
+ require 'rails_helper'
2
+
3
+ describe HomesteadingPublisher::PostsController, type: :controller do
4
+ routes { HomesteadingPublisher::Engine.routes }
5
+ describe "GET index" do
6
+ it "assigns @page_title" do
7
+ get :index
8
+ expect(assigns(:page_title)).to eq "Posts"
9
+ end
10
+
11
+ it "renders the index template" do
12
+ get :index
13
+ expect(response).to render_template "index"
14
+ end
15
+
16
+ context "when page param is blank" do
17
+ before { 6.times { create(:post) } }
18
+ before { get :index }
19
+
20
+ it "assings @posts to be 5 most recent posts" do
21
+ expect(assigns(:posts).to_a).to eq(
22
+ Post.unscoped.order("published_at DESC").limit(5))
23
+ end
24
+ end
25
+
26
+ context "when page param is present" do
27
+ before { 6.times { create(:post) } }
28
+ before { get :index, page: "2" }
29
+
30
+ it "assings @posts to be 5 most recent posts after (page number * 5)" do
31
+ expect(assigns(:posts).to_a).to eq(
32
+ [Post.unscoped.order("published_at DESC").last])
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "GET show" do
38
+ let!(:entry) { create(:post) }
39
+ before { get :show, year: entry.year, month: entry.month,
40
+ day: entry.month, slug: entry.slug }
41
+
42
+ it "assigns @post" do
43
+ expect(assigns(:post)).to eq entry
44
+ end
45
+
46
+ it "assigns @page_title" do
47
+ expect(assigns(:page_title)).to eq entry.name
48
+ end
49
+
50
+ it "renders the show template" do
51
+ expect(response).to render_template "show"
52
+ end
53
+ end
54
+
55
+ describe "GET new" do
56
+ before { get :new }
57
+
58
+ it "assigns @post" do
59
+ expect(assigns(:post)).to be_a Post
60
+ end
61
+
62
+ it "assigns @page_title" do
63
+ expect(assigns(:page_title)).to eq "New Post"
64
+ end
65
+
66
+ it "renders the new template" do
67
+ expect(response).to render_template "new"
68
+ end
69
+ end
70
+
71
+ describe "GET edit" do
72
+ let!(:entry) { create(:post) }
73
+ before { get :edit, year: entry.year, month: entry.month,
74
+ day: entry.month, slug: entry.slug }
75
+
76
+ it "assigns @post" do
77
+ expect(assigns(:post)).to eq entry
78
+ end
79
+
80
+ it "assigns @page_title" do
81
+ expect(assigns(:page_title)).to eq "Editing Post - #{entry.name}"
82
+ end
83
+
84
+ it "renders the edit template" do
85
+ expect(response).to render_template "edit"
86
+ end
87
+ end
88
+
89
+ describe "POST create" do
90
+ let!(:entry) { create(:post) }
91
+
92
+ context "when create is successful" do
93
+ before { post :create, year: entry.year, month: entry.month,
94
+ day: entry.day, slug: entry.slug, post: { title: "Update post title"} }
95
+
96
+ it "redirects to posts" do
97
+ expect(response).to redirect_to post_path(entry.params)
98
+ end
99
+ end
100
+
101
+ context "when create is unsuccessful" do
102
+ before { Post.any_instance.stub(:save) { false } }
103
+ before { post :create, year: entry.year, month: entry.month,
104
+ day: entry.month, slug: entry.slug, post: { title: "Update post title"} }
105
+
106
+ it "renders edit template" do
107
+ expect(response).to render_template "new"
108
+ end
109
+ end
110
+ end
111
+
112
+ describe "PATCH update" do
113
+ let!(:entry) { create(:post) }
114
+
115
+ it "assigns @post" do
116
+ patch :update, year: entry.year, month: entry.month,
117
+ day: entry.month, slug: entry.slug, post: { title: "Update post title"}
118
+ expect(assigns(:post)).to eq entry
119
+ end
120
+
121
+ context "when update is successful" do
122
+ before { Post.any_instance.stub(:update) { true } }
123
+ before { patch :update, year: entry.year, month: entry.month,
124
+ day: entry.month, slug: entry.slug, post: { title: "Update post title"} }
125
+
126
+ it "redirects to post" do
127
+ expect(response).to redirect_to post_path(entry.params)
128
+ end
129
+ end
130
+
131
+ context "when update is unsuccessful" do
132
+ before { Post.any_instance.stub(:update) { false } }
133
+ before { patch :update, year: entry.year, month: entry.month,
134
+ day: entry.month, slug: entry.slug, post: { title: "Update post title"} }
135
+
136
+ it "renders edit template" do
137
+ expect(response).to render_template "edit"
138
+ end
139
+ end
140
+ end
141
+ end
File without changes