enju_search_log 0.0.1

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.
Files changed (72) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +45 -0
  4. data/app/controllers/search_histories_controller.rb +48 -0
  5. data/app/helpers/search_histories_helper.rb +32 -0
  6. data/app/models/search_history.rb +42 -0
  7. data/app/views/search_histories/edit.html.erb +74 -0
  8. data/app/views/search_histories/index.html.erb +56 -0
  9. data/app/views/search_histories/new.html.erb +10 -0
  10. data/app/views/search_histories/show.html.erb +73 -0
  11. data/config/locales/translation_en.yml +31 -0
  12. data/config/locales/translation_ja.yml +31 -0
  13. data/config/routes.rb +3 -0
  14. data/db/migrate/090_create_search_histories.rb +31 -0
  15. data/db/migrate/20100623173800_rename_search_history_version_to_sru_version.rb +9 -0
  16. data/lib/enju_search_log.rb +16 -0
  17. data/lib/enju_search_log/engine.rb +8 -0
  18. data/lib/enju_search_log/version.rb +3 -0
  19. data/lib/tasks/enju_search_log_tasks.rake +4 -0
  20. data/spec/controllers/search_histories_controller_spec.rb +303 -0
  21. data/spec/dummy/Rakefile +7 -0
  22. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  23. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  24. data/spec/dummy/app/controllers/application_controller.rb +62 -0
  25. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  26. data/spec/dummy/app/models/ability.rb +20 -0
  27. data/spec/dummy/app/models/role.rb +5 -0
  28. data/spec/dummy/app/models/user.rb +27 -0
  29. data/spec/dummy/app/models/user_has_role.rb +4 -0
  30. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  31. data/spec/dummy/app/views/page/403.html.erb +9 -0
  32. data/spec/dummy/app/views/page/403.xml.erb +4 -0
  33. data/spec/dummy/app/views/page/404.html.erb +9 -0
  34. data/spec/dummy/app/views/page/404.xml.erb +4 -0
  35. data/spec/dummy/config.ru +4 -0
  36. data/spec/dummy/config/application.rb +45 -0
  37. data/spec/dummy/config/boot.rb +10 -0
  38. data/spec/dummy/config/database.yml +25 -0
  39. data/spec/dummy/config/environment.rb +5 -0
  40. data/spec/dummy/config/environments/development.rb +30 -0
  41. data/spec/dummy/config/environments/production.rb +60 -0
  42. data/spec/dummy/config/environments/test.rb +39 -0
  43. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  44. data/spec/dummy/config/initializers/devise.rb +209 -0
  45. data/spec/dummy/config/initializers/inflections.rb +10 -0
  46. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  47. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  48. data/spec/dummy/config/initializers/session_store.rb +8 -0
  49. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  50. data/spec/dummy/config/locales/en.yml +5 -0
  51. data/spec/dummy/config/routes.rb +60 -0
  52. data/spec/dummy/db/migrate/20111201121844_create_roles.rb +12 -0
  53. data/spec/dummy/db/migrate/20111201155456_create_users.rb +13 -0
  54. data/spec/dummy/db/migrate/20111201155513_add_devise_to_users.rb +31 -0
  55. data/spec/dummy/db/migrate/20111201163718_create_user_has_roles.rb +10 -0
  56. data/spec/dummy/db/schema.rb +81 -0
  57. data/spec/dummy/db/test.sqlite3 +0 -0
  58. data/spec/dummy/log/development.log +0 -0
  59. data/spec/dummy/log/test.log +1737 -0
  60. data/spec/dummy/public/404.html +26 -0
  61. data/spec/dummy/public/422.html +26 -0
  62. data/spec/dummy/public/500.html +26 -0
  63. data/spec/dummy/public/favicon.ico +0 -0
  64. data/spec/dummy/script/rails +6 -0
  65. data/spec/fixtures/roles.yml +21 -0
  66. data/spec/fixtures/search_histories.yml +90 -0
  67. data/spec/fixtures/user_has_roles.yml +41 -0
  68. data/spec/fixtures/users.yml +69 -0
  69. data/spec/spec_helper.rb +33 -0
  70. data/spec/support/controller_macros.rb +48 -0
  71. data/spec/support/devise.rb +4 -0
  72. metadata +245 -0
@@ -0,0 +1,31 @@
1
+ ja:
2
+ activerecord:
3
+ models:
4
+ search_history: 検索履歴
5
+
6
+ attributes:
7
+ user:
8
+ save_search_history: 検索履歴を保存する
9
+ search_history:
10
+ operation: 操作
11
+ version: バージョン
12
+ query: クエリ
13
+ start_record: スタート記録
14
+ maximum_records: 最大レコード数
15
+ record_packing: レコードの梱包
16
+ record_schema: レコードスキーマ
17
+ result_set_ttl: 結果のTTL設定
18
+ stylesheet: スタイルシート
19
+ extra_request_data: 余分なリクエストデータ
20
+ number_of_records: レコードの数
21
+ result_set_idle_time: 結果のアイドル時間を設定
22
+ records: レコード
23
+ next_record_position: 次のレコードの位置
24
+ diagnostics: 診断
25
+ extra_response_data: 余分な応答データ
26
+ echoed_search_retrieve_request: エコーの検索リクエストを取得
27
+
28
+ search_history:
29
+ all_history: "全ての検索履歴"
30
+ failed_search: "失敗した検索"
31
+ searched_at: "検索時刻"
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ resources :search_histories, :only => [:index, :show, :destroy]
3
+ end
@@ -0,0 +1,31 @@
1
+ class CreateSearchHistories < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :search_histories do |t|
4
+ t.integer :user_id
5
+ t.string :operation, :default => 'searchRetrieve'
6
+ t.float :version, :default => 1.2
7
+ t.string :query
8
+ t.integer :start_record
9
+ t.integer :maximum_records
10
+ t.string :record_packing
11
+ t.string :record_schema
12
+ t.integer :result_set_ttl
13
+ t.string :stylesheet
14
+ t.string :extra_request_data
15
+ t.integer :number_of_records, :default => 0
16
+ t.string :result_set_id
17
+ t.integer :result_set_idle_time
18
+ t.text :records
19
+ t.integer :next_record_position
20
+ t.text :diagnostics
21
+ t.text :extra_response_data
22
+ t.text :echoed_search_retrieve_request
23
+ t.timestamps
24
+ end
25
+ add_index :search_histories, :user_id
26
+ end
27
+
28
+ def self.down
29
+ drop_table :search_histories
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ class RenameSearchHistoryVersionToSruVersion < ActiveRecord::Migration
2
+ def self.up
3
+ rename_column :search_histories, :version, :sru_version
4
+ end
5
+
6
+ def self.down
7
+ rename_column :search_histories, :sru_version, :version
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ require "enju_search_log/engine"
2
+
3
+ module EnjuSearchLog
4
+ def save_search_history(query, offset = 0, total = 0, user = nil)
5
+ return unless user.try(:save_search_history)
6
+ if configatron.write_search_log_to_file
7
+ write_search_log(query, total, user)
8
+ else
9
+ history = SearchHistory.create(:query => query, :user => user, :start_record => offset + 1, :maximum_records => nil, :number_of_records => total)
10
+ end
11
+ end
12
+
13
+ def write_search_log(query, total, user)
14
+ SEARCH_LOGGER.info "#{Time.zone.now}\t#{query}\t#{total}\t#{user.try(:username)}\t#{params[:format]}"
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ require 'devise'
2
+ require 'cancan'
3
+ require 'will_paginate'
4
+
5
+ module EnjuSearchLog
6
+ class Engine < Rails::Engine
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module EnjuSearchLog
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :enju_search_log do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,303 @@
1
+ require 'spec_helper'
2
+
3
+ describe SearchHistoriesController do
4
+ fixtures :all
5
+
6
+ describe "GET index" do
7
+ describe "When logged in as Administrator" do
8
+ before(:each) do
9
+ @user = users(:admin)
10
+ sign_in @user
11
+ end
12
+
13
+ it "assigns all search_histories as @search_histories" do
14
+ get :index
15
+ assigns(:search_histories).should_not be_empty
16
+ end
17
+ end
18
+
19
+ describe "When logged in as Librarian" do
20
+ before(:each) do
21
+ @user = users(:librarian1)
22
+ sign_in @user
23
+ end
24
+
25
+ it "assigns its own search_histories as @search_histories" do
26
+ get :index
27
+ assigns(:search_histories).should eq @user.search_histories.order('created_at DESC').page(1)
28
+ assert_response :success
29
+ end
30
+
31
+ it "assigns failed search_histories as @search_histories" do
32
+ get :index, :mode => 'not_found'
33
+ assigns(:search_histories).should eq @user.search_histories.not_found.order('created_at DESC').page(1)
34
+ assert_response :success
35
+ end
36
+ end
37
+
38
+ describe "When logged in as User" do
39
+ before(:each) do
40
+ @user = users(:user1)
41
+ sign_in @user
42
+ end
43
+
44
+ it "assigns its own search_histories as @search_histories" do
45
+ get :index
46
+ assigns(:search_histories).should eq @user.search_histories.order('created_at DESC').page(1)
47
+ assert_response :success
48
+ end
49
+ end
50
+
51
+ describe "When not logged in" do
52
+ it "assigns all search_histories as @search_histories" do
53
+ get :index
54
+ assigns(:search_histories).should be_empty
55
+ response.should redirect_to new_user_session_url
56
+ end
57
+
58
+ it "should not get other's search_histories" do
59
+ get :index, :user_id => users(:admin).username
60
+ assigns(:search_histories).should be_empty
61
+ response.should redirect_to new_user_session_url
62
+ end
63
+ end
64
+ end
65
+
66
+ describe "GET show" do
67
+ describe "When logged in as Administrator" do
68
+ before(:each) do
69
+ sign_in users(:admin)
70
+ @search_history = search_histories(:one)
71
+ end
72
+
73
+ describe "if the record is mine" do
74
+ before(:each) do
75
+ @search_history = search_histories(:one)
76
+ end
77
+
78
+ it "assigns the requested search_history as @search_history" do
79
+ get :show, :id => @search_history.id
80
+ response.should be_success
81
+ assigns(:search_history).should eq(@search_history)
82
+ end
83
+ end
84
+
85
+ describe "if the record is not mine" do
86
+ before(:each) do
87
+ @search_history = search_histories(:two)
88
+ end
89
+
90
+ it "assigns the requested search_history as @search_history" do
91
+ get :show, :id => @search_history.id
92
+ response.should be_success
93
+ assigns(:search_history).should eq(@search_history)
94
+ end
95
+ end
96
+
97
+ it "should not show missing search_history" do
98
+ get :show, :id => 100
99
+ response.should be_missing
100
+ end
101
+ end
102
+
103
+ describe "When logged in as Librarian" do
104
+ before(:each) do
105
+ sign_in users(:librarian1)
106
+ end
107
+
108
+ describe "if the record is mine" do
109
+ before(:each) do
110
+ @search_history = search_histories(:two)
111
+ end
112
+
113
+ it "assigns the requested search_history as @search_history" do
114
+ get :show, :id => @search_history.id
115
+ response.should be_success
116
+ assigns(:search_history).should eq(@search_history)
117
+ end
118
+ end
119
+
120
+ describe "if the record is not mine" do
121
+ before(:each) do
122
+ @search_history = search_histories(:one)
123
+ end
124
+
125
+ it "should be forbidden" do
126
+ get :show, :id => @search_history.id
127
+ response.should be_forbidden
128
+ end
129
+ end
130
+ end
131
+
132
+ describe "When logged in as User" do
133
+ before(:each) do
134
+ sign_in users(:user1)
135
+ end
136
+
137
+ describe "if the record is mine" do
138
+ before(:each) do
139
+ @search_history = search_histories(:three)
140
+ end
141
+
142
+ it "assigns the requested search_history as @search_history" do
143
+ get :show, :id => @search_history.id
144
+ response.should be_success
145
+ assigns(:search_history).should eq(@search_history)
146
+ end
147
+ end
148
+
149
+ describe "if the record is not mine" do
150
+ before(:each) do
151
+ @search_history = search_histories(:two)
152
+ end
153
+
154
+ it "should be forbidden" do
155
+ get :show, :id => @search_history.id
156
+ response.should be_forbidden
157
+ end
158
+ end
159
+ end
160
+
161
+ describe "When not logged in" do
162
+ before(:each) do
163
+ @search_history = search_histories(:one)
164
+ end
165
+
166
+ it "should be forbidden" do
167
+ get :show, :id => @search_history.id
168
+ response.should redirect_to new_user_session_url
169
+ end
170
+ end
171
+ end
172
+
173
+ describe "DELETE destroy" do
174
+ describe "When logged in as Administrator" do
175
+ before(:each) do
176
+ sign_in users(:admin)
177
+ @search_history = search_histories(:one)
178
+ end
179
+
180
+ describe "if the record is mine" do
181
+ before(:each) do
182
+ @search_history = search_histories(:one)
183
+ end
184
+
185
+ it "destroys the requested search_history" do
186
+ delete :destroy, :id => @search_history.id
187
+ end
188
+
189
+ it "redirects to the search_histories list" do
190
+ delete :destroy, :id => @search_history.id
191
+ response.should redirect_to search_histories_url
192
+ end
193
+ end
194
+
195
+ describe "if the record is not mine" do
196
+ before(:each) do
197
+ @search_history = search_histories(:two)
198
+ end
199
+
200
+ it "destroys the requested search_history" do
201
+ delete :destroy, :id => @search_history.id
202
+ end
203
+
204
+ it "redirects to the search_histories list" do
205
+ delete :destroy, :id => @search_history.id
206
+ response.should redirect_to search_histories_url
207
+ end
208
+ end
209
+
210
+ it "should not destroy missing search_history" do
211
+ delete :destroy, :id => 100
212
+ response.should be_missing
213
+ end
214
+ end
215
+
216
+ describe "When logged in as Librarian" do
217
+ before(:each) do
218
+ sign_in users(:librarian1)
219
+ end
220
+
221
+ describe "if the record is mine" do
222
+ before(:each) do
223
+ @search_history = search_histories(:two)
224
+ end
225
+
226
+ it "destroys the requested search_history" do
227
+ delete :destroy, :id => @search_history.id
228
+ end
229
+
230
+ it "redirects to the search_histories list" do
231
+ delete :destroy, :id => @search_history.id
232
+ response.should redirect_to search_histories_url
233
+ end
234
+ end
235
+
236
+ describe "if the record is not mine" do
237
+ before(:each) do
238
+ @search_history = search_histories(:one)
239
+ end
240
+
241
+ it "destroys the requested search_history" do
242
+ delete :destroy, :id => @search_history.id
243
+ end
244
+
245
+ it "should be forbidden" do
246
+ delete :destroy, :id => @search_history.id
247
+ response.should be_forbidden
248
+ end
249
+ end
250
+ end
251
+
252
+ describe "When logged in as User" do
253
+ before(:each) do
254
+ sign_in users(:user1)
255
+ end
256
+
257
+ describe "if the record is mine" do
258
+ before(:each) do
259
+ @search_history = search_histories(:three)
260
+ end
261
+
262
+ it "destroys the requested search_history" do
263
+ delete :destroy, :id => @search_history.id
264
+ end
265
+
266
+ it "redirects to the search_histories list" do
267
+ delete :destroy, :id => @search_history.id
268
+ response.should redirect_to search_histories_url
269
+ end
270
+ end
271
+
272
+ describe "if the record is not mine" do
273
+ before(:each) do
274
+ @search_history = search_histories(:two)
275
+ end
276
+
277
+ it "destroys the requested search_history" do
278
+ delete :destroy, :id => @search_history.id
279
+ end
280
+
281
+ it "should be forbidden" do
282
+ delete :destroy, :id => @search_history.id
283
+ response.should be_forbidden
284
+ end
285
+ end
286
+ end
287
+
288
+ describe "When not logged in" do
289
+ before(:each) do
290
+ @search_history = search_histories(:one)
291
+ end
292
+
293
+ it "destroys the requested search_history" do
294
+ delete :destroy, :id => @search_history.id
295
+ end
296
+
297
+ it "should be forbidden" do
298
+ delete :destroy, :id => @search_history.id
299
+ response.should redirect_to(new_user_session_url)
300
+ end
301
+ end
302
+ end
303
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,9 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require jquery
8
+ //= require jquery_ujs
9
+ //= require_tree .
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */