Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 119 lines (103 sloc) 4.054 kB
7141728 @jkrall Initial commit to analytical.
authored
1 require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
da70a43 @jkrall Analytical first cut at google, clicky, console module code
authored
2 require 'ostruct'
7141728 @jkrall Initial commit to analytical.
authored
3
4 describe "Analytical" do
0282644 @jkrall First cut, WIP of analytical... all specs pass for core Analytical lib.
authored
5 describe 'on initialization' do
6 class DummyForInit
7 extend Analytical
26e8899 @jkrall Fixing up tests
authored
8 include Analytical::InstanceMethods
9 include Analytical::BotDetector
10 if ::Rails::VERSION::MAJOR < 3
11 class_inheritable_accessor :analytical_options
12 else
13 class_attribute :analytical_options
14 end
15
ff92c87 @jkrall Reworked design slightly, added .now for js-only
authored
16 def self.helper_method(*a); end
790f5d1 @jkrall Add bot-detector code from KISSMetrics
authored
17 def request
d6ddd7e @dblock Upgraded rspec, now runs after bundle instal.
dblock authored
18 RSpec::Mocks::Mock.new 'request',
790f5d1 @jkrall Add bot-detector code from KISSMetrics
authored
19 :'ssl?'=>true,
20 :user_agent=>'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 GTB7.0'
21 end
0282644 @jkrall First cut, WIP of analytical... all specs pass for core Analytical lib.
authored
22 end
23
d5e893c @dblock Refactored to support environment-based settings.
dblock authored
24 it 'should have the options from analytical.yml' do
0282644 @jkrall First cut, WIP of analytical... all specs pass for core Analytical lib.
authored
25 DummyForInit.analytical
26 d = DummyForInit.new.analytical
dd7aa05 @gib Added a test for empty options in the required config file and logic …
gib authored
27 d.options[:modules].sort_by { |m| m.to_s }.should == [:chartbeat, :clicky, :google, :kiss_metrics]
4790a74 @dblock Bug: reading other options than modules broken.
dblock authored
28 d.options[:true_option].should be_true
29 d.options[:false_option].should be_false
30 d.options[:string_option].should == "string"
0282644 @jkrall First cut, WIP of analytical... all specs pass for core Analytical lib.
authored
31 end
32
3cb1871 @dblock Bug: overwriting javascript_helpers option.
dblock authored
33 it 'should preserve :javascript_helpers option' do
34 options = { :javascript_helpers => false, :modules => [] }
35 DummyForInit.analytical options
36 a = DummyForInit.new.analytical
37 a.options[:javascript_helpers].should be_false
38 end
39
790f5d1 @jkrall Add bot-detector code from KISSMetrics
authored
40 it 'should use the supplied options' do
41 DummyForInit.analytical :modules=>[:google]
42 d = DummyForInit.new.analytical
43 d.options[:modules].should == [:google]
d5e893c @dblock Refactored to support environment-based settings.
dblock authored
44 end
45
46 describe 'conditionally disabled' do
47 it 'should set the modules to []' do
48 DummyForInit.analytical :disable_if => lambda { |x| true }
49 d = DummyForInit.new
50 d.analytical.options[:modules].should == []
51 end
790f5d1 @jkrall Add bot-detector code from KISSMetrics
authored
52 end
26e8899 @jkrall Fixing up tests
authored
53
54 describe 'with filtered modules' do
55 it 'should set the modules to []' do
56 DummyForInit.analytical :filter_modules => lambda { |x, modules| modules - [:clicky] }
57 d = DummyForInit.new
58 d.analytical.options[:modules].include?(:clicky).should be_false
59 end
60 end
61
790f5d1 @jkrall Add bot-detector code from KISSMetrics
authored
62 describe 'with a robot request' do
63 it 'should set the modules to []' do
64 DummyForInit.analytical
65 d = DummyForInit.new
66 d.stub!(:'analytical_is_robot?').and_return(true)
67 d.analytical.options[:modules].should == []
68 end
69 end
70
8cdc33a @jkrall Added support for config file
authored
71 it 'should open the initialization file' do
41f0ece @bryanl Use Rails.root instead of the deprecated RAILS_ROOT
bryanl authored
72 File.should_receive(:'exists?').with("#{Rails.root}/config/analytical.yml").and_return(true)
8cdc33a @jkrall Added support for config file
authored
73 DummyForInit.analytical
74 DummyForInit.analytical_options[:google].should == {:key=>'google_12345'}
75 DummyForInit.analytical_options[:kiss_metrics].should == {:key=>'kiss_metrics_12345'}
c331cfd @nwp Added Chartbeat module
nwp authored
76 DummyForInit.analytical_options[:clicky].should == {:key=>'clicky_12345'}
77 DummyForInit.analytical_options[:chartbeat].should == {:key=>'chartbeat_12345', :domain => 'your.domain.com'}
8cdc33a @jkrall Added support for config file
authored
78 end
79
26e8899 @jkrall Fixing up tests
authored
80 it 'should allow for module-specific controller overrides' do
81 DummyForInit.analytical :google=>{:key=>'override_google_key'}
82 DummyForInit.analytical_options[:google].should == {:key=>'override_google_key'}
83 end
84
0282644 @jkrall First cut, WIP of analytical... all specs pass for core Analytical lib.
authored
85 describe 'in production mode' do
86 before(:each) do
87 Rails.env.stub!(:production?).and_return(true)
88 end
89 it 'should start with no modules' do
90 Analytical::Api.should_not_receive(:include)
91 DummyForInit.analytical
92 DummyForInit.new.analytical.options[:modules] = []
93 end
94 end
95
dd7aa05 @gib Added a test for empty options in the required config file and logic …
gib authored
96 describe 'in non-production mode' do
0282644 @jkrall First cut, WIP of analytical... all specs pass for core Analytical lib.
authored
97 before(:each) do
98 Rails.env.stub!(:production?).and_return(false)
99 end
100 it 'should start with no modules' do
101 DummyForInit.analytical
102 DummyForInit.new.analytical.options[:modules] = [:console]
103 end
104 end
105
dd7aa05 @gib Added a test for empty options in the required config file and logic …
gib authored
106 describe 'in development mode' do
107 before(:each) do
108 Rails.stub!(:env).and_return(:development)
109 end
110 it 'should start with no modules' do
111 DummyForInit.analytical
112 DummyForInit.new.analytical.options[:modules] = []
113 end
114 end
115
0282644 @jkrall First cut, WIP of analytical... all specs pass for core Analytical lib.
authored
116 end
117
7141728 @jkrall Initial commit to analytical.
authored
118 end
Something went wrong with that request. Please try again.