cachai 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c36116e0dedcd0acb87163ee6ff79ee9aa29439
4
- data.tar.gz: 921d378a62e1b6f784d90577ac553b1768d462fd
3
+ metadata.gz: d1077a9878d131805e696c2e1b2105c52dcc6578
4
+ data.tar.gz: 572ed93566a73bf464953dc844b7469f95becdfa
5
5
  SHA512:
6
- metadata.gz: 7b69c92fdf62712fa2c509088ac70e091ea1c284e366f3ca6101f43fc7f07026b5ffc32ac4e7ea02b66199e7e767fce6602629b88af625adb123638c63baf38f
7
- data.tar.gz: c13f891bdde3ba0b87b8cedaf587444a5980f3d4be7de04dec1ae26ef50c3da348b35eae4dafb98568f78ca87f1bc5eeef32f9b9d878a6728de28bb448f7c011
6
+ metadata.gz: bc98cd8492e345a9a3bb1bbd1c983c34b72f746a3c2648977aa60f4ae92684c035e0bbc6e984b5f69b402216c0c9c10afc4e3a124636ef9c07ef7832f1a0cc78
7
+ data.tar.gz: 7e8b2dd17bac39e58840db4e91c4574e0b9e325bd8564e26aaf8342fa2f829adba41bdd812b6e7861c46c401b556d33e340943d9df9db97a22fc2c8bb50055b6
@@ -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.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.}
@@ -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
- CACHE_MINUTES = 10 * 60 # 10 minutes
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'],
@@ -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 @domain
58
- "comments:#{@domain}:#{path}"
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
 
@@ -17,6 +17,7 @@ describe 'post comment' do
17
17
  :author_email => 'test@email.com',
18
18
  :author_url => 'http://url.com'
19
19
  }.merge(opts)
20
+
20
21
  post '/comments.json', data.to_json, { 'CONTENT_TYPE' => 'application/json' }
21
22
  end
22
23
 
@@ -24,6 +24,7 @@ class TestApp < Sinatra::Base
24
24
  :api_user => 'test'
25
25
  }
26
26
  }
27
+
27
28
  get '/' do
28
29
  'Hello world'
29
30
  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.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/get_comments_test.rb
167
- - spec/post_comments_test.rb
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/get_comments_test.rb
196
- - spec/post_comments_test.rb
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: