charcoal 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c2b9d115a474b7323570364469ac972460ab8dc0
4
- data.tar.gz: b285b15b478984c94aec28b60a566496a67c2672
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MmYyMGE0ZTYxOGUyNDJhNDE0YTZkODUzODBhYjg5NmZiNzY4N2Y4Ng==
5
+ data.tar.gz: !binary |-
6
+ ZTdlYmJhOTZkZWYwY2Y5NTUyMzRkYzVlODRlY2U0MWYwMmZlY2I2Ng==
5
7
  SHA512:
6
- metadata.gz: 5d96db339355db4e360e7d483846e4f5ca9f7cd81214a96d8b7f911153abc501a32c9e294b3efbdb2b7e022aff6f4bc79abf0aa4d071953f163ac404d1605941
7
- data.tar.gz: 43fe4602cad6fe0c8e54d0b14aa9e9ea7ac5716581b191d0a0aec13a14eee489fb64e2292b7b75cfcb3693d28442d4123d9229d56f19638c2757a5475dcc9c2e
8
+ metadata.gz: !binary |-
9
+ N2RlZDY2YTc5Y2ZjNzAxY2I4MDRjM2UyMGU2YWU4NmRmZDQ1ODAwZDFjYjlk
10
+ MWE1ZjNlMzI2NmE2NTNjOTJhNDRiYWE3NGU2NjYzYTA4MjkyNTdjMGUzY2Ix
11
+ NDE2Njg3NzA2MDVkYzk3NTViZjhiOWJiNWQxMzM4OGY5ODcwNzQ=
12
+ data.tar.gz: !binary |-
13
+ NTYxMDk2YTZkOGE0MWRjMGMxOWY5OGY2YTJmNGE5ZjU4NGQxNjk3YTE1MTBh
14
+ NDM1OGRjODA0OTBmMzA5ZWVhYjRiZWJlYTZjYWIwMTkwODg1MWMwYTE4MGEy
15
+ MDhhMjE2NjVhMDVmZmM0YjZmOGY3MDE4Yzk4NWFiZDBiNjNmYTA=
data/charcoal.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: charcoal 0.2.0 ruby lib
5
+ # stub: charcoal 0.2.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "charcoal"
9
- s.version = "0.2.0"
9
+ s.version = "0.2.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Steven Davidovitz"]
13
- s.date = "2013-12-19"
13
+ s.date = "2013-12-21"
14
14
  s.description = "Helps you support JSONP and CORS in your Rails app"
15
15
  s.email = "sdavidovitz@zendesk.com"
16
16
  s.extra_rdoc_files = [
@@ -7,7 +7,7 @@ gem "activesupport", ">= 2.3.5"
7
7
  gem "actionpack", ">= 2.3.5"
8
8
  gem "rake", :group=>:development
9
9
  gem "yard", "~> 0.7", :group=>:development
10
- gem "jeweler", "~> 1.8.4", :group=>:development
10
+ gem "jeweler", :group=>:development
11
11
  gem "appraisal", ">= 0.5.0", :group=>:test
12
12
  gem "shoulda", "~> 3.0", :group=>:test
13
13
  gem "shoulda-context", :group=>:test
@@ -7,7 +7,7 @@ gem "activesupport", ">= 2.3.5"
7
7
  gem "actionpack", ">= 2.3.5"
8
8
  gem "rake", :group=>:development
9
9
  gem "yard", "~> 0.7", :group=>:development
10
- gem "jeweler", "~> 1.8.4", :group=>:development
10
+ gem "jeweler", :group=>:development
11
11
  gem "appraisal", ">= 0.5.0", :group=>:test
12
12
  gem "shoulda", "~> 3.0", :group=>:test
13
13
  gem "shoulda-context", :group=>:test
@@ -29,32 +29,39 @@ class Charcoal::CORSController < ActionController::Base
29
29
  @allowed_methods ||= ActionController::Routing::HTTP_METHODS.select do |verb|
30
30
  next if verb == :options
31
31
 
32
- begin
33
- route = if ActiveSupport::VERSION::MAJOR >= 3
34
- Rails.application.routes.recognize_path(request.path, request.env.merge(:method => verb))
35
- else
36
- ActionController::Routing::Routes.routes.find {|r| r.recognize(request.path, request.env.merge(:method => verb))}
37
- end
32
+ route = find_route(request.path, request.env.merge(:method => verb))
38
33
 
39
- if route
40
- route = route.requirements if ActiveSupport::VERSION::MAJOR < 3
34
+ if route
35
+ controller = route[:controller].camelize
36
+ controller = "#{controller}Controller".constantize
41
37
 
42
- controller = route[:controller].camelize
43
- controller = "#{controller}Controller".constantize
38
+ action = route[:action] || params[:path].last.split(".").first
44
39
 
45
- action = route[:action] || params[:path].last.split(".").first
40
+ instance = controller.new
41
+ instance.request = request
42
+ instance.response = response
46
43
 
47
- instance = controller.new
48
- instance.request = request
49
- instance.response = response
44
+ controller.respond_to?(:cors_allowed) && controller.cors_allowed?(instance, action)
45
+ else
46
+ false
47
+ end
48
+ end
49
+ end
50
50
 
51
- controller.respond_to?(:cors_allowed) && controller.cors_allowed?(instance, action)
52
- else
53
- false
51
+ def find_route(path, env)
52
+ if ActiveSupport::VERSION::MAJOR >= 3
53
+ [Rails.application.routes, *Rails.application.railties.engines.map(&:routes)].each do |route_set|
54
+ begin
55
+ return route_set.recognize_path(path, env)
56
+ rescue ActionController::RoutingError
54
57
  end
55
- rescue ActionController::RoutingError
56
- false
57
58
  end
59
+
60
+ nil
61
+ else
62
+ ActionController::Routing::Routes.routes.find {|r| r.recognize(path, env)}.try(:requirements)
58
63
  end
64
+ rescue ActionController::RoutingError
65
+ nil
59
66
  end
60
67
  end
@@ -1,3 +1,3 @@
1
1
  module Charcoal
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -8,6 +8,14 @@ class TestController < ActionController::Base
8
8
  def test; end
9
9
  end
10
10
 
11
+ class EngineController < ActionController::Base
12
+ include Charcoal::CORS
13
+ allow_cors :test
14
+
15
+ # POST
16
+ def test; end
17
+ end
18
+
11
19
  class Charcoal::CORSControllerTest < ActionController::TestCase
12
20
  context Charcoal::CORSController do
13
21
  setup do
@@ -50,5 +58,31 @@ class Charcoal::CORSControllerTest < ActionController::TestCase
50
58
  end
51
59
  end
52
60
  end
61
+
62
+ if ActiveSupport::VERSION::MAJOR >= 3
63
+ context "engine request path" do
64
+ setup do
65
+ @request.stubs(:path => "/engine/abc/test")
66
+ get :preflight
67
+ end
68
+
69
+ should "allow proper methods" do
70
+ assert_equal "POST", @response.headers["Access-Control-Allow-Methods"], @response.headers.inspect
71
+ end
72
+
73
+ should "set Access-Control-Allow-Headers header" do
74
+ assert_equal Charcoal.configuration["allow-headers"].join(","), @response.headers["Access-Control-Allow-Headers"], @response.headers.inspect
75
+ end
76
+
77
+ should "set Access-Control-Max-Age header" do
78
+ assert_equal Charcoal.configuration["max-age"].to_s, @response.headers["Access-Control-Max-Age"], @response.headers.inspect
79
+ end
80
+
81
+ should "render text/plain response" do
82
+ assert_equal " ", @response.body
83
+ assert_match %r[text/plain], @response.headers["Content-Type"], @response.headers.inspect
84
+ end
85
+ end
86
+ end
53
87
  end
54
88
  end
data/test/helper.rb CHANGED
@@ -29,11 +29,19 @@ if ActiveSupport::VERSION::MAJOR >= 3
29
29
  config.logger = Logger.new(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i ? 'NUL:' : '/dev/null')
30
30
  end
31
31
 
32
+ class TestEngine < Rails::Engine
33
+ end
34
+
32
35
  TestApp.initialize!
33
36
 
37
+ TestEngine.routes.draw do
38
+ match '/engine/abc/test' => "engine#test", :via => :post
39
+ end
40
+
34
41
  TestApp.routes.draw do
42
+ mount TestEngine => ''
35
43
  match '/test' => "test#test", :via => [:get, :put]
36
- match "*path.:format", :conditions => { :method => :options }, :action => "preflight", :controller => "C_O_R_S", :namespace => "charcoal/"
44
+ match '*path.:format' => 'charcoal/C_O_R_S#preflight', :via => :options
37
45
  match ':controller/:action'
38
46
  end
39
47
 
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: charcoal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Davidovitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-19 00:00:00.000000000 Z
11
+ date: 2013-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: 2.3.5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.3.5
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: actionpack
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.3.5
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.3.5
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
@@ -84,14 +84,14 @@ dependencies:
84
84
  name: jeweler
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ! '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ! '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: Helps you support JSONP and CORS in your Rails app
@@ -133,12 +133,12 @@ require_paths:
133
133
  - lib
134
134
  required_ruby_version: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ! '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  requirements:
141
- - - '>='
141
+ - - ! '>='
142
142
  - !ruby/object:Gem::Version
143
143
  version: '0'
144
144
  requirements: []