backdrop 0.3.1 → 0.4.0
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/.ruby-version +1 -1
- data/.travis.yml +4 -3
- data/Gemfile +1 -1
- data/README.md +2 -2
- data/backdrop.gemspec +2 -2
- data/lib/backdrop.rb +3 -2
- data/lib/backdrop/api_builder.rb +17 -16
- data/lib/backdrop/version.rb +1 -1
- data/spec/backdrop/api_builder_spec.rb +16 -2
- data/spec/backdrop/configuration_spec.rb +0 -1
- data/spec/backdrop_spec.rb +27 -2
- data/spec/integration/backdrop_end_to_end_spec.rb +29 -14
- data/spec/spec_helper.rb +0 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjJkMDFkMzkzNTMwNzUzNWQ3ODIxMDJjZTQ0NTMxMDkyYzQ5ZjYzNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NGQ0YWU4NzcyOGU0MWY1ZTlkNGRlMDdjZDViM2JjOGRkZGRjMmZjMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MWZhNDFhMjBiNDA0ZmVkMjIxZGE2NGYzYjM4OTVmMjNmZDZiZGU3ZDY5OTEz
|
10
|
+
YjllMGQ3ZjIyM2IxYjk0ODg3NWM0ZGRmYjZhODg1Yjc5MDMzZmRiN2M5N2Y5
|
11
|
+
MjNlYTI5OWFmODFlNmNhNDJiOWQxNDA2OTExOWI1ZDcwZjc2Mjk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzliMjRlMzA3MTIwZTNlMzJhYjU2N2NmZDNlM2I2YjhkYzE0M2RkNTIyOTFl
|
14
|
+
ZTFkNTg2ZjFjYmFkZGY3N2RhNjIxM2Y5ZTViNTAwOGU5Nzc4YTRkZDY5Yjky
|
15
|
+
MjJkZWExMzM5MGZiMTk4MzlkMTRhNjkxMDczMTM4MTUyOWQ5Mzk=
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
1.9.3-p551
|
data/.travis.yml
CHANGED
@@ -10,8 +10,9 @@ os:
|
|
10
10
|
- linux
|
11
11
|
- osx
|
12
12
|
rvm:
|
13
|
-
-
|
14
|
-
-
|
13
|
+
- ruby-head
|
14
|
+
- jruby-1.7.19
|
15
|
+
- 1.9.3
|
15
16
|
script:
|
16
17
|
- bundle exec rake
|
17
18
|
deploy:
|
@@ -22,4 +23,4 @@ deploy:
|
|
22
23
|
tags: true
|
23
24
|
all_branches: true
|
24
25
|
repo: tpbowden/backdrop
|
25
|
-
rvm:
|
26
|
+
rvm: 1.9.3
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -49,7 +49,7 @@ Backdrop is most easily used alongside [FactoryGirl](https://github.com/thoughtb
|
|
49
49
|
|
50
50
|
You can then use `Backdrop.load(FactoryGirl.build :example)` to create the following JSON at `/backdrop/example`:
|
51
51
|
|
52
|
-
|
52
|
+
{"name":"example"}
|
53
53
|
|
54
54
|
Similarly, `Backdrop.load(FactoryGirl.build_list :example, 2)` would create the following JSON:
|
55
55
|
|
@@ -59,4 +59,4 @@ Similarly, `Backdrop.load(FactoryGirl.build_list :example, 2)` would create the
|
|
59
59
|
Dependencies
|
60
60
|
------------
|
61
61
|
|
62
|
-
* Ruby >=
|
62
|
+
* Ruby >= 1.9.3
|
data/backdrop.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.email = 'tom.b1992@gmail.com'
|
15
15
|
s.homepage = 'http://github.com/tpbowden/backdrop'
|
16
16
|
s.license = 'MIT'
|
17
|
-
s.required_ruby_version = '>=
|
18
|
-
s.add_dependency 'rake', '~> 10.1'
|
17
|
+
s.required_ruby_version = '>= 1.9.3'
|
19
18
|
s.add_dependency 'sinatra', '~> 1.4'
|
19
|
+
s.add_dependency 'backports', '~> 3.6'
|
20
20
|
end
|
data/lib/backdrop.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'backports/2.0.0/stdlib/ostruct'
|
1
2
|
require 'backdrop/configuration'
|
2
3
|
require 'backdrop/api_builder'
|
3
4
|
require 'backdrop/app'
|
@@ -15,8 +16,8 @@ module Backdrop
|
|
15
16
|
yield(configuration) if block_given?
|
16
17
|
end
|
17
18
|
|
18
|
-
def self.load(input)
|
19
|
-
APIBuilder.new.build input
|
19
|
+
def self.load(input, url = nil)
|
20
|
+
APIBuilder.new(url).build input
|
20
21
|
end
|
21
22
|
|
22
23
|
def self.clear
|
data/lib/backdrop/api_builder.rb
CHANGED
@@ -4,34 +4,35 @@ require 'backdrop/app'
|
|
4
4
|
|
5
5
|
module Backdrop
|
6
6
|
class APIBuilder
|
7
|
+
def initialize(default_url = nil)
|
8
|
+
@config = Backdrop.configuration
|
9
|
+
@url = default_url
|
10
|
+
end
|
11
|
+
|
7
12
|
def build(input)
|
13
|
+
hashes = Array(input).map(&:to_h)
|
14
|
+
url = extract_url(hashes)
|
15
|
+
|
8
16
|
if input.respond_to?(:map)
|
9
|
-
|
17
|
+
write_api(@url || url, hashes)
|
10
18
|
else
|
11
|
-
|
19
|
+
write_api(@url || url, hashes.first)
|
12
20
|
end
|
13
21
|
end
|
14
22
|
|
15
23
|
private
|
16
24
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
url = record.delete_field 'backdrop_url'
|
21
|
-
record.to_h
|
25
|
+
def extract_url(hashes)
|
26
|
+
hashes.reduce(nil) do |_, record|
|
27
|
+
record.delete :backdrop_url
|
22
28
|
end
|
23
|
-
write_api(url, JSON.generate(formatted_data))
|
24
|
-
end
|
25
|
-
|
26
|
-
def build_single(input)
|
27
|
-
url = input.delete_field('backdrop_url')
|
28
|
-
write_api(url, JSON.generate(input.to_h))
|
29
29
|
end
|
30
30
|
|
31
|
-
def write_api(url,
|
32
|
-
|
31
|
+
def write_api(url, hashes)
|
32
|
+
base_dir = @config.output_dir
|
33
|
+
file = "#{File.join(base_dir, url)}.json"
|
33
34
|
FileUtils.mkdir_p(File.dirname(file))
|
34
|
-
File.write(file,
|
35
|
+
File.write(file, JSON.generate(hashes))
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
data/lib/backdrop/version.rb
CHANGED
@@ -9,7 +9,8 @@ describe Backdrop::APIBuilder do
|
|
9
9
|
context 'when the input is a single item' do
|
10
10
|
let(:sample_input) { build :example, backdrop_url: url }
|
11
11
|
let(:json) { '{"some":"data"}' }
|
12
|
-
|
12
|
+
|
13
|
+
it 'writes a JSON file at the URL path' do
|
13
14
|
subject.build sample_input
|
14
15
|
expect(File.read(output_file)).to eq json
|
15
16
|
end
|
@@ -18,7 +19,20 @@ describe Backdrop::APIBuilder do
|
|
18
19
|
context 'when the input is an array of items' do
|
19
20
|
let(:sample_input) { build_list :example, 2, backdrop_url: url }
|
20
21
|
let(:json) { '[{"some":"data"},{"some":"data"}]' }
|
21
|
-
|
22
|
+
|
23
|
+
it 'writes a JSON file at the URL path' do
|
24
|
+
subject.build sample_input
|
25
|
+
expect(File.read(output_file)).to eq json
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when the URL is specified' do
|
30
|
+
let(:sample_input) { build :example }
|
31
|
+
let(:json) { '{"some":"data"}' }
|
32
|
+
|
33
|
+
subject { described_class.new(url) }
|
34
|
+
|
35
|
+
it 'writes a JSON file at the URL path' do
|
22
36
|
subject.build sample_input
|
23
37
|
expect(File.read(output_file)).to eq json
|
24
38
|
end
|
data/spec/backdrop_spec.rb
CHANGED
@@ -21,6 +21,7 @@ describe Backdrop do
|
|
21
21
|
|
22
22
|
describe '.reset' do
|
23
23
|
let!(:subject) { Backdrop.configuration }
|
24
|
+
|
24
25
|
it 'resets all configuration' do
|
25
26
|
Backdrop.reset
|
26
27
|
expect(Backdrop.configuration).to_not eq subject
|
@@ -29,11 +30,35 @@ describe Backdrop do
|
|
29
30
|
|
30
31
|
describe '.load' do
|
31
32
|
let(:input) { %w('some', 'data') }
|
33
|
+
let(:builder) { double :builder, build: true }
|
34
|
+
|
35
|
+
before do
|
36
|
+
allow(Backdrop::APIBuilder)
|
37
|
+
.to receive(:new).and_return builder
|
38
|
+
end
|
39
|
+
|
32
40
|
it 'delegates to the Backdrop API Builder' do
|
33
|
-
expect(
|
34
|
-
.to receive_message_chain('new.build').with input
|
41
|
+
expect(builder).to receive(:build).with input
|
35
42
|
described_class.load input
|
36
43
|
end
|
44
|
+
|
45
|
+
context 'when the Backdrop URL is specified' do
|
46
|
+
it 'delegates with the URL' do
|
47
|
+
expect(Backdrop::APIBuilder)
|
48
|
+
.to receive(:new).with 'a/url'
|
49
|
+
|
50
|
+
described_class.load input, 'a/url'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when the Backdrop URL is implicit' do
|
55
|
+
it 'delegates with a nil URL' do
|
56
|
+
expect(Backdrop::APIBuilder)
|
57
|
+
.to receive(:new).with nil
|
58
|
+
|
59
|
+
described_class.load input
|
60
|
+
end
|
61
|
+
end
|
37
62
|
end
|
38
63
|
|
39
64
|
describe '.clear' do
|
@@ -9,29 +9,44 @@ describe Backdrop do
|
|
9
9
|
Backdrop::App
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
context 'when the route is implicit' do
|
13
|
+
before do
|
14
|
+
Backdrop.load sample_factory_data
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
context 'when it is a single object' do
|
18
|
+
let(:sample_factory_data) { build :example }
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
it 'builds an API based on factory girl data' do
|
21
|
+
get '/example/data'
|
22
|
+
expect(last_response.body).to eq '{"some":"data"}'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when it is an array of objects' do
|
27
|
+
let(:sample_factory_data) { build_list :example, 2 }
|
28
|
+
|
29
|
+
it 'builds an API based on the array of factory girl data' do
|
30
|
+
get '/example/data'
|
31
|
+
expect(last_response.body).to eq '[{"some":"data"},{"some":"data"}]'
|
32
|
+
end
|
22
33
|
end
|
23
34
|
end
|
24
35
|
|
25
|
-
context 'when
|
26
|
-
let(:sample_factory_data) {
|
36
|
+
context 'when the route is explicit' do
|
37
|
+
let(:sample_factory_data) { build :example }
|
38
|
+
|
39
|
+
before do
|
40
|
+
Backdrop.load sample_factory_data, 'my/custom/url'
|
41
|
+
end
|
27
42
|
|
28
|
-
it 'builds an API based on
|
29
|
-
get '/
|
30
|
-
expect(last_response.body).to eq '
|
43
|
+
it 'builds an API based on factory girl data' do
|
44
|
+
get 'my/custom/url'
|
45
|
+
expect(last_response.body).to eq '{"some":"data"}'
|
31
46
|
end
|
32
47
|
end
|
33
48
|
|
34
|
-
context 'when
|
49
|
+
context 'when the route does not exist' do
|
35
50
|
let(:sample_factory_data) { build :example }
|
36
51
|
it 'gives status 404' do
|
37
52
|
get '/nothing'
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backdrop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Bowden
|
@@ -11,33 +11,33 @@ cert_chain: []
|
|
11
11
|
date: 2014-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: sinatra
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.4'
|
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: '1.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: backports
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3.6'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '3.6'
|
41
41
|
description: ! "Create and host fixture generation based on simple ruby\n objects
|
42
42
|
for use in local integration testing against\n multiple remote
|
43
43
|
APIs"
|
@@ -81,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
81
|
requirements:
|
82
82
|
- - ! '>='
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
84
|
+
version: 1.9.3
|
85
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ! '>='
|
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|
91
91
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.4.
|
92
|
+
rubygems_version: 2.4.5
|
93
93
|
signing_key:
|
94
94
|
specification_version: 4
|
95
95
|
summary: JSON Fixture generation
|