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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c5348f3dd52c6fbd18db55c08fb2c8f9d17257b
4
- data.tar.gz: 3e07b40b717a7f310cb07906e0bba261f7a25ba9
3
+ metadata.gz: c0c3299c71cb309bb0e515975b8231709543b2d9
4
+ data.tar.gz: a36668e89747f76f7207ff652bc64d02fc46a9be
5
5
  SHA512:
6
- metadata.gz: 37ba6d74737dc2a8856bde578b5e26a8db32355e17cb12a4ea4dde7dc3ed2559dc5c525252a6849dff591f82a404f80df34f502fa7421e9734aa83497b4f64cc
7
- data.tar.gz: 3f4f31b85e531a01c9f9fe05e26c0bdf4b3c5b503ca4fdd6297d549da455107575f4966a05b3566fa50897cc41fa56d3a404c205068f790b41de7a9d08ce4428
6
+ metadata.gz: d3754d69657a49c48d405827e90b6a279e0ea797da583e528d87bfb3a573e3b3ab90d1e4077c2b289f7280371edc58bec389649b2b4dd68495b7f81495472240
7
+ data.tar.gz: 626c20990b9fbce6a5b8594f7f5b92c33d647871186f2d1a4667252f17c48e4bcbd71b64b96b3f0aef3890bd75e903ebe3f4a1953adbb39fce844a1e12f8095f
@@ -14,22 +14,20 @@ module EnjuSearchLog
14
14
  end
15
15
 
16
16
  module InstanceMethods
17
- def save_search_history(query, offset = 0, total = 0, user = nil)
18
- return unless user.try(:save_search_history)
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, user)
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 = 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, user)
29
- if user
30
- username = user.username if user.save_search_history
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
@@ -1,3 +1,3 @@
1
1
  module EnjuSearchLog
2
- VERSION = "0.1.0.pre5"
2
+ VERSION = "0.1.0.pre6"
3
3
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enju_search_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre5
4
+ version: 0.1.0.pre6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kosuke Tanabe