admin_data 1.1.12 → 1.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile.lock +1 -1
  3. data/README.md +1 -1
  4. data/app/controllers/admin_data/analytics_controller.rb +38 -0
  5. data/app/controllers/admin_data/public_controller.rb +2 -0
  6. data/app/controllers/admin_data/search_controller.rb +10 -5
  7. data/app/helpers/admin_data/application_helper.rb +21 -0
  8. data/app/views/admin_data/analytics/_bar_chart.html.erb +39 -0
  9. data/app/views/admin_data/analytics/index.html.erb +41 -0
  10. data/app/views/admin_data/search/search/_advance_search_form.html.erb +1 -7
  11. data/app/views/admin_data/search/search/_listing.html.erb +4 -2
  12. data/app/views/admin_data/search/search/_search_form.html.erb +0 -1
  13. data/app/views/admin_data/shared/_secondary_navigation.html.erb +5 -0
  14. data/app/views/layouts/admin_data.html.erb +4 -1
  15. data/config/routes.rb +8 -5
  16. data/lib/admin_data/analytics.rb +176 -0
  17. data/lib/admin_data/exceptions.rb +5 -0
  18. data/lib/admin_data/search.rb +139 -137
  19. data/lib/admin_data/version.rb +1 -1
  20. data/lib/admin_data.rb +3 -0
  21. data/lib/public/images/sort_by_asc.jpg +0 -0
  22. data/lib/public/images/sort_by_desc.jpg +0 -0
  23. data/lib/public/images/sort_by_nothing.jpg +0 -0
  24. data/lib/public/javascripts/advance_search/sortby.js +14 -0
  25. data/lib/public/javascripts/analytics/report.js +7 -0
  26. data/lib/public/stylesheets/base.css +25 -1
  27. data/test/rails_root/Gemfile +15 -12
  28. data/test/rails_root/Gemfile.lock +8 -2
  29. data/test/rails_root/README.md +16 -8
  30. data/test/rails_root/app/models/car.rb +3 -0
  31. data/test/rails_root/config/application.rb +0 -27
  32. data/test/rails_root/config/cucumber.yml +0 -2
  33. data/test/rails_root/config/database.yml.mysql +22 -0
  34. data/test/rails_root/config/database.yml.pg +15 -0
  35. data/test/rails_root/config/{database.yml → database.yml.sqlite3} +1 -1
  36. data/test/rails_root/db/development.sqlite3 +0 -0
  37. data/test/rails_root/db/migrate/{20091030202259_create_users.rb → 20091030202259_create_tables.rb} +7 -1
  38. data/test/rails_root/db/schema.rb +6 -0
  39. data/test/rails_root/features/quick_search.feature +0 -11
  40. data/test/rails_root/lib/tasks/dbs.rake +30 -0
  41. data/test/rails_root/lib/tasks/sample_cars.rake +18 -0
  42. data/test/rails_root/test/unit/car_test.rb +100 -0
  43. metadata +30 -13
  44. data/app/views/admin_data/search/search/_sortby.html.erb +0 -19
  45. data/test/rails_root/features/advance_search/sort.feature +0 -16
  46. data/test/rails_root/test/performance/browsing_test.rb +0 -9
@@ -0,0 +1,30 @@
1
+ require "fileutils"
2
+
3
+ namespace :db do
4
+
5
+ namespace :use do
6
+
7
+ desc 'set database.yml to sqlite3'
8
+ task :sqlite3 do
9
+ file = Rails.root.join('config', 'database.yml')
10
+ orig = Rails.root.join('config', 'database.yml.sqlite3')
11
+ FileUtils.cp(orig, file)
12
+ end
13
+
14
+ desc 'set database.yml to pg'
15
+ task :pg do
16
+ file = Rails.root.join('config', 'database.yml')
17
+ orig = Rails.root.join('config', 'database.yml.pg')
18
+ FileUtils.cp(orig, file)
19
+ end
20
+
21
+ desc 'set database.yml to mysql'
22
+ task :mysql do
23
+ file = Rails.root.join('config', 'database.yml')
24
+ orig = Rails.root.join('config', 'database.yml.mysql')
25
+ FileUtils.cp(orig, file)
26
+ end
27
+
28
+
29
+ end
30
+ end
@@ -0,0 +1,18 @@
1
+ namespace :db do
2
+
3
+ desc 'populate cars'
4
+ task :sample_cars => :environment do
5
+ Car.delete_all
6
+
7
+ (1..400).to_a.each_with_index do |i, e|
8
+ i.times do
9
+ car = Car.new(:name => "car-#{i}")
10
+ puts i
11
+ car.created_at = i.send(:days).send(:ago)
12
+ car.save!
13
+ end
14
+ end
15
+ end
16
+
17
+
18
+ end
@@ -0,0 +1,100 @@
1
+ require "test_helper"
2
+ require "minitest/autorun"
3
+
4
+ class Time
5
+ def fmt
6
+ self.strftime('%Y-%m-%d')
7
+ end
8
+ end
9
+
10
+ class CarTest < MiniTest::Unit::TestCase
11
+
12
+ def setup
13
+ Car.delete_all
14
+ end
15
+
16
+ def test_by_default_all_values_are_zero
17
+ now = Time.now.utc
18
+ result = AdminData::Analytics.daily_report(Car, now)
19
+ expected = []
20
+ expected << ["'2011-05-23'", 0] << ["'2011-05-24'", 0] << ["'2011-05-25'", 0] << ["'2011-05-26'", 0] << ["'2011-05-27'", 0]
21
+ expected << ["'2011-05-28'", 0] << ["'2011-05-29'", 0] << ["'2011-05-30'", 0] << ["'2011-05-31'", 0]
22
+ expected << ["'2011-06-01'", 0] << ["'2011-06-02'", 0]
23
+ expected << ["'2011-06-03'", 0] << ["'2011-06-04'", 0] << ["'2011-06-05'", 0] << ["'2011-06-06'", 0] << ["'2011-06-07'", 0]
24
+ expected << ["'2011-06-08'", 0] << ["'2011-06-09'", 0] << ["'2011-06-10'", 0] << ["'2011-06-11'", 0] << ["'2011-06-12'", 0]
25
+ expected << ["'2011-06-13'", 0] << ["'2011-06-14'", 0] << ["'2011-06-15'", 0] << ["'2011-06-16'", 0] << ["'2011-06-17'", 0]
26
+ expected << ["'2011-06-18'", 0] << ["'2011-06-19'", 0] << ["'2011-06-20'", 0] << ["'2011-06-21'", 0] << ["'2011-06-22'", 0]
27
+ expected << ["'2011-06-23'", 0]
28
+
29
+ assert_all(expected, result)
30
+ end
31
+
32
+ def test_yesterday_vs_today
33
+ now = Time.now.utc
34
+ y = now.yesterday
35
+ Car.create!(:created_at => now.ago(3.days))
36
+ Car.create!(:created_at => y)
37
+ Car.create!(:created_at => y)
38
+ Car.create!(:created_at => now)
39
+ result = AdminData::Analytics.daily_report(Car, now)
40
+ expected = []
41
+ expected << ["'2011-05-23'", 0] << ["'2011-05-24'", 0] << ["'2011-05-25'", 0] << ["'2011-05-26'", 0] << ["'2011-05-27'", 0]
42
+ expected << ["'2011-05-28'", 0] << ["'2011-05-29'", 0] << ["'2011-05-30'", 0] << ["'2011-05-31'", 0]
43
+ expected << ["'2011-06-01'", 0] << ["'2011-06-02'", 0]
44
+ expected << ["'2011-06-03'", 0] << ["'2011-06-04'", 0] << ["'2011-06-05'", 0] << ["'2011-06-06'", 0] << ["'2011-06-07'", 0]
45
+ expected << ["'2011-06-08'", 0] << ["'2011-06-09'", 0] << ["'2011-06-10'", 0] << ["'2011-06-11'", 0] << ["'2011-06-12'", 0]
46
+ expected << ["'2011-06-13'", 0] << ["'2011-06-14'", 0] << ["'2011-06-15'", 0] << ["'2011-06-16'", 0] << ["'2011-06-17'", 0]
47
+ expected << ["'2011-06-18'", 0] << ["'2011-06-19'", 0] << ["'2011-06-20'", 1] << ["'2011-06-21'", 0] << ["'2011-06-22'", 2]
48
+ expected << ["'2011-06-23'", 1]
49
+
50
+ assert_all(expected, result)
51
+ end
52
+
53
+
54
+ def test_one_year_data_with_data_for_each_month
55
+ now = Time.now.utc
56
+ Car.create!(:created_at => now)
57
+ 2.times { cc(now.ago(1.month)) }; 3.times { cc(now.ago(2.month)) }; 4.times { cc(now.ago(3.month)) }
58
+ 5.times { cc(now.ago(4.month)) }; 6.times { cc(now.ago(5.month)) }; 7.times { cc(now.ago(6.month)) }
59
+ 8.times { cc(now.ago(7.month)) }; 9.times { cc(now.ago(8.month)) }; 10.times { cc(now.ago(9.month)) }
60
+ 11.times { cc(now.ago(10.month)) }; 12.times { cc(now.ago(11.month)) }; 13.times { cc(now.ago(12.month)) }
61
+ 14.times { cc(now.ago(13.month)) }; 15.times { cc(now.ago(14.month)) };
62
+
63
+ result = AdminData::Analytics.monthly_report(Car, now)
64
+
65
+ expected = []
66
+ expected << ["'Jul-2010'", 12] << ["'Aug-2010'", 11] << ["'Sep-2010'", 10] << ["'Oct-2010'", 9]
67
+ expected << ["'Nov-2010'", 8] << ["'Dec-2010'", 7] << ["'Jan-2011'", 6] << ["'Feb-2011'", 5]
68
+ expected << ["'Mar-2011'", 4] << ["'Apr-2011'", 3] << ["'May-2011'", 2] << ["'Jun-2011'", 1]
69
+
70
+ assert_all(expected, result)
71
+ end
72
+
73
+ def test_one_year_data_with_data_missing_for_last_9_months
74
+ Car.delete_all
75
+ now = Time.now.utc
76
+ Car.create!(:created_at => now)
77
+ 2.times { cc(now.ago(1.month)) }; 3.times { cc(now.ago(2.month)) };
78
+
79
+ result = AdminData::Analytics.monthly_report(Car, now)
80
+
81
+ expected = []
82
+ expected << ["'Jul-2010'", 0] << ["'Aug-2010'", 0] << ["'Sep-2010'", 0] << ["'Oct-2010'", 0]
83
+ expected << ["'Nov-2010'", 0] << ["'Dec-2010'", 0] << ["'Jan-2011'", 0] << ["'Feb-2011'", 0]
84
+ expected << ["'Mar-2011'", 0] << ["'Apr-2011'", 3] << ["'May-2011'", 2] << ["'Jun-2011'", 1]
85
+
86
+ assert_all(expected, result)
87
+ end
88
+
89
+ def assert_all(expected, result)
90
+ assert_equal expected.size, result.size
91
+ expected.each_with_index do |e, i|
92
+ assert_equal e, result[i]
93
+ end
94
+ end
95
+
96
+ def cc(time)
97
+ Car.create!(:created_at => time)
98
+ end
99
+
100
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: admin_data
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 12
10
- version: 1.1.12
9
+ - 13
10
+ version: 1.1.13
11
11
  platform: ruby
12
12
  authors:
13
13
  - Neeraj Singh
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-21 00:00:00 -04:00
18
+ date: 2011-06-24 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -51,6 +51,7 @@ files:
51
51
  - README.md
52
52
  - Rakefile
53
53
  - admin_data.gemspec
54
+ - app/controllers/admin_data/analytics_controller.rb
54
55
  - app/controllers/admin_data/application_controller.rb
55
56
  - app/controllers/admin_data/crud_controller.rb
56
57
  - app/controllers/admin_data/feed_controller.rb
@@ -60,6 +61,8 @@ files:
60
61
  - app/controllers/admin_data/search_controller.rb
61
62
  - app/controllers/admin_data/table_structure_controller.rb
62
63
  - app/helpers/admin_data/application_helper.rb
64
+ - app/views/admin_data/analytics/_bar_chart.html.erb
65
+ - app/views/admin_data/analytics/index.html.erb
63
66
  - app/views/admin_data/crud/association/_association_info.html.erb
64
67
  - app/views/admin_data/crud/association/_belongs_to_info.html.erb
65
68
  - app/views/admin_data/crud/association/_habtm_info.html.erb
@@ -80,7 +83,6 @@ files:
80
83
  - app/views/admin_data/search/search/_errors.html.erb
81
84
  - app/views/admin_data/search/search/_listing.html.erb
82
85
  - app/views/admin_data/search/search/_search_form.html.erb
83
- - app/views/admin_data/search/search/_sortby.html.erb
84
86
  - app/views/admin_data/search/search/_title.html.erb
85
87
  - app/views/admin_data/shared/_breadcrum.html.erb
86
88
  - app/views/admin_data/shared/_drop_down_klasses.html.erb
@@ -94,10 +96,12 @@ files:
94
96
  - config/routes.rb
95
97
  - lib/admin_data.rb
96
98
  - lib/admin_data/active_record_util.rb
99
+ - lib/admin_data/analytics.rb
97
100
  - lib/admin_data/authenticator.rb
98
101
  - lib/admin_data/config.rb
99
102
  - lib/admin_data/configuration.rb
100
103
  - lib/admin_data/date_util.rb
104
+ - lib/admin_data/exceptions.rb
101
105
  - lib/admin_data/rails_version_check.rb
102
106
  - lib/admin_data/railtie.rb
103
107
  - lib/admin_data/search.rb
@@ -107,6 +111,9 @@ files:
107
111
  - lib/public/images/add.png
108
112
  - lib/public/images/no.png
109
113
  - lib/public/images/site.png
114
+ - lib/public/images/sort_by_asc.jpg
115
+ - lib/public/images/sort_by_desc.jpg
116
+ - lib/public/images/sort_by_nothing.jpg
110
117
  - lib/public/javascripts/advance_search/act_on_result.js
111
118
  - lib/public/javascripts/advance_search/advance_search.js
112
119
  - lib/public/javascripts/advance_search/advance_search_structure.js
@@ -114,7 +121,9 @@ files:
114
121
  - lib/public/javascripts/advance_search/build_first_row.js
115
122
  - lib/public/javascripts/advance_search/event_bindings.js
116
123
  - lib/public/javascripts/advance_search/global_ajax_setting.js
124
+ - lib/public/javascripts/advance_search/sortby.js
117
125
  - lib/public/javascripts/advance_search/trigger_submit_on_domready.js
126
+ - lib/public/javascripts/analytics/report.js
118
127
  - lib/public/javascripts/misc/drop_down_change.js
119
128
  - lib/public/javascripts/misc/js_util.js
120
129
  - lib/public/javascripts/misc/quick_search_input_focus.js
@@ -139,6 +148,7 @@ files:
139
148
  - test/rails_root/Rakefile
140
149
  - test/rails_root/app/controllers/application_controller.rb
141
150
  - test/rails_root/app/helpers/application_helper.rb
151
+ - test/rails_root/app/models/car.rb
142
152
  - test/rails_root/app/models/city.rb
143
153
  - test/rails_root/app/models/club.rb
144
154
  - test/rails_root/app/models/newspaper.rb
@@ -150,7 +160,9 @@ files:
150
160
  - test/rails_root/config/application.rb
151
161
  - test/rails_root/config/boot.rb
152
162
  - test/rails_root/config/cucumber.yml
153
- - test/rails_root/config/database.yml
163
+ - test/rails_root/config/database.yml.mysql
164
+ - test/rails_root/config/database.yml.pg
165
+ - test/rails_root/config/database.yml.sqlite3
154
166
  - test/rails_root/config/environment.rb
155
167
  - test/rails_root/config/environments/development.rb
156
168
  - test/rails_root/config/environments/production.rb
@@ -165,7 +177,7 @@ files:
165
177
  - test/rails_root/config/locales/en.yml
166
178
  - test/rails_root/config/routes.rb
167
179
  - test/rails_root/db/development.sqlite3
168
- - test/rails_root/db/migrate/20091030202259_create_users.rb
180
+ - test/rails_root/db/migrate/20091030202259_create_tables.rb
169
181
  - test/rails_root/db/production.sqlite3
170
182
  - test/rails_root/db/schema.rb
171
183
  - test/rails_root/db/seeds.rb
@@ -175,7 +187,6 @@ files:
175
187
  - test/rails_root/features/advance_search/destroy_all.feature
176
188
  - test/rails_root/features/advance_search/integer.feature
177
189
  - test/rails_root/features/advance_search/multiple_rows.feature
178
- - test/rails_root/features/advance_search/sort.feature
179
190
  - test/rails_root/features/advance_search/string.feature
180
191
  - test/rails_root/features/crud.feature
181
192
  - test/rails_root/features/crud_show.feature
@@ -198,12 +209,14 @@ files:
198
209
  - test/rails_root/features/table_structure.feature
199
210
  - test/rails_root/lib/tasks/.gitkeep
200
211
  - test/rails_root/lib/tasks/cucumber.rake
212
+ - test/rails_root/lib/tasks/dbs.rake
213
+ - test/rails_root/lib/tasks/sample_cars.rake
201
214
  - test/rails_root/public/.gitkeep
202
215
  - test/rails_root/script/cucumber
203
216
  - test/rails_root/script/rails
204
217
  - test/rails_root/test/factories.rb
205
- - test/rails_root/test/performance/browsing_test.rb
206
218
  - test/rails_root/test/test_helper.rb
219
+ - test/rails_root/test/unit/car_test.rb
207
220
  has_rdoc: true
208
221
  homepage: ""
209
222
  licenses: []
@@ -245,6 +258,7 @@ test_files:
245
258
  - test/rails_root/Rakefile
246
259
  - test/rails_root/app/controllers/application_controller.rb
247
260
  - test/rails_root/app/helpers/application_helper.rb
261
+ - test/rails_root/app/models/car.rb
248
262
  - test/rails_root/app/models/city.rb
249
263
  - test/rails_root/app/models/club.rb
250
264
  - test/rails_root/app/models/newspaper.rb
@@ -256,7 +270,9 @@ test_files:
256
270
  - test/rails_root/config/application.rb
257
271
  - test/rails_root/config/boot.rb
258
272
  - test/rails_root/config/cucumber.yml
259
- - test/rails_root/config/database.yml
273
+ - test/rails_root/config/database.yml.mysql
274
+ - test/rails_root/config/database.yml.pg
275
+ - test/rails_root/config/database.yml.sqlite3
260
276
  - test/rails_root/config/environment.rb
261
277
  - test/rails_root/config/environments/development.rb
262
278
  - test/rails_root/config/environments/production.rb
@@ -271,7 +287,7 @@ test_files:
271
287
  - test/rails_root/config/locales/en.yml
272
288
  - test/rails_root/config/routes.rb
273
289
  - test/rails_root/db/development.sqlite3
274
- - test/rails_root/db/migrate/20091030202259_create_users.rb
290
+ - test/rails_root/db/migrate/20091030202259_create_tables.rb
275
291
  - test/rails_root/db/production.sqlite3
276
292
  - test/rails_root/db/schema.rb
277
293
  - test/rails_root/db/seeds.rb
@@ -281,7 +297,6 @@ test_files:
281
297
  - test/rails_root/features/advance_search/destroy_all.feature
282
298
  - test/rails_root/features/advance_search/integer.feature
283
299
  - test/rails_root/features/advance_search/multiple_rows.feature
284
- - test/rails_root/features/advance_search/sort.feature
285
300
  - test/rails_root/features/advance_search/string.feature
286
301
  - test/rails_root/features/crud.feature
287
302
  - test/rails_root/features/crud_show.feature
@@ -304,9 +319,11 @@ test_files:
304
319
  - test/rails_root/features/table_structure.feature
305
320
  - test/rails_root/lib/tasks/.gitkeep
306
321
  - test/rails_root/lib/tasks/cucumber.rake
322
+ - test/rails_root/lib/tasks/dbs.rake
323
+ - test/rails_root/lib/tasks/sample_cars.rake
307
324
  - test/rails_root/public/.gitkeep
308
325
  - test/rails_root/script/cucumber
309
326
  - test/rails_root/script/rails
310
327
  - test/rails_root/test/factories.rb
311
- - test/rails_root/test/performance/browsing_test.rb
312
328
  - test/rails_root/test/test_helper.rb
329
+ - test/rails_root/test/unit/car_test.rb
@@ -1,19 +0,0 @@
1
- <label class='label sortby_label'>Sort by</label>
2
-
3
- <select name='sortby' id='sortby'>
4
- <%= AdminData::Util.build_sort_options(klass, params[:sortby]).html_safe %>
5
- </select>
6
-
7
- <style>
8
- .sortby_label {
9
- float: left;
10
- vertical-align: bottom;
11
- margin-left: 40px;
12
- width: 70px;
13
- }
14
- #sortyby {
15
- width: 200px;
16
- float: left;
17
- }
18
- </style>
19
-
@@ -1,16 +0,0 @@
1
- Feature: Advance Search
2
-
3
- @javascript
4
- Scenario: sorting
5
- Given the following user exists:
6
- | first name | last name |
7
- | Mary | Jane |
8
- | John | Smith |
9
- Given I visit advance_search page
10
- When I press "Search"
11
- Then async verify that user "first_name" is "John"
12
- Then async verify that user "last_name" is "Smith"
13
- When I select "id asc" from "sortby"
14
- When I press "Search"
15
- Then async verify that user "first_name" is "Mary"
16
- Then async verify that user "last_name" is "Jane"
@@ -1,9 +0,0 @@
1
- require 'test_helper'
2
- require 'rails/performance_test_help'
3
-
4
- # Profiling results for each test method are written to tmp/performance.
5
- class BrowsingTest < ActionDispatch::PerformanceTest
6
- def test_homepage
7
- get '/'
8
- end
9
- end