london-bike-hire-cli 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -0
- data/README.md +19 -17
- data/lib/london_bike_hire_cli/application.rb +8 -1
- data/lib/london_bike_hire_cli/basic_renderer.rb +15 -22
- data/lib/london_bike_hire_cli/color_helper.rb +24 -0
- data/lib/london_bike_hire_cli/controller.rb +21 -31
- data/lib/london_bike_hire_cli/feed_parser.rb +9 -10
- data/lib/london_bike_hire_cli/queries/stations_by_name.rb +9 -0
- data/lib/london_bike_hire_cli/queries/stations_near.rb +5 -0
- data/lib/london_bike_hire_cli/query_response.rb +4 -14
- data/lib/london_bike_hire_cli/repository/in_memory_store_adapter.rb +69 -0
- data/lib/london_bike_hire_cli/repository/repo.rb +39 -0
- data/lib/london_bike_hire_cli/repository/spatial_search_adapter.rb +28 -0
- data/lib/london_bike_hire_cli/repository/station_repo.rb +35 -0
- data/lib/london_bike_hire_cli/repository/station_store.rb +22 -0
- data/lib/london_bike_hire_cli/station.rb +4 -0
- data/lib/london_bike_hire_cli/station_not_found_error.rb +3 -0
- data/lib/london_bike_hire_cli/version.rb +1 -1
- data/lib/london_bike_hire_cli/views/error.erb +5 -0
- data/lib/london_bike_hire_cli/views/stations.erb +11 -0
- data/lib/london_bike_hire_cli.rb +12 -7
- data/london-bike-hire-cli.gemspec +3 -2
- data/spec/controller_spec.rb +29 -61
- data/spec/feed_parser_spec.rb +10 -12
- data/spec/station_repo_spec.rb +148 -0
- data/spec/support/test_datasource.rb +8 -4
- data/test.rb +1 -0
- metadata +17 -13
- data/lib/london_bike_hire_cli/spatial_search.rb +0 -20
- data/lib/london_bike_hire_cli/station_adapter.rb +0 -19
- data/lib/london_bike_hire_cli/station_repository.rb +0 -51
- data/spec/spatial_search_spec.rb +0 -27
- data/spec/station_adapter_spec.rb +0 -29
- data/spec/station_respository_spec.rb +0 -117
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe LondonBikeHireCli::StationAdapter do
|
4
|
-
let(:datasource) { TestDatasource.new }
|
5
|
-
let(:test_repository) { LondonBikeHireCli::StationRepository.new(datasource) }
|
6
|
-
subject { described_class.new(test_repository.all) }
|
7
|
-
|
8
|
-
describe '#to_triples' do
|
9
|
-
context 'given datasource' do
|
10
|
-
it 'returns expected number of results' do
|
11
|
-
results = subject.to_triples
|
12
|
-
|
13
|
-
expect(results.size).to eq(2)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'produces triple of first station' do
|
17
|
-
results = subject.to_triples
|
18
|
-
|
19
|
-
expect(results.first).to eq([51.53005939, -0.120973687, 1])
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'produces triple of second station' do
|
23
|
-
results = subject.to_triples
|
24
|
-
|
25
|
-
expect(results.last).to eq([51.50810309, -0.12602103, 2])
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,117 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe LondonBikeHireCli::StationRepository do
|
4
|
-
let(:datasource) { TestDatasource.new }
|
5
|
-
subject { described_class.new(datasource) }
|
6
|
-
|
7
|
-
describe '#all' do
|
8
|
-
context 'given feed_parser returns dataset' do
|
9
|
-
it 'should return expected number of results' do
|
10
|
-
results = subject.all
|
11
|
-
|
12
|
-
expect(results.size).to eq(2)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#find_by_id' do
|
18
|
-
context 'given feed_parser returns dataset' do
|
19
|
-
it 'should return expected number of results' do
|
20
|
-
results = subject.find_by_id(1)
|
21
|
-
|
22
|
-
expect(results.size).to eq(1)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should return expected result' do
|
26
|
-
result = subject.find_by_id(1).first
|
27
|
-
|
28
|
-
expect(result.name).to eq('test-station-1')
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'given a request for an id that does not exist' do
|
32
|
-
it 'should raise error' do
|
33
|
-
expect do
|
34
|
-
subject.find_by_id(99)
|
35
|
-
end.to raise_error
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'given a request for more than one id' do
|
40
|
-
it 'should return expected number of results' do
|
41
|
-
results = subject.find_by_id(1, 2)
|
42
|
-
|
43
|
-
expect(results.size).to eq(2)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '#find_by_name' do
|
50
|
-
context 'given feed_parser returns dataset' do
|
51
|
-
it 'should return expected number of results' do
|
52
|
-
results = subject.find_by_name('test-station-1')
|
53
|
-
|
54
|
-
expect(results.size).to eq(1)
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'should return expected result' do
|
58
|
-
result = subject.find_by_name('test-station-1').first
|
59
|
-
|
60
|
-
expect(result.id).to eq(1)
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'given a request for an id that does not exist' do
|
64
|
-
it 'should not raise error' do
|
65
|
-
expect do
|
66
|
-
subject.find_by_name('foo')
|
67
|
-
end.not_to raise_error
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'should return empty array' do
|
71
|
-
expect(subject.find_by_name('foo').size).to eq(0)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe 'integration tests', vcr: { cassette_name: 'feed_xml' } do
|
77
|
-
subject { LondonBikeHireCli::StationRepository.new(LondonBikeHireCli::FeedParser.new) }
|
78
|
-
|
79
|
-
describe '#find_by_id' do
|
80
|
-
it 'should return expected number of results' do
|
81
|
-
results = subject.find_by_id(777)
|
82
|
-
|
83
|
-
expect(results.size).to eq(1)
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'should return expected result' do
|
87
|
-
result = subject.find_by_id(777).first
|
88
|
-
|
89
|
-
expect(result.name).to eq('Limburg Road, Clapham Common')
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe '#find_by_name' do
|
94
|
-
it 'should return expected number of results' do
|
95
|
-
results = subject.find_by_name('kings')
|
96
|
-
|
97
|
-
expect(results.size).to eq(3)
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'should return expected result' do
|
101
|
-
results = subject.find_by_name('kings')
|
102
|
-
actual_ids = results.map(&:id)
|
103
|
-
|
104
|
-
expect(actual_ids).to include(283, 439, 594)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe '#all' do
|
109
|
-
it 'should return expected number of results' do
|
110
|
-
results = subject.all
|
111
|
-
|
112
|
-
expect(results.size).to eq(747)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|