gricer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +84 -0
  3. data/Rakefile +49 -0
  4. data/app/assets/images/gricer/fluid/breadcrumb.png +0 -0
  5. data/app/assets/javascripts/gricer.js.coffee +85 -0
  6. data/app/assets/javascripts/gricer_backend_jquery.js.coffee +352 -0
  7. data/app/assets/javascripts/jquery.flot.js +2599 -0
  8. data/app/assets/javascripts/jquery.flot.pie.js +750 -0
  9. data/app/assets/javascripts/jquery.flot.resize.js +60 -0
  10. data/app/assets/javascripts/jquery.flot.symbol.js +70 -0
  11. data/app/assets/javascripts/worldmap.js +146 -0
  12. data/app/assets/stylesheets/gricer/fluid-jquery-ui.css.scss +1298 -0
  13. data/app/assets/stylesheets/gricer/fluid.css.scss +240 -0
  14. data/app/assets/stylesheets/gricer/helpers/css3.css.scss +21 -0
  15. data/app/controllers/gricer/base_controller.rb +141 -0
  16. data/app/controllers/gricer/capture_controller.rb +42 -0
  17. data/app/controllers/gricer/dashboard_controller.rb +18 -0
  18. data/app/controllers/gricer/requests_controller.rb +42 -0
  19. data/app/controllers/gricer/sessions_controller.rb +24 -0
  20. data/app/helpers/gricer/base_helper.rb +22 -0
  21. data/app/models/gricer/agent.rb +789 -0
  22. data/app/models/gricer/request.rb +239 -0
  23. data/app/models/gricer/session.rb +433 -0
  24. data/app/views/gricer/capture/index.html.erb +1 -0
  25. data/app/views/gricer/dashboard/_menu.html.erb +10 -0
  26. data/app/views/gricer/dashboard/_overview.html.erb +33 -0
  27. data/app/views/gricer/dashboard/index.html.erb +19 -0
  28. data/config/routes.rb +51 -0
  29. data/lib/gricer.rb +36 -0
  30. data/lib/gricer/action_controller/base.rb +28 -0
  31. data/lib/gricer/action_controller/track.rb +132 -0
  32. data/lib/gricer/active_model/statistics.rb +167 -0
  33. data/lib/gricer/config.rb +125 -0
  34. data/lib/gricer/engine.rb +9 -0
  35. data/lib/gricer/localization.rb +3 -0
  36. data/lib/tasks/gricer_tasks.rake +92 -0
  37. data/spec/controllers/gricer/base_controller_spec.rb +207 -0
  38. data/spec/controllers/gricer/capture_controller_spec.rb +44 -0
  39. data/spec/controllers/gricer/dashboard_controller_spec.rb +44 -0
  40. data/spec/controllers/gricer/requests_controller_spec.rb +36 -0
  41. data/spec/controllers/gricer/sessions_controller_spec.rb +37 -0
  42. data/spec/dummy/Rakefile +7 -0
  43. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  44. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  45. data/spec/dummy/app/assets/stylesheets/dashboard.css +4 -0
  46. data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
  47. data/spec/dummy/app/assets/stylesheets/sessions.css +4 -0
  48. data/spec/dummy/app/controllers/application_controller.rb +23 -0
  49. data/spec/dummy/app/controllers/dashboard_controller.rb +19 -0
  50. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  51. data/spec/dummy/app/helpers/dashboard_helper.rb +2 -0
  52. data/spec/dummy/app/views/dashboard/index.html.erb +236 -0
  53. data/spec/dummy/app/views/layouts/application.html.erb +16 -0
  54. data/spec/dummy/config.ru +4 -0
  55. data/spec/dummy/config/application.rb +48 -0
  56. data/spec/dummy/config/boot.rb +10 -0
  57. data/spec/dummy/config/cucumber.yml +9 -0
  58. data/spec/dummy/config/database.yml +25 -0
  59. data/spec/dummy/config/environment.rb +5 -0
  60. data/spec/dummy/config/environments/development.rb +27 -0
  61. data/spec/dummy/config/environments/production.rb +51 -0
  62. data/spec/dummy/config/environments/test.rb +39 -0
  63. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  64. data/spec/dummy/config/initializers/inflections.rb +10 -0
  65. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  66. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  67. data/spec/dummy/config/initializers/session_store.rb +8 -0
  68. data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  69. data/spec/dummy/config/locales/en.yml +5 -0
  70. data/spec/dummy/config/routes.rb +11 -0
  71. data/spec/dummy/db/schema.rb +241 -0
  72. data/spec/dummy/log/development.log +0 -0
  73. data/spec/dummy/public/404.html +26 -0
  74. data/spec/dummy/public/422.html +26 -0
  75. data/spec/dummy/public/500.html +26 -0
  76. data/spec/dummy/public/favicon.ico +0 -0
  77. data/spec/dummy/script/rails +6 -0
  78. data/spec/helpers/gricer/base_helper_spec.rb +28 -0
  79. data/spec/lib/gricer/action_controller/track_spec.rb +63 -0
  80. data/spec/models/gricer/agent_spec.rb +829 -0
  81. data/spec/models/gricer/request_spec.rb +145 -0
  82. data/spec/models/gricer/session_spec.rb +209 -0
  83. data/spec/routing/capture_routes_spec.rb +6 -0
  84. data/spec/routing/dashboard_routes_spec.rb +9 -0
  85. data/spec/routing/requests_routes_spec.rb +90 -0
  86. data/spec/routing/sessions_routes_spec.rb +115 -0
  87. data/spec/spec_helper.rb +23 -0
  88. metadata +185 -0
@@ -0,0 +1,125 @@
1
+ module Gricer
2
+ # The configuration object for Gricer
3
+ #
4
+ #
5
+ class Config
6
+ attr_writer :table_name_prefix, :admin_prefix, :admin_layout
7
+ attr_writer :max_session_duration
8
+ attr_writer :geoip_db, :geoip_dat
9
+ attr_writer :exclude_paths
10
+ attr_writer :admin_menu
11
+
12
+ # A new instance of Gricer::Config.
13
+ #
14
+ # Configure options can be passed in a block.
15
+ #
16
+ # @see #configure
17
+ #
18
+ # @return [Gricer::Config]
19
+ def initialize(&block)
20
+ configure(&block) if block_given?
21
+ end
22
+
23
+ # Configure your Gricer Rails Engine with the given parameters in
24
+ # the block. For possible options see Instance Attributes.
25
+ #
26
+ # @yield (config) The actual configuration instance
27
+ # @return [Gricer::Config] The actual configuration instance
28
+ def configure(&block)
29
+ yield(self)
30
+ end
31
+
32
+ # The prefix for table names of gricer database tables.
33
+ #
34
+ # Default value is 'gricer_'
35
+ # @return [String]
36
+ def table_name_prefix
37
+ @table_name_prefix ||= 'gricer_'
38
+ end
39
+
40
+ # Configure the prefix for admin pages paths
41
+ #
42
+ # Default value is 'gricer'
43
+ # @return [String]
44
+ def admin_prefix
45
+ @admin_prefix.blank? ? 'gricer' : @admin_prefix
46
+ end
47
+
48
+ # Configure to use another layout than the application default for Gricer controllers
49
+ #
50
+ # Default value is nil
51
+ # @return [String]
52
+ def admin_layout
53
+ @admin_layout
54
+ end
55
+
56
+ # Configure the structure of Gricer's admin menu
57
+ #
58
+ # Default value see source
59
+ # @return [Array]
60
+ def admin_menu
61
+ @admin_menu ||= [
62
+ ['Overview', :dashboard, {controller: 'gricer/dashboard', action: 'overview'}],
63
+ ['Visitors', :menu, [
64
+ ['Entry Pages', :spread, {controller: 'gricer/requests', action: 'spread_stats', field: 'entry_path'}],
65
+ ['Referers', :spread, {controller: 'gricer/requests', action: 'spread_stats', field: 'referer_host'}],
66
+ ['Search Engines', :spread, {controller: 'gricer/requests', action: 'spread_stats', field: 'search_engine'}],
67
+ ['Search Terms', :spread, {controller: 'gricer/requests', action: 'spread_stats', field: 'search_query'}],
68
+ ['Countries', :spread, {controller: 'gricer/sessions', action: 'spread_stats', field: 'country'}],
69
+ ['Domains', :spread, {controller: 'gricer/sessions', action: 'spread_stats', field: 'domain'}],
70
+ ['Locales', :spread, {controller: 'gricer/sessions', action: 'spread_stats', field: 'requested_locale_major'}]
71
+ ] ],
72
+ ['Pages', :menu, [
73
+ ['Views', :spread, {controller: 'gricer/requests', action: 'spread_stats', field: 'path'}],
74
+ ['Hosts', :spread, {controller: 'gricer/requests', action: 'spread_stats', field: 'host'}],
75
+ ['Methods', :spread, {controller: 'gricer/requests', action: 'spread_stats', field: 'method'}],
76
+ ['Protocols', :spread, {controller: 'gricer/requests', action: 'spread_stats', field: 'protocol'}],
77
+ ] ],
78
+ ['Browsers', :menu, [
79
+ ['Browsers', :spread, {controller: 'gricer/sessions', action: 'spread_stats', field: 'agent.name'}],
80
+ ['Operating Systems', :spread, {controller: 'gricer/sessions', action: 'spread_stats', field: 'agent.os'}],
81
+ ['Engines', :spread, {controller: 'gricer/sessions', action: 'spread_stats', field: 'agent.engine_name'}],
82
+ ['JavaScript', :spread, {controller: 'gricer/sessions', action: 'spread_stats', field: 'javascript'}],
83
+ ['Java', :spread, {controller: 'gricer/sessions', action: 'spread_stats', field: 'java'}],
84
+ ['Silverlight', :spread, {controller: 'gricer/sessions', action: 'spread_stats', field: 'silverlight_major_version'}],
85
+ ['Flash', :spread, {controller: 'gricer/sessions', action: 'spread_stats', field: 'flash_major_version'}],
86
+ ['Screen Size', :spread, {controller: 'gricer/sessions', action: 'spread_stats', field: 'screen_size'}],
87
+ ['Color Depth', :spread, {controller: 'gricer/sessions', action: 'spread_stats', field: 'screen_depth'}]
88
+ ] ]
89
+ ]
90
+ end
91
+
92
+ # Configure page urls matching this Expression to be excluded from being tracked in Gricer statistics
93
+ # Default is to exclude the admin pages
94
+ # @return [Regexp]
95
+ def exclude_paths
96
+ @exclude_actions ||= /^#{admin_prefix}$/
97
+ end
98
+
99
+ # Configure the data file used by GeoIP
100
+ # If you configure #geoip_db this property will be ignored.
101
+ #
102
+ # Default is no data file given.
103
+ # @return [String]
104
+ def geoip_dat
105
+ @geoip_dat
106
+ end
107
+
108
+ # Configure the database instance used by GeoIP
109
+ #
110
+ # Default is none GeoIP database configured
111
+ # @return [GeoIP::City]
112
+ def geoip_db
113
+ @geoip_db ||= geoip_dat ? GeoIP::City.new(geoip_dat, :index, false) : nil
114
+ end
115
+
116
+ # Configure after which time of inactivity the Gricer::Session should expire
117
+ #
118
+ # Default is 15 minutes
119
+ # @return [Integer]
120
+ def max_session_duration
121
+ @max_session_duration ||= 15.minutes
122
+ end
123
+
124
+ end
125
+ end
@@ -0,0 +1,9 @@
1
+ module Gricer
2
+ # The Rails Engine object for Gricer gem.
3
+ #
4
+ #
5
+ class Engine < Rails::Engine
6
+ # breaks path calls
7
+ # isolate_namespace Gricer
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ require 'i18n'
2
+ I18n.load_path += Dir.glob("#{File.dirname(__FILE__)}/../../config/locales/*.yml")
3
+ I18n.backend.reload!
@@ -0,0 +1,92 @@
1
+ namespace :gricer do
2
+ namespace :db do
3
+ desc "Migrate the database through scripts in db/migrate and update db/schema.rb by invoking db:schema:dump. Target specific version with VERSION=x. Turn off output with VERBOSE=false."
4
+ task :migrate => [:environment, :prepare_namespace] do
5
+ ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
6
+ ActiveRecord::Migrator.migrate("#{File.dirname(__FILE__)}/../../db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
7
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
8
+ end
9
+
10
+ task :prepare_namespace do
11
+ require 'active_record'
12
+ puts 'prepage gricer table_name_prefix'
13
+ # ActiveRecord::Base.configurations = Rails::Application.config.database_configuration
14
+
15
+ class ActiveRecord::Base
16
+ self.table_name_prefix = "#{::ActiveRecord::Base.table_name_prefix}#{Gricer::config.table_name_prefix}"
17
+ end
18
+ end
19
+
20
+ task :remove_namespace do
21
+ puts 'remove gricer table_name_prefix'
22
+
23
+ class ActiveRecord::Base
24
+ self.table_name_prefix = "#{::ActiveRecord::Base.table_name_prefix[Gricer::config.table_name_prefix.length,1000]}"
25
+ end
26
+ end
27
+
28
+ namespace :migrate do
29
+ desc 'Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x. Target specific version with VERSION=x.'
30
+ task :redo => [:environment, :prepare_namespace] do
31
+ if ENV["VERSION"]
32
+ Rake::Task["gricer:db:migrate:down"].invoke
33
+ Rake::Task["gricer:db:migrate:up"].invoke
34
+ else
35
+ Rake::Task["gricer:db:rollback"].invoke
36
+ Rake::Task["gricer:db:migrate"].invoke
37
+ end
38
+ end
39
+
40
+ desc 'Runs the "up" for a given migration VERSION.'
41
+ task :up => [:environment, :prepare_namespace] do
42
+ version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
43
+ raise "VERSION is required" unless version
44
+ ActiveRecord::Migrator.run(:up, "#{File.dirname(__FILE__)}/../../db/migrate/", version)
45
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
46
+ end
47
+
48
+ desc 'Runs the "down" for a given migration VERSION.'
49
+ task :down => [:environment, :prepare_namespace] do
50
+ version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
51
+ raise "VERSION is required" unless version
52
+ ActiveRecord::Migrator.run(:down, "#{File.dirname(__FILE__)}/../../db/migrate/", version)
53
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
54
+ end
55
+ end
56
+
57
+ desc 'Rolls the schema back to the previous version. Specify the number of steps with STEP=n'
58
+ task :rollback => [:environment, :prepare_namespace] do
59
+ step = ENV['STEP'] ? ENV['STEP'].to_i : 1
60
+ ActiveRecord::Migrator.rollback("#{File.dirname(__FILE__)}/../../db/migrate/", step)
61
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
62
+ end
63
+
64
+ desc 'Pushes the schema to the next version. Specify the number of steps with STEP=n'
65
+ task :forward => [:environment, :prepare_namespace] do
66
+ step = ENV['STEP'] ? ENV['STEP'].to_i : 1
67
+ ActiveRecord::Migrator.forward("#{File.dirname(__FILE__)}/../../db/migrate/", step)
68
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
69
+ end
70
+
71
+ desc "Retrieves the current schema version number"
72
+ task :version => [:environment, :prepare_namespace] do
73
+ puts "Current version: #{ActiveRecord::Migrator.current_version}"
74
+ end
75
+
76
+ desc "Raises an error if there are pending migrations"
77
+ task :abort_if_pending_migrations => [:environment, :prepare_namespace] do
78
+ if defined? ActiveRecord
79
+ pending_migrations = ActiveRecord::Migrator.new(:up, "#{File.dirname(__FILE__)}/../../db/migrate/").pending_migrations
80
+ if pending_migrations.any?
81
+ puts "You have #{pending_migrations.size} pending migrations:"
82
+ pending_migrations.each do |pending_migration|
83
+ puts ' %4d %s' % [pending_migration.version, pending_migration.name]
84
+ end
85
+ abort %{Run "rake gricer:db:migrate" to update your database then try again.}
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ task :'db:migrate' => [:'gricer:db:migrate', :'gricer:db:remove_namespace']
@@ -0,0 +1,207 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gricer::BaseController do
4
+ context 'process_stats' do
5
+ let(:collection) { mock_model('MyStatClass') }
6
+
7
+ before do
8
+ controller.params = {
9
+ field: 'my_field',
10
+ filters: nil,
11
+ from: '2011-04-01',
12
+ thru: '2011-04-05'
13
+ }
14
+ controller.send(:guess_from_thru)
15
+ controller.stub(:basic_collection) {collection}
16
+
17
+ controller.stub(:url_for).with(action: "spread_stats", field: 'my_field', filters: nil, only_path: true) { 'my_alt_url' }
18
+
19
+ collection.stub(:stat) { {some: :values} }
20
+ end
21
+
22
+ it 'should render ajax' do
23
+ controller.stub(:render).with(json: {
24
+ alternatives: [
25
+ {type: "spread", uri: "my_alt_url"},
26
+ {type: "process"}
27
+ ],
28
+ from: 1301608800000,
29
+ thru: 1301954400000,
30
+ step: 3600000,
31
+ data: {some: :values}
32
+ })
33
+
34
+ controller.send(:process_stats)
35
+ end
36
+
37
+ it 'should render ajax with filter' do
38
+ controller.stub(:url_for).with(action: "spread_stats", field: 'my_field', filters: {"filter"=>"some_value"}, only_path: true) { 'my_filtered_alt_url' }
39
+
40
+ controller.params[:filters] = {'filter' => 'some_value'}
41
+
42
+ controller.stub(:render).with(json: {
43
+ alternatives: [
44
+ {type: "spread", uri: "my_filtered_alt_url"},
45
+ {type: "process"}
46
+ ],
47
+ from: 1301608800000,
48
+ thru: 1301954400000,
49
+ step: 3600000,
50
+ data: {some: :values}
51
+ })
52
+
53
+ controller.send(:process_stats)
54
+ end
55
+
56
+ it 'should render ajax with further details' do
57
+ controller.stub(:further_details) { {'my_field' => 'my_detail_field'} }
58
+ controller.stub(:url_for).with({:action=>"process_stats", :field=>"my_detail_field", :filters=>{"my_field"=>"%{self}"}, :only_path=>true}) {'my_detail_url'}
59
+
60
+ controller.stub(:render).with(json: {
61
+ alternatives: [
62
+ {type: "spread", uri: "my_alt_url"},
63
+ {type: "process"}
64
+ ],
65
+ from: 1301608800000,
66
+ thru: 1301954400000,
67
+ step: 3600000,
68
+ data: {some: :values},
69
+ detail_uri: 'my_detail_url'
70
+ })
71
+
72
+ controller.send(:process_stats)
73
+ end
74
+ end
75
+
76
+ context 'spread_stats' do
77
+ let(:collection) { mock_model('MyStatClass') }
78
+ let(:items) { {some: :values} }
79
+
80
+ before do
81
+ controller.params = {
82
+ field: 'my_field',
83
+ filters: nil,
84
+ from: '2011-04-01',
85
+ thru: '2011-04-05'
86
+ }
87
+ controller.send(:guess_from_thru)
88
+ controller.stub(:basic_collection) {collection}
89
+
90
+ controller.stub(:url_for).with(action: "process_stats", field: 'my_field', filters: nil, only_path: true) { 'my_alt_url' }
91
+
92
+ collection.stub(:between_dates) { items }
93
+ items.stub(:count).with(:id) { 42 }
94
+ items.stub(:count_by).with('my_field') { [['Item 1', 23], ['Item 2', 19]]}
95
+ end
96
+
97
+ it 'should render ajax' do
98
+ controller.stub(:render).with(json: {
99
+ alternatives: [
100
+ {type: "spread"},
101
+ {type: "process", uri: "my_alt_url"}
102
+ ],
103
+ from: 1301608800000,
104
+ thru: 1301954400000,
105
+ total: 42,
106
+ data: [["Item 1", 23], ["Item 2", 19]]
107
+ })
108
+
109
+ controller.send(:spread_stats)
110
+ end
111
+
112
+ it 'should render ajax with filter' do
113
+ controller.stub(:url_for).with(action: "process_stats", field: 'my_field', filters: {"filter"=>"some_value"}, only_path: true) { 'my_filtered_alt_url' }
114
+
115
+ controller.params[:filters] = {'filter' => 'some_value'}
116
+
117
+ controller.stub(:render).with(json: {
118
+ alternatives: [
119
+ {type: "spread"},
120
+ {type: "process", uri: "my_filtered_alt_url"}
121
+ ],
122
+ from: 1301608800000,
123
+ thru: 1301954400000,
124
+ total: 42,
125
+ data: [["Item 1", 23], ["Item 2", 19]]
126
+ })
127
+
128
+ controller.send(:spread_stats)
129
+ end
130
+
131
+ it 'should render ajax with further details' do
132
+ controller.stub(:further_details) { {'my_field' => 'my_detail_field'} }
133
+ controller.stub(:url_for).with({:action=>"spread_stats", :field=>"my_detail_field", :filters=>{"my_field"=>"%{self}"}, :only_path=>true}) {'my_detail_url'}
134
+
135
+ controller.stub(:render).with(json: {
136
+ alternatives: [
137
+ {type: "spread"},
138
+ {type: "process", uri: "my_alt_url"}
139
+ ],
140
+ from: 1301608800000,
141
+ thru: 1301954400000,
142
+ total: 42,
143
+ data: [["Item 1", 23], ["Item 2", 19]],
144
+ detail_uri: 'my_detail_url'
145
+ })
146
+
147
+ controller.send(:spread_stats)
148
+ end
149
+ end
150
+
151
+ context 'basic_collection' do
152
+ it 'should raise error (as it has to be implemented in child classes)' do
153
+ proc{ controller.send(:basic_collection) }.should raise_error('basic_collection must be defined')
154
+ end
155
+ end
156
+
157
+ context 'handle_special_fields' do
158
+ it 'should do nothing' do
159
+ controller.send(:handle_special_fields).should be_nil
160
+ end
161
+ end
162
+
163
+ context 'further_details' do
164
+ it 'should return empty hash' do
165
+ controller.send(:further_details).should == {}
166
+ end
167
+ end
168
+
169
+ context 'guess_from_thru' do
170
+ it 'should assign sane values' do
171
+ Time.stub(:now) {'2011-04-01 12:42:23'.to_time}
172
+
173
+ controller.send(:guess_from_thru)
174
+ assigns[:stat_from].should == '2011-03-25'.to_date
175
+ assigns[:stat_thru].should == '2011-03-31'.to_date
176
+ assigns[:stat_step].should == 1.hour
177
+ end
178
+
179
+ it 'should assign given values' do
180
+ controller.params[:from] = '2010-06-15'
181
+ controller.params[:thru] = '2011-06-15'
182
+
183
+ controller.send(:guess_from_thru)
184
+ assigns[:stat_from].should == '2010-06-15'.to_date
185
+ assigns[:stat_thru].should == '2011-06-15'.to_date
186
+ assigns[:stat_step].should == 1.day
187
+ end
188
+
189
+ it 'should assign sane values with from given' do
190
+ controller.params[:from] = '2011-03-15'
191
+
192
+ controller.send(:guess_from_thru)
193
+ assigns[:stat_from].should == '2011-03-15'.to_date
194
+ assigns[:stat_thru].should == '2011-03-21'.to_date
195
+ assigns[:stat_step].should == 1.hour
196
+ end
197
+
198
+ it 'should assign sane values with from thru' do
199
+ controller.params[:thru] = '2009-08-15'
200
+
201
+ controller.send(:guess_from_thru)
202
+ assigns[:stat_from].should == '2009-08-09'.to_date
203
+ assigns[:stat_thru].should == '2009-08-15'.to_date
204
+ assigns[:stat_step].should == 1.hour
205
+ end
206
+ end
207
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gricer::CaptureController do
4
+ context 'index' do
5
+ it 'should handle proper request' do
6
+ gricer_session = mock_model(Gricer::Session)
7
+ gricer_request = mock_model(Gricer::Request, session: gricer_session)
8
+ controller.stub(:session) { { gricer_session: 42 } }
9
+ Gricer::Session.should_receive(:find_by_id).with(42) { gricer_session }
10
+ Gricer::Request.should_receive(:find_by_id).with('23') { gricer_request }
11
+
12
+ gricer_session.should_receive(:javascript=).with(true)
13
+ gricer_session.should_receive(:java=).with('true')
14
+ gricer_session.should_receive(:flash_version=).with('10.0 r45')
15
+ gricer_session.should_receive(:silverlight_version=).with('4.0.51204.0')
16
+ gricer_session.should_receive(:screen_width=).with('1024')
17
+ gricer_session.should_receive(:screen_height=).with('768')
18
+ gricer_session.should_receive(:screen_size=).with('1024x768')
19
+ gricer_session.should_receive(:screen_depth=).with('8')
20
+
21
+ gricer_session.should_receive(:save) { true }
22
+
23
+ gricer_request.should_receive(:javascript=).with(true)
24
+ gricer_request.should_receive(:window_width=).with('800')
25
+ gricer_request.should_receive(:window_height=).with('600')
26
+
27
+ gricer_request.should_receive(:save) { true }
28
+
29
+ xhr(
30
+ :post,
31
+ :index,
32
+ id: '23',
33
+ f: '10.0 r45',
34
+ j: 'true',
35
+ sl: '4.0.51204.0',
36
+ sx: '1024',
37
+ sy: '768',
38
+ sd: '8',
39
+ wx: '800',
40
+ wy: '600'
41
+ )
42
+ end
43
+ end
44
+ end