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 +4 -4
- data/cachai.gemspec +1 -1
- data/lib/cachai.rb +11 -4
- data/spec/post_comments_spec.rb +56 -8
- data/spec/spec_helper.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12ab8f63663887eb16edbe178e1289d8c92d8e79
|
4
|
+
data.tar.gz: 8840bce666685bf34f3eaf4388d81f1a2c97f93c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
27
|
-
redis_host
|
28
|
-
@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)
|
data/spec/post_comments_spec.rb
CHANGED
@@ -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
|
-
|
111
|
-
|
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
|
-
|
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
|
-
|
133
|
-
|
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
|
-
|
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