excursion 0.0.5 → 0.0.6
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.
- checksums.yaml +4 -4
- data/lib/excursion/datastores/active_record.rb +47 -0
- data/lib/excursion/datastores/active_record_with_memcache.rb +40 -0
- data/lib/excursion/datastores/file.rb +3 -3
- data/lib/excursion/exceptions/active_record.rb +4 -0
- data/lib/excursion/helpers/url_helper.rb +18 -10
- data/lib/excursion/pool.rb +7 -0
- data/lib/excursion/railtie.rb +1 -1
- data/lib/excursion/route_pool.rb +5 -0
- data/lib/excursion/version.rb +1 -1
- data/lib/excursion.rb +1 -0
- data/lib/generators/excursion/active_record_generator.rb +19 -0
- data/lib/generators/excursion/templates/migration.rb +14 -0
- data/spec/dummy/config/environments/development.rb +1 -3
- data/spec/dummy/config/environments/test.rb +1 -3
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20130618222840_create_excursion_route_pool.rb +14 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +70166 -0
- data/spec/excursion/datastores/active_record_spec.rb +106 -0
- data/spec/excursion/datastores/active_record_with_memcache_spec.rb +158 -0
- data/spec/excursion/datastores/file_spec.rb +1 -0
- data/spec/excursion/datastores/memcache_spec.rb +1 -0
- data/spec/excursion/route_pool_spec.rb +4 -0
- data/spec/spec_helper.rb +4 -2
- metadata +22 -4
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'excursion/datastores/active_record'
|
|
3
|
+
|
|
4
|
+
describe 'Excursion::Datastores::ActiveRecord' do
|
|
5
|
+
|
|
6
|
+
def fill_pool
|
|
7
|
+
Excursion::RoutePool.all.each { |m| m.destroy }
|
|
8
|
+
Excursion::Specs::Mocks::SIMPLE_VALUES.each do |key,val|
|
|
9
|
+
Excursion::RoutePool.create key: key, value: val
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
subject do
|
|
14
|
+
fill_pool
|
|
15
|
+
Excursion::Datastores::ActiveRecord.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe '#read' do
|
|
19
|
+
describe 'key' do
|
|
20
|
+
it 'should be required' do
|
|
21
|
+
expect { subject.read }.to raise_exception
|
|
22
|
+
expect { subject.read('test_key') }.to_not raise_exception
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'should accept a symbol or string' do
|
|
26
|
+
expect { subject.read('test_key') }.to_not raise_exception
|
|
27
|
+
expect { subject.read(:test_key) }.to_not raise_exception
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'should convert symbols to strings' do
|
|
31
|
+
expect(subject.read(:key1)).to eql(subject.read('key1'))
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context 'when the requested key does not exist' do
|
|
36
|
+
it 'should return nil' do
|
|
37
|
+
subject.read('non_existent_key').should be_nil
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context 'when the requested key exists' do
|
|
42
|
+
it 'should return the value of the requested key' do
|
|
43
|
+
Excursion::Specs::Mocks::SIMPLE_VALUES.each do |key,val|
|
|
44
|
+
expect(subject.read(key)).to eql(val)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe '#write' do
|
|
51
|
+
describe 'key' do
|
|
52
|
+
it 'should be required' do
|
|
53
|
+
expect { subject.write }.to raise_exception
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'should accept a symbol or string' do
|
|
57
|
+
expect { subject.write('str_key', 'strval') }.to_not raise_exception
|
|
58
|
+
expect { subject.write(:sym_key, 'symval') }.to_not raise_exception
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'should convert symbols to strings' do
|
|
62
|
+
subject.write(:sym_key, 'symval')
|
|
63
|
+
subject.read('sym_key').should == 'symval'
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
describe 'value' do
|
|
68
|
+
it 'should be required' do
|
|
69
|
+
expect { subject.write('test_key') }.to raise_exception(ArgumentError)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'should add the key to the datastore and set the value' do
|
|
74
|
+
subject.write('test_key', 'testval')
|
|
75
|
+
subject.read('test_key').should == 'testval'
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'should return the value of the added key' do
|
|
79
|
+
subject.write('test_key', 'testval').should == 'testval'
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
context '#delete' do
|
|
84
|
+
describe 'key' do
|
|
85
|
+
it 'should be required' do
|
|
86
|
+
expect { subject.delete }.to raise_exception(ArgumentError)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'should remove the key from the datastore' do
|
|
91
|
+
subject.read('key1').should_not eql(nil)
|
|
92
|
+
subject.delete('key1')
|
|
93
|
+
subject.read('key1').should be(nil)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'should return the value of the deleted key if it exists' do
|
|
97
|
+
keyval = subject.read('key1')
|
|
98
|
+
subject.delete('key1').should eql(keyval)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'should return nil if the deleted key does not exist' do
|
|
102
|
+
subject.delete('non_existent_key').should eql(nil)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
end
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'excursion/datastores/active_record_with_memcache'
|
|
3
|
+
|
|
4
|
+
describe 'Excursion::Datastores::ActiveRecordWithMemcache' do
|
|
5
|
+
|
|
6
|
+
def dalli_client
|
|
7
|
+
@dalli_client ||= Dalli::Client.new dummy_pool, {namespace: 'excursion'}
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def dummy_pool
|
|
11
|
+
Excursion::Specs::DUMMY_MEMCACHE_SERVER
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def fill_pool
|
|
15
|
+
Excursion::RoutePool.all.each { |m| m.destroy }
|
|
16
|
+
dalli_client.flush_all
|
|
17
|
+
Excursion::Specs::Mocks::SIMPLE_VALUES.each do |key,val|
|
|
18
|
+
dalli_client.set(key, val)
|
|
19
|
+
Excursion::RoutePool.create key: key, value: val
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
subject do
|
|
24
|
+
fill_pool
|
|
25
|
+
Excursion::Datastores::ActiveRecordWithMemcache.new dummy_pool
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe '#read' do
|
|
29
|
+
describe 'key' do
|
|
30
|
+
it 'should be required' do
|
|
31
|
+
expect { subject.read }.to raise_exception
|
|
32
|
+
expect { subject.read('test_key') }.to_not raise_exception
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'should accept a symbol or string' do
|
|
36
|
+
expect { subject.read('test_key') }.to_not raise_exception
|
|
37
|
+
expect { subject.read(:test_key) }.to_not raise_exception
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'should convert symbols to strings' do
|
|
41
|
+
expect(subject.read(:key1)).to eql(subject.read('key1'))
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context 'when the requested key does not exist' do
|
|
46
|
+
it 'should return nil' do
|
|
47
|
+
subject.read('non_existent_key').should be_nil
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context 'when the requested key exists' do
|
|
52
|
+
context 'in the cache' do
|
|
53
|
+
it 'should return the value of the requested key' do
|
|
54
|
+
Excursion::Specs::Mocks::SIMPLE_VALUES.each do |key,val|
|
|
55
|
+
expect(dalli_client.get(key)).to eql(val)
|
|
56
|
+
expect(subject.read(key)).to eql(val)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
context 'in the database' do
|
|
62
|
+
it 'should return the value of the requested key' do
|
|
63
|
+
Excursion::Specs::Mocks::SIMPLE_VALUES.each do |key,val|
|
|
64
|
+
dalli_client.delete(key)
|
|
65
|
+
expect(dalli_client.get(key)).to be_nil
|
|
66
|
+
expect(subject.read(key)).to eql(val)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
describe '#write' do
|
|
74
|
+
describe 'key' do
|
|
75
|
+
it 'should be required' do
|
|
76
|
+
expect { subject.write }.to raise_exception
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'should accept a symbol or string' do
|
|
80
|
+
expect { subject.write('str_key', 'strval') }.to_not raise_exception
|
|
81
|
+
expect { subject.write(:sym_key, 'symval') }.to_not raise_exception
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'should convert symbols to strings' do
|
|
85
|
+
subject.write(:sym_key, 'symval')
|
|
86
|
+
subject.read('sym_key').should == 'symval'
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
describe 'value' do
|
|
91
|
+
it 'should be required' do
|
|
92
|
+
expect { subject.write('test_key') }.to raise_exception(ArgumentError)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'should add the key to the datastore and set the value' do
|
|
97
|
+
subject.write('test_key', 'testval')
|
|
98
|
+
subject.read('test_key').should == 'testval'
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'should add the key to the active record table and set the value' do
|
|
102
|
+
subject.write('test_key', 'testval')
|
|
103
|
+
Excursion::RoutePool.find_by(key: 'test_key').value.should eql('testval') if Excursion.rails4?
|
|
104
|
+
Excursion::RoutePool.find_by_key('test_key').value.should eql('testval') if Excursion.rails3?
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it 'should add the key to the cache and set the value' do
|
|
108
|
+
subject.write('test_key', 'testval')
|
|
109
|
+
dalli_client.get('test_key').should eql('testval')
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it 'should return the value of the added key' do
|
|
113
|
+
subject.write('test_key', 'testval').should == 'testval'
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
context '#delete' do
|
|
118
|
+
before(:each) do
|
|
119
|
+
fill_pool
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
describe 'key' do
|
|
123
|
+
it 'should be required' do
|
|
124
|
+
expect { subject.delete }.to raise_exception(ArgumentError)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it 'should remove the key from the datastore' do
|
|
129
|
+
subject.read('key1').should_not eql(nil)
|
|
130
|
+
subject.delete('key1')
|
|
131
|
+
subject.read('key1').should be(nil)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it 'should remove the key from the active record table' do
|
|
135
|
+
Excursion::RoutePool.find_by(key: 'key1').should_not be_nil if Excursion.rails4?
|
|
136
|
+
Excursion::RoutePool.find_by_key('key1').should_not be_nil if Excursion.rails3?
|
|
137
|
+
subject.delete('key1')
|
|
138
|
+
Excursion::RoutePool.find_by(key: 'key1').should be_nil if Excursion.rails4?
|
|
139
|
+
Excursion::RoutePool.find_by_key('key1').should be_nil if Excursion.rails3?
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it 'should remove the key from the cache if it exists' do
|
|
143
|
+
dalli_client.get('key1').should_not be_nil
|
|
144
|
+
subject.delete('key1')
|
|
145
|
+
dalli_client.get('key1').should be_nil
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it 'should return the value of the deleted key if it exists' do
|
|
149
|
+
keyval = subject.read('key1')
|
|
150
|
+
subject.delete('key1').should eql(keyval)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it 'should return nil if the deleted key does not exist' do
|
|
154
|
+
subject.delete('non_existent_key').should eql(nil)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
require File.expand_path("../dummy/config/environment", __FILE__)
|
|
2
2
|
require 'rspec/core'
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
|
|
4
|
+
ActiveRecord::Base.establish_connection :adapter => "sqlite3",
|
|
5
|
+
:database => ":memory:"
|
|
6
|
+
ActiveRecord::Migrator.migrate(File.join(File.dirname(__FILE__), "dummy/db/migrate"))
|
|
5
7
|
|
|
6
8
|
Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each { |f| require f }
|
|
7
9
|
|
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.
|
|
4
|
+
version: 0.0.6
|
|
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-06-
|
|
11
|
+
date: 2013-06-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - '>='
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
19
|
+
version: '0'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - '>='
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
26
|
+
version: '0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rspec-rails
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -78,6 +78,7 @@ files:
|
|
|
78
78
|
- lib/excursion/pool.rb
|
|
79
79
|
- lib/excursion/exceptions/datastores.rb
|
|
80
80
|
- lib/excursion/exceptions/pool.rb
|
|
81
|
+
- lib/excursion/exceptions/active_record.rb
|
|
81
82
|
- lib/excursion/exceptions/memcache.rb
|
|
82
83
|
- lib/excursion/pool/application.rb
|
|
83
84
|
- lib/excursion/railtie.rb
|
|
@@ -86,10 +87,15 @@ files:
|
|
|
86
87
|
- lib/excursion/helpers/application_helper.rb
|
|
87
88
|
- lib/excursion/exceptions.rb
|
|
88
89
|
- lib/excursion/datastores/datastore.rb
|
|
90
|
+
- lib/excursion/datastores/active_record_with_memcache.rb
|
|
89
91
|
- lib/excursion/datastores/file.rb
|
|
92
|
+
- lib/excursion/datastores/active_record.rb
|
|
90
93
|
- lib/excursion/datastores/memcache.rb
|
|
91
94
|
- lib/excursion/helpers.rb
|
|
95
|
+
- lib/excursion/route_pool.rb
|
|
92
96
|
- lib/excursion/version.rb
|
|
97
|
+
- lib/generators/excursion/active_record_generator.rb
|
|
98
|
+
- lib/generators/excursion/templates/migration.rb
|
|
93
99
|
- lib/excursion.rb
|
|
94
100
|
- spec/excursion_spec.rb
|
|
95
101
|
- spec/dummy/public/500.html
|
|
@@ -115,7 +121,10 @@ files:
|
|
|
115
121
|
- spec/dummy/config/environment.rb
|
|
116
122
|
- spec/dummy/config/boot.rb
|
|
117
123
|
- spec/dummy/db/seeds.rb
|
|
124
|
+
- spec/dummy/db/migrate/20130618222840_create_excursion_route_pool.rb
|
|
118
125
|
- spec/dummy/db/development.sqlite3
|
|
126
|
+
- spec/dummy/db/test.sqlite3
|
|
127
|
+
- spec/dummy/db/schema.rb
|
|
119
128
|
- spec/dummy/config.ru
|
|
120
129
|
- spec/dummy/README.rdoc
|
|
121
130
|
- spec/dummy/log/development.log
|
|
@@ -130,10 +139,13 @@ files:
|
|
|
130
139
|
- spec/dummy/Rakefile
|
|
131
140
|
- spec/support/mocks.rb
|
|
132
141
|
- spec/excursion/helpers_spec.rb
|
|
142
|
+
- spec/excursion/route_pool_spec.rb
|
|
133
143
|
- spec/excursion/pool/application_spec.rb
|
|
134
144
|
- spec/excursion/pool_spec.rb
|
|
135
145
|
- spec/excursion/helpers/url_helper_spec.rb
|
|
136
146
|
- spec/excursion/helpers/application_helper_spec.rb
|
|
147
|
+
- spec/excursion/datastores/active_record_with_memcache_spec.rb
|
|
148
|
+
- spec/excursion/datastores/active_record_spec.rb
|
|
137
149
|
- spec/excursion/datastores/memcache_spec.rb
|
|
138
150
|
- spec/excursion/datastores/file_spec.rb
|
|
139
151
|
- spec/spec_helper.rb
|
|
@@ -185,7 +197,10 @@ test_files:
|
|
|
185
197
|
- spec/dummy/config/environment.rb
|
|
186
198
|
- spec/dummy/config/boot.rb
|
|
187
199
|
- spec/dummy/db/seeds.rb
|
|
200
|
+
- spec/dummy/db/migrate/20130618222840_create_excursion_route_pool.rb
|
|
188
201
|
- spec/dummy/db/development.sqlite3
|
|
202
|
+
- spec/dummy/db/test.sqlite3
|
|
203
|
+
- spec/dummy/db/schema.rb
|
|
189
204
|
- spec/dummy/config.ru
|
|
190
205
|
- spec/dummy/README.rdoc
|
|
191
206
|
- spec/dummy/log/development.log
|
|
@@ -200,10 +215,13 @@ test_files:
|
|
|
200
215
|
- spec/dummy/Rakefile
|
|
201
216
|
- spec/support/mocks.rb
|
|
202
217
|
- spec/excursion/helpers_spec.rb
|
|
218
|
+
- spec/excursion/route_pool_spec.rb
|
|
203
219
|
- spec/excursion/pool/application_spec.rb
|
|
204
220
|
- spec/excursion/pool_spec.rb
|
|
205
221
|
- spec/excursion/helpers/url_helper_spec.rb
|
|
206
222
|
- spec/excursion/helpers/application_helper_spec.rb
|
|
223
|
+
- spec/excursion/datastores/active_record_with_memcache_spec.rb
|
|
224
|
+
- spec/excursion/datastores/active_record_spec.rb
|
|
207
225
|
- spec/excursion/datastores/memcache_spec.rb
|
|
208
226
|
- spec/excursion/datastores/file_spec.rb
|
|
209
227
|
- spec/spec_helper.rb
|