alephant-preview 0.3.9 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fcda4eb6c69ce0fb086ae7d9c213695497f1e79d
4
- data.tar.gz: 136476e63d5eff470c063e08e0928a3473835cf3
3
+ metadata.gz: cb29527d9bf9c048e248aa1aacb116c25db7f0ea
4
+ data.tar.gz: 2fd1eea531051f54534cb1074c338e3854c368c4
5
5
  SHA512:
6
- metadata.gz: af200493984a52bf0e820a57df296db0489ec9440a3ac89cd5b878c1c011ed6e4fd93a33c5cddcd222cd33bd5e0a695594bd5b02ae11257a6c9c7e202fc3a6ca
7
- data.tar.gz: c1460d492c879c0dc57e4747a2410272fa8a4232953a781872cd793453e3df0b8b1288d1c5d4ae9327cefe314ef306d66b121ff5641e1894216edd0b452c1a6d
6
+ metadata.gz: 41fceee23cfb06b4a574c71cb7576549cbb9dbcf6c73a293c3855bd5589c9890773702303396f6c55cc5a5fdd8cdd14e6341893465493373b60f2b26ba0cf91d
7
+ data.tar.gz: 8976cf2f8131f63a057bf99c3d9d82c1da9644c32861b296752aec66f0d9ece770619bbb611a6eb39ec3d0547cafe07cfcffc7bad2b2fa26e228068ea5a87233
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in alephant-preview.gemspec
4
4
  gemspec
data/Guardfile CHANGED
@@ -1,10 +1,10 @@
1
- guard 'rake', :task => 'spec' do
1
+ guard "rake", :task => "spec" do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
3
  watch(%r{^lib/.+\.rb$})
4
- watch('spec/spec_helper.rb')
5
- watch('spec/fixtures/.+$')
4
+ watch("spec/spec_helper.rb")
5
+ watch("spec/fixtures/.+$")
6
6
  end
7
7
 
8
- guard 'rake', :task => 'integration' do
8
+ guard "rake", :task => "integration" do
9
9
  watch(%r{^spec/integration/.+_spec\.rb$})
10
10
  end
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
- $:.unshift File.join(File.dirname(__FILE__), 'lib')
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "lib")
2
2
 
3
- require 'rspec/core/rake_task'
4
- require 'rake/rspec'
5
- require 'bundler/gem_tasks'
3
+ require "rspec/core/rake_task"
4
+ require "rake/rspec"
5
+ require "bundler/gem_tasks"
6
6
 
7
7
  task :default => :all
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.add_development_dependency "rspec"
21
21
  spec.add_development_dependency "rspec-nc"
22
22
  spec.add_development_dependency "rack-test"
23
- spec.add_development_dependency "guard"
23
+ spec.add_development_dependency "guard", "<= 1.0.3"
24
24
  spec.add_development_dependency "guard-rake"
25
25
  spec.add_development_dependency "pry"
26
26
  spec.add_development_dependency "bundler"
data/bin/alephant-preview CHANGED
@@ -1,20 +1,20 @@
1
1
  #!/usr/bin/env RUBYOPT=-Ku ruby
2
2
 
3
- require 'pathname'
4
- require 'trollop'
3
+ require "pathname"
4
+ require "trollop"
5
5
 
6
6
  root = Pathname.new(__FILE__).dirname.parent
7
- lib_path = (root + 'lib').realdirpath
7
+ lib_path = (root + "lib").realdirpath
8
8
  current_dir = File.join(Dir.pwd, "lib")
9
9
 
10
10
  $LOAD_PATH.unshift(lib_path)
11
11
  $LOAD_PATH.unshift(current_dir)
12
12
 
13
- require 'alephant/preview'
14
- require 'alephant/preview/tasks'
13
+ require "alephant/preview"
14
+ require "alephant/preview/tasks"
15
15
 
16
- SUB_COMMANDS = %w(preview)
17
- global_opts = Trollop::options do
16
+ SUB_COMMANDS = %w(preview).freeze
17
+ global_opts = Trollop.options do
18
18
  banner <<-EOS
19
19
  Static publishing to S3 based on SQS messages
20
20
  Usage:
@@ -30,10 +30,9 @@ end
30
30
  cmd = ARGV.shift # get the subcommand
31
31
  case cmd
32
32
  when nil
33
- Rake::Task['alephant:preview:go'].invoke
33
+ Rake::Task["alephant:preview:go"].invoke
34
34
  when "update"
35
- Rake::Task['alephant:preview:update'].invoke
35
+ Rake::Task["alephant:preview:update"].invoke
36
36
  else
37
- Trollop::die "unknown subcommand #{cmd.inspect}"
37
+ Trollop.die "unknown subcommand #{cmd.inspect}"
38
38
  end
39
-
@@ -8,7 +8,7 @@ module Alephant
8
8
  @fixtures = Dir.glob("#{base_path}/fixtures/*")
9
9
  end
10
10
 
11
- def get(uri)
11
+ def get(_uri)
12
12
  OpenStruct.new(
13
13
  :status => 200,
14
14
  :body => fixture
@@ -22,7 +22,6 @@ module Alephant
22
22
  raise "There isn't a fixture matching the request call, please add one" if path.nil?
23
23
  File.open(path).read
24
24
  end
25
-
26
25
  end
27
26
  end
28
27
  end
@@ -1,54 +1,69 @@
1
- require 'alephant/renderer/views/html'
2
- require 'alephant/renderer/views/json'
3
- require 'alephant/renderer/view_mapper'
4
- require 'alephant/publisher/request/data_mapper_factory'
5
- require 'alephant/publisher/request/data_mapper'
6
- require 'alephant/publisher/request/error'
7
-
8
- require 'alephant/support/parser'
9
- require 'alephant/preview/fixture_loader'
10
- require 'alephant/preview/template/base'
11
-
12
- require 'sinatra/base'
1
+ require "alephant/renderer/views/html"
2
+ require "alephant/renderer/views/json"
3
+ require "alephant/renderer/view_mapper"
4
+ require "alephant/publisher/request/data_mapper_factory"
5
+ require "alephant/publisher/request/data_mapper"
6
+ require "alephant/publisher/request/error"
7
+
8
+ require "alephant/support/parser"
9
+ require "alephant/preview/fixture_loader"
10
+ require "alephant/preview/template/base"
11
+
12
+ require "sinatra/base"
13
13
  require "sinatra/reloader"
14
- require 'faraday'
15
- require 'json'
16
- require 'uri'
14
+ require "faraday"
15
+ require "json"
16
+ require "uri"
17
17
 
18
18
  module Alephant
19
19
  module Preview
20
20
  class Server < Sinatra::Base
21
- set :bind, '0.0.0.0'
21
+ set :bind, "0.0.0.0"
22
22
 
23
23
  register Sinatra::Reloader
24
- also_reload 'components/*/models/*.rb'
25
- also_reload 'components/*/mapper.rb'
26
- also_reload 'components/shared/mappers/*.rb'
24
+ also_reload "components/*/models/*.rb"
25
+ also_reload "components/*/mapper.rb"
26
+ also_reload "components/shared/mappers/*.rb"
27
27
 
28
- BASE_LOCATION = "#{(ENV['BASE_LOCATION'] || Dir.pwd)}/components"
28
+ BASE_LOCATION = "#{(ENV['BASE_LOCATION'] || Dir.pwd)}/components".freeze
29
29
 
30
30
  before do
31
31
  response["Access-Control-Allow-Origin"] = "*"
32
32
  end
33
33
 
34
- get '/preview/:id/:template/:region/?:fixture?' do
34
+ get "/preview/:id/:template/:region/?:fixture?" do
35
35
  render_preview
36
36
  end
37
37
 
38
- get '/component/:template/?:fixture?' do
39
- params['id'] = find_id_from_template params['template']
40
- params['fixture'] = 'responsive' unless params['fixture']
38
+ get "/component/:template/?:fixture?" do
39
+ params["id"] = find_id_from_template params["template"]
40
+ params["fixture"] = "responsive" unless params["fixture"]
41
41
  render_component
42
42
  end
43
43
 
44
- get '/component/:id/:template/?:fixture?' do
44
+ get "/component/:id/:template/?:fixture?" do
45
45
  render_component
46
46
  end
47
47
 
48
+ get "/components/batch" do
49
+ batch_components = []
50
+
51
+ get_batched_components.each do |component|
52
+ component = component[1]
53
+ options = component.fetch("options", {})
54
+ params["template"] = component.fetch("component")
55
+ params["id"] = find_id_from_template params["template"]
56
+ params["fixture"] = options.fetch("fixture", "responsive") || "responsive"
57
+ batch_components << render_batch_component
58
+ end
59
+
60
+ { :components => batch_components }.to_json
61
+ end
62
+
48
63
  post "/components/batch" do
49
64
  batch_components = []
50
65
 
51
- batched_components.each do |component|
66
+ post_batched_components.each do |component|
52
67
  options = symbolize component.fetch(:options, {})
53
68
  params["template"] = component.fetch(:component)
54
69
  params["id"] = find_id_from_template params["template"]
@@ -59,21 +74,19 @@ module Alephant
59
74
  { :components => batch_components }.to_json
60
75
  end
61
76
 
62
- get '/status' do
63
- 'ok'
77
+ get "/status" do
78
+ "ok"
64
79
  end
65
80
 
66
81
  not_found do
67
- 'Not found'
82
+ "Not found"
68
83
  end
69
84
 
70
85
  def find_id_from_template(template)
71
- files = Dir.glob(BASE_LOCATION + '/**/models/*')
86
+ files = Dir.glob(BASE_LOCATION + "/**/models/*")
72
87
  file = files.select! { |file| file.include? "/#{template}.rb" }.pop
73
88
 
74
- if file.nil?
75
- halt(404)
76
- end
89
+ halt(404) if file.nil?
77
90
 
78
91
  result = /#{BASE_LOCATION}\/(\w+)/.match(file)
79
92
  result[1]
@@ -105,10 +118,18 @@ module Alephant
105
118
  JSON.parse(request.body.read, :symbolize_names => true) || {}
106
119
  end
107
120
 
108
- def batched_components
121
+ def query_string
122
+ Rack::Utils.parse_nested_query(request.query_string)
123
+ end
124
+
125
+ def post_batched_components
109
126
  request_body.fetch(:components, [])
110
127
  end
111
128
 
129
+ def get_batched_components
130
+ query_string.fetch("components", [])
131
+ end
132
+
112
133
  def model
113
134
  require model_location
114
135
  Alephant::Renderer::Views.get_registered_class(template).new(fixture_data)
@@ -119,27 +140,27 @@ module Alephant
119
140
  end
120
141
 
121
142
  def model_location
122
- File.join(base_path, 'models', "#{template}.rb")
143
+ File.join(base_path, "models", "#{template}.rb")
123
144
  end
124
145
 
125
146
  def template
126
- params['template']
147
+ params["template"]
127
148
  end
128
149
 
129
150
  def region
130
- params['region']
151
+ params["region"]
131
152
  end
132
153
 
133
154
  def id
134
- params['id']
155
+ params["id"]
135
156
  end
136
157
 
137
158
  def fixture
138
- params['fixture'] || id
159
+ params["fixture"] || id
139
160
  end
140
161
 
141
162
  def fixture_data
142
- if File.exists? "#{base_path}/mapper.rb"
163
+ if File.exist? "#{base_path}/mapper.rb"
143
164
  loader = Alephant::Preview::FixtureLoader.new(base_path)
144
165
  data_mapper_factory = Alephant::Publisher::Request::DataMapperFactory.new(loader, BASE_LOCATION)
145
166
  begin
@@ -152,7 +173,7 @@ module Alephant
152
173
  end
153
174
  else
154
175
  msg = Struct.new(:body)
155
- .new(raw_fixture_data)
176
+ .new(raw_fixture_data)
156
177
  parser.parse msg
157
178
  end
158
179
  end
@@ -1,5 +1,5 @@
1
- require 'alephant/preview/server'
2
- require 'alephant/preview/template'
1
+ require "alephant/preview/server"
2
+ require "alephant/preview/template"
3
3
 
4
4
  namespace :alephant do
5
5
  namespace :preview do
@@ -13,4 +13,3 @@ namespace :alephant do
13
13
  end
14
14
  end
15
15
  end
16
-
@@ -1,8 +1,7 @@
1
- require 'rake'
2
- require 'pathname'
1
+ require "rake"
2
+ require "pathname"
3
3
 
4
4
  root = Pathname.new(__FILE__).dirname
5
- task_path = (root + 'tasks').realdirpath
5
+ task_path = (root + "tasks").realdirpath
6
6
 
7
7
  Dir["#{task_path}/**/*.rake"].each { |ext| load ext } if defined?(Rake)
8
-
@@ -1,19 +1,18 @@
1
- require 'mustache'
1
+ require "mustache"
2
2
 
3
3
  module Alephant
4
4
  module Preview
5
5
  module Template
6
-
7
6
  class Base < Mustache
8
7
  attr_accessor :regions
9
8
 
10
9
  def initialize(regions, template_location)
11
- @regions=regions
10
+ @regions = regions
12
11
  self.template_file = template_location
13
12
  end
14
13
 
15
14
  def static_host
16
- ENV['STATIC_HOST'] || 'localhost:8000'
15
+ ENV["STATIC_HOST"] || "localhost:8000"
17
16
  end
18
17
 
19
18
  def method_missing(name, *args, &block)
@@ -26,7 +25,7 @@ module Alephant
26
25
  end
27
26
 
28
27
  def region(components)
29
- if components.kind_of?(Array)
28
+ if components.is_a?(Array)
30
29
  components.join
31
30
  else
32
31
  components
@@ -34,13 +33,12 @@ module Alephant
34
33
  end
35
34
 
36
35
  def valid_regions
37
- self.template.tokens.find_all { |token|
36
+ template.tokens.find_all do |token|
38
37
  token.is_a?(Array) && token[0] == :mustache
39
- }.map{ |token|
38
+ end.map do |token|
40
39
  token[2][2][0].to_s
41
- }
40
+ end
42
41
  end
43
-
44
42
  end
45
43
  end
46
44
  end
@@ -1,5 +1,5 @@
1
- require 'faraday'
2
- require 'uri'
1
+ require "faraday"
2
+ require "uri"
3
3
 
4
4
  module Alephant
5
5
  module Preview
@@ -13,9 +13,9 @@ module Alephant
13
13
  end
14
14
 
15
15
  def update(template_location)
16
- File.open(template_location, 'w') { |file|
16
+ File.open(template_location, "w") do |file|
17
17
  file.write(template)
18
- }
18
+ end
19
19
  end
20
20
 
21
21
  def host
@@ -27,22 +27,22 @@ module Alephant
27
27
  end
28
28
 
29
29
  def uri
30
- return @uri if not @uri.nil?
30
+ return @uri unless @uri.nil?
31
31
 
32
- uri_from_env = ENV['PREVIEW_TEMPLATE_URL']
32
+ uri_from_env = ENV["PREVIEW_TEMPLATE_URL"]
33
33
  raise Exception.new("PREVIEW_TEMPLATE_URL is unset!") if uri_from_env.nil?
34
34
 
35
35
  @uri = URI(uri_from_env)
36
36
  end
37
37
 
38
38
  def apply_static_host_regex_to(string)
39
- string.gsub(static_host_regex, '{{{static_host}}}')
39
+ string.gsub(static_host_regex, "{{{static_host}}}")
40
40
  end
41
41
 
42
42
  def static_host_regex
43
- return @static_host_regex if not @static_host_regex.nil?
43
+ return @static_host_regex unless @static_host_regex.nil?
44
44
 
45
- static_host_regex_from_env = ENV['STATIC_HOST_REGEX']
45
+ static_host_regex_from_env = ENV["STATIC_HOST_REGEX"]
46
46
  raise Exception.new("STATIC_HOST_REGEX is unset!") if static_host_regex_from_env.nil?
47
47
 
48
48
  @static_host_regex = Regexp.new(static_host_regex_from_env)
@@ -1,11 +1,11 @@
1
- require 'alephant/preview/template/base'
2
- require 'alephant/preview/template/updater'
1
+ require "alephant/preview/template/base"
2
+ require "alephant/preview/template/updater"
3
3
 
4
4
  module Alephant
5
5
  module Preview
6
6
  module Template
7
7
  def self.path
8
- ENV['PREVIEW_TEMPLATE_PATH'] || "#{Dir.pwd}/components/lib"
8
+ ENV["PREVIEW_TEMPLATE_PATH"] || "#{Dir.pwd}/components/lib"
9
9
  end
10
10
 
11
11
  def self.update(template_location)
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Preview
3
- VERSION = "0.3.9"
3
+ VERSION = "0.4.0".freeze
4
4
  end
5
5
  end
@@ -1,7 +1,6 @@
1
- lib = File.expand_path('../..', __FILE__)
1
+ lib = File.expand_path("../..", __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  require "alephant/preview/version"
5
5
  require "alephant/preview/server"
6
6
  require "alephant/preview/template"
7
-
@@ -1,13 +1,12 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Alephant::Preview::FixtureLoader do
4
- let (:fixtures_base) { File.join(File.dirname(__FILE__), 'fixtures') }
5
- let (:base_path) { File.join(fixtures_base, 'components', 'bar') }
4
+ let (:fixtures_base) { File.join(File.dirname(__FILE__), "fixtures") }
5
+ let (:base_path) { File.join(fixtures_base, "components", "bar") }
6
6
  subject { described_class.new(base_path) }
7
7
 
8
8
  describe ".new" do
9
-
10
- context 'using valid parameters' do
9
+ context "using valid parameters" do
11
10
  let (:expected) { described_class }
12
11
 
13
12
  specify { expect(subject).to be_a expected }
@@ -15,22 +14,21 @@ describe Alephant::Preview::FixtureLoader do
15
14
  end
16
15
 
17
16
  describe "#get" do
18
- let (:uri) { '/test/uri' }
17
+ let (:uri) { "/test/uri" }
19
18
 
20
- context 'with a single fixture' do
21
- let (:fixture_data) { File.open(File.join(fixtures_base, 'components', 'bar', 'fixtures', 'bar.json')).read }
22
- specify { expect(subject.get(uri).body).to eq fixture_data}
19
+ context "with a single fixture" do
20
+ let (:fixture_data) { File.open(File.join(fixtures_base, "components", "bar", "fixtures", "bar.json")).read }
21
+ specify { expect(subject.get(uri).body).to eq fixture_data }
23
22
  end
24
23
 
25
- context 'with multiple fixtures' do
26
- let (:base_path) { File.join(fixtures_base, 'components', 'baz') }
24
+ context "with multiple fixtures" do
25
+ let (:base_path) { File.join(fixtures_base, "components", "baz") }
27
26
  let (:fixture_data) do
28
- fixtures = Dir.glob(File.join(fixtures_base, 'components', 'baz', 'fixtures', '*'))
27
+ fixtures = Dir.glob(File.join(fixtures_base, "components", "baz", "fixtures", "*"))
29
28
  fixtures.map { |fixture| File.open(fixture).read }
30
29
  end
31
30
 
32
- context 'using a valid amount of fixtures' do
33
-
31
+ context "using a valid amount of fixtures" do
34
32
  it "should return each fixture on subsequent calls" do
35
33
  (0..2).each do |index|
36
34
  expect(subject.get(uri).body).to eq fixture_data[index]
@@ -40,7 +38,7 @@ describe Alephant::Preview::FixtureLoader do
40
38
 
41
39
  context "using incorrect amount of fixtures" do
42
40
  it "should raise an exception" do
43
- (0..2).each { |index| subject.get(uri).body }
41
+ (0..2).each { |_index| subject.get(uri).body }
44
42
  expect do
45
43
  subject.get(uri).body
46
44
  end.to raise_error(
@@ -1,7 +1,7 @@
1
1
  class BarMapper < Alephant::Publisher::Request::DataMapper
2
2
  def data
3
3
  {
4
- :bar => 'data mapped content'
4
+ :bar => "data mapped content"
5
5
  }
6
6
  end
7
7
  end
@@ -1,4 +1,4 @@
1
- require 'alephant/renderer/views/html'
1
+ require "alephant/renderer/views/html"
2
2
 
3
3
  module MyApp
4
4
  class Bar < ::Alephant::Renderer::Views::Html
@@ -2,7 +2,7 @@ require "json"
2
2
 
3
3
  class BazMapper < Alephant::Publisher::Request::DataMapper
4
4
  def data
5
- (1..3).reduce({}) do |accum, index|
5
+ (1..3).reduce({}) do |accum, _index|
6
6
  accum.merge(
7
7
  JSON.parse(
8
8
  get("/test/call").body
@@ -1,4 +1,4 @@
1
- require 'alephant/renderer/views/html'
1
+ require "alephant/renderer/views/html"
2
2
 
3
3
  module MyApp
4
4
  class Baz < ::Alephant::Renderer::Views::Html
@@ -1,4 +1,4 @@
1
- require 'alephant/renderer/views/html'
1
+ require "alephant/renderer/views/html"
2
2
 
3
3
  module MyApp
4
4
  class Foo < ::Alephant::Renderer::Views::Html
@@ -1,55 +1,51 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Alephant::Preview::Server do
4
4
  include Rack::Test::Methods
5
5
  let (:app) { subject }
6
6
 
7
- describe 'preview endpoint (GET /preview/{id}/{template}/{region}/{fixture})' do
8
-
9
- describe 'content' do
10
-
11
- context 'with valid data' do
7
+ describe "preview endpoint (GET /preview/{id}/{template}/{region}/{fixture})" do
8
+ describe "content" do
9
+ context "with valid data" do
12
10
  before(:each) do
13
11
  get "/preview/#{id}/#{template}/#{region}/#{fixture}"
14
12
  end
15
- let (:id) { 'foo' }
13
+ let (:id) { "foo" }
16
14
  let (:template) { id }
17
15
  let (:fixture) { id }
18
- let (:region) { 'page_region' }
16
+ let (:region) { "page_region" }
19
17
 
20
18
  specify { expect(last_response.body).to eq("topcontent\nbottom\n") }
21
19
  end
22
20
  end
23
21
  end
24
22
 
25
- describe 'component endpoint (GET /component/{id}/{template}/{fixture})' do
26
-
27
- describe 'content' do
23
+ describe "component endpoint (GET /component/{id}/{template}/{fixture})" do
24
+ describe "content" do
28
25
  before(:each) do
29
26
  get "/component/#{id}/#{template}/#{fixture}"
30
27
  end
31
28
  let (:response) { last_response.body.chomp }
32
29
 
33
- context 'without a data mapper' do
34
- let (:id) { 'foo' }
30
+ context "without a data mapper" do
31
+ let (:id) { "foo" }
35
32
  let (:template) { id }
36
33
  let (:fixture) { id }
37
34
 
38
35
  specify { expect(response).to eq("content") }
39
36
  end
40
37
 
41
- context 'with a data mapper' do
42
-
43
- context 'using a single fixture' do
44
- let (:id) { 'bar' }
38
+ context "with a data mapper" do
39
+ context "using a single fixture" do
40
+ let (:id) { "bar" }
45
41
  let (:template) { id }
46
42
  let (:fixture) { id }
47
43
 
48
44
  specify { expect(response).to eq("data mapped content") }
49
45
  end
50
46
 
51
- context 'using multiple fixtures' do
52
- let (:id) { 'baz' }
47
+ context "using multiple fixtures" do
48
+ let (:id) { "baz" }
53
49
  let (:template) { id }
54
50
  let (:fixture) { id }
55
51
 
@@ -59,8 +55,76 @@ describe Alephant::Preview::Server do
59
55
  end
60
56
  end
61
57
 
62
- describe "component batch endpoint (POST /components/batch" do
58
+ describe 'component batch endpoint (GET /components/batch?components[#{id}]=#{id})' do
59
+ describe "content" do
60
+ before(:each) do
61
+ get "/components/batch?components[#{id}][component]=#{id}&components[#{id}][options][fixture]=#{id}"
62
+ end
63
+
64
+ let (:response) { JSON.parse(last_response.body.chomp, :symbolize_names => true) }
65
+
66
+ context "without a data mapper" do
67
+ let (:id) { "foo" }
68
+ let (:template) { id }
69
+ let (:fixture) { id }
70
+
71
+ expected = {
72
+ :components => [
73
+ {
74
+ :component => "foo",
75
+ :options => {},
76
+ :status => 200,
77
+ :body => "content\n"
78
+ }
79
+ ]
80
+ }
81
+
82
+ specify { expect(response).to eq(expected) }
83
+ end
84
+
85
+ context "with a data mapper" do
86
+ context "using a single fixture" do
87
+ let (:id) { "bar" }
88
+ let (:template) { id }
89
+ let (:fixture) { id }
90
+
91
+ expected = {
92
+ :components => [
93
+ {
94
+ :component => "bar",
95
+ :options => {},
96
+ :status => 200,
97
+ :body => "data mapped content\n"
98
+ }
99
+ ]
100
+ }
101
+
102
+ specify { expect(response).to eq(expected) }
103
+ end
104
+
105
+ context "using multiple fixtures" do
106
+ let (:id) { "baz" }
107
+ let (:template) { id }
108
+ let (:fixture) { id }
109
+
110
+ expected = {
111
+ :components => [
112
+ {
113
+ :component => "baz",
114
+ :options => {},
115
+ :status => 200,
116
+ :body => "multiple endpoint data mapped content\n"
117
+ }
118
+ ]
119
+ }
120
+
121
+ specify { expect(response).to eq(expected) }
122
+ end
123
+ end
124
+ end
125
+ end
63
126
 
127
+ describe "component batch endpoint (POST /components/batch" do
64
128
  describe "content" do
65
129
  before(:each) do
66
130
  post "/components/batch", {
@@ -95,7 +159,6 @@ describe Alephant::Preview::Server do
95
159
  end
96
160
 
97
161
  context "with a data mapper" do
98
-
99
162
  context "using a single fixture" do
100
163
  let (:id) { "bar" }
101
164
 
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,11 @@
1
- $: << File.join(File.dirname(__FILE__),"..", "lib")
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "..", "lib")
2
2
 
3
- FIXTURE_PATH = File.join(File.dirname(__FILE__),'fixtures')
3
+ FIXTURE_PATH = File.join(File.dirname(__FILE__), "fixtures")
4
4
 
5
- ENV['BASE_LOCATION'] = FIXTURE_PATH
6
- ENV['PREVIEW_TEMPLATE_PATH'] = File.join(FIXTURE_PATH, 'lib')
7
- ENV['RACK_ENV'] = 'test'
5
+ ENV["BASE_LOCATION"] = FIXTURE_PATH
6
+ ENV["PREVIEW_TEMPLATE_PATH"] = File.join(FIXTURE_PATH, "lib")
7
+ ENV["RACK_ENV"] = "test"
8
8
 
9
- require 'pry'
10
- require 'rack/test'
11
- require 'alephant/preview'
9
+ require "pry"
10
+ require "rack/test"
11
+ require "alephant/preview"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-preview
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BBC News
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-07 00:00:00.000000000 Z
11
+ date: 2016-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -55,17 +55,17 @@ dependencies:
55
55
  - !ruby/object:Gem::Dependency
56
56
  requirement: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - '>='
58
+ - - <=
59
59
  - !ruby/object:Gem::Version
60
- version: '0'
60
+ version: 1.0.3
61
61
  name: guard
62
62
  prerelease: false
63
63
  type: :development
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - <=
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 1.0.3
69
69
  - !ruby/object:Gem::Dependency
70
70
  requirement: !ruby/object:Gem::Requirement
71
71
  requirements: