charcoal 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +8 -2
- data/Rakefile +2 -2
- data/charcoal.gemspec +2 -2
- data/lib/charcoal/cors.rb +6 -1
- data/lib/charcoal/version.rb +1 -1
- data/test/cors_test.rb +20 -0
- metadata +3 -3
data/README.md
CHANGED
@@ -35,7 +35,7 @@ map.connect "*path.:format", :conditions => { :method => :options }, :action =>
|
|
35
35
|
|
36
36
|
Rails 3:
|
37
37
|
```ruby
|
38
|
-
|
38
|
+
map.connect "*path.:format", :conditions => { :method => :options }, :action => "preflight", :controller => "C_O_R_S", :namespace => "charcoal/"
|
39
39
|
```
|
40
40
|
|
41
41
|
#### Configuration
|
@@ -44,7 +44,13 @@ The configuration options and defaults for CORS are as follows:
|
|
44
44
|
|
45
45
|
```ruby
|
46
46
|
# Access-Control-Allow-Origin
|
47
|
-
"allow-origin" => "*"
|
47
|
+
Charcoal.configuration["allow-origin"] # => "*"
|
48
|
+
# Can be set to a string
|
49
|
+
Charcoal.configuration["allow-origin"] = "https://google.com"
|
50
|
+
# Or a block
|
51
|
+
Charcoal.configuration["allow-origin"] = lambda do |controller|
|
52
|
+
controller.request.host
|
53
|
+
end
|
48
54
|
|
49
55
|
# Access-Control-Allow-Headers
|
50
56
|
"allow-headers" => ["X-Requested-With", "X-Prototype-Version"]
|
data/Rakefile
CHANGED
@@ -43,11 +43,11 @@ Rake::TestTask.new(:test) do |test|
|
|
43
43
|
end
|
44
44
|
|
45
45
|
desc 'Test the plugin under all supported Rails versions.'
|
46
|
-
task :all => ["appraisal:
|
46
|
+
task :all => ["appraisal:install"] do
|
47
47
|
exec('rake appraisal test')
|
48
48
|
end
|
49
49
|
|
50
|
-
task :default => :
|
50
|
+
task :default => :all
|
51
51
|
|
52
52
|
require 'yard'
|
53
53
|
YARD::Rake::YardocTask.new
|
data/charcoal.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "charcoal"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Steven Davidovitz"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-07-17"
|
13
13
|
s.description = "Helps you support JSONP and CORS in your Rails app"
|
14
14
|
s.email = "sdavidovitz@zendesk.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/charcoal/cors.rb
CHANGED
@@ -31,9 +31,14 @@ module Charcoal
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def set_cors_headers
|
34
|
-
headers["Access-Control-Allow-Origin"] =
|
34
|
+
headers["Access-Control-Allow-Origin"] = allowed_origin
|
35
35
|
headers["Access-Control-Allow-Credentials"] = Charcoal.configuration["credentials"].to_s
|
36
36
|
headers["Access-Control-Expose-Headers"] = Charcoal.configuration["expose-headers"].join(",")
|
37
37
|
end
|
38
|
+
|
39
|
+
def allowed_origin
|
40
|
+
value = Charcoal.configuration["allow-origin"]
|
41
|
+
value.respond_to?(:call) ? value.call(self) : value.to_s
|
42
|
+
end
|
38
43
|
end
|
39
44
|
end
|
data/lib/charcoal/version.rb
CHANGED
data/test/cors_test.rb
CHANGED
@@ -46,6 +46,26 @@ class TestCorsControllerTest < ActionController::TestCase
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
context "when Allow-Origin is a block" do
|
50
|
+
setup do
|
51
|
+
block = lambda do |controller|
|
52
|
+
controller.class.name
|
53
|
+
end
|
54
|
+
|
55
|
+
@original, Charcoal.configuration["allow-origin"] = Charcoal.configuration["allow-origin"], block
|
56
|
+
|
57
|
+
get :test_action
|
58
|
+
end
|
59
|
+
|
60
|
+
teardown do
|
61
|
+
Charcoal.configuration["allow-origin"] = @original
|
62
|
+
end
|
63
|
+
|
64
|
+
should "be the same as the configuration" do
|
65
|
+
assert_equal "TestCorsController", @response.headers["Access-Control-Allow-Origin"], @response.headers.inspect
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
49
69
|
context "without any other request method" do
|
50
70
|
setup do
|
51
71
|
@original, Charcoal.configuration["expose-headers"] = Charcoal.configuration["expose-headers"], %w{test 123}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: charcoal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -141,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
141
|
version: '0'
|
142
142
|
segments:
|
143
143
|
- 0
|
144
|
-
hash: -
|
144
|
+
hash: -2898595895829027545
|
145
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
146
|
none: false
|
147
147
|
requirements:
|