diff --git a/.travis.yml b/.travis.yml index a26bf33..36dbd57 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ sudo: required language: ruby +cache: bundler services: - docker diff --git a/app/controllers/import_controller.rb b/app/controllers/import_controller.rb new file mode 100644 index 0000000..247a420 --- /dev/null +++ b/app/controllers/import_controller.rb @@ -0,0 +1,11 @@ +class ImportController < ApplicationController + skip_before_filter :verify_authenticity_token, :only => [:new_papers_callback] + + def new_papers_callback + require 'open-uri' + api_key = Rails.application.config_for(:morph)["key"] + uri = URI.parse("https://api.morph.io/jrlover/city_council_leipzig_recent_papers/data.json?key=#{api_key}&query=select%20*%20from%20%27data%27") + Paper.import_from_json(uri.read) + render :nothing => true + end +end \ No newline at end of file diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb deleted file mode 100644 index d153c7a..0000000 --- a/app/controllers/sessions_controller.rb +++ /dev/null @@ -1,19 +0,0 @@ -class SessionsController < ApplicationController - def create - if user = User.find_or_create_from_auth_hash(auth_hash) - session[:user_id] = user.id - end - redirect_to root_path - end - - def destroy - reset_session - redirect_to root_path - end - - protected - - def auth_hash - request.env['omniauth.auth'] - end -end diff --git a/app/views/layouts/application.html.slim b/app/views/layouts/application.html.slim index 9d19b35..375f103 100644 --- a/app/views/layouts/application.html.slim +++ b/app/views/layouts/application.html.slim @@ -11,7 +11,7 @@ html .row .small-12.columns .clearfix - h1#title = link_to 'Stadtratmonitor Leipzig', root_path + h1#title = 'Stadtratmonitor Leipzig' - flash.each do |name, msg| = content_tag :div, msg, class: name = yield diff --git a/app/views/search/index.rss.builder b/app/views/search/index.rss.builder index 6c488b6..5f0f7c6 100644 --- a/app/views/search/index.rss.builder +++ b/app/views/search/index.rss.builder @@ -1,15 +1,37 @@ +require 'date' + xml.instruct! :xml, :version => "1.0" -xml.rss :version => "2.0" do +xml.rss :version => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do xml.channel do xml.title "Search results" xml.description "Papers matching search criteria" - xml.link root_url @papers.each do |doc| xml.item do xml.title doc.name - xml.description truncate(doc.content, length: 768) - xml.pubDate doc.published_at.to_date.to_s(:rfc822) + if !doc.content.blank? + xml.description do + xml.cdata! truncate(doc.content, length: 768) + end + end + if !doc.published_at.blank? + xml.pubDate DateTime.parse(doc.published_at).utc.strftime("%a, %d %b %Y %H:%M:%S %z") + end + doc.originator.each do |originator| + xml.dc :creator do + xml.cdata! originator + end + end + if !doc.paper_type.blank? + xml.category do + xml.cdata! doc.paper_type + end + end + if !doc.resolution.blank? + xml.category do + xml.cdata! doc.resolution + end + end xml.link doc.url xml.guid doc.url end diff --git a/config/routes.rb b/config/routes.rb index 5cc218c..9f519cc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,15 +1,6 @@ Rails.application.routes.draw do - root to: redirect { |path_params| "/leipzig" } - - scope ':body' do - get '/' => 'search#index', as: :search - get '/:id' => 'search#show', as: :saved_search - end - - post '/auth/:provider/callback', to: 'sessions#create' - get '/auth/browser_id', as: 'sign_in' - - resource :session, only: [:create, :destroy] + root :to => 'search#index', as: :search + post '/import' => 'import#new_papers_callback' # Example of regular route: # get 'products/:id' => 'catalog#view' diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index 4db4133..171b17f 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -28,6 +28,21 @@ RSpec.describe SearchController, type: :controller, elasticsearch: true do get :index, body: 'leipzig' end + + it "returns rss" do + get :index, :format => "rss", body: 'leipzig' + expect(response).to be_success + expect(response).to render_template(:index) + expect(response.content_type).to eq("application/rss+xml") + #expect(response.body).to have_tag "rss" do + # with_tag "channel" do + # with_tag "title" + # with_tag "description" + # with_tag "link" + # end + #end + end + end end diff --git a/test/integration/routes_test.rb b/test/integration/routes_test.rb new file mode 100644 index 0000000..29f95fa --- /dev/null +++ b/test/integration/routes_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class RoutesTest < ActionDispatch::IntegrationTest + test "route test" do + assert_generates "/import", { :controller => "import", :action => "new_papers_callback" } + assert_generates "/", :controller => "search", :action => "index" + end +end \ No newline at end of file