enju_search_log 0.1.0.pre5 → 0.1.0.pre6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/enju_search_log/user.rb +8 -10
- data/lib/enju_search_log/version.rb +1 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/models/search_history_spec.rb +11 -0
- 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: c0c3299c71cb309bb0e515975b8231709543b2d9
|
4
|
+
data.tar.gz: a36668e89747f76f7207ff652bc64d02fc46a9be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3754d69657a49c48d405827e90b6a279e0ea797da583e528d87bfb3a573e3b3ab90d1e4077c2b289f7280371edc58bec389649b2b4dd68495b7f81495472240
|
7
|
+
data.tar.gz: 626c20990b9fbce6a5b8594f7f5b92c33d647871186f2d1a4667252f17c48e4bcbd71b64b96b3f0aef3890bd75e903ebe3f4a1953adbb39fce844a1e12f8095f
|
data/lib/enju_search_log/user.rb
CHANGED
@@ -14,22 +14,20 @@ module EnjuSearchLog
|
|
14
14
|
end
|
15
15
|
|
16
16
|
module InstanceMethods
|
17
|
-
def
|
18
|
-
return unless
|
17
|
+
def save_history(query, offset = 0, total = 0, format = nil)
|
18
|
+
return nil unless self.save_search_history
|
19
19
|
if Setting.write_search_log_to_file
|
20
|
-
write_search_log(query, total,
|
20
|
+
write_search_log(query, total, username, format)
|
21
21
|
else
|
22
22
|
history = SearchHistory.new(:query => query, :start_record => offset + 1, :maximum_records => nil, :number_of_records => total)
|
23
|
-
history.user =
|
24
|
-
history.save
|
23
|
+
history.user = self
|
24
|
+
history.save(:validate => false)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def write_search_log(query, total,
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
SEARCH_LOGGER.info "#{Time.zone.now}\t#{query}\t#{total}\t#{username}\t#{params[:format]}"
|
28
|
+
def write_search_log(query, total, username, format)
|
29
|
+
logger = ActiveSupport::BufferedLogger.new(File.join(Rails.root, 'log', 'search.log'))
|
30
|
+
logger.info "#{Time.zone.now}\t#{query}\t#{total}\t#{username}\t#{format}"
|
33
31
|
end
|
34
32
|
end
|
35
33
|
end
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -4,6 +4,17 @@ require 'spec_helper'
|
|
4
4
|
describe SearchHistory do
|
5
5
|
fixtures :all
|
6
6
|
|
7
|
+
it "should create search history" do
|
8
|
+
user = users(:admin)
|
9
|
+
user.save_search_history = true
|
10
|
+
user.save_history('test', 1, 10).should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should not create search history if the user disabled logging" do
|
14
|
+
user = users(:admin)
|
15
|
+
user.save_history('test', 1, 10).should be_nil
|
16
|
+
end
|
17
|
+
|
7
18
|
it "should destroy all history" do
|
8
19
|
user = users(:admin)
|
9
20
|
old_count = SearchHistory.count
|