methodmissing-scrooge 1.0.1 → 1.0.2
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.
- data/README.textile +227 -22
- data/VERSION.yml +1 -1
- data/assets/config/scrooge.yml.template +6 -0
- data/lib/scrooge/framework/base.rb +26 -15
- data/lib/scrooge/framework/rails.rb +28 -4
- data/lib/scrooge/middleware/tracker.rb +0 -1
- data/lib/scrooge/orm/active_record.rb +7 -3
- data/lib/scrooge/profile.rb +72 -73
- data/lib/scrooge/strategy/base.rb +74 -0
- data/lib/scrooge/strategy/controller.rb +29 -0
- data/lib/scrooge/strategy/scope.rb +14 -0
- data/lib/scrooge/strategy/stage.rb +77 -0
- data/lib/scrooge/strategy/track.rb +19 -0
- data/lib/scrooge/strategy/track_then_scope.rb +41 -0
- data/lib/scrooge/tracker/app.rb +63 -3
- data/lib/scrooge/tracker/base.rb +10 -0
- data/lib/scrooge/tracker/model.rb +7 -0
- data/lib/scrooge/tracker/resource.rb +17 -2
- data/lib/scrooge.rb +2 -1
- data/rails/init.rb +1 -1
- data/spec/fixtures/config/scrooge.yml +5 -1
- data/spec/units/scrooge/framework/base_spec.rb +9 -3
- data/spec/units/scrooge/profile_spec.rb +13 -15
- data/spec/units/scrooge/strategy/base_spec.rb +62 -0
- data/spec/units/scrooge/strategy/controller_spec.rb +26 -0
- data/spec/units/scrooge/strategy/scope_spec.rb +18 -0
- data/spec/units/scrooge/strategy/stage_spec.rb +35 -0
- data/spec/units/scrooge/strategy/track_spec.rb +19 -0
- data/spec/units/scrooge/strategy/track_then_scope_spec.rb +22 -0
- data/spec/units/scrooge/tracker/app_spec.rb +5 -1
- data/spec/units/scrooge/tracker/base_spec.rb +8 -0
- data/spec/units/scrooge/tracker/model_spec.rb +14 -1
- data/spec/units/scrooge/tracker/resource_spec.rb +21 -0
- data/tasks/scrooge.rake +1 -1
- metadata +16 -2
@@ -77,6 +77,7 @@ describe Scrooge::Framework::Base do
|
|
77
77
|
@signature = Time.now.to_i.to_s
|
78
78
|
FileUtils.mkdir_p( File.join( @base.scopes_path, @signature ) )
|
79
79
|
@base.scopes.should include( @signature )
|
80
|
+
FileUtils.rm_r( File.join( @base.scopes_path, @signature ) )
|
80
81
|
end
|
81
82
|
end
|
82
83
|
|
@@ -84,7 +85,7 @@ describe Scrooge::Framework::Base do
|
|
84
85
|
with_rails do
|
85
86
|
@base.stub!(:config).and_return( CONFIG )
|
86
87
|
@base.send( :ensure_scopes_path )
|
87
|
-
@base.scopes?().should eql(
|
88
|
+
@base.scopes?().should eql( false )
|
88
89
|
end
|
89
90
|
end
|
90
91
|
|
@@ -106,7 +107,8 @@ describe Scrooge::Framework::Base do
|
|
106
107
|
with_rails do
|
107
108
|
@base.stub!(:config).and_return( CONFIG )
|
108
109
|
::Rails.stub!(:env).and_return( "test" )
|
109
|
-
|
110
|
+
@base.to_scope!()
|
111
|
+
@base.scopes.size.should == 1
|
110
112
|
end
|
111
113
|
end
|
112
114
|
|
@@ -115,7 +117,7 @@ describe Scrooge::Framework::Base do
|
|
115
117
|
@base.stub!(:config).and_return( CONFIG )
|
116
118
|
::Rails.stub!(:env).and_return( "test" )
|
117
119
|
@scope = @base.to_scope!
|
118
|
-
lambda{ @base.from_scope!( @scope ) }.should change( Scrooge::Base.profile.tracker, :object_id )
|
120
|
+
lambda{ Scrooge::Base.profile.scope = @base.from_scope!( @scope ) }.should change( Scrooge::Base.profile.tracker, :object_id )
|
119
121
|
end
|
120
122
|
end
|
121
123
|
|
@@ -132,6 +134,10 @@ describe Scrooge::Framework::Base do
|
|
132
134
|
lambda{ @base.install_tracking_middleware() }.should raise_error( Scrooge::Framework::Base::NotImplemented )
|
133
135
|
end
|
134
136
|
|
137
|
+
it "should be able to uninstall tracking middleware" do
|
138
|
+
lambda{ @base.uninstall_tracking_middleware() }.should raise_error( Scrooge::Framework::Base::NotImplemented )
|
139
|
+
end
|
140
|
+
|
135
141
|
it "should be able to install scoping middleware" do
|
136
142
|
lambda{ @base.install_scope_middleware( 'tracker' ) }.should raise_error( Scrooge::Framework::Base::NotImplemented )
|
137
143
|
end
|
@@ -17,7 +17,9 @@ describe "Scrooge::Profile instance" do
|
|
17
17
|
|
18
18
|
before(:each) do
|
19
19
|
@profile = Scrooge::Profile.setup( File.join( FIXTURES, 'config', 'scrooge.yml' ), :production )
|
20
|
-
|
20
|
+
with_rails do
|
21
|
+
@profile.framework.stub!(:scopes).and_return( %w(1234567891) )
|
22
|
+
end
|
21
23
|
@profile.options = { 'scope' => '1234567891'}
|
22
24
|
end
|
23
25
|
|
@@ -38,27 +40,15 @@ describe "Scrooge::Profile instance" do
|
|
38
40
|
it "should return a valid tracker instance" do
|
39
41
|
@profile.tracker.class.should equal( Scrooge::Tracker::App )
|
40
42
|
end
|
41
|
-
|
42
|
-
it "should be able to determine if the active profile should track or scope" do
|
43
|
-
@profile.track?().should equal( false )
|
44
|
-
@profile.scope?().should equal( false )
|
45
|
-
end
|
46
43
|
|
47
44
|
it "should be able to infer the current scope" do
|
48
|
-
@profile.
|
45
|
+
@profile.scope.should eql( "1234567891" )
|
49
46
|
end
|
50
47
|
|
51
48
|
it "should be able to determine if it's enabled" do
|
52
49
|
@profile.enabled?().should eql( false )
|
53
50
|
end
|
54
51
|
|
55
|
-
it "should neither track or scope if not enabled" do
|
56
|
-
@profile.should_receive(:track!).never
|
57
|
-
@profile.should_receive(:scope!).never
|
58
|
-
@profile.stub!(:enabled?).and_return(false)
|
59
|
-
@profile.track_or_scope!
|
60
|
-
end
|
61
|
-
|
62
52
|
it "should be able to determine if it should raise on missing attributes" do
|
63
53
|
@profile.raise_on_missing_attribute?().should equal( false )
|
64
54
|
end
|
@@ -67,7 +57,15 @@ describe "Scrooge::Profile instance" do
|
|
67
57
|
@profile.framework.stub!(:scopes).and_return( [] )
|
68
58
|
ENV['scope'] = 'scope_from_env'
|
69
59
|
@profile.send(:configure!)
|
70
|
-
@profile.
|
60
|
+
@profile.scope.should eql( 'scope_from_env' )
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should be able to yield a stategy instance" do
|
64
|
+
@profile.strategy.class.should == Scrooge::Strategy::Track
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should be able to expose it's warmup tracking period" do
|
68
|
+
@profile.warmup.should == 0
|
71
69
|
end
|
72
70
|
|
73
71
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe 'Scrooge::Strategy::Base singleton' do
|
4
|
+
|
5
|
+
after(:each) do
|
6
|
+
Scrooge::Strategy::Base.flush!
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be able to determine if it has any stages" do
|
10
|
+
Scrooge::Strategy::Base.stages?().should equal( false )
|
11
|
+
Scrooge::Strategy::Base.stage( :stage ) do
|
12
|
+
'payload'
|
13
|
+
end
|
14
|
+
Scrooge::Strategy::Base.stages?().should equal( true )
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be able to yield all it's defined stages" do
|
18
|
+
Scrooge::Strategy::Base.stages.should eql( [] )
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be able to register one or more execution stages" do
|
22
|
+
lambda do
|
23
|
+
Scrooge::Strategy::Base.stage( :stage ) do
|
24
|
+
'payload'
|
25
|
+
end
|
26
|
+
end.should change( Scrooge::Strategy::Base.stages, :size ).from(0).to(1)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should require at least one defined stage" do
|
30
|
+
lambda{ @base.scope_to( Scrooge::Strategy::Base.new ) }.should raise_error( Scrooge::Strategy::Base::NoStages )
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe Scrooge::Strategy::Base do
|
36
|
+
|
37
|
+
before(:each) do
|
38
|
+
Scrooge::Strategy::Base.stage( :stage ) do
|
39
|
+
'payload'
|
40
|
+
end
|
41
|
+
@base = Scrooge::Strategy::Base.new
|
42
|
+
Scrooge::Base.profile.stub!(:enabled?).and_return(true)
|
43
|
+
end
|
44
|
+
|
45
|
+
after(:each) do
|
46
|
+
Scrooge::Strategy::Base.flush!
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should be able to infer all defined stages" do
|
50
|
+
@base.stages.first.class.should eql( Scrooge::Strategy::Stage )
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should be able to execute itself" do
|
54
|
+
@base.execute!().class.should == Thread
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should provide access to it's controller Thread" do
|
58
|
+
@base.execute!
|
59
|
+
@base.thread.class.should == Thread
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe Scrooge::Strategy::Base do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
Scrooge::Strategy::Base.stage( :stage ) do
|
7
|
+
'payload'
|
8
|
+
end
|
9
|
+
@base = Scrooge::Strategy::Base.new
|
10
|
+
@controller = Scrooge::Strategy::Controller.new( @base )
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:each) do
|
14
|
+
Scrooge::Strategy::Base.flush!
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be able to execute a given strategy" do
|
18
|
+
@controller.run!().value.should include( 'payload' )
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be able to provide access to the background thread" do
|
22
|
+
@controller.run!()
|
23
|
+
@controller.thread.class.should == Thread
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe Scrooge::Strategy::Scope do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@scope = Scrooge::Strategy::Scope.new
|
7
|
+
@controller = Scrooge::Strategy::Controller.new( @scope )
|
8
|
+
Scrooge::Base.profile.framework.stub!(:install_scope_middleware).and_return('installed')
|
9
|
+
Scrooge::Base.profile.stub!(:scope).and_return( '1234567891' )
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be able to execute a given strategy" do
|
13
|
+
with_rails do
|
14
|
+
lambda{ @controller.run!().value }.should raise_error( SystemExit )
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe Scrooge::Strategy::Stage do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@stage = Scrooge::Strategy::Stage.new( :test, :for => 0.5 ) do
|
7
|
+
'payload'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be able to determine if it's executeable" do
|
12
|
+
@stage.executeable?().should equal( true )
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be able to determine if it's initialized" do
|
16
|
+
@stage.initialized?().should equal( true )
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be able to determine if it's in execution" do
|
20
|
+
@stage.running?().should equal( false )
|
21
|
+
@stage.execute!
|
22
|
+
@stage.running?().should equal( false )
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be able to execute itself" do
|
26
|
+
@stage.execute!().should eql( "payload" )
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should be able to determine if it's terminated" do
|
30
|
+
@stage.terminated?().should equal( false )
|
31
|
+
@stage.execute!
|
32
|
+
@stage.terminated?().should equal( true )
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe Scrooge::Strategy::Track do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
Scrooge::Base.profile.stub!(:warmup).and_return( 1 )
|
7
|
+
@track = Scrooge::Strategy::Track.new
|
8
|
+
@controller = Scrooge::Strategy::Controller.new( @track )
|
9
|
+
Scrooge::Base.profile.framework.stub!(:install_tracking_middleware).and_return('installed')
|
10
|
+
Scrooge::Base.profile.stub!(:start_tracking!).and_return('tracking')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be able to execute a given strategy" do
|
14
|
+
with_rails do
|
15
|
+
lambda{ @controller.run!().value }.should raise_error( SystemExit )
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe Scrooge::Strategy::TrackThenScope do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
Scrooge::Base.profile.stub!(:warmup).and_return( 1 )
|
7
|
+
@track_then_scope = Scrooge::Strategy::TrackThenScope.new
|
8
|
+
@controller = Scrooge::Strategy::Controller.new( @track_then_scope )
|
9
|
+
Scrooge::Base.profile.framework.stub!(:install_tracking_middleware).and_return('installed')
|
10
|
+
Scrooge::Base.profile.framework.stub!(:uninstall_tracking_middleware).and_return('installed')
|
11
|
+
Scrooge::Base.profile.framework.stub!(:install_scope_middleware).and_return('installed')
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should be able to execute a given strategy" do
|
15
|
+
Scrooge::Base.profile.stub!(:synchronize!).and_return([])
|
16
|
+
Scrooge::Base.profile.stub!(:aggregate!).and_return([])
|
17
|
+
with_rails do
|
18
|
+
@controller.run!().value.should include( 'installed' )
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -55,8 +55,12 @@ describe Scrooge::Tracker::App do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should be able to determine if a resource's been seen before" do
|
58
|
-
@app << @resource
|
59
58
|
@app.resource_for( @resource ).should eql( @resource )
|
60
59
|
end
|
61
60
|
|
61
|
+
it "should be able to find a resource" do
|
62
|
+
@app << @resource
|
63
|
+
@app.resource( @resource ).should eql( @resource )
|
64
|
+
end
|
65
|
+
|
62
66
|
end
|
@@ -1,5 +1,13 @@
|
|
1
1
|
require 'spec/spec_helper'
|
2
2
|
|
3
|
+
describe "Scrooge::Tracker::Base singleton" do
|
4
|
+
|
5
|
+
it "should be able to yield an instance from given Marshalled data" do
|
6
|
+
lambda{ Scrooge::Tracker::Base.load( [] ) }.should raise_error( Scrooge::Tracker::Base::NotImplemented )
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
|
3
11
|
describe Scrooge::Tracker::Base do
|
4
12
|
|
5
13
|
before(:each) do
|
@@ -7,6 +7,8 @@ describe Scrooge::Tracker::Model do
|
|
7
7
|
@model.stub!(:name).and_return( 'Product' )
|
8
8
|
@model.stub!(:table_name).and_return( 'products' )
|
9
9
|
@model.stub!(:primary_key).and_return( 'id' )
|
10
|
+
@other_model = Scrooge::Tracker::Model.new( 'OtherPost' )
|
11
|
+
@another_model = Scrooge::Tracker::Model.new( 'AnotherPost' )
|
10
12
|
end
|
11
13
|
|
12
14
|
it "should be able to determine if any attributes has been tracked" do
|
@@ -28,7 +30,8 @@ describe Scrooge::Tracker::Model do
|
|
28
30
|
|
29
31
|
it "should be able to restore itself from a serialized representation" do
|
30
32
|
@model << [:name, :description, :price]
|
31
|
-
|
33
|
+
@model.marshal_load( { "Product" => [:price] } )
|
34
|
+
@model.attributes.size.should eql( 1 )
|
32
35
|
end
|
33
36
|
|
34
37
|
it "should be able to render a attribute selection SQL snippet from it's referenced attributes" do
|
@@ -47,4 +50,14 @@ describe Scrooge::Tracker::Model do
|
|
47
50
|
@model.inspect().should match( /:name/ )
|
48
51
|
end
|
49
52
|
|
53
|
+
it "should be able to merge itself with another model tracker" do
|
54
|
+
@other_model << %w(name description)
|
55
|
+
@model.merge( @other_model )
|
56
|
+
@model.attributes.to_a.sort.should eql( %w(description name) )
|
57
|
+
@another_model.merge( @model )
|
58
|
+
@another_model.attributes.to_a.sort.should eql( %w(description name) )
|
59
|
+
@another_model.attributes.should_not_receive(:merge)
|
60
|
+
@another_model.merge( nil )
|
61
|
+
end
|
62
|
+
|
50
63
|
end
|
@@ -13,6 +13,12 @@ describe Scrooge::Tracker::Resource do
|
|
13
13
|
@model.stub!(:name).and_return( 'Product' )
|
14
14
|
@model.stub!(:table_name).and_return( 'products' )
|
15
15
|
@model.stub!(:primary_key).and_return( 'id' )
|
16
|
+
@other_resource = Scrooge::Tracker::Resource.new do |resource|
|
17
|
+
resource.controller = 'categories'
|
18
|
+
resource.action = 'show'
|
19
|
+
resource.method = :get
|
20
|
+
resource.format = :html
|
21
|
+
end
|
16
22
|
end
|
17
23
|
|
18
24
|
it "should be able to determine if any models has been tracked" do
|
@@ -80,4 +86,19 @@ describe Scrooge::Tracker::Resource do
|
|
80
86
|
@resource.inspect().should match( /Product/ )
|
81
87
|
end
|
82
88
|
|
89
|
+
it "should be able to find a given model" do
|
90
|
+
@resource << @model
|
91
|
+
other_model = mock('model')
|
92
|
+
other_model.stub!(:name).and_return('Product')
|
93
|
+
@resource.model( other_model ).should == @model
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should be able to merge itself with another resource" do
|
97
|
+
@other_resource << @model
|
98
|
+
@resource.merge( @other_resource )
|
99
|
+
@resource.models.to_a.should eql( [@model] )
|
100
|
+
@resource.models.should_not_receive(:merge)
|
101
|
+
@resource.merge( nil )
|
102
|
+
end
|
103
|
+
|
83
104
|
end
|
data/tasks/scrooge.rake
CHANGED
@@ -24,7 +24,7 @@ namespace :scrooge do
|
|
24
24
|
task :inspect do
|
25
25
|
any_scopes do
|
26
26
|
begin
|
27
|
-
Scrooge::Base.profile.
|
27
|
+
Scrooge::Base.profile.scope = ENV['scope']
|
28
28
|
puts Scrooge::Base.profile.tracker.inspect
|
29
29
|
rescue Scrooge::Framework::Base::InvalidScopeSignature
|
30
30
|
puts "Please set ENV['scope'] to the scope you'd like to inspect."
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: methodmissing-scrooge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Lourens Naud\xC3\xA9"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-16 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -43,6 +43,13 @@ files:
|
|
43
43
|
- lib/scrooge/storage
|
44
44
|
- lib/scrooge/storage/base.rb
|
45
45
|
- lib/scrooge/storage/memory.rb
|
46
|
+
- lib/scrooge/strategy
|
47
|
+
- lib/scrooge/strategy/base.rb
|
48
|
+
- lib/scrooge/strategy/controller.rb
|
49
|
+
- lib/scrooge/strategy/scope.rb
|
50
|
+
- lib/scrooge/strategy/stage.rb
|
51
|
+
- lib/scrooge/strategy/track.rb
|
52
|
+
- lib/scrooge/strategy/track_then_scope.rb
|
46
53
|
- lib/scrooge/tracker
|
47
54
|
- lib/scrooge/tracker/app.rb
|
48
55
|
- lib/scrooge/tracker/base.rb
|
@@ -76,6 +83,13 @@ files:
|
|
76
83
|
- spec/units/scrooge/storage
|
77
84
|
- spec/units/scrooge/storage/base_spec.rb
|
78
85
|
- spec/units/scrooge/storage/memory_spec.rb
|
86
|
+
- spec/units/scrooge/strategy
|
87
|
+
- spec/units/scrooge/strategy/base_spec.rb
|
88
|
+
- spec/units/scrooge/strategy/controller_spec.rb
|
89
|
+
- spec/units/scrooge/strategy/scope_spec.rb
|
90
|
+
- spec/units/scrooge/strategy/stage_spec.rb
|
91
|
+
- spec/units/scrooge/strategy/track_spec.rb
|
92
|
+
- spec/units/scrooge/strategy/track_then_scope_spec.rb
|
79
93
|
- spec/units/scrooge/tracker
|
80
94
|
- spec/units/scrooge/tracker/app_spec.rb
|
81
95
|
- spec/units/scrooge/tracker/base_spec.rb
|