Merge remote-tracking branch 'origin/master' into HEAD

This commit is contained in:
Continuous Integration
2017-01-18 18:14:10 +11:00
11 changed files with 53 additions and 28 deletions

View File

@@ -0,0 +1,11 @@
class SitemapController < ApplicationController
layout nil
def index
headers['Content-Type'] = 'application/xml'
@page_urls = [shops_url, map_url, producers_url, groups_url]
@enterprises = Enterprise.is_hub
@groups = EnterpriseGroup.all
respond_to :xml
end
end

View File

@@ -163,10 +163,18 @@ class Enterprise < ActiveRecord::Base
}
scope :distributing_products, lambda { |products|
with_distributed_products_outer.with_order_cycles_and_exchange_variants_outer.
where('product_distributions.product_id IN (?) OR spree_variants.product_id IN (?)', products, products).
select('DISTINCT enterprises.*')
# TODO: remove this when we pull out product distributions
pds = joins("INNER JOIN product_distributions ON product_distributions.distributor_id = enterprises.id").
where("product_distributions.product_id IN (?)", products).select('DISTINCT enterprises.id')
exs = joins("INNER JOIN exchanges ON (exchanges.receiver_id = enterprises.id AND exchanges.incoming = 'f')").
joins('INNER JOIN exchange_variants ON (exchange_variants.exchange_id = exchanges.id)').
joins('INNER JOIN spree_variants ON (spree_variants.id = exchange_variants.variant_id)').
where('spree_variants.product_id IN (?)', products).select('DISTINCT enterprises.id')
where(id: pds | exs)
}
scope :managed_by, lambda { |user|
if user.has_spree_role?('admin')
scoped

View File

@@ -0,0 +1,17 @@
!!! XML
%urlset{xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9"}
- for page_url in @page_urls
%url
%loc= page_url
%changefreq monthly
- for enterprise in @enterprises
%url
%loc= enterprise_shop_url(enterprise)
%lastmod= enterprise.updated_at.strftime('%Y-%m-%d')
%changefreq weekly
- for group in @groups
%url
%loc= group_url(group)
%changefreq monthly

View File

@@ -169,6 +169,8 @@ Openfoodnetwork::Application.routes.draw do
end
end
get 'sitemap.xml', to: 'sitemap#index', defaults: { format: 'xml' }
# Mount Spree's routes
mount Spree::Core::Engine, :at => '/'

View File

@@ -0,0 +1,12 @@
require 'spec_helper'
feature 'sitemap' do
let(:enterprise) { create(:distributor_enterprise) }
let!(:group) { create(:enterprise_group, enterprises: [enterprise], on_front_page: true) }
it "renders sitemap" do
visit '/sitemap.xml'
expect(page).to have_content enterprise_shop_url(enterprise)
expect(page).to have_content group_url(group)
end
end

View File

View File

@@ -1,12 +0,0 @@
require 'test_helper'
require 'rails/performance_test_help'
class BrowsingTest < ActionDispatch::PerformanceTest
# Refer to the documentation for all available options
# self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
# :output => 'tmp/performance', :formats => [:flat] }
def test_homepage
get '/'
end
end

View File

@@ -1,13 +0,0 @@
ENV["RAILS_ENV"] = "test"
require_relative '../config/environment'
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all
# Add more helper methods to be used by all tests here...
end

View File