iceburn 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a79b92788b7e450df00428879d8d7dd0ca3e167b
4
- data.tar.gz: 6be5570ba58214811d2f6de1a24054611e741e59
3
+ metadata.gz: f6e02310aea7adbca0b0ec5601d1a94fca78b87d
4
+ data.tar.gz: 93f07e64ad647a36e28797a8e0b0e1cd19067329
5
5
  SHA512:
6
- metadata.gz: 75d359fc1d953c7cb4d02861436ab11cf6cc3bae559434e6cc31c855cefd2aacc120a6e82f71c79538536e5e5dc384666424f7a2de3bd3223ada3c08cd8f4996
7
- data.tar.gz: 9597602fbc7fc5bfb8cf3f45cfa126f7b874f03f8d610dfba4a14ac72f318836b3ab8e163b4821c36df8a45084e46decb1f533c0493f465517ea1f7bf3629323
6
+ metadata.gz: d9dfbb362c9709d87d1177858e33cfaa3ca8ef868f63f7f390454b489a51b570e9acf670c5200f1a0c1d814aa8dbdbe7c6ce347ae5db2b89d267e0daba7e3dcd
7
+ data.tar.gz: d8b05b361fb852cde4c5e8d81437abaae687ab024caf930c6c3fb68c9ca917f97d7d62c47388964fac88dfe6c783433cf99b35be1977fb04569a4cbc7d2e7a5b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- iceburn (0.0.3)
4
+ iceburn (0.0.4)
5
5
  rails
6
6
 
7
7
  GEM
@@ -1,3 +1,3 @@
1
1
  module Iceburn
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -9,11 +9,11 @@ module Iceburn
9
9
  extend ActiveSupport::Concern
10
10
 
11
11
  module ClassMethods
12
- cattr_accessor :iceburn_whitelisted_controllers
12
+ cattr_accessor :iceburn_whitelisted_routes
13
13
 
14
14
  # Set the whitelist of controllers not affected by Filters.
15
- def iceburn_whitelist(*controllers)
16
- self.iceburn_whitelisted_controllers = controllers
15
+ def iceburn_whitelist(*routes)
16
+ self.iceburn_whitelisted_routes = routes
17
17
  end
18
18
  end
19
19
 
@@ -21,11 +21,22 @@ module Iceburn
21
21
  # Test if this controller is in the pre-defined whitelist controller
22
22
  # params.
23
23
  def whitelisted?
24
- iceburn_whitelisted_controllers.include? params[:controller]
24
+ controller_whitelisted? || action_whitelisted?
25
25
  end
26
26
 
27
- def iceburn_whitelisted_controllers
28
- self.class.iceburn_whitelisted_controllers || []
27
+ private
28
+ def controller_whitelisted?
29
+ iceburn_whitelisted_routes.include? params[:controller]
30
+ end
31
+
32
+ def action_whitelisted?
33
+ iceburn_whitelisted_routes.any? do |route|
34
+ route =~ /#{params[:controller]}##{params[:action]}/
35
+ end
36
+ end
37
+
38
+ def iceburn_whitelisted_routes
39
+ self.class.iceburn_whitelisted_routes || []
29
40
  end
30
41
  end
31
42
  end
@@ -9,23 +9,48 @@ module Iceburn
9
9
  describe Whitelist do
10
10
  subject { Controller.new }
11
11
 
12
- context "when a whitelist is defined" do
12
+ context "when a whitelist is defined with only controllers" do
13
13
  before do
14
14
  Controller.class_eval { iceburn_whitelist 'sessions', 'users' }
15
15
  end
16
16
 
17
17
  it "defines a whitelist" do
18
- expect(Controller.iceburn_whitelisted_controllers).to include('sessions')
19
- expect(Controller.iceburn_whitelisted_controllers).to include('users')
18
+ expect(Controller.iceburn_whitelisted_routes).to include('sessions')
19
+ expect(Controller.iceburn_whitelisted_routes).to include('users')
20
20
  end
21
21
 
22
22
  it "whitelists controllers in the whitelist" do
23
23
  allow(subject).to receive(:params).and_return(:controller => 'sessions')
24
+ expect(subject.send(:controller_whitelisted?)).to eq(true)
24
25
  expect(subject).to be_whitelisted
25
26
  end
26
27
 
27
28
  it "allows other controllers to be filtered html" do
28
29
  allow(subject).to receive(:params).and_return(:controller => 'posts')
30
+ expect(subject.send(:controller_whitelisted?)).to eq(false)
31
+ expect(subject).to_not be_whitelisted
32
+ end
33
+ end
34
+
35
+ context "when a whitelist is defined with actions" do
36
+ before do
37
+ Controller.class_eval { iceburn_whitelist 'sessions#new' }
38
+ end
39
+
40
+ it "defines a whitelist" do
41
+ expect(Controller.iceburn_whitelisted_routes).to include('sessions#new')
42
+ end
43
+
44
+ it "whitelists controllers in the whitelist" do
45
+ allow(subject).to receive(:params).and_return \
46
+ :controller => 'sessions', :action => 'new'
47
+ expect(subject).to be_whitelisted
48
+ expect(subject.send(:action_whitelisted?)).to eq(true)
49
+ end
50
+
51
+ it "allows other controllers to be filtered html" do
52
+ allow(subject).to receive(:params).and_return(:controller => 'posts')
53
+ expect(subject.send(:action_whitelisted?)).to eq(false)
29
54
  expect(subject).to_not be_whitelisted
30
55
  end
31
56
  end
@@ -37,6 +62,8 @@ module Iceburn
37
62
 
38
63
  it "allows all controllers to be filtered html" do
39
64
  allow(subject).to receive(:params).and_return(:controller => 'sessions')
65
+ expect(subject.send(:controller_whitelisted?)).to eq(false)
66
+ expect(subject.send(:action_whitelisted?)).to eq(false)
40
67
  expect(subject).to_not be_whitelisted
41
68
  end
42
69
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iceburn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Scott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-21 00:00:00.000000000 Z
11
+ date: 2014-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails