charcoal 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fda5dfba100b8fcd078a883a677592325a604fe7
4
+ data.tar.gz: 269dce65316a9da4bbd1b6422d1b4bb4e8e04e41
5
+ SHA512:
6
+ metadata.gz: 0837c0cb9c6d537909ad952506f72d953644e3c3a6fbb82f66207f3e89f807df07b35e38087802d7fa988646e34de46e7d496e16786291c12f0f008f7d48a60c
7
+ data.tar.gz: 12743fae3e6df84e2ec3ce4f3ecd88d37a62a1d484b5d287da3c424e3cf7e399e81d4239e0dda1f0276f340a5b7a8f3d4d249f82f80f3a1d3dc1a451a176e4f9
data/README.md CHANGED
@@ -33,9 +33,9 @@ Rails 2:
33
33
  map.connect "*path.:format", :conditions => { :method => :options }, :action => "preflight", :controller => "CORS", :namespace => "charcoal/"
34
34
  ```
35
35
 
36
- Rails 3:
36
+ Rails 3 / 4:
37
37
  ```ruby
38
- match '*path' => 'charcoal/C_O_R_S#preflight', :via => :options
38
+ match '*path.:format' => 'charcoal/cors#preflight', :via => :options
39
39
  ```
40
40
 
41
41
  #### Configuration
@@ -106,7 +106,7 @@ This example adds the `allow_animals` directive that logs "QUACK!" if an applica
106
106
 
107
107
  ## Supported Versions
108
108
 
109
- Tested with Ruby 1.9.3 and 2.0 and Rails 2.3 and 3.2.
109
+ Tested with Ruby 1.9.3, 2.0 and 2.1.1 and Rails 2.3, 3.2, 4.0 and 4.1.
110
110
  [![Build Status](https://secure.travis-ci.org/steved555/charcoal.png?branch=master)](http://travis-ci.org/steved555/charcoal)
111
111
 
112
112
  ## Contributing to charcoal
@@ -9,6 +9,8 @@ require 'charcoal/cors_helper'
9
9
  class Charcoal::CORSController < ActionController::Base
10
10
  include Charcoal::CORS
11
11
 
12
+ Routing = defined?(ActionDispatch) ? ActionDispatch::Routing : ActionController::Routing
13
+
12
14
  allow_cors :all
13
15
  skip_after_filter :set_cors_headers
14
16
 
@@ -27,7 +29,7 @@ class Charcoal::CORSController < ActionController::Base
27
29
  private
28
30
 
29
31
  def allowed_methods
30
- @allowed_methods ||= ActionController::Routing::HTTP_METHODS.select do |verb|
32
+ @allowed_methods ||= Routing::HTTP_METHODS.select do |verb|
31
33
  next if verb == :options
32
34
 
33
35
  route = find_route(request.path, request.env.merge(:method => verb))
@@ -51,7 +53,13 @@ class Charcoal::CORSController < ActionController::Base
51
53
 
52
54
  def find_route(path, env)
53
55
  if ActiveSupport::VERSION::MAJOR >= 3
54
- [Rails.application.routes, *Rails.application.railties.engines.map(&:routes)].each do |route_set|
56
+ routes = [Rails.application.routes]
57
+
58
+ railties = Rails.application.railties
59
+ railties = railties.respond_to?(:all) ? railties.all : railties._all
60
+ routes += railties.select {|tie| tie.is_a?(Rails::Engine)}.map(&:routes)
61
+
62
+ routes.each do |route_set|
55
63
  begin
56
64
  return route_set.recognize_path(path, env)
57
65
  rescue ActionController::RoutingError
@@ -1,3 +1,3 @@
1
1
  module Charcoal
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,112 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: charcoal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Steven Davidovitz
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-12-24 00:00:00.000000000 Z
11
+ date: 2014-09-02 00:00:00.000000000 Z
13
12
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: bundler
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
13
  - !ruby/object:Gem::Dependency
31
14
  name: activesupport
32
15
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
16
  requirements:
35
- - - ! '>='
17
+ - - ">="
36
18
  - !ruby/object:Gem::Version
37
19
  version: 2.3.5
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5'
38
23
  type: :runtime
39
24
  prerelease: false
40
25
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
26
  requirements:
43
- - - ! '>='
27
+ - - ">="
44
28
  - !ruby/object:Gem::Version
45
29
  version: 2.3.5
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5'
46
33
  - !ruby/object:Gem::Dependency
47
34
  name: actionpack
48
35
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
36
  requirements:
51
- - - ! '>='
37
+ - - ">="
52
38
  - !ruby/object:Gem::Version
53
39
  version: 2.3.5
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '5'
54
43
  type: :runtime
55
44
  prerelease: false
56
45
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
46
  requirements:
59
- - - ! '>='
47
+ - - ">="
60
48
  - !ruby/object:Gem::Version
61
49
  version: 2.3.5
62
- - !ruby/object:Gem::Dependency
63
- name: rake
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: yard
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ~>
84
- - !ruby/object:Gem::Version
85
- version: '0.7'
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ~>
92
- - !ruby/object:Gem::Version
93
- version: '0.7'
94
- - !ruby/object:Gem::Dependency
95
- name: jeweler
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
50
+ - - "<"
108
51
  - !ruby/object:Gem::Version
109
- version: '0'
52
+ version: '5'
110
53
  description: Helps you support JSONP and CORS in your Rails app
111
54
  email: sdavidovitz@zendesk.com
112
55
  executables: []
@@ -115,15 +58,8 @@ extra_rdoc_files:
115
58
  - LICENSE
116
59
  - README.md
117
60
  files:
118
- - .travis.yml
119
- - Appraisals
120
- - Gemfile
121
61
  - LICENSE
122
62
  - README.md
123
- - Rakefile
124
- - charcoal.gemspec
125
- - gemfiles/rails_2.3.gemfile
126
- - gemfiles/rails_3.2.gemfile
127
63
  - lib/charcoal.rb
128
64
  - lib/charcoal/controller_filter.rb
129
65
  - lib/charcoal/cors.rb
@@ -131,37 +67,29 @@ files:
131
67
  - lib/charcoal/cors_helper.rb
132
68
  - lib/charcoal/jsonp.rb
133
69
  - lib/charcoal/version.rb
134
- - test/cors_controller_test.rb
135
- - test/cors_test.rb
136
- - test/filters_test.rb
137
- - test/helper.rb
138
- - test/jsonp_test.rb
139
- homepage: http://github.com/steved555/charcoal
70
+ homepage: https://github.com/steved555/charcoal
140
71
  licenses:
141
72
  - MIT
73
+ metadata: {}
142
74
  post_install_message:
143
75
  rdoc_options: []
144
76
  require_paths:
145
77
  - lib
146
78
  required_ruby_version: !ruby/object:Gem::Requirement
147
- none: false
148
79
  requirements:
149
- - - ! '>='
80
+ - - ">="
150
81
  - !ruby/object:Gem::Version
151
82
  version: '0'
152
- segments:
153
- - 0
154
- hash: 2616342384870554307
155
83
  required_rubygems_version: !ruby/object:Gem::Requirement
156
- none: false
157
84
  requirements:
158
- - - ! '>='
85
+ - - ">="
159
86
  - !ruby/object:Gem::Version
160
87
  version: '0'
161
88
  requirements: []
162
89
  rubyforge_project:
163
- rubygems_version: 1.8.25
90
+ rubygems_version: 2.2.2
164
91
  signing_key:
165
- specification_version: 3
92
+ specification_version: 4
166
93
  summary: Cross-Origin helper for Rails
167
94
  test_files: []
95
+ has_rdoc:
data/.travis.yml DELETED
@@ -1,12 +0,0 @@
1
- rvm:
2
- - 1.9.3
3
- - 2.0.0
4
- gemfile:
5
- - gemfiles/rails_2.3.gemfile
6
- - gemfiles/rails_3.2.gemfile
7
- cache: bundler
8
- script: "bundle exec rake test"
9
- matrix:
10
- exclude:
11
- - rvm: 2.0.0
12
- gemfile: gemfiles/rails_2.3.gemfile
data/Appraisals DELETED
@@ -1,7 +0,0 @@
1
- appraise "rails-2.3" do
2
- gem "rails", "~> 2.3.0"
3
- end
4
-
5
- appraise "rails-3.2" do
6
- gem "rails", "~> 3.2.0"
7
- end
data/Gemfile DELETED
@@ -1,16 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem "bundler"
4
-
5
- gem "activesupport", ">= 2.3.5"
6
- gem "actionpack", ">= 2.3.5"
7
-
8
- gem "rake", :group => :development
9
- gem "yard", "~> 0.7", :group => :development
10
- gem "jeweler", :group => :development
11
-
12
- gem "rails", ">= 2.3.5", :group => :test
13
- gem "appraisal", ">= 0.5.0", :group => :test
14
- gem "shoulda", "~> 3.0", :group => :test
15
- gem "shoulda-context", :group => :test
16
- gem "mocha", :group => :test, :require => false
data/Rakefile DELETED
@@ -1,53 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
-
6
- begin
7
- Bundler.setup(:default, :development, :test)
8
- rescue Bundler::BundlerError => e
9
- $stderr.puts e.message
10
- $stderr.puts "Run `bundle install` to install missing gems"
11
- exit e.status_code
12
- end
13
-
14
- lib = File.expand_path('../lib/', __FILE__)
15
- $:.unshift lib unless $:.include?(lib)
16
-
17
- require 'charcoal/version'
18
-
19
- require 'rake'
20
- require 'jeweler'
21
-
22
- Jeweler::Tasks.new do |gem|
23
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
24
- gem.name = "charcoal"
25
- gem.version = Charcoal::VERSION
26
- gem.homepage = "http://github.com/steved555/charcoal"
27
- gem.license = "MIT"
28
- gem.summary = %Q{Cross-Origin helper for Rails}
29
- gem.description = %Q{Helps you support JSONP and CORS in your Rails app}
30
- gem.email = "sdavidovitz@zendesk.com"
31
- gem.authors = ["Steven Davidovitz"]
32
- # dependencies defined in Gemfile
33
- end
34
- Jeweler::RubygemsDotOrgTasks.new
35
-
36
- require 'appraisal'
37
-
38
- require 'rake/testtask'
39
- Rake::TestTask.new(:test) do |test|
40
- test.libs << 'lib' << 'test'
41
- test.pattern = 'test/**/*_test.rb'
42
- test.verbose = true
43
- end
44
-
45
- desc 'Test the plugin under all supported Rails versions.'
46
- task :all => ["appraisal:install"] do
47
- exec('rake appraisal test')
48
- end
49
-
50
- task :default => :all
51
-
52
- require 'yard'
53
- YARD::Rake::YardocTask.new
data/charcoal.gemspec DELETED
@@ -1,75 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = "charcoal"
8
- s.version = "0.2.2"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Steven Davidovitz"]
12
- s.date = "2013-12-24"
13
- s.description = "Helps you support JSONP and CORS in your Rails app"
14
- s.email = "sdavidovitz@zendesk.com"
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.md"
18
- ]
19
- s.files = [
20
- ".travis.yml",
21
- "Appraisals",
22
- "Gemfile",
23
- "LICENSE",
24
- "README.md",
25
- "Rakefile",
26
- "charcoal.gemspec",
27
- "gemfiles/rails_2.3.gemfile",
28
- "gemfiles/rails_3.2.gemfile",
29
- "lib/charcoal.rb",
30
- "lib/charcoal/controller_filter.rb",
31
- "lib/charcoal/cors.rb",
32
- "lib/charcoal/cors_controller.rb",
33
- "lib/charcoal/cors_helper.rb",
34
- "lib/charcoal/jsonp.rb",
35
- "lib/charcoal/version.rb",
36
- "test/cors_controller_test.rb",
37
- "test/cors_test.rb",
38
- "test/filters_test.rb",
39
- "test/helper.rb",
40
- "test/jsonp_test.rb"
41
- ]
42
- s.homepage = "http://github.com/steved555/charcoal"
43
- s.licenses = ["MIT"]
44
- s.require_paths = ["lib"]
45
- s.rubygems_version = "1.8.25"
46
- s.summary = "Cross-Origin helper for Rails"
47
-
48
- if s.respond_to? :specification_version then
49
- s.specification_version = 3
50
-
51
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
- s.add_runtime_dependency(%q<bundler>, [">= 0"])
53
- s.add_runtime_dependency(%q<activesupport>, [">= 2.3.5"])
54
- s.add_runtime_dependency(%q<actionpack>, [">= 2.3.5"])
55
- s.add_development_dependency(%q<rake>, [">= 0"])
56
- s.add_development_dependency(%q<yard>, ["~> 0.7"])
57
- s.add_development_dependency(%q<jeweler>, [">= 0"])
58
- else
59
- s.add_dependency(%q<bundler>, [">= 0"])
60
- s.add_dependency(%q<activesupport>, [">= 2.3.5"])
61
- s.add_dependency(%q<actionpack>, [">= 2.3.5"])
62
- s.add_dependency(%q<rake>, [">= 0"])
63
- s.add_dependency(%q<yard>, ["~> 0.7"])
64
- s.add_dependency(%q<jeweler>, [">= 0"])
65
- end
66
- else
67
- s.add_dependency(%q<bundler>, [">= 0"])
68
- s.add_dependency(%q<activesupport>, [">= 2.3.5"])
69
- s.add_dependency(%q<actionpack>, [">= 2.3.5"])
70
- s.add_dependency(%q<rake>, [">= 0"])
71
- s.add_dependency(%q<yard>, ["~> 0.7"])
72
- s.add_dependency(%q<jeweler>, [">= 0"])
73
- end
74
- end
75
-
@@ -1,16 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "bundler"
6
- gem "activesupport", ">= 2.3.5"
7
- gem "actionpack", ">= 2.3.5"
8
- gem "rake", :group=>:development
9
- gem "yard", "~> 0.7", :group=>:development
10
- gem "jeweler", :group=>:development
11
- gem "appraisal", ">= 0.5.0", :group=>:test
12
- gem "shoulda", "~> 3.0", :group=>:test
13
- gem "shoulda-context", :group=>:test
14
- gem "mocha", :group=>:test, :require=>false
15
- gem "rails", "~> 2.3.0"
16
-
@@ -1,16 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "bundler"
6
- gem "activesupport", ">= 2.3.5"
7
- gem "actionpack", ">= 2.3.5"
8
- gem "rake", :group=>:development
9
- gem "yard", "~> 0.7", :group=>:development
10
- gem "jeweler", :group=>:development
11
- gem "appraisal", ">= 0.5.0", :group=>:test
12
- gem "shoulda", "~> 3.0", :group=>:test
13
- gem "shoulda-context", :group=>:test
14
- gem "mocha", :group=>:test, :require=>false
15
- gem "rails", "~> 3.2.0"
16
-
@@ -1,92 +0,0 @@
1
- require File.expand_path("helper", File.dirname(__FILE__))
2
-
3
- class TestController < ActionController::Base
4
- include Charcoal::CORS
5
- allow_cors :test
6
-
7
- # GET, PUT
8
- def test; end
9
- end
10
-
11
- class EngineController < ActionController::Base
12
- include Charcoal::CORS
13
- allow_cors :test
14
-
15
- # POST
16
- def test; end
17
- end
18
-
19
- class Charcoal::CORSControllerTest < ActionController::TestCase
20
- context Charcoal::CORSController do
21
- setup do
22
- @request.env["HTTPS"] = "on"
23
- end
24
-
25
- context "unrecognized path to #preflight" do
26
- setup do
27
- @request.stubs(:path => "/my_unrecognized_path")
28
- get :preflight
29
- end
30
-
31
- should "not set allow-origin" do
32
- assert_nil @response.headers["Access-Control-Allow-Origin"], @response.headers.inspect
33
- end
34
-
35
- should "allow proper methods" do
36
- assert_nil @response.headers["Access-Control-Allow-Methods"], @response.headers.inspect
37
- end
38
- end
39
-
40
- context "OPTIONS to #preflight" do
41
- context "with request method = OPTIONS" do
42
- setup do
43
- @request.stubs(:path => "/test")
44
- get :preflight
45
- end
46
-
47
- should "allow proper methods" do
48
- assert_equal "GET,PUT", @response.headers["Access-Control-Allow-Methods"], @response.headers.inspect
49
- end
50
-
51
- should "set Access-Control-Allow-Headers header" do
52
- assert_equal Charcoal.configuration["allow-headers"].join(","), @response.headers["Access-Control-Allow-Headers"], @response.headers.inspect
53
- end
54
-
55
- should "set Access-Control-Max-Age header" do
56
- assert_equal Charcoal.configuration["max-age"].to_s, @response.headers["Access-Control-Max-Age"], @response.headers.inspect
57
- end
58
-
59
- should "render text/plain response" do
60
- assert_equal " ", @response.body
61
- assert_match %r[text/plain], @response.headers["Content-Type"], @response.headers.inspect
62
- end
63
- end
64
- end
65
-
66
- if ActiveSupport::VERSION::MAJOR >= 3
67
- context "engine request path" do
68
- setup do
69
- @request.stubs(:path => "/engine/abc/test")
70
- get :preflight
71
- end
72
-
73
- should "allow proper methods" do
74
- assert_equal "POST", @response.headers["Access-Control-Allow-Methods"], @response.headers.inspect
75
- end
76
-
77
- should "set Access-Control-Allow-Headers header" do
78
- assert_equal Charcoal.configuration["allow-headers"].join(","), @response.headers["Access-Control-Allow-Headers"], @response.headers.inspect
79
- end
80
-
81
- should "set Access-Control-Max-Age header" do
82
- assert_equal Charcoal.configuration["max-age"].to_s, @response.headers["Access-Control-Max-Age"], @response.headers.inspect
83
- end
84
-
85
- should "render text/plain response" do
86
- assert_equal " ", @response.body
87
- assert_match %r[text/plain], @response.headers["Content-Type"], @response.headers.inspect
88
- end
89
- end
90
- end
91
- end
92
- end
data/test/cors_test.rb DELETED
@@ -1,90 +0,0 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
2
-
3
- class TestCorsController < ActionController::Base
4
- include Charcoal::CORS
5
-
6
- allow_cors :test_action
7
-
8
- def test_action
9
- render :text => "noop"
10
- end
11
- end
12
-
13
- class TestCorsControllerTest < ActionController::TestCase
14
- context TestCorsController do
15
- context "allowing cors" do
16
- subject { TestCorsController.new }
17
-
18
- setup do
19
- subject.params = { :action => "test_action" }
20
- end
21
-
22
- should "allow cors" do
23
- assert subject.send(:cors_allowed?)
24
- end
25
- end
26
-
27
- context "cors callback" do
28
- {
29
- "Access-Control-Allow-Origin" => "allow-origin",
30
- "Access-Control-Allow-Credentials" => "credentials",
31
- }.each do |header, key|
32
- context "CORS header -> #{header}" do
33
- setup do
34
- @original, Charcoal.configuration[key] = Charcoal.configuration[key], "test"
35
-
36
- get :test_action
37
- end
38
-
39
- teardown do
40
- Charcoal.configuration[key] = @original
41
- end
42
-
43
- should "be the same as the configuration" do
44
- assert_equal "test", @response.headers[header], @response.headers.inspect
45
- end
46
- end
47
- end
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
-
69
- context "without any other request method" do
70
- setup do
71
- @original, Charcoal.configuration["expose-headers"] = Charcoal.configuration["expose-headers"], %w{test 123}
72
-
73
- get :test_action
74
- end
75
-
76
- teardown do
77
- Charcoal.configuration["expose-headers"] = @original
78
- end
79
-
80
- should "render action" do
81
- assert_equal "noop", @response.body
82
- end
83
-
84
- should "set Access-Control-Expose-Headers" do
85
- assert_equal "test,123", @response.headers["Access-Control-Expose-Headers"], @response.headers.inspect
86
- end
87
- end
88
- end
89
- end
90
- end
data/test/filters_test.rb DELETED
@@ -1,128 +0,0 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
2
-
3
- class FiltersControllerTester < ActionController::Base
4
- class << self
5
- include Charcoal::ControllerFilter
6
-
7
- allow :filtering do |method, directive|
8
- filtering_allowed[method] = directive
9
- end
10
-
11
- def filtering_allowed
12
- @filtering_allowed ||= Hash.new(lambda {|_| false })
13
- end
14
-
15
- def filtering_allowed?(instance, action)
16
- filtering_allowed[action.to_sym].try(:call, instance) ||
17
- (action != :all && filtering_allowed?(instance, :all))
18
- end
19
- end
20
-
21
- def filtering_allowed?
22
- self.class.filtering_allowed?(self, params[:action])
23
- end
24
-
25
- def test_action1; true; end
26
- def test_action2; false; end
27
- end
28
-
29
- class FiltersTest < ActiveSupport::TestCase
30
- context Charcoal::ControllerFilter do
31
- subject { FiltersControllerTester.new }
32
- setup do
33
- subject.params = {}
34
- end
35
-
36
- context "controller action filtering" do
37
- teardown do
38
- FiltersControllerTester.filtering_allowed.clear
39
- end
40
-
41
- context "if" do
42
- context "with a lambda" do
43
- setup { FiltersControllerTester.allow_filtering :test_action1, :if => lambda {|c| c.test_action1 } }
44
-
45
- should "should allow filtering for test_action1" do
46
- subject.params.replace(:action => :test_action1)
47
- assert subject.filtering_allowed?
48
- end
49
- end
50
-
51
- context "with a method" do
52
- setup { FiltersControllerTester.allow_filtering :test_action1, :if => :test_action1 }
53
-
54
- should "should allow filtering for test_action1" do
55
- subject.params.replace(:action => :test_action1)
56
- assert subject.filtering_allowed?
57
- end
58
- end
59
-
60
- context "with a true/false" do
61
- setup { FiltersControllerTester.allow_filtering :test_action1, :if => true }
62
-
63
- should "should allow filtering for test_action1" do
64
- subject.params.replace(:action => :test_action1)
65
- assert subject.filtering_allowed?
66
- end
67
- end
68
- end
69
-
70
- context "unless" do
71
- context "with a lambda" do
72
- setup { FiltersControllerTester.allow_filtering :test_action1, :unless => lambda {|c| c.test_action2 } }
73
-
74
- should "should allow filtering for test_action1" do
75
- subject.params.replace(:action => :test_action1)
76
- assert subject.filtering_allowed?
77
- end
78
- end
79
-
80
- context "with a method" do
81
- setup { FiltersControllerTester.allow_filtering :test_action1, :unless => :test_action2 }
82
-
83
- should "should allow filtering for test_action1" do
84
- subject.params.replace(:action => :test_action1)
85
- assert subject.filtering_allowed?
86
- end
87
- end
88
-
89
- context "with a true/false" do
90
- setup { FiltersControllerTester.allow_filtering :test_action1, :unless => false }
91
-
92
- should "should allow filtering for test_action1" do
93
- subject.params.replace(:action => :test_action1)
94
- assert subject.filtering_allowed?
95
- end
96
- end
97
- end
98
-
99
- context "only" do
100
- setup { FiltersControllerTester.allow_filtering :test_action1 }
101
-
102
- should "should allow filtering for test_action1" do
103
- subject.params.replace(:action => :test_action1)
104
- assert subject.filtering_allowed?
105
- end
106
-
107
- should "should not allow filtering for test_action2" do
108
- subject.params.replace(:action => :test_action2)
109
- assert !subject.filtering_allowed?
110
- end
111
- end
112
-
113
- context "none" do
114
- setup { FiltersControllerTester.allow_filtering }
115
-
116
- should "should allow filtering for test_action1" do
117
- subject.params.replace(:action => :test_action1)
118
- assert subject.filtering_allowed?
119
- end
120
-
121
- should "should allow filtering for test_action2" do
122
- subject.params.replace(:action => :test_action1)
123
- assert subject.filtering_allowed?
124
- end
125
- end
126
- end
127
- end
128
- end
data/test/helper.rb DELETED
@@ -1,68 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
-
4
- ENV["RAILS_ENV"] = "test"
5
-
6
- begin
7
- Bundler.setup(:default, :development, :test)
8
- rescue Bundler::BundlerError => e
9
- $stderr.puts e.message
10
- $stderr.puts "Run `bundle install` to install missing gems"
11
- exit e.status_code
12
- end
13
-
14
- require 'test/unit'
15
- require 'mocha/setup'
16
-
17
- # https://github.com/freerange/mocha/issues/94
18
- Mocha::Integration::TestUnit::AssertionCounter = Mocha::Integration::AssertionCounter
19
-
20
- require 'shoulda'
21
- require 'active_support/version'
22
-
23
- if ActiveSupport::VERSION::MAJOR >= 3
24
- require "action_controller/railtie"
25
- require "rails/test_unit/railtie"
26
-
27
- class TestApp < Rails::Application
28
- config.active_support.deprecation = :stderr
29
- config.logger = Logger.new(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i ? 'NUL:' : '/dev/null')
30
- end
31
-
32
- class TestEngine < Rails::Engine
33
- end
34
-
35
- TestApp.initialize!
36
-
37
- TestEngine.routes.draw do
38
- match '/engine/abc/test' => "engine#test", :via => :post
39
- end
40
-
41
- TestApp.routes.draw do
42
- mount TestEngine => ''
43
- match '/test' => "test#test", :via => [:get, :put]
44
- match '*path.:format' => 'charcoal/C_O_R_S#preflight', :via => :options
45
- match ':controller/:action'
46
- end
47
-
48
- class ActionController::TestCase
49
- def setup
50
- @routes = TestApp.routes
51
- end
52
- end
53
- else
54
- require "action_controller"
55
- require "active_support"
56
-
57
- MissingSourceFile::REGEXPS.push([/^cannot load such file -- (.+)$/i, 1])
58
-
59
- ActionController::Routing::Routes.draw do |map|
60
- map.connect '/test', :controller => :test, :action => :test, :conditions => { :method => [:get, :put] }
61
- map.connect "*path.:format", :conditions => { :method => :options }, :action => "preflight", :controller => "CORS", :namespace => "charcoal/"
62
- map.connect ':controller/:action'
63
- end
64
-
65
- ActionDispatch = ActionController
66
- end
67
-
68
- require 'charcoal'
data/test/jsonp_test.rb DELETED
@@ -1,105 +0,0 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
2
-
3
- class JSONPControllerTester < ActionController::Base
4
- include Charcoal::JSONP
5
-
6
- caches_action :test
7
- allow_jsonp :test
8
-
9
- def test
10
- render :json => { :key => :value }
11
- end
12
- end
13
-
14
- class JSONPTest < ActionController::TestCase
15
- tests JSONPControllerTester
16
-
17
- context JSONPControllerTester do
18
- context "with caching" do
19
- setup do
20
- @caching, ActionController::Base.perform_caching = ActionController::Base.perform_caching, true
21
- @cache_store, ActionController::Base.cache_store = ActionController::Base.cache_store, :memory_store
22
- end
23
-
24
- teardown do
25
- ActionController::Base.perform_caching = @caching
26
- ActionController::Base.cache_store = @cache_store
27
- end
28
-
29
- context "a GET to :test" do
30
- setup do
31
- get :test, :callback => "hello"
32
- end
33
-
34
- should "return a proper response" do
35
- assert_match /hello\(.*\)/, @response.body
36
- end
37
-
38
- should "return a proper response type" do
39
- assert_equal "application/javascript", @response.content_type
40
- end
41
-
42
- context "a second call" do
43
- setup do
44
- get :test, :callback => "hello"
45
- end
46
-
47
- should "properly cache the response" do
48
- assert_match /hello\(.*\)/, @response.body
49
- end
50
-
51
- should "properly cache the response type" do
52
- assert_equal "application/javascript", @response.content_type
53
- end
54
- end
55
- end
56
- end
57
- end
58
-
59
- context Charcoal::JSONP do
60
- subject { JSONPControllerTester.new }
61
-
62
- setup do
63
- subject.params = {}
64
- end
65
-
66
- context "jsonp callback" do
67
- setup do
68
- @response = '{"test": 123}'
69
- @content_type = "application/json"
70
-
71
- subject.response = ActionDispatch::Response.new
72
- subject.response.body = @response
73
- subject.response.status = '200 OK'
74
- subject.response.content_type = @content_type
75
- end
76
-
77
- context "with params" do
78
- setup do
79
- subject.params.replace(:callback => "callback", :action => "test")
80
- subject.send(:add_jsonp_callback) {}
81
- end
82
-
83
- should "add jsonp if there is a callback" do
84
- assert_equal "callback(#{@response})", subject.response.body
85
- end
86
-
87
- should "change content-type" do
88
- assert_equal "application/javascript", subject.response.content_type
89
- end
90
- end
91
-
92
- context "without params" do
93
- setup { subject.send(:add_jsonp_callback) {} }
94
-
95
- should "not add jsonp callback" do
96
- assert_equal @response, subject.response.body
97
- end
98
-
99
- should "not change content-type" do
100
- assert_equal @content_type, subject.response.content_type
101
- end
102
- end
103
- end
104
- end
105
- end