restful_acl 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.1
1
+ 3.0.2
@@ -10,7 +10,7 @@ class UrlParser
10
10
  TypesOfURLs = [
11
11
  {:name => "parent_with_specific_child", :controller_bit => 3, :object_id_bit => 4, :regex => /\/(\w+)\/(\d+)[\w-]*\/(\w+)\/(\d+)[\w-]*$/},
12
12
  {:name => "parent_with_edit_child", :controller_bit => 3, :object_id_bit => 4, :regex => /\/(\w+)\/(\d+)[\w-]*\/(\w+)\/(\d+)[\w-]*\/edit$/},
13
- {:name => "parent_with_child_index", :controller_bit => 3, :object_id_bit => nil, :regex => /\/(\w+)\/(\d+)[\w-]*\/(\w+)$/},
13
+ {:name => "parent_with_child_index", :controller_bit => 3, :object_id_bit => nil, :regex => /\/(\w+)\/(\d+)\/\b(?!edit\b)(\w+)$/},
14
14
  {:name => "parent_with_new_child", :controller_bit => 3, :object_id_bit => nil, :regex => /\/(\w+)\/(\d+)[\w-]*\/(\w+)\/new$/},
15
15
  {:name => "edit_singleton_child", :controller_bit => 3, :object_id_bit => nil, :regex => /\/(\w+)\/(\d+)[\w-]*\/(\w+)\/edit$/},
16
16
  {:name => "new_singleton_child", :controller_bit => 3, :object_id_bit => nil, :regex => /\/(\w+)\/(\d+)[\w-]*\/(\w+)\/new$/},
@@ -92,11 +92,14 @@ class UrlParser
92
92
  def requested_action(controller_name)
93
93
  return "destroy" if @text =~ DestroyURL
94
94
 
95
- case @url
96
- when EditURL then "edit"
97
- when NewURL then "new"
98
- when ObjectURL || controller_name.singular? then "show"
99
- else "index"
95
+ if @url =~ EditURL
96
+ "edit"
97
+ elsif @url =~ NewURL
98
+ "new"
99
+ elsif @url =~ ObjectURL || controller_name.singular?
100
+ "show"
101
+ else
102
+ "index"
100
103
  end
101
104
  end
102
105
 
data/restful_acl.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{restful_acl}
8
- s.version = "3.0.1"
8
+ s.version = "3.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matt Darby"]
12
- s.date = %q{2009-12-07}
12
+ s.date = %q{2009-12-08}
13
13
  s.description = %q{A Ruby on Rails plugin that provides fine grained access control to RESTful resources.}
14
14
  s.email = %q{matt@matt-darby.com}
15
15
  s.extra_rdoc_files = [
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  "lib/restful_acl/url_parser.rb",
33
33
  "rails/init.rb",
34
34
  "restful_acl.gemspec",
35
+ "spec/lib/url_parser.rb",
35
36
  "spec/spec_helper.rb",
36
37
  "uninstall.rb"
37
38
  ]
@@ -41,7 +42,8 @@ Gem::Specification.new do |s|
41
42
  s.rubygems_version = %q{1.3.5}
42
43
  s.summary = %q{A Ruby on Rails plugin that provides fine grained access control to RESTful resources.}
43
44
  s.test_files = [
44
- "spec/spec_helper.rb"
45
+ "spec/lib/url_parser.rb",
46
+ "spec/spec_helper.rb"
45
47
  ]
46
48
 
47
49
  if s.respond_to? :specification_version then
@@ -0,0 +1,157 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe UrlParser do
4
+
5
+ before do
6
+ @user = mock('user')
7
+ end
8
+
9
+ describe "deducing the requested action" do
10
+
11
+ describe "parent_widget resources" do
12
+
13
+ it "should recognize parent_widget index URLs" do
14
+ expected = {
15
+ :controller_name => "parent_widgets",
16
+ :object_id => nil,
17
+ :action => "index",
18
+ :uri => "/parent_widgets",
19
+ :user => @user
20
+ }
21
+
22
+ UrlParser.new(@user){url("/parent_widgets")}.options_hash.should == expected
23
+ end
24
+
25
+ it "should recognize parent_widget edit URLs" do
26
+ expected = {
27
+ :controller_name => "parent_widgets",
28
+ :object_id => "1",
29
+ :action => "edit",
30
+ :uri => "/parent_widgets/1/edit",
31
+ :user => @user
32
+ }
33
+
34
+ UrlParser.new(@user){url("/parent_widgets/1/edit")}.options_hash.should == expected
35
+ end
36
+
37
+ it "should recognize new parent_widget URLs" do
38
+ expected = {
39
+ :controller_name => "parent_widgets",
40
+ :object_id => nil,
41
+ :action => "new",
42
+ :uri => "/parent_widgets/new",
43
+ :user => @user
44
+ }
45
+
46
+ UrlParser.new(@user){url("/parent_widgets/new")}.options_hash.should == expected
47
+ end
48
+
49
+ it "should recognize show parent_widget URLs" do
50
+ expected = {
51
+ :controller_name => "parent_widgets",
52
+ :object_id => "1",
53
+ :action => "show",
54
+ :uri => "/parent_widgets/1",
55
+ :user => @user
56
+ }
57
+
58
+ UrlParser.new(@user){url("/parent_widgets/1")}.options_hash.should == expected
59
+ end
60
+
61
+ end
62
+
63
+ describe "child resources" do
64
+
65
+ it "should recognize child index URLs" do
66
+ expected = {
67
+ :controller_name => "child_widgets",
68
+ :object_id => nil,
69
+ :action => "index",
70
+ :uri => "/parent_widgets/1/child_widgets",
71
+ :user => @user
72
+ }
73
+
74
+ UrlParser.new(@user){url("/parent_widgets/1/child_widgets")}.options_hash.should == expected
75
+ end
76
+
77
+ it "should recognize child edit URLs" do
78
+ expected = {
79
+ :controller_name => "child_widgets",
80
+ :object_id => "1",
81
+ :action => "edit",
82
+ :uri => "/parent_widgets/1/child_widgets/1/edit",
83
+ :user => @user
84
+ }
85
+
86
+ UrlParser.new(@user){url("/parent_widgets/1/child_widgets/1/edit")}.options_hash.should == expected
87
+ end
88
+
89
+ it "should recognize new child URLs" do
90
+ expected = {
91
+ :controller_name => "child_widgets",
92
+ :object_id => nil,
93
+ :action => "new",
94
+ :uri => "/parent_widgets/1/child_widgets/new",
95
+ :user => @user
96
+ }
97
+
98
+ UrlParser.new(@user){url("/parent_widgets/1/child_widgets/new")}.options_hash.should == expected
99
+ end
100
+
101
+ it "should recognize show child URLs" do
102
+ expected = {
103
+ :controller_name => "child_widgets",
104
+ :object_id => "1",
105
+ :action => "show",
106
+ :uri => "/parent_widgets/1/child_widgets/1",
107
+ :user => @user
108
+ }
109
+
110
+ UrlParser.new(@user){url("/parent_widgets/1/child_widgets/1")}.options_hash.should == expected
111
+ end
112
+
113
+ end
114
+
115
+ describe "singleton resources" do
116
+
117
+ it "should recognize singleton_widget edit URLs" do
118
+ expected = {
119
+ :controller_name => "singleton_widget",
120
+ :object_id => nil,
121
+ :action => "edit",
122
+ :uri => "/parent_widgets/1/singleton_widget/edit",
123
+ :user => @user
124
+ }
125
+
126
+ UrlParser.new(@user){url("/parent_widgets/1/singleton_widget/edit")}.options_hash.should == expected
127
+ end
128
+
129
+ it "should recognize new singleton_widget URLs" do
130
+ expected = {
131
+ :controller_name => "singleton_widget",
132
+ :object_id => nil,
133
+ :action => "new",
134
+ :uri => "/parent_widgets/1/singleton_widget/new",
135
+ :user => @user
136
+ }
137
+
138
+ UrlParser.new(@user){url("/parent_widgets/1/singleton_widget/new")}.options_hash.should == expected
139
+ end
140
+
141
+ it "should recognize show singleton_widget URLs" do
142
+ expected = {
143
+ :controller_name => "singleton_widget",
144
+ :object_id => nil,
145
+ :action => "show",
146
+ :uri => "/parent_widgets/1/singleton_widget",
147
+ :user => @user
148
+ }
149
+
150
+ UrlParser.new(@user){url("/parent_widgets/1/singleton_widget")}.options_hash.should == expected
151
+ end
152
+
153
+ end
154
+
155
+ end
156
+
157
+ end
data/spec/spec_helper.rb CHANGED
@@ -8,4 +8,8 @@ require 'activesupport'
8
8
 
9
9
  Spec::Runner.configure do |config|
10
10
 
11
+ def url(path)
12
+ "<a href=\"#{path}\">#{path}</a>"
13
+ end
14
+
11
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restful_acl
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Darby
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-07 00:00:00 -05:00
12
+ date: 2009-12-08 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -47,6 +47,7 @@ files:
47
47
  - lib/restful_acl/url_parser.rb
48
48
  - rails/init.rb
49
49
  - restful_acl.gemspec
50
+ - spec/lib/url_parser.rb
50
51
  - spec/spec_helper.rb
51
52
  - uninstall.rb
52
53
  has_rdoc: true
@@ -78,4 +79,5 @@ signing_key:
78
79
  specification_version: 3
79
80
  summary: A Ruby on Rails plugin that provides fine grained access control to RESTful resources.
80
81
  test_files:
82
+ - spec/lib/url_parser.rb
81
83
  - spec/spec_helper.rb