cachai 0.2.2 → 0.2.3
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 +4 -4
- data/cachai.gemspec +1 -1
- data/lib/cachai.rb +4 -1
- data/lib/models.rb +4 -2
- data/spec/akismet_spec.rb +77 -0
- data/spec/{get_comments_test.rb → get_comments_spec.rb} +6 -0
- data/spec/{post_comments_test.rb → post_comments_spec.rb} +1 -0
- data/spec/spec_helper.rb +1 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1077a9878d131805e696c2e1b2105c52dcc6578
|
4
|
+
data.tar.gz: 572ed93566a73bf464953dc844b7469f95becdfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc98cd8492e345a9a3bb1bbd1c983c34b72f746a3c2648977aa60f4ae92684c035e0bbc6e984b5f69b402216c0c9c10afc4e3a124636ef9c07ef7832f1a0cc78
|
7
|
+
data.tar.gz: 7e8b2dd17bac39e58840db4e91c4574e0b9e325bd8564e26aaf8342fa2f829adba41bdd812b6e7861c46c401b556d33e340943d9df9db97a22fc2c8bb50055b6
|
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.
|
7
|
+
spec.version = '0.2.3'
|
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
@@ -18,7 +18,9 @@ module Cachai
|
|
18
18
|
# use Rack::Static, :urls => %w(/css /img /js /favicon.ico), :root => 'public'
|
19
19
|
use ActiveRecord::ConnectionAdapters::ConnectionManagement
|
20
20
|
|
21
|
-
|
21
|
+
error do
|
22
|
+
'Oops, nasty error: ' + env['sinatra.error'].message
|
23
|
+
end
|
22
24
|
|
23
25
|
def initialize(app, opts = {})
|
24
26
|
domain = opts.delete(:domain) or raise 'Domain required.'
|
@@ -146,6 +148,7 @@ module Cachai
|
|
146
148
|
:referrer => request.referrer,
|
147
149
|
:user_agent => request.user_agent,
|
148
150
|
:permalink => link,
|
151
|
+
:blog => 'http://' + data['domain'],
|
149
152
|
:comment_type => 'comment',
|
150
153
|
:comment_content => data['content'],
|
151
154
|
:comment_author => data['author_name'],
|
data/lib/models.rb
CHANGED
@@ -7,6 +7,8 @@ ENV_NAME = ENV['RACK_ENV'] || 'development'
|
|
7
7
|
|
8
8
|
module Cachai
|
9
9
|
|
10
|
+
CACHE_MINUTES = 10 * 60 # 10 minutes
|
11
|
+
|
10
12
|
def self.boot(domain, redis_host = 'localhost')
|
11
13
|
self.domain = domain
|
12
14
|
self.cache = Redis.new(:host => redis_host)
|
@@ -54,8 +56,8 @@ module Cachai
|
|
54
56
|
end
|
55
57
|
|
56
58
|
def self.key_for(path)
|
57
|
-
raise "Domain not set!" unless
|
58
|
-
"comments:#{
|
59
|
+
raise "Domain not set!" unless domain
|
60
|
+
"comments:#{domain}:#{path}"
|
59
61
|
end
|
60
62
|
|
61
63
|
def self.get_comments_for(path, nocache = false)
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require './lib/akismet'
|
2
|
+
|
3
|
+
describe 'Akismet' do
|
4
|
+
|
5
|
+
def check(opts = {})
|
6
|
+
comment = {
|
7
|
+
:user_ip => "#{rand(255)}.#{rand(255)}.#{rand(255)}.#{rand(255)}",
|
8
|
+
:referrer => 'http://www.google.com',
|
9
|
+
:user_agent => user_agent,
|
10
|
+
:permalink => link,
|
11
|
+
:blog => "http://#{domain}",
|
12
|
+
:comment_type => 'comment',
|
13
|
+
:comment_content => opts['content'],
|
14
|
+
:comment_author => opts['author_name'],
|
15
|
+
:comment_author_url => opts['author_url'],
|
16
|
+
:comment_author_email => opts['author_email']
|
17
|
+
}.merge(opts)
|
18
|
+
|
19
|
+
client.check_comment(comment)
|
20
|
+
end
|
21
|
+
|
22
|
+
def client
|
23
|
+
Akismet.new(:api_key => key, :blog => "http://#{domain}")
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:domain) {
|
27
|
+
'test.com'
|
28
|
+
}
|
29
|
+
|
30
|
+
let(:user_agent) {
|
31
|
+
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36'
|
32
|
+
}
|
33
|
+
|
34
|
+
let(:link) {
|
35
|
+
"http://#{domain}/blog/#{Time.now.year}/#{Time.now.month}/welcome-back.html"
|
36
|
+
}
|
37
|
+
|
38
|
+
describe 'with valid key' do
|
39
|
+
|
40
|
+
let(:key) { 'e4c6b40ac9e0' } # test key
|
41
|
+
|
42
|
+
describe 'with spammy comment' do
|
43
|
+
|
44
|
+
it 'says its spam' do
|
45
|
+
resp = check({
|
46
|
+
:content => 'Buy viagra',
|
47
|
+
:author_name => 'Viagra guy',
|
48
|
+
:author_url => 'http://viagra.com/buy',
|
49
|
+
:author_email => 'viagra@viagra.com'
|
50
|
+
})
|
51
|
+
|
52
|
+
resp[:spam].should eql(true)
|
53
|
+
resp[:message].should eql("true")
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'with not spammy comment' do
|
59
|
+
|
60
|
+
it 'says its not spam' do
|
61
|
+
resp = check({
|
62
|
+
:content => "Hey man, it's me for the #{rand(1000)}th time.",
|
63
|
+
:author_name => 'jk2000',
|
64
|
+
:author_url => nil,
|
65
|
+
:author_email => 'jk2000@gmial.com'
|
66
|
+
})
|
67
|
+
|
68
|
+
# puts resp.inspect
|
69
|
+
resp[:spam].should eql(false)
|
70
|
+
resp[:message].should eql("false")
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -7,6 +7,11 @@ describe 'get comments' do
|
|
7
7
|
TestApp
|
8
8
|
end
|
9
9
|
|
10
|
+
before do
|
11
|
+
Cachai.domain = 'domain.com'
|
12
|
+
Cachai.cache = Redis.new
|
13
|
+
end
|
14
|
+
|
10
15
|
describe 'no domain' do
|
11
16
|
|
12
17
|
it 'returns 400' do
|
@@ -49,6 +54,7 @@ describe 'get comments' do
|
|
49
54
|
|
50
55
|
it 'returns 200' do
|
51
56
|
get '/comments.json', :domain => 'domain.com', :path => '/blog/post.html'
|
57
|
+
File.open('/tmp/error.html', 'w') { |f| f.write(last_response.body) }
|
52
58
|
last_response.status.should == 200
|
53
59
|
end
|
54
60
|
|
data/spec/spec_helper.rb
CHANGED
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
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomás Pollak
|
@@ -163,8 +163,9 @@ files:
|
|
163
163
|
- lib/views/comments.erb
|
164
164
|
- lib/views/layout.erb
|
165
165
|
- lib/views/posts.erb
|
166
|
-
- spec/
|
167
|
-
- spec/
|
166
|
+
- spec/akismet_spec.rb
|
167
|
+
- spec/get_comments_spec.rb
|
168
|
+
- spec/post_comments_spec.rb
|
168
169
|
- spec/spec_helper.rb
|
169
170
|
- test/app_test.rb
|
170
171
|
homepage: ''
|
@@ -192,8 +193,9 @@ signing_key:
|
|
192
193
|
specification_version: 4
|
193
194
|
summary: Middleware for embedabble comments.
|
194
195
|
test_files:
|
195
|
-
- spec/
|
196
|
-
- spec/
|
196
|
+
- spec/akismet_spec.rb
|
197
|
+
- spec/get_comments_spec.rb
|
198
|
+
- spec/post_comments_spec.rb
|
197
199
|
- spec/spec_helper.rb
|
198
200
|
- test/app_test.rb
|
199
201
|
has_rdoc:
|