excursion 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Excursion::Pool::DSL' do
4
+
5
+ context 'when an application is provided' do
6
+ let(:dummy_app) { Excursion::Pool::Application.new('dummy', {}) }
7
+
8
+ it 'should use the provided application' do
9
+ expect(Excursion::Pool::DSL.block_eval(dummy_app)).to eql(dummy_app)
10
+ end
11
+
12
+ it 'should allow overriding the name of the application' do
13
+ modified = Excursion::Pool::DSL.block_eval(dummy_app) do
14
+ name 'modified'
15
+ end
16
+ expect(modified.name).to eql('modified')
17
+ expect(modified).to eql(dummy_app)
18
+ end
19
+
20
+ it 'should allow overriding the default_url_options for the application' do
21
+ url_opts = {host: 'dummy.local', port: 1234}
22
+ modified = Excursion::Pool::DSL.block_eval(dummy_app) do
23
+ default_url_options url_opts
24
+ end
25
+ expect(modified.default_url_options).to eql(url_opts)
26
+ expect(modified).to eql(dummy_app)
27
+ end
28
+
29
+ it 'should allow overriding the routes for the application' do
30
+ dummy_routes = {root: '/', other_route: '/other/route', another_route: '/another/route'}
31
+ modified = Excursion::Pool::DSL.block_eval(dummy_app) do
32
+ routes dummy_routes
33
+ end
34
+ dummy_routes.each do |key,val|
35
+ expect(modified.route(key).path.spec.to_s).to eql(val)
36
+ end
37
+ expect(modified).to eql(dummy_app)
38
+ end
39
+
40
+ it 'should allow adding a route to the application' do
41
+ dummy_routes = {root: '/', other_route: '/other/route', another_route: '/another/route'}
42
+ modified = Excursion::Pool::DSL.block_eval(dummy_app) do
43
+ dummy_routes.each do |key,val|
44
+ route key, val
45
+ end
46
+ end
47
+ dummy_routes.each do |key,val|
48
+ expect(modified.route(key).path.spec.to_s).to eql(val)
49
+ end
50
+ expect(modified).to eql(dummy_app)
51
+ end
52
+ end
53
+
54
+ context 'when an application is not provided' do
55
+ it 'should create a new application' do
56
+ expect(Excursion::Pool::DSL.block_eval { name 'dummy' }).to be_an_instance_of(Excursion::Pool::Application)
57
+ end
58
+
59
+ it 'should require setting the name of the application' do
60
+ expect(Excursion::Pool::DSL.block_eval { name 'dummy' }.name).to eql('dummy')
61
+ expect { Excursion::Pool::DSL.block_eval }.to raise_exception(RuntimeError)
62
+ end
63
+
64
+ it 'should allow setting the default_url_options for the application' do
65
+ url_opts = {host: 'dummy.local', port: 1234}
66
+ modified = Excursion::Pool::DSL.block_eval do
67
+ name 'dummy'
68
+ default_url_options url_opts
69
+ end
70
+ expect(modified.default_url_options).to eql(url_opts)
71
+ end
72
+
73
+ it 'should allow setting the routes for the application' do
74
+ dummy_routes = {root: '/', other_route: '/other/route', another_route: '/another/route'}
75
+ modified = Excursion::Pool::DSL.block_eval do
76
+ name 'dummy'
77
+ routes dummy_routes
78
+ end
79
+ dummy_routes.each do |key,val|
80
+ expect(modified.route(key).path.spec.to_s).to eql(val)
81
+ end
82
+ end
83
+
84
+ it 'should allow adding a route to the application' do
85
+ dummy_routes = {root: '/', other_route: '/other/route', another_route: '/another/route'}
86
+ modified = Excursion::Pool::DSL.block_eval do
87
+ name 'dummy'
88
+ dummy_routes.each do |key,val|
89
+ route key, val
90
+ end
91
+ end
92
+ dummy_routes.each do |key,val|
93
+ expect(modified.route(key).path.spec.to_s).to eql(val)
94
+ end
95
+ end
96
+ end
97
+
98
+
99
+ end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'Excursion::Pool' do
4
+ DUMMY_HASH = {name: 'dummy', default_url_options: {host: 'dummy.local', port: 3000}, routes: {root: '/', other_route: '/other/route'}}
4
5
 
5
6
  describe '::datastore' do
6
7
  cleaner = Proc.new do
@@ -58,7 +59,7 @@ describe 'Excursion::Pool' do
58
59
  end
59
60
  end
60
61
  end
61
-
62
+
62
63
  describe '::register_application' do
63
64
  before(:each) do
64
65
  Excursion::Pool.class_variable_set(:@@applications, {})
@@ -79,13 +80,16 @@ describe 'Excursion::Pool' do
79
80
  end
80
81
  end
81
82
 
82
- it 'should require a rails application as the only argument' do
83
+ it 'should require a rails application and/or a block' do
83
84
  expect { Excursion::Pool.register_application }.to raise_exception(ArgumentError)
84
85
  expect { Excursion::Pool.register_application 'string arg' }.to raise_exception(ArgumentError)
85
86
  expect { Excursion::Pool.register_application 123 }.to raise_exception(ArgumentError)
86
87
  expect { Excursion::Pool.register_application :symbol_arg }.to raise_exception(ArgumentError)
87
88
  expect { Excursion::Pool.register_application Object }.to raise_exception(ArgumentError)
88
89
  expect { Excursion::Pool.register_application Object.new }.to raise_exception(ArgumentError)
90
+ expect { Excursion::Pool.register_application Rails.application }.to_not raise_exception
91
+ expect { Excursion::Pool.register_application { name 'dummy' } }.to_not raise_exception
92
+ expect { Excursion::Pool.register_application(Rails.application) do; end }.to_not raise_exception
89
93
  end
90
94
 
91
95
  it 'should add the application to the local hash pool' do
@@ -101,6 +105,47 @@ describe 'Excursion::Pool' do
101
105
  end
102
106
  end
103
107
 
108
+ describe '::register_hash' do
109
+ before(:each) do
110
+ Excursion::Pool.class_variable_set(:@@applications, {})
111
+ File.unlink(Excursion::Specs::DUMMY_POOL_FILE) if File.exists?(Excursion::Specs::DUMMY_POOL_FILE)
112
+ Excursion.configure do |config|
113
+ config.datastore = :file
114
+ config.datastore_file = Excursion::Specs::DUMMY_POOL_FILE
115
+ end
116
+ end
117
+
118
+ after(:each) do
119
+ Excursion::Pool.class_variable_set(:@@applications, {})
120
+ File.unlink(Excursion::Specs::DUMMY_POOL_FILE) if File.exists?(Excursion::Specs::DUMMY_POOL_FILE)
121
+ Excursion.configure do |config|
122
+ config.datastore = nil
123
+ config.datastore_file = nil
124
+ config.memcache_server = nil
125
+ end
126
+ end
127
+
128
+ it 'should require a hash with a :name key' do
129
+ expect { Excursion::Pool.register_hash }.to raise_exception(ArgumentError)
130
+ expect { Excursion::Pool.register_hash {} }.to raise_exception(ArgumentError)
131
+ expect { Excursion::Pool.register_hash 'string arg' }.to raise_exception(ArgumentError)
132
+ expect { Excursion::Pool.register_hash 123 }.to raise_exception(ArgumentError)
133
+ expect { Excursion::Pool.register_hash :symbol_arg }.to raise_exception(ArgumentError)
134
+ end
135
+
136
+ it 'should add the application to the local hash pool' do
137
+ Excursion::Pool.class_variable_get(:@@applications).should_not have_key('dummy')
138
+ Excursion::Pool.register_hash(DUMMY_HASH)
139
+ Excursion::Pool.class_variable_get(:@@applications).should have_key('dummy')
140
+ end
141
+
142
+ it 'should set the application in the datastore pool' do
143
+ Excursion::Pool.datastore.get('dummy').should be_nil
144
+ Excursion::Pool.register_hash(DUMMY_HASH)
145
+ Excursion::Pool.datastore.get('dummy').should_not be_nil
146
+ end
147
+ end
148
+
104
149
  describe '::remove_application' do
105
150
  before(:each) do
106
151
  Excursion::Pool.class_variable_set(:@@applications, {})
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excursion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rebec
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-30 00:00:00.000000000 Z
11
+ date: 2013-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -81,6 +81,7 @@ files:
81
81
  - lib/excursion/exceptions/active_record.rb
82
82
  - lib/excursion/exceptions/memcache.rb
83
83
  - lib/excursion/pool/dummy_application.rb
84
+ - lib/excursion/pool/dsl.rb
84
85
  - lib/excursion/pool/application.rb
85
86
  - lib/excursion/railtie.rb
86
87
  - lib/excursion/configuration.rb
@@ -130,6 +131,7 @@ files:
130
131
  - spec/dummy/db/schema.rb
131
132
  - spec/dummy/config.ru
132
133
  - spec/dummy/README.rdoc
134
+ - spec/dummy/log/development.log
133
135
  - spec/dummy/script/rails
134
136
  - spec/dummy/doc/README_FOR_APP
135
137
  - spec/dummy/app/views/layouts/application.html.erb
@@ -142,6 +144,7 @@ files:
142
144
  - spec/support/mocks.rb
143
145
  - spec/excursion/helpers_spec.rb
144
146
  - spec/excursion/route_pool_spec.rb
147
+ - spec/excursion/pool/dsl_spec.rb
145
148
  - spec/excursion/pool/application_spec.rb
146
149
  - spec/excursion/pool/dummy_application_spec.rb
147
150
  - spec/excursion/pool_spec.rb
@@ -208,6 +211,7 @@ test_files:
208
211
  - spec/dummy/db/schema.rb
209
212
  - spec/dummy/config.ru
210
213
  - spec/dummy/README.rdoc
214
+ - spec/dummy/log/development.log
211
215
  - spec/dummy/script/rails
212
216
  - spec/dummy/doc/README_FOR_APP
213
217
  - spec/dummy/app/views/layouts/application.html.erb
@@ -220,6 +224,7 @@ test_files:
220
224
  - spec/support/mocks.rb
221
225
  - spec/excursion/helpers_spec.rb
222
226
  - spec/excursion/route_pool_spec.rb
227
+ - spec/excursion/pool/dsl_spec.rb
223
228
  - spec/excursion/pool/application_spec.rb
224
229
  - spec/excursion/pool/dummy_application_spec.rb
225
230
  - spec/excursion/pool_spec.rb