restful_acl 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/restful_acl/url_parser.rb +1 -1
- data/restful_acl.gemspec +1 -1
- data/spec/lib/url_parser.rb +50 -0
- data/spec/spec_helper.rb +14 -3
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.
|
1
|
+
3.0.3
|
@@ -81,8 +81,8 @@ class UrlParser
|
|
81
81
|
# Find the requested URL out of the text block received
|
82
82
|
def requested_url
|
83
83
|
link = case @text
|
84
|
-
when URL then URL.match(@text)[1]
|
85
84
|
when AJAXURL then AJAXURL.match(@text)[1]
|
85
|
+
when URL then URL.match(@text)[1]
|
86
86
|
else raise RestfulAcl::UnrecognizedURLError, "'#{@text}' doesn't seem to contain a valid URL?"
|
87
87
|
end
|
88
88
|
end
|
data/restful_acl.gemspec
CHANGED
data/spec/lib/url_parser.rb
CHANGED
@@ -58,6 +58,18 @@ describe UrlParser do
|
|
58
58
|
UrlParser.new(@user){url("/parent_widgets/1")}.options_hash.should == expected
|
59
59
|
end
|
60
60
|
|
61
|
+
it "should recognize destroy parent_widget URLs" do
|
62
|
+
expected = {
|
63
|
+
:controller_name => "parent_widgets",
|
64
|
+
:object_id => "1",
|
65
|
+
:action => "destroy",
|
66
|
+
:uri => "/parent_widgets/1",
|
67
|
+
:user => @user
|
68
|
+
}
|
69
|
+
|
70
|
+
UrlParser.new(@user){ destroy_url("/parent_widgets/1") }.options_hash.should == expected
|
71
|
+
end
|
72
|
+
|
61
73
|
end
|
62
74
|
|
63
75
|
describe "child resources" do
|
@@ -110,6 +122,18 @@ describe UrlParser do
|
|
110
122
|
UrlParser.new(@user){url("/parent_widgets/1/child_widgets/1")}.options_hash.should == expected
|
111
123
|
end
|
112
124
|
|
125
|
+
it "should recognize destroy child URLs" do
|
126
|
+
expected = {
|
127
|
+
:controller_name => "child_widgets",
|
128
|
+
:object_id => "1",
|
129
|
+
:action => "destroy",
|
130
|
+
:uri => "/parent_widgets/1/child_widgets/1",
|
131
|
+
:user => @user
|
132
|
+
}
|
133
|
+
|
134
|
+
UrlParser.new(@user){ destroy_url("/parent_widgets/1/child_widgets/1") }.options_hash.should == expected
|
135
|
+
end
|
136
|
+
|
113
137
|
end
|
114
138
|
|
115
139
|
describe "singleton resources" do
|
@@ -150,6 +174,32 @@ describe UrlParser do
|
|
150
174
|
UrlParser.new(@user){url("/parent_widgets/1/singleton_widget")}.options_hash.should == expected
|
151
175
|
end
|
152
176
|
|
177
|
+
it "should recognize destroy singleton_widget URLs" do
|
178
|
+
expected = {
|
179
|
+
:controller_name => "singleton_widget",
|
180
|
+
:object_id => nil,
|
181
|
+
:action => "destroy",
|
182
|
+
:uri => "/parent_widgets/1/singleton_widget",
|
183
|
+
:user => @user
|
184
|
+
}
|
185
|
+
|
186
|
+
UrlParser.new(@user){destroy_url("/parent_widgets/1/singleton_widget")}.options_hash.should == expected
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "handling AJAX links" do
|
192
|
+
it "should give precidence to AJAX urls" do
|
193
|
+
expected = {
|
194
|
+
:controller_name => "parent_widgets",
|
195
|
+
:object_id => "1",
|
196
|
+
:action => "show",
|
197
|
+
:uri => "/parent_widgets/1",
|
198
|
+
:user => @user
|
199
|
+
}
|
200
|
+
|
201
|
+
UrlParser.new(@user){ajax_url("/parent_widgets/1")}.options_hash.should == expected
|
202
|
+
end
|
153
203
|
end
|
154
204
|
|
155
205
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,9 +7,20 @@ require 'rubygems'
|
|
7
7
|
require 'activesupport'
|
8
8
|
|
9
9
|
Spec::Runner.configure do |config|
|
10
|
-
|
10
|
+
|
11
11
|
def url(path)
|
12
12
|
"<a href=\"#{path}\">#{path}</a>"
|
13
13
|
end
|
14
|
-
|
15
|
-
|
14
|
+
|
15
|
+
def destroy_url(path)
|
16
|
+
"<a href=\"#{path}\" onclick=\"if (confirm('Are you sure?')) { var f = document.createElement('form');
|
17
|
+
f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;
|
18
|
+
var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method');
|
19
|
+
m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); };return false;\">Delete Image</a>"
|
20
|
+
end
|
21
|
+
|
22
|
+
def ajax_url(path)
|
23
|
+
"<a href=\"#\" onclick=\"if (confirm('Are you sure?')) { $.ajax({beforeSend:function(request){;}, complete:function(request){}, data:'_method=delete', dataType:'script', type:'post', url:'#{path}'}); }; return false;\"></a>"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|