excursion 0.0.4 → 0.0.5

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/lib/excursion/configuration.rb +1 -1
  3. data/lib/excursion/{datasources/datasource.rb → datastores/datastore.rb} +2 -2
  4. data/lib/excursion/{datasources → datastores}/file.rb +7 -10
  5. data/lib/excursion/{datasources → datastores}/memcache.rb +9 -9
  6. data/lib/excursion/exceptions/datastores.rb +7 -0
  7. data/lib/excursion/helpers/application_helper.rb +2 -0
  8. data/lib/excursion/helpers/url_helper.rb +11 -0
  9. data/lib/excursion/pool/application.rb +44 -16
  10. data/lib/excursion/pool.rb +22 -15
  11. data/lib/excursion/version.rb +1 -1
  12. data/lib/excursion.rb +8 -0
  13. data/spec/dummy/README.rdoc +261 -0
  14. data/spec/dummy/Rakefile +7 -0
  15. data/spec/dummy/app/assets/images/rails.png +0 -0
  16. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  17. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  18. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  19. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  20. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  21. data/spec/dummy/config/application.rb +64 -0
  22. data/spec/dummy/config/boot.rb +6 -0
  23. data/spec/dummy/config/database.yml +25 -0
  24. data/spec/dummy/config/environment.rb +5 -0
  25. data/spec/dummy/config/environments/development.rb +37 -0
  26. data/spec/dummy/config/environments/production.rb +67 -0
  27. data/spec/dummy/config/environments/test.rb +37 -0
  28. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  29. data/spec/dummy/config/initializers/excursion.rb +1 -0
  30. data/spec/dummy/config/initializers/inflections.rb +15 -0
  31. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  32. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  33. data/spec/dummy/config/initializers/session_store.rb +8 -0
  34. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  35. data/spec/dummy/config/locales/en.yml +5 -0
  36. data/spec/dummy/config/routes.rb +63 -0
  37. data/spec/dummy/config.ru +4 -0
  38. data/spec/dummy/db/development.sqlite3 +0 -0
  39. data/spec/dummy/db/seeds.rb +7 -0
  40. data/spec/dummy/doc/README_FOR_APP +2 -0
  41. data/spec/dummy/log/development.log +5066 -0
  42. data/spec/dummy/public/404.html +26 -0
  43. data/spec/dummy/public/422.html +26 -0
  44. data/spec/dummy/public/500.html +25 -0
  45. data/spec/dummy/public/favicon.ico +0 -0
  46. data/spec/dummy/public/index.html +241 -0
  47. data/spec/dummy/public/robots.txt +5 -0
  48. data/spec/dummy/script/rails +6 -0
  49. data/spec/excursion/datastores/file_spec.rb +118 -0
  50. data/spec/excursion/datastores/memcache_spec.rb +119 -0
  51. data/spec/excursion/helpers/application_helper_spec.rb +48 -0
  52. data/spec/excursion/helpers/url_helper_spec.rb +55 -0
  53. data/spec/excursion/helpers_spec.rb +65 -0
  54. data/spec/excursion/pool/application_spec.rb +214 -0
  55. data/spec/excursion/pool_spec.rb +203 -0
  56. data/spec/excursion_spec.rb +4 -0
  57. data/spec/spec_helper.rb +21 -1
  58. data/spec/support/mocks.rb +51 -0
  59. metadata +126 -8
  60. data/lib/excursion/exceptions/datasources.rb +0 -7
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ class Excursion::Specs::TestHelperOne
4
+ include Excursion::Helpers::ApplicationHelper
5
+ end
6
+ class Excursion::Specs::TestHelperTwo
7
+ include Excursion::Helpers::ApplicationHelper
8
+ end
9
+
10
+ describe 'Excursion' do
11
+ before(:each) do
12
+ Excursion::Pool.class_variable_set(:@@applications, {})
13
+ File.unlink(Excursion::Specs::DUMMY_POOL_FILE) if File.exists?(Excursion::Specs::DUMMY_POOL_FILE)
14
+ Excursion.configure do |config|
15
+ config.datastore = :file
16
+ config.datastore_file = Excursion::Specs::DUMMY_POOL_FILE
17
+ end
18
+ end
19
+
20
+ after(:each) do
21
+ Excursion::Pool.class_variable_set(:@@applications, {})
22
+ File.unlink(Excursion::Specs::DUMMY_POOL_FILE) if File.exists?(Excursion::Specs::DUMMY_POOL_FILE)
23
+ Excursion.configure do |config|
24
+ config.datastore = nil
25
+ config.datastore_file = nil
26
+ config.memcache_server = nil
27
+ end
28
+ end
29
+
30
+ context '::url_helpers' do
31
+ it 'should provide access to application url helpers' do
32
+ Excursion::Pool.register_application(Rails.application)
33
+ expect { Excursion.url_helpers.dummy }.to_not raise_exception(NoMethodError)
34
+ end
35
+ end
36
+ end
37
+
38
+ describe 'Excursion::Helpers' do
39
+ before(:each) do
40
+ Excursion::Pool.class_variable_set(:@@applications, {})
41
+ File.unlink(Excursion::Specs::DUMMY_POOL_FILE) if File.exists?(Excursion::Specs::DUMMY_POOL_FILE)
42
+ Excursion.configure do |config|
43
+ config.datastore = :file
44
+ config.datastore_file = Excursion::Specs::DUMMY_POOL_FILE
45
+ end
46
+ end
47
+
48
+ after(:each) do
49
+ Excursion::Pool.class_variable_set(:@@applications, {})
50
+ File.unlink(Excursion::Specs::DUMMY_POOL_FILE) if File.exists?(Excursion::Specs::DUMMY_POOL_FILE)
51
+ Excursion.configure do |config|
52
+ config.datastore = nil
53
+ config.datastore_file = nil
54
+ config.memcache_server = nil
55
+ end
56
+ end
57
+
58
+ it 'should share instances of helper classes' do
59
+ h1 = Excursion::Specs::TestHelperOne.new
60
+ h2 = Excursion::Specs::TestHelperTwo.new
61
+ Excursion::Pool.register_application(Rails.application)
62
+ h1.dummy.should eql(h2.dummy)
63
+ h1.dummy.should eql(Excursion::Specs::TestHelperOne.new.dummy)
64
+ end
65
+ end
@@ -0,0 +1,214 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Excursion::Pool::Application' do
4
+
5
+ context '::new' do
6
+ it 'should require a name' do
7
+ expect { Excursion::Pool::Application.new }.to raise_exception(ArgumentError)
8
+ end
9
+
10
+ it 'should require a config hash' do
11
+ expect { Excursion::Pool::Application.new 'app_name' }.to raise_exception(ArgumentError)
12
+ end
13
+
14
+ it 'should accept an optional route collection' do
15
+ expect { Excursion::Pool::Application.new 'app_name', {} }.to_not raise_exception(ArgumentError)
16
+ expect { Excursion::Pool::Application.new 'app_name', {}, {} }.to_not raise_exception(ArgumentError)
17
+ end
18
+
19
+ it 'should return a populated Application object' do
20
+ mock = Excursion::Specs::Mocks::SIMPLE_APP
21
+ mock_routes = Excursion::Specs::Mocks::NAMED_ROUTES
22
+
23
+ app = Excursion::Pool::Application.new mock[:name], {default_url_options: mock[:default_url_options], registered_at: mock[:registered_at]}, mock_routes
24
+ app.should be_an_instance_of(Excursion::Pool::Application)
25
+ app.name.should eql(mock[:name])
26
+ app.default_url_options.should eql(mock[:default_url_options])
27
+ mock_routes.each do |name,path|
28
+ app.routes.routes.keys.should include(name)
29
+ end
30
+ end
31
+ end
32
+
33
+ describe '::from_cache' do
34
+ it 'should require a cached application hash' do
35
+ expect { Excursion::Pool::Application.from_cache }.to raise_exception(ArgumentError)
36
+ end
37
+
38
+ it 'should return an Application object with the cached properties' do
39
+ mock = Excursion::Specs::Mocks::SIMPLE_APP
40
+
41
+ app = Excursion::Pool::Application.from_cache(mock)
42
+ app.should be_an_instance_of(Excursion::Pool::Application)
43
+ app.name.should eql(mock[:name])
44
+ app.default_url_options.should eql(mock[:default_url_options])
45
+ mock[:routes].each do |name,path|
46
+ app.routes.routes.keys.should include(name)
47
+ end
48
+ end
49
+ end
50
+
51
+ describe '#to_cache' do
52
+ subject { Excursion::Pool::Application.from_cache(Excursion::Specs::Mocks::SIMPLE_APP) }
53
+
54
+ it 'should return a hash' do
55
+ subject.to_cache.should be_an_instance_of(Hash)
56
+ end
57
+
58
+ context 'returned hash' do
59
+ it 'should contain the app name' do
60
+ subject.to_cache[:name].should eql(subject.name)
61
+ end
62
+
63
+ it 'should contain the default_url_options' do
64
+ subject.to_cache[:default_url_options].should eql(subject.default_url_options)
65
+ end
66
+
67
+ it 'should contain a hash of the routes' do
68
+ subject.to_cache[:routes].should be_an_instance_of(Hash)
69
+ subject.to_cache[:routes].each do |name,path|
70
+ subject.routes.routes.keys.should include(name)
71
+ end
72
+ end
73
+
74
+ it 'should contain the registered_at property' do
75
+ subject.to_cache[:registered_at].should eql(subject.instance_variable_get(:@registered_at))
76
+ end
77
+ end
78
+ end
79
+
80
+ describe '#from_cache' do
81
+ subject { Excursion::Pool::Application.new 'test_app', {} }
82
+
83
+ it 'should require a cached application object' do
84
+ expect { subject.from_cache }.to raise_exception(ArgumentError)
85
+ end
86
+
87
+ it 'should populate the object with the cached values' do
88
+ mock = Excursion::Specs::Mocks::SIMPLE_APP
89
+ subject.from_cache(mock)
90
+ subject.default_url_options.should eql(mock[:default_url_options])
91
+ subject.instance_variable_get(:@registered_at).to_i.should eql(mock[:registered_at].to_i)
92
+ subject.routes.each do |name,path|
93
+ mock[:routes].keys.should include(name)
94
+ end
95
+ end
96
+ end
97
+
98
+ describe '#route' do
99
+ subject { Excursion::Pool::Application.from_cache(Excursion::Specs::Mocks::SIMPLE_APP) }
100
+
101
+ it 'should require a name' do
102
+ expect { subject.route }.to raise_exception(ArgumentError)
103
+ end
104
+
105
+ context 'when the route exists' do
106
+ it 'should return the route object' do
107
+ if Excursion.rails3?
108
+ subject.route(:example).should be_an_instance_of(Journey::Route)
109
+ elsif Excursion.rails4?
110
+ subject.route(:example).should be_an_instance_of(ActionDispatch::Journey::Route)
111
+ end
112
+ end
113
+ end
114
+
115
+ context 'when the route does not exist' do
116
+ it 'should return nil' do
117
+ subject.route(:non_existent_route).should be_nil
118
+ end
119
+ end
120
+ end
121
+
122
+ describe '#routes' do
123
+ subject { Excursion::Pool::Application.from_cache(Excursion::Specs::Mocks::SIMPLE_APP) }
124
+
125
+ it 'should return a NamedRouteCollection' do
126
+ subject.routes.should be_an_instance_of(ActionDispatch::Routing::RouteSet::NamedRouteCollection)
127
+ end
128
+ end
129
+
130
+ describe '#routes=' do
131
+ subject { Excursion::Pool::Application.new 'test_app', {} }
132
+
133
+ it 'should accept a Hash of named routes' do
134
+ expect { subject.routes = {} }.to_not raise_exception(ArgumentError)
135
+ end
136
+
137
+ it 'should accept a NamedRouteCollection' do
138
+ expect { subject.routes = ActionDispatch::Routing::RouteSet::NamedRouteCollection.new }.to_not raise_exception(ArgumentError)
139
+ end
140
+
141
+ it 'should only accept a Hash or NamedRouteCollection' do
142
+ expect { subject.routes = 'test string' }.to raise_exception(ArgumentError)
143
+ expect { subject.routes = 123 }.to raise_exception(ArgumentError)
144
+ expect { subject.routes = :test_symbol }.to raise_exception(ArgumentError)
145
+ expect { subject.routes = [] }.to raise_exception(ArgumentError)
146
+ expect { subject.routes = Object }.to raise_exception(ArgumentError)
147
+ expect { subject.routes = Object.new }.to raise_exception(ArgumentError)
148
+ end
149
+
150
+ context 'when passing a Hash' do
151
+ it 'should override the application routes with the ones provided' do
152
+ subject.routes = Hash[Excursion::Specs::Mocks::NAMED_ROUTES.collect {|k,v| [k,v] }]
153
+ Excursion::Specs::Mocks::NAMED_ROUTES.each do |name,path|
154
+ subject.routes.routes.keys.should include(name)
155
+ end
156
+ end
157
+ end
158
+
159
+ context 'when passing a NamedRouteCollection' do
160
+ it 'should override the application routes with the ones provided' do
161
+ subject.routes = Excursion::Specs::Mocks::NAMED_ROUTES
162
+ Excursion::Specs::Mocks::NAMED_ROUTES.each do |name,path|
163
+ subject.routes.routes.keys.should include(name)
164
+ end
165
+ end
166
+ end
167
+ end
168
+
169
+ describe '#set_routes' do
170
+ subject { Excursion::Pool::Application.new 'test_app', {} }
171
+
172
+ context 'routes' do
173
+ it 'should be required' do
174
+ expect { subject.set_routes }.to raise_exception(ArgumentError)
175
+ end
176
+
177
+ it 'should accept a Hash of named routes' do
178
+ expect { subject.set_routes({}) }.to_not raise_exception(ArgumentError)
179
+ end
180
+
181
+ it 'should accept a NamedRouteCollection' do
182
+ expect { subject.set_routes ActionDispatch::Routing::RouteSet::NamedRouteCollection.new }.to_not raise_exception(ArgumentError)
183
+ end
184
+
185
+ it 'should only accept a Hash or NamedRouteCollection' do
186
+ expect { subject.set_routes 'test string' }.to raise_exception(ArgumentError)
187
+ expect { subject.set_routes 123 }.to raise_exception(ArgumentError)
188
+ expect { subject.set_routes :test_symbol }.to raise_exception(ArgumentError)
189
+ expect { subject.set_routes [] }.to raise_exception(ArgumentError)
190
+ expect { subject.set_routes Object }.to raise_exception(ArgumentError)
191
+ expect { subject.set_routes Object.new }.to raise_exception(ArgumentError)
192
+ end
193
+ end
194
+
195
+ context 'when passing a Hash' do
196
+ it 'should override the application routes with the ones provided' do
197
+ subject.set_routes Hash[Excursion::Specs::Mocks::NAMED_ROUTES]
198
+ Excursion::Specs::Mocks::NAMED_ROUTES.each do |name,path|
199
+ subject.routes.routes.keys.should include(name)
200
+ end
201
+ end
202
+ end
203
+
204
+ context 'when passing a NamedRouteCollection' do
205
+ it 'should override the application routes with the ones provided' do
206
+ subject.set_routes Excursion::Specs::Mocks::NAMED_ROUTE_COLLECTION
207
+ Excursion::Specs::Mocks::NAMED_ROUTES.each do |name,path|
208
+ subject.routes.routes.keys.should include(name)
209
+ end
210
+ end
211
+ end
212
+ end
213
+
214
+ end
@@ -0,0 +1,203 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Excursion::Pool' do
4
+
5
+ describe '::datastore' do
6
+ cleaner = Proc.new do
7
+ Excursion::Pool.class_variable_set(:@@datastore, nil)
8
+ Excursion.configure do |config|
9
+ datastore = nil
10
+ datastore_file = nil
11
+ memcache_server = nil
12
+ end
13
+ end
14
+ before :each, &cleaner
15
+ after :each, &cleaner
16
+
17
+ it 'should require a configured datastore' do
18
+ expect { Excursion::Pool.datastore }.to raise_exception(Excursion::NoDatastoreError)
19
+ end
20
+
21
+ it 'should support the :file datastore' do
22
+ Excursion.configuration.datastore = :file
23
+ expect { Excursion::Pool.datastore }.to_not raise_exception(Excursion::NoDatastoreError)
24
+ end
25
+
26
+ it 'should support the :memcache datastore' do
27
+ Excursion.configuration.datastore = :memcache
28
+ expect { Excursion::Pool.datastore }.to_not raise_exception(Excursion::NoDatastoreError)
29
+ end
30
+
31
+ context 'when using the :file datastore' do
32
+ it 'should require the datastore_file option be configured' do
33
+ Excursion.configuration.datastore = :file
34
+ expect { Excursion::Pool.datastore }.to raise_exception(Excursion::DatastoreConfigurationError)
35
+ end
36
+
37
+ it 'should return an instance of Excursion::Datastores::File' do
38
+ Excursion.configuration.datastore = :file
39
+ Excursion.configuration.datastore_file = Excursion::Specs::DUMMY_POOL_FILE
40
+ Excursion::Pool.datastore.should be_an_instance_of(Excursion::Datastores::File)
41
+ end
42
+ end
43
+
44
+ context 'when using the :memcache datastore' do
45
+ it 'should require the memcache_server option be configured' do
46
+ Excursion.configuration.datastore = :memcache
47
+ expect { Excursion::Pool.datastore }.to raise_exception(Excursion::MemcacheConfigurationError)
48
+ end
49
+
50
+ it 'should return an instance of Excursion::Datastores::Memcache' do
51
+ Excursion.configuration.datastore = :memcache
52
+ Excursion.configuration.memcache_server = Excursion::Specs::DUMMY_MEMCACHE_SERVER
53
+ Excursion::Pool.datastore.should be_an_instance_of(Excursion::Datastores::Memcache)
54
+ end
55
+ end
56
+ end
57
+
58
+ describe '::register_application' do
59
+ before(:each) do
60
+ Excursion::Pool.class_variable_set(:@@applications, {})
61
+ File.unlink(Excursion::Specs::DUMMY_POOL_FILE) if File.exists?(Excursion::Specs::DUMMY_POOL_FILE)
62
+ Excursion.configure do |config|
63
+ config.datastore = :file
64
+ config.datastore_file = Excursion::Specs::DUMMY_POOL_FILE
65
+ end
66
+ end
67
+
68
+ after(:each) do
69
+ Excursion::Pool.class_variable_set(:@@applications, {})
70
+ File.unlink(Excursion::Specs::DUMMY_POOL_FILE) if File.exists?(Excursion::Specs::DUMMY_POOL_FILE)
71
+ Excursion.configure do |config|
72
+ config.datastore = nil
73
+ config.datastore_file = nil
74
+ config.memcache_server = nil
75
+ end
76
+ end
77
+
78
+ it 'should require a rails application as the only argument' do
79
+ expect { Excursion::Pool.register_application }.to raise_exception(ArgumentError)
80
+ expect { Excursion::Pool.register_application 'string arg' }.to raise_exception(ArgumentError)
81
+ expect { Excursion::Pool.register_application 123 }.to raise_exception(ArgumentError)
82
+ expect { Excursion::Pool.register_application :symbol_arg }.to raise_exception(ArgumentError)
83
+ expect { Excursion::Pool.register_application Object }.to raise_exception(ArgumentError)
84
+ expect { Excursion::Pool.register_application Object.new }.to raise_exception(ArgumentError)
85
+ end
86
+
87
+ it 'should add the application to the local hash pool' do
88
+ Excursion::Pool.class_variable_get(:@@applications).should_not have_key('dummy')
89
+ Excursion::Pool.register_application(Rails.application) # Use the dummy app class
90
+ Excursion::Pool.class_variable_get(:@@applications).should have_key('dummy')
91
+ end
92
+
93
+ it 'should set the application in the datastore pool' do
94
+ Excursion::Pool.datastore.get('dummy').should be_nil
95
+ Excursion::Pool.register_application(Rails.application) # Use the dummy app class
96
+ Excursion::Pool.datastore.get('dummy').should_not be_nil
97
+ end
98
+ end
99
+
100
+ describe '::remove_application' do
101
+ before(:each) do
102
+ Excursion::Pool.class_variable_set(:@@applications, {})
103
+ File.unlink(Excursion::Specs::DUMMY_POOL_FILE) if File.exists?(Excursion::Specs::DUMMY_POOL_FILE)
104
+ Excursion.configure do |config|
105
+ config.datastore = :file
106
+ config.datastore_file = Excursion::Specs::DUMMY_POOL_FILE
107
+ end
108
+ end
109
+
110
+ after(:each) do
111
+ Excursion::Pool.class_variable_set(:@@applications, {})
112
+ File.unlink(Excursion::Specs::DUMMY_POOL_FILE) if File.exists?(Excursion::Specs::DUMMY_POOL_FILE)
113
+ Excursion.configure do |config|
114
+ config.datastore = nil
115
+ config.datastore_file = nil
116
+ config.memcache_server = nil
117
+ end
118
+ end
119
+
120
+ it 'should require a rails application as the only argument' do
121
+ expect { Excursion::Pool.remove_application }.to raise_exception(ArgumentError)
122
+ expect { Excursion::Pool.remove_application 'string arg' }.to raise_exception(ArgumentError)
123
+ expect { Excursion::Pool.remove_application 123 }.to raise_exception(ArgumentError)
124
+ expect { Excursion::Pool.remove_application :symbol_arg }.to raise_exception(ArgumentError)
125
+ expect { Excursion::Pool.remove_application Object }.to raise_exception(ArgumentError)
126
+ expect { Excursion::Pool.remove_application Object.new }.to raise_exception(ArgumentError)
127
+ end
128
+
129
+ it 'should remove the application from the local hash pool' do
130
+ Excursion::Pool.class_variable_get(:@@applications).should_not have_key('dummy')
131
+ Excursion::Pool.register_application(Rails.application) # Use the dummy app class
132
+ Excursion::Pool.class_variable_get(:@@applications).should have_key('dummy')
133
+ Excursion::Pool.remove_application(Rails.application)
134
+ Excursion::Pool.class_variable_get(:@@applications).should_not have_key('dummy')
135
+ end
136
+
137
+ it 'should remove the application from the datastore pool' do
138
+ Excursion::Pool.datastore.get('dummy').should be_nil
139
+ Excursion::Pool.register_application(Rails.application) # Use the dummy app class
140
+ Excursion::Pool.datastore.get('dummy').should_not be_nil
141
+ Excursion::Pool.remove_application(Rails.application)
142
+ Excursion::Pool.datastore.get('dummy').should be_nil
143
+ end
144
+ end
145
+
146
+ describe '::application' do
147
+ before(:each) do
148
+ Excursion::Pool.class_variable_set(:@@applications, {})
149
+ File.unlink(Excursion::Specs::DUMMY_POOL_FILE) if File.exists?(Excursion::Specs::DUMMY_POOL_FILE)
150
+ Excursion.configure do |config|
151
+ config.datastore = :file
152
+ config.datastore_file = Excursion::Specs::DUMMY_POOL_FILE
153
+ end
154
+ end
155
+
156
+ after(:each) do
157
+ Excursion::Pool.class_variable_set(:@@applications, {})
158
+ File.unlink(Excursion::Specs::DUMMY_POOL_FILE) if File.exists?(Excursion::Specs::DUMMY_POOL_FILE)
159
+ Excursion.configure do |config|
160
+ config.datastore = nil
161
+ config.datastore_file = nil
162
+ config.memcache_server = nil
163
+ end
164
+ end
165
+
166
+ it 'should require an application name string' do
167
+ expect { Excursion::Pool.application }.to raise_exception(ArgumentError)
168
+ end
169
+
170
+ context 'when the requested app exists' do
171
+ context 'in the local hash pool' do
172
+ before(:each) do
173
+ Excursion::Pool.register_application(Rails.application)
174
+ end
175
+
176
+ it 'should return the Application object' do
177
+ Excursion::Pool.class_variable_get(:@@applications).should have_key('dummy')
178
+ Excursion::Pool.application('dummy').should be_an_instance_of(Excursion::Pool::Application)
179
+ Excursion::Pool.application('dummy').should eql(Excursion::Pool.class_variable_get(:@@applications)['dummy'])
180
+ end
181
+ end
182
+
183
+ context 'in the datastore pool' do
184
+ before(:each) do
185
+ Excursion::Pool.register_application(Rails.application)
186
+ Excursion::Pool.class_variable_set(:@@applications, {})
187
+ end
188
+
189
+ it 'should return the Application object' do
190
+ Excursion::Pool.class_variable_get(:@@applications).should_not have_key('dummy')
191
+ Excursion::Pool.application('dummy').should be_an_instance_of(Excursion::Pool::Application)
192
+ Excursion::Pool.application('dummy').should eql(Excursion::Pool.class_variable_get(:@@applications)['dummy'])
193
+ end
194
+ end
195
+ end
196
+
197
+ context 'when the requested app does not exist' do
198
+ it 'should return nil' do
199
+ Excursion::Pool.application('dummy').should be_nil
200
+ end
201
+ end
202
+ end
203
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Excursion' do
4
+ end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,21 @@
1
- # TODO: specs!
1
+ require File.expand_path("../dummy/config/environment", __FILE__)
2
+ require 'rspec/core'
3
+ #require 'rspec/rails'
4
+ #require 'rspec/autorun'
5
+
6
+ Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each { |f| require f }
7
+
8
+ RSpec.configure do |config|
9
+ #config.before(:suite) do
10
+ #end
11
+
12
+ #config.before(:each) do
13
+ #end
14
+
15
+ #config.around(:each) do |example|
16
+ #ActiveRecord::Base.transaction do
17
+ # example.run
18
+ # raise ActiveRecord::Rollback
19
+ #end
20
+ #end
21
+ end
@@ -0,0 +1,51 @@
1
+ module Excursion
2
+ module Specs
3
+ DUMMY_POOL_FILE = File.expand_path('../../dummy/tmp/spec_pool.yml', __FILE__)
4
+ DUMMY_MEMCACHE_SERVER = 'localhost:11211'
5
+
6
+ module Mocks
7
+ def self.journey_route(name, path)
8
+ if Excursion.rails3?
9
+ Journey::Route.new(name, Rails.application, Journey::Path::Pattern.new(path), {required_defaults: []})
10
+ elsif Excursion.rails4?
11
+ ActionDispatch::Journey::Route.new(name, Rails.application, ActionDispatch::Journey::Path::Pattern.new(path), {required_defaults: []})
12
+ end
13
+ end
14
+
15
+ SIMPLE_VALUES = {
16
+ 'key1' => 'value_one',
17
+ 'key2' => 'value_two',
18
+ 'key3' => 'value_three',
19
+ }
20
+
21
+ SIMPLE_APP = {
22
+ name: 'simple_app',
23
+ routes: {
24
+ root: '/',
25
+ example: '/example',
26
+ with_id: '/example/:id'
27
+ },
28
+ default_url_options: {
29
+ host: 'www.example.com',
30
+ port: 3000
31
+ },
32
+ registered_at: Time.now
33
+ }
34
+
35
+ SIMPLE_ROUTES = {
36
+ test: '/test',
37
+ example_route: '/abc',
38
+ foo: '/this/is/foo',
39
+ bar: '/and/this/is/bar'
40
+ }
41
+
42
+ NAMED_ROUTES = Hash[SIMPLE_ROUTES.collect { |name,path|[name, journey_route(name, path)] }]
43
+ NAMED_ROUTE_COLLECTION = ActionDispatch::Routing::RouteSet::NamedRouteCollection.new
44
+ NAMED_ROUTES.each { |name,route| NAMED_ROUTE_COLLECTION.add(name, route) }
45
+
46
+ APP_POOL = {
47
+ SIMPLE_APP[:name] => SIMPLE_APP
48
+ }
49
+ end
50
+ end
51
+ end