cachai 0.2.6 → 0.2.7

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: e2771f0f431dbdfe8167760a4181b00e233f454e
4
- data.tar.gz: 0b9fd384140c9aa2f142947c6152820372d004fc
3
+ metadata.gz: 12ab8f63663887eb16edbe178e1289d8c92d8e79
4
+ data.tar.gz: 8840bce666685bf34f3eaf4388d81f1a2c97f93c
5
5
  SHA512:
6
- metadata.gz: 9d7dd2ab773f193801139f79dc765113932f870a4c6fd41ed78eeabd6e21d40ab75daa465e511f745ade360f742a70a3ff51d810fb82bb17ccc7a2e1ca91c31f
7
- data.tar.gz: 2d83937bac6ba16abd4a3fd936a97074161216c5c3decaf6ad3eed589d4c1a775819099487188bcbff5a224f01e8db19c73aac6e47e888bce6c26efd6f857905
6
+ metadata.gz: e0097506b4e9d93e7e12e2733b588b2562ba6f1caf809bbd7e72b7c28ba6566dcb0ecfbb18f93da0cc6a9858a9988c6c7af78ff3d1a182cb8391ce4b97b597da
7
+ data.tar.gz: 4f4f39f81b688598f50452d9da0315f395189eb40205144e94f6f44a3792c5efa37f8525566ad1938f109b6c2d69ad8d4630bf904f79ca22a801af01390c88a7
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.6'
7
+ spec.version = '0.2.7'
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
@@ -23,9 +23,10 @@ module Cachai
23
23
  end
24
24
 
25
25
  def initialize(app, opts = {})
26
- domain = opts.delete(:domain) or raise 'Domain required.'
27
- redis_host = opts.delete(:redis_host) || 'localhost'
28
- @duration = opts.delete(:duration)
26
+ domain = opts.delete(:domain) or raise 'Domain required.'
27
+ redis_host = opts.delete(:redis_host) || 'localhost'
28
+ @duration = opts.delete(:duration)
29
+ @blocked_ips = opts.delete(:blocked_ips) || []
29
30
 
30
31
  Cachai.boot(domain, redis_host)
31
32
 
@@ -100,10 +101,12 @@ module Cachai
100
101
  :author_email => data['author_email'],
101
102
  :author_url => data['author_url'],
102
103
  :parent_id => data['parent_id'].to_i,
103
- :author_ip => request.ip
104
+ :author_ip => request.ip,
105
+ :approved => is_blocked?(request.ip) ? 0 : 1
104
106
  }
105
107
 
106
108
  response = Response.create!(attrs.merge(:post_id => post.id))
109
+
107
110
  Cachai.clear_cache(data['path'])
108
111
  notify_new_response(response, data['path']) if @recipient
109
112
 
@@ -149,6 +152,10 @@ module Cachai
149
152
  return obj.is_a?(String) ? obj : obj.to_json
150
153
  end
151
154
 
155
+ def is_blocked?(user_ip)
156
+ @blocked_ips.include?(user_ip)
157
+ end
158
+
152
159
  def is_spam?(data, link, request)
153
160
  return false unless @akismet
154
161
  # return true if blacklisted?(name, email, content)
@@ -7,7 +7,7 @@ describe 'post comment' do
7
7
  TestApp
8
8
  end
9
9
 
10
- def post_comment(opts = {})
10
+ def post_comment(opts = {}, env_opts = {})
11
11
  data = {
12
12
  :domain => 'domain.com',
13
13
  :protocol => 'http',
@@ -18,7 +18,7 @@ describe 'post comment' do
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
+ post '/comments.json', data.to_json, { 'CONTENT_TYPE' => 'application/json' }.merge(env_opts)
22
22
  end
23
23
 
24
24
  describe 'no domain' do
@@ -107,10 +107,34 @@ describe 'post comment' do
107
107
  Cachai::Post.last.created_at.should_not be_nil
108
108
  end
109
109
 
110
- it 'creates a new response for that post' do
111
- expect do
110
+ describe 'if not blocked' do
111
+
112
+ it 'creates a new response for that post' do
113
+ expect do
114
+ post_comment
115
+ end.to change(Cachai::Response, :count).by(1)
116
+ end
117
+
118
+ it 'post is approved' do
112
119
  post_comment
113
- end.to change(Cachai::Response, :count).by(1)
120
+ expect(Cachai::Response.last.approved).to eql(1)
121
+ end
122
+
123
+ end
124
+
125
+ describe 'if blocked' do
126
+
127
+ it 'creates a new response for that post' do
128
+ expect do
129
+ post_comment({}, {'REMOTE_ADDR' => '12.12.12.12'})
130
+ end.to change(Cachai::Response, :count).by(1)
131
+ end
132
+
133
+ it 'post is not approved' do
134
+ post_comment({}, {'REMOTE_ADDR' => '12.12.12.12'})
135
+ expect(Cachai::Response.last.approved).to eql(0)
136
+ end
137
+
114
138
  end
115
139
 
116
140
  end
@@ -129,10 +153,34 @@ describe 'post comment' do
129
153
 
130
154
  describe 'if within comments duration' do
131
155
 
132
- it 'creates a new response for that post' do
133
- expect do
156
+ describe 'if not blocked' do
157
+
158
+ it 'creates a new response for that post' do
159
+ expect do
160
+ post_comment
161
+ end.to change(Cachai::Response, :count).by(1)
162
+ end
163
+
164
+ it 'post is approved' do
134
165
  post_comment
135
- end.to change(Cachai::Response, :count).by(1)
166
+ expect(Cachai::Response.last.approved).to eql(1)
167
+ end
168
+
169
+ end
170
+
171
+ describe 'if blocked' do
172
+
173
+ it 'creates a new response for that post' do
174
+ expect do
175
+ post_comment({}, {'REMOTE_ADDR' => '12.12.12.12'})
176
+ end.to change(Cachai::Response, :count).by(1)
177
+ end
178
+
179
+ it 'post is not approved' do
180
+ post_comment({}, {'REMOTE_ADDR' => '12.12.12.12'})
181
+ expect(Cachai::Response.last.approved).to eql(0)
182
+ end
183
+
136
184
  end
137
185
 
138
186
  end
data/spec/spec_helper.rb CHANGED
@@ -23,7 +23,8 @@ class TestApp < Sinatra::Base
23
23
  :sendgrid => {
24
24
  :api_key => 'test',
25
25
  :api_user => 'test'
26
- }
26
+ },
27
+ :blocked_ips => [ "12.12.12.12" ]
27
28
  }
28
29
 
29
30
  get '/' do
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.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás Pollak