Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
pikesley committed Jan 3, 2016
1 parent 0989cdb commit 8b23654
Show file tree
Hide file tree
Showing 7 changed files with 896 additions and 11 deletions.
10 changes: 5 additions & 5 deletions features/json.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ Feature: Get JSON
Background:
Given I send and accept JSON

Scenario: Get JSON for a repo
When I send a GET request to "snake"
Then the response status should be "200"
And the JSON response should have "$[0]name" with the text "feeds"

Scenario: Get JSON for a dataset
When I send a GET request to "catface/flea-treatment"
Then the response status should be "200"
And the JSON response should have "$.title" with the text "Flea Treatment"
And the JSON response should have "$.data[0].Date" with the text "2015-12-03"

Scenario: Get JSON for a repo
When I send a GET request to "snake"
Then the response status should be "200"
And the JSON response should have "$[0]name" with the text "feeds"
7 changes: 7 additions & 0 deletions features/step_definitions/dashboard_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Given /^I accept CSV$/ do
add_headers(
{
'Accept' => 'text/csv'
}
)
end
870 changes: 870 additions & 0 deletions features/support/vcr/Get_JSON/Get_JSON_for_a_repo.yml

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions lib/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class App < Sinatra::Base
respond_to do |wants|
headers 'Vary' => 'Accept'


wants.html do
@title = 'Catface'
erb :grid, layout: :default
Expand All @@ -50,7 +49,7 @@ class App < Sinatra::Base
}.map { |dataset|
{
name: dataset['id'],
url: "#{request.scheme}://#{request.env['HTTP_HOST']}/#{params[:repo]}/#{dataset['id']}"
url: "#{request.scheme}://#{request.env['HTTP_HOST']}/#{params[:repo]}/#{dataset['id']}.json"
}
}.to_json
end
Expand All @@ -66,6 +65,12 @@ class App < Sinatra::Base
Cleaner.sanitized_data(url).to_json
end

wants.csv do
puts "WTF"
require "pry" ; binding.pry

end

wants.html do
erb :dataset, layout: :default
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dashboard/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def self.sanitized_data url
j['id'] = trim d['name']
j['date-field'] = l.dig(d['repo'], 'datasets', trim(d['name']), 'date-field') || 'Date'
j['type'] = l.dig(d['repo'], 'datasets', trim(d['name']), 'type') || 'latest'
j['url'] = d['_links']['html']
j['source-url'] = d['_links']['html']
sf = l.dig(d['repo'], 'datasets', trim(d['name']), 'special-fields')
j['special_fields'] = sf if sf
j['data'] = jsonise d['data']
Expand Down
5 changes: 4 additions & 1 deletion lib/dashboard/racks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ class App < Sinatra::Base
conneg.set :fallback, :html
conneg.ignore('/css/')
conneg.ignore('/js/')
conneg.provide([:html, :json])
conneg.provide [
:html,
:json
]
end

before do
Expand Down
4 changes: 2 additions & 2 deletions spec/cleaner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module Dashboard
'name' => 'length.csv',
'id' => 'length',
'type' => 'graph',
'url' => 'https://github.com/pikesley/snake-data/blob/master/length.csv',
'source-url' => 'https://github.com/pikesley/snake-data/blob/master/length.csv',
'data' => [
{
'Date' => '2014-09-30',
Expand Down Expand Up @@ -120,7 +120,7 @@ module Dashboard
'name' => 'flea-treatment.csv',
'id' => 'flea-treatment',
'type' => 'latest',
'url' => 'https://github.com/pikesley/catface/blob/master/flea-treatment.csv',
'source-url' => 'https://github.com/pikesley/catface/blob/master/flea-treatment.csv',
'data' => [
{
'Date' => '2015-12-03'
Expand Down

0 comments on commit 8b23654

Please sign in to comment.