Skip to content

Commit

Permalink
allow CORS on episode index
Browse files Browse the repository at this point in the history
  • Loading branch information
cpytel committed Mar 21, 2014
1 parent 8d34dfc commit 3ceed77
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 14 deletions.
6 changes: 6 additions & 0 deletions app/controllers/episodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ def index
expires_in 1.hour, public: true
@show = current_show
fresh_when(@show.episodes.published.first, public: true)
set_access_control_headers
end

def show
Expand All @@ -21,4 +22,9 @@ def show
def current_show
Show.find_by_slug!(params[:show_id])
end

def set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Request-Method'] = '*'
end
end
14 changes: 6 additions & 8 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env ruby

if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
else
ARGV.unshift "rails"
load Gem.bin_path("spring", "spring")
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
11 changes: 5 additions & 6 deletions bin/rake
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env ruby

if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
exec "bundle", "exec", "rake", *ARGV
else
ARGV.unshift "rake"
load Gem.bin_path("spring", "spring")
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
require 'bundler/setup'
load Gem.bin_path('rake', 'rake')
18 changes: 18 additions & 0 deletions bin/spring
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env ruby

# This file loads spring without using Bundler, in order to be fast
# It gets overwritten when you run the `spring binstub` command

unless defined?(Spring)
require "rubygems"
require "bundler"

if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m)
ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
ENV["GEM_HOME"] = ""
Gem.paths = ENV

gem "spring", match[1]
require "spring/binstub"
end
end
9 changes: 9 additions & 0 deletions spec/controllers/episodes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
get :index, show_id: episode.show.to_param, format: :xml
expect(response).to render_template("index")
end

it 'allows cross origin resources' do
episode = create(:episode)

get :index, show_id: episode.show.to_param, format: :xml

expect(response.headers['Access-Control-Allow-Origin']).to eq '*'
expect(response.headers['Access-Control-Request-Method']).to eq '*'
end
end

describe '#show a non-published episode' do
Expand Down

0 comments on commit 3ceed77

Please sign in to comment.