backdrop 0.3.0 → 0.3.1
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 +8 -8
- data/.gitignore +1 -0
- data/.travis.yml +3 -0
- data/README.md +29 -17
- data/lib/backdrop/api_builder.rb +10 -2
- data/lib/backdrop/app.rb +10 -3
- data/lib/backdrop/configuration.rb +5 -0
- data/lib/backdrop/version.rb +1 -1
- data/spec/backdrop/api_builder_spec.rb +4 -3
- data/spec/integration/backdrop_end_to_end_spec.rb +8 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2Y4MDRhNmQzZTQwOGFkNjM5YzVmNTFhOTkxNTZmYzQ3YWYxNjZmNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjU3YmZkOWQ5MWVlY2YxOWM0OWIzM2EyYTY3ZDcxZDY4MzlhZjczNQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjY2NGNkODVlYmE0ZGE0ODAzYTliY2EyZTlhZmQ5YjI3MTEwZmI1MTg0OGVi
|
10
|
+
OWIyNzBlZmZjNzg5MTAzMTViZGEwN2RlNjRmNTFmODYwMDA1OTNjNTc4ZjA1
|
11
|
+
NmI2NTI4Y2VhYTY0ZmFkNGU2Y2MxYmM1MzE0ZWY1MmYxNWY0OGE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzU4OTY3NGY1YzgxZTg2YzgxN2FkZThlNmEzY2E2ZmQ3Y2YyZjZkMmJlMTc5
|
14
|
+
MGZjMjVlNmFiOTkxZGU2ZDdiZjNmNzdlMDUyOGY0ZDJiZjgyOTA4YTI5MTlh
|
15
|
+
NDRmMTU3MWViMzRjNmM1MDYxNGE0NzUxOWYwZDQ4ZjQzMGEyMDY=
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
Backdrop
|
1
|
+
Backdrop
|
2
2
|
========
|
3
3
|
|
4
4
|
[](http://badge.fury.io/rb/backdrop) [](https://travis-ci.org/tpbowden/backdrop) [](https://coveralls.io/r/tpbowden/backdrop?branch=master) [](https://codeclimate.com/github/tpbowden/backdrop) [](https://gemnasium.com/tpbowden/Backdrop)
|
5
5
|
|
6
|
-
|
6
|
+
JSON fixture generation for integration testing apps which consume multiple remote APIs.
|
7
7
|
|
8
8
|
Installation
|
9
9
|
------------
|
@@ -16,33 +16,45 @@ config/routes.rb
|
|
16
16
|
|
17
17
|
mount Backdrop::App => '/backdrop'
|
18
18
|
|
19
|
-
Ensure your APIs are generating JSON docs
|
20
|
-
|
21
|
-
RspecApiDocumentation.configure do |config|
|
22
|
-
config.format = :json
|
23
|
-
end
|
24
|
-
|
25
19
|
Configuration
|
26
20
|
-------------
|
27
21
|
|
28
|
-
|
22
|
+
Backdrop stores JSON in temporary files whilst it runs which should not be checked into version control. This can be specificied in an initializer:
|
29
23
|
|
30
24
|
Backdrop.configure do |config|
|
31
|
-
|
25
|
+
# defaults to tmp/backdrop
|
26
|
+
config.output_dir = '/your/temp/path'
|
32
27
|
end
|
33
28
|
|
34
|
-
|
35
|
-
|
29
|
+
Usage
|
30
|
+
-----
|
31
|
+
|
32
|
+
require 'backdrop'
|
33
|
+
|
34
|
+
Backdrop can be used on either a single OpenStruct or an array of OpenStructs. Each of these must have a property called 'backdrop_url' which is where the generated JSON will be located. This will be removed before being used for the API.
|
35
|
+
|
36
|
+
To create an API, call `Backdrop.load` on the data. To clear all loaded APIs, use `Backdrop.clear`.
|
37
|
+
|
38
|
+
Integration with Factory Girl
|
39
|
+
-----------------------------
|
40
|
+
|
41
|
+
Backdrop is most easily used alongside [FactoryGirl](https://github.com/thoughtbot/factory_girl).
|
42
|
+
|
43
|
+
FactoryGirl.define do
|
44
|
+
factory :example, class: OpenStruct do
|
45
|
+
backdrop_url { name }
|
46
|
+
name "example"
|
47
|
+
end
|
48
|
+
end
|
36
49
|
|
37
|
-
|
50
|
+
You can then use `Backdrop.load(FactoryGirl.build :example)` to create the following JSON at `/backdrop/example`:
|
38
51
|
|
39
|
-
|
52
|
+
`{"name":"example"}`
|
40
53
|
|
41
|
-
|
54
|
+
Similarly, `Backdrop.load(FactoryGirl.build_list :example, 2)` would create the following JSON:
|
42
55
|
|
43
|
-
|
56
|
+
[{"name":"example"},{"name":"example"}]
|
44
57
|
|
45
|
-
Call `rake backdrop` to create all RAD APIs in the specified output directory
|
46
58
|
|
47
59
|
Dependencies
|
48
60
|
------------
|
data/lib/backdrop/api_builder.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'backdrop'
|
1
3
|
require 'backdrop/app'
|
2
4
|
|
3
5
|
module Backdrop
|
@@ -18,12 +20,18 @@ module Backdrop
|
|
18
20
|
url = record.delete_field 'backdrop_url'
|
19
21
|
record.to_h
|
20
22
|
end
|
21
|
-
|
23
|
+
write_api(url, JSON.generate(formatted_data))
|
22
24
|
end
|
23
25
|
|
24
26
|
def build_single(input)
|
25
27
|
url = input.delete_field('backdrop_url')
|
26
|
-
|
28
|
+
write_api(url, JSON.generate(input.to_h))
|
29
|
+
end
|
30
|
+
|
31
|
+
def write_api(url, json)
|
32
|
+
file = "#{File.join(Backdrop.configuration.output_dir, url)}.json"
|
33
|
+
FileUtils.mkdir_p(File.dirname(file))
|
34
|
+
File.write(file, json)
|
27
35
|
end
|
28
36
|
end
|
29
37
|
end
|
data/lib/backdrop/app.rb
CHANGED
@@ -2,9 +2,16 @@ require 'sinatra'
|
|
2
2
|
|
3
3
|
module Backdrop
|
4
4
|
class App < Sinatra::Base
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
get '/*' do
|
6
|
+
file = File.join(
|
7
|
+
Backdrop.configuration.output_dir,
|
8
|
+
"#{params[:splat].first}.json"
|
9
|
+
)
|
10
|
+
if File.exist? file
|
11
|
+
status 200
|
12
|
+
File.read file
|
13
|
+
else
|
14
|
+
status 404
|
8
15
|
end
|
9
16
|
end
|
10
17
|
end
|
data/lib/backdrop/version.rb
CHANGED
@@ -4,13 +4,14 @@ require 'backdrop/api_builder'
|
|
4
4
|
describe Backdrop::APIBuilder do
|
5
5
|
describe '#build' do
|
6
6
|
let(:url) { '/some/location' }
|
7
|
+
let(:output_file) { 'tmp/backdrop/some/location.json' }
|
7
8
|
|
8
9
|
context 'when the input is a single item' do
|
9
10
|
let(:sample_input) { build :example, backdrop_url: url }
|
10
11
|
let(:json) { '{"some":"data"}' }
|
11
|
-
it '
|
12
|
-
expect(Backdrop::App).to receive(:load_api).with url, json
|
12
|
+
it 'writes a file at the URL path containing the json' do
|
13
13
|
subject.build sample_input
|
14
|
+
expect(File.read(output_file)).to eq json
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
@@ -18,8 +19,8 @@ describe Backdrop::APIBuilder do
|
|
18
19
|
let(:sample_input) { build_list :example, 2, backdrop_url: url }
|
19
20
|
let(:json) { '[{"some":"data"},{"some":"data"}]' }
|
20
21
|
it 'tells the server to load the API array' do
|
21
|
-
expect(Backdrop::App).to receive(:load_api).with url, json
|
22
22
|
subject.build sample_input
|
23
|
+
expect(File.read(output_file)).to eq json
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
@@ -10,7 +10,6 @@ describe Backdrop do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
before do
|
13
|
-
Backdrop.clear
|
14
13
|
Backdrop.load sample_factory_data
|
15
14
|
end
|
16
15
|
|
@@ -31,4 +30,12 @@ describe Backdrop do
|
|
31
30
|
expect(last_response.body).to eq '[{"some":"data"},{"some":"data"}]'
|
32
31
|
end
|
33
32
|
end
|
33
|
+
|
34
|
+
context 'when there is no data for a route' do
|
35
|
+
let(:sample_factory_data) { build :example }
|
36
|
+
it 'gives status 404' do
|
37
|
+
get '/nothing'
|
38
|
+
expect(last_response.status).to eq 404
|
39
|
+
end
|
40
|
+
end
|
34
41
|
end
|