Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 373
- Log:
Initial import of Radiant 0.9.1, which is now packaged as a gem. This is an
import of the tagged 0.9.1 source checked out from GitHub, which isn't quite
the same as the gem distribution - but it doesn't seem to be available in an
archived form and the installed gem already has modifications, so this is
the closest I can get.
- Author:
- rool
- Date:
- Mon Mar 21 13:40:05 +0000 2011
- Size:
- 2316 Bytes
1 | module Spec |
2 | module Rails |
3 | module Matchers |
4 | class LoginRequirement |
5 | def initialize(example) |
6 | @example = example |
7 | end |
8 | |
9 | def matches?(proc) |
10 | proc.call |
11 | @response = @example.response |
12 | @was_redirect = @response.redirect? |
13 | @was_redirect_to_login = @response.redirect_url_match?("/admin/login") |
14 | @was_redirect && @was_redirect_to_login |
15 | end |
16 | |
17 | def failure_message |
18 | if @was_redirect |
19 | "expected to redirect to /admin/login but redirected to #{@response.redirect_url}" |
20 | else |
21 | "expected to require login but did not redirect" |
22 | end |
23 | end |
24 | |
25 | def negative_failure_message |
26 | "expected not to require login" |
27 | end |
28 | end |
29 | |
30 | class ActionRestriction |
31 | def initialize(options, example) |
32 | @allow = [options[:allow]].flatten.compact |
33 | @deny = [options[:deny]].flatten.compact |
34 | @url = options[:url] |
35 | @example = example |
36 | end |
37 | |
38 | def matches?(proc) |
39 | @proc = proc |
40 | @result = {} |
41 | @urls = {} |
42 | @allow.all? {|u| !denied?(u) } && @deny.all? {|u| denied?(u) } |
43 | end |
44 | |
45 | def failure_message |
46 | message = [] |
47 | @allow.each do |user| |
48 | message << "expected to allow user #{user.name} but was denied" if @result[user] |
49 | end |
50 | @deny.each do |user| |
51 | if !@result[user] |
52 | message << "expected to deny user #{user.name} but was allowed" |
53 | elsif @urls[user] |
54 | message << "expected to redirect user #{user.name} to #{@url} but redirected to #{@urls[user]}" |
55 | end |
56 | end |
57 | message.to_sentence |
58 | end |
59 | |
60 | private |
61 | def denied?(user) |
62 | @example.request.session['user_id'] = user.id |
63 | @proc.call |
64 | response = @example.response |
65 | @urls[user] = response.redirect_url if @url && !response.redirect_url_match?(@url) |
66 | @result[user] = response.redirect? && (@url.nil? || response.redirect_url_match?(@url)) |
67 | end |
68 | end |
69 | |
70 | def require_login |
71 | LoginRequirement.new(self) |
72 | end |
73 | |
74 | def restrict_access(options) |
75 | ActionRestriction.new(options, self) |
76 | end |
77 | end |
78 | end |
79 | end |