cachai 0.2.4 → 0.2.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3798691a1372fd5f11bbb2a04d67ca5f76c33133
4
- data.tar.gz: 0ac3cafdb7f2fd8fed54ef8ecddf864f0b261157
3
+ metadata.gz: 2a72957264e1ccf48109bf8f163e6aff81473387
4
+ data.tar.gz: 3da03625f16a46f617c7044a9c86886dac91821e
5
5
  SHA512:
6
- metadata.gz: b8fc4320584cc9216cc59a347a3f3d43432b2614a7d549375024fe9deb54d784105fc0b476351ae5a7132d8223c24beb76911b341781c32460f2ab775278b9b6
7
- data.tar.gz: 5672e5803fd65fa80ce4d7dbb869891d96e39a4f034e31de0fcd5e8332b35fd040c81e414b8456cf9cc40435a53b82566d002a92c56ece03d99d0adcedd39adb
6
+ metadata.gz: 2b020330eef6ad3433877f6ed7806e01d635ca691eadec2c2fa17ba0382d9d56aab49fc3120776b404bef7475cbefc6ed863b551230b20f8b7b54bff89e18c48
7
+ data.tar.gz: 91f5a0a28a0e86b7e0c76d8ac4a854833aa697263c2ba2d019964627cdd913833935159717c286ffb08f5720dbdb5ce5f5b86bebcf2ac4f9f24e0e1ed8c98340
data/cachai.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "cachai"
7
- spec.version = '0.2.4'
7
+ spec.version = '0.2.5'
8
8
  spec.authors = ["Tomás Pollak"]
9
9
  spec.email = ["tomas@forkhq.com"]
10
10
  spec.description = %q{Middleware for embedabble comments.}
data/lib/cachai.rb CHANGED
@@ -84,7 +84,7 @@ module Cachai
84
84
  end
85
85
 
86
86
  post = Post.find_or_create_by_path(data['path'])
87
- if @duration && post.created_at < @duration.days.ago
87
+ if post.comments_closed?(@duration && @duration.days)
88
88
  return halt(400, "Comments closed.")
89
89
  end
90
90
 
data/lib/models.rb CHANGED
@@ -106,6 +106,18 @@ module Cachai
106
106
  find_by_path(path) || create({:path => path})
107
107
  end
108
108
 
109
+ def comments_closed?(days_to_remain_open)
110
+ return true if comments_allowed.to_i == 0
111
+
112
+ return false if !days_to_remain_open
113
+
114
+ # ok, we got an expiration period (seconds)
115
+ # if we add it to the creation date and it's past
116
+ # that date then yes, comments are closed.
117
+
118
+ (created_at + days_to_remain_open) < Time.now
119
+ end
120
+
109
121
  def clear_cache
110
122
  Cachai.clear_cache(path)
111
123
  end
data/lib/views/posts.erb CHANGED
@@ -5,6 +5,7 @@
5
5
  <tr>
6
6
  <td><a href="<%= url("/posts/#{post.id}") %>"><%= post.id %></a></td>
7
7
  <td><%= post.path %></td>
8
+ <td><%= post.created_at %></td>
8
9
  </tr>
9
10
  <% end %>
10
11
  </table>
@@ -102,6 +102,11 @@ describe 'post comment' do
102
102
  end.to change(Cachai::Post, :count).by(1)
103
103
  end
104
104
 
105
+ it 'sets a created_at timestamp on new post' do
106
+ post_comment
107
+ Cachai::Post.last.created_at.should_not be_nil
108
+ end
109
+
105
110
  it 'creates a new response for that post' do
106
111
  expect do
107
112
  post_comment
@@ -150,7 +155,6 @@ describe 'post comment' do
150
155
  end.not_to change(Cachai::Response, :count)
151
156
  end
152
157
 
153
-
154
158
  end
155
159
 
156
160
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cachai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás Pollak