radiant 0.6.7 → 0.6.8
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of radiant might be problematic. Click here for more details.
- data/CHANGELOG +35 -3
- data/CONTRIBUTORS +11 -1
- data/README +5 -3
- data/app/controllers/admin/welcome_controller.rb +7 -0
- data/app/migrate/020_add_session_info_to_users.rb +11 -0
- data/app/models/page.rb +22 -9
- data/app/models/standard_tags.rb +133 -10
- data/app/models/user.rb +9 -1
- data/app/views/admin/page/edit.html.haml +5 -4
- data/app/views/admin/welcome/login.html.haml +42 -24
- data/app/views/layouts/application.html.haml +1 -1
- data/config/environment.rb +4 -2
- data/db/migrate/020_add_session_info_to_users.rb +11 -0
- data/db/migrate/021_remove_session_expire_from_users.rb +9 -0
- data/db/schema.rb +3 -2
- data/lib/generators/instance/instance_generator.rb +2 -1
- data/lib/generators/instance/templates/instance_environment.rb +5 -3
- data/lib/login_system.rb +13 -0
- data/lib/radiant.rb +1 -1
- data/lib/radiant/admin_ui.rb +21 -21
- data/lib/radiant/extension/script.rb +251 -0
- data/lib/radiant/extension_loader.rb +22 -20
- data/lib/radiant/initializer.rb +1 -1
- data/lib/radiant/setup.rb +2 -0
- data/lib/tasks/framework.rake +39 -29
- data/public/500.html +1 -1
- data/public/javascripts/admin/admin.js +11 -9
- data/script/extension +5 -0
- data/spec/controllers/admin/user_controller_spec.rb +1 -1
- data/spec/controllers/admin/welcome_controller_spec.rb +31 -5
- data/spec/controllers/site_controller_spec.rb +15 -2
- data/spec/lib/login_system_spec.rb +106 -60
- data/spec/lib/radiant/extension/script_spec.rb +349 -0
- data/spec/lib/radiant/extension_loader_spec.rb +3 -0
- data/spec/models/page_spec.rb +62 -2
- data/spec/models/standard_tags_spec.rb +150 -3
- data/spec/models/user_spec.rb +28 -0
- data/spec/scenarios/file_not_found_scenario.rb +5 -0
- data/spec/scenarios/pages_scenario.rb +6 -0
- data/spec/scenarios/snippets_scenario.rb +4 -0
- data/test/fixtures/users.yml +11 -6
- data/vendor/plugins/haml/FAQ +138 -0
- data/vendor/plugins/haml/REVISION +1 -0
- data/vendor/plugins/haml/Rakefile +54 -62
- data/vendor/plugins/haml/VERSION +1 -1
- data/vendor/plugins/haml/init.rb +6 -1
- data/vendor/plugins/haml/lib/haml.rb +72 -12
- data/vendor/plugins/haml/lib/haml/buffer.rb +47 -40
- data/vendor/plugins/haml/lib/haml/engine.rb +20 -30
- data/vendor/plugins/haml/lib/haml/error.rb +4 -5
- data/vendor/plugins/haml/lib/haml/exec.rb +4 -2
- data/vendor/plugins/haml/lib/haml/filters.rb +30 -15
- data/vendor/plugins/haml/lib/haml/helpers.rb +47 -28
- data/vendor/plugins/haml/lib/haml/helpers/action_view_mods.rb +74 -25
- data/vendor/plugins/haml/lib/haml/precompiler.rb +92 -51
- data/vendor/plugins/haml/lib/haml/template.rb +11 -3
- data/vendor/plugins/haml/lib/haml/template/patch.rb +1 -1
- data/vendor/plugins/haml/lib/sass.rb +26 -3
- data/vendor/plugins/haml/lib/sass/constant.rb +26 -57
- data/vendor/plugins/haml/lib/sass/constant/literal.rb +1 -0
- data/vendor/plugins/haml/lib/sass/constant/nil.rb +9 -0
- data/vendor/plugins/haml/lib/sass/css.rb +17 -2
- data/vendor/plugins/haml/lib/sass/engine.rb +11 -5
- data/vendor/plugins/haml/test/haml/engine_test.rb +57 -39
- data/vendor/plugins/haml/test/haml/helper_test.rb +20 -4
- data/vendor/plugins/haml/test/haml/html2haml_test.rb +1 -3
- data/vendor/plugins/haml/test/haml/results/content_for_layout.xhtml +1 -2
- data/vendor/plugins/haml/test/haml/results/eval_suppressed.xhtml +2 -4
- data/vendor/plugins/haml/test/haml/results/filters.xhtml +12 -8
- data/vendor/plugins/haml/test/haml/results/helpers.xhtml +2 -5
- data/vendor/plugins/haml/test/haml/results/just_stuff.xhtml +1 -3
- data/vendor/plugins/haml/test/haml/results/nuke_inner_whitespace.xhtml +40 -0
- data/vendor/plugins/haml/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
- data/vendor/plugins/haml/test/haml/results/original_engine.xhtml +2 -4
- data/vendor/plugins/haml/test/haml/results/tag_parsing.xhtml +1 -6
- data/vendor/plugins/haml/test/haml/results/very_basic.xhtml +2 -4
- data/vendor/plugins/haml/test/haml/results/whitespace_handling.xhtml +13 -21
- data/vendor/plugins/haml/test/haml/template_test.rb +31 -48
- data/vendor/plugins/haml/test/haml/templates/filters.haml +13 -0
- data/vendor/plugins/haml/test/haml/templates/helpers.haml +1 -1
- data/vendor/plugins/haml/test/haml/templates/just_stuff.haml +0 -1
- data/vendor/plugins/haml/test/haml/templates/nuke_inner_whitespace.haml +32 -0
- data/vendor/plugins/haml/test/haml/templates/nuke_outer_whitespace.haml +144 -0
- data/vendor/plugins/haml/test/haml/templates/partials.haml +1 -1
- data/vendor/plugins/haml/test/haml/templates/tag_parsing.haml +0 -3
- data/vendor/plugins/haml/test/haml/templates/whitespace_handling.haml +10 -10
- data/vendor/plugins/haml/test/sass/engine_test.rb +11 -5
- data/vendor/plugins/haml/test/sass/plugin_test.rb +2 -6
- data/vendor/plugins/haml/test/sass/results/constants.css +2 -0
- data/vendor/plugins/haml/test/sass/templates/constants.sass +3 -0
- data/vendor/plugins/haml/test/{haml/test_helper.rb → test_helper.rb} +4 -3
- metadata +21 -11
- data/vendor/plugins/haml/TODO +0 -9
- data/vendor/plugins/haml/extra/haml-mode.el +0 -328
- data/vendor/plugins/haml/extra/sass-mode.el +0 -88
- data/vendor/plugins/haml/test/profile.rb +0 -65
@@ -3,18 +3,18 @@ require 'method_observer'
|
|
3
3
|
|
4
4
|
module Radiant
|
5
5
|
class ExtensionLoader
|
6
|
-
|
6
|
+
|
7
7
|
class DependenciesObserver < MethodObserver
|
8
8
|
attr_accessor :config
|
9
|
-
|
9
|
+
|
10
10
|
def initialize(rails_config)
|
11
11
|
@config = rails_config
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def before_clear(*args)
|
15
15
|
ExtensionLoader.deactivate_extensions
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def after_clear(*args)
|
19
19
|
ExtensionLoader.load_extensions
|
20
20
|
ExtensionLoader.activate_extensions
|
@@ -22,17 +22,17 @@ module Radiant
|
|
22
22
|
end
|
23
23
|
|
24
24
|
include Simpleton
|
25
|
-
|
25
|
+
|
26
26
|
attr_accessor :initializer, :extensions
|
27
|
-
|
27
|
+
|
28
28
|
def initialize
|
29
29
|
self.extensions = []
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def configuration
|
33
33
|
initializer.configuration
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def extension_load_paths
|
37
37
|
load_extension_roots.map { |extension| load_paths_for(extension) }.flatten.select { |d| File.directory?(d) }
|
38
38
|
end
|
@@ -40,14 +40,14 @@ module Radiant
|
|
40
40
|
def plugin_paths
|
41
41
|
load_extension_roots.map {|extension| "#{extension}/vendor/plugins" }.select {|d| File.directory?(d) }
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def add_extension_paths
|
45
45
|
extension_load_paths.reverse_each do |path|
|
46
46
|
configuration.load_paths.unshift path
|
47
47
|
$LOAD_PATH.unshift path
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
def add_plugin_paths
|
52
52
|
configuration.plugin_paths.concat plugin_paths
|
53
53
|
end
|
@@ -55,15 +55,15 @@ module Radiant
|
|
55
55
|
def controller_paths
|
56
56
|
extensions.map { |extension| "#{extension.root}/app/controllers" }.select { |d| File.directory?(d) }
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def add_controller_paths
|
60
60
|
configuration.controller_paths.concat(controller_paths)
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
def view_paths
|
64
64
|
extensions.map { |extension| "#{extension.root}/app/views" }.select { |d| File.directory?(d) }
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
# Load the extensions
|
68
68
|
def load_extensions
|
69
69
|
@observer ||= DependenciesObserver.new(configuration).observe(::Dependencies)
|
@@ -80,15 +80,17 @@ module Radiant
|
|
80
80
|
end
|
81
81
|
end.compact
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
def deactivate_extensions
|
85
85
|
extensions.each &:deactivate
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def activate_extensions
|
89
89
|
initializer.initialize_default_admin_tabs
|
90
|
-
# Reset the view paths after
|
90
|
+
# Reset the view paths after
|
91
91
|
initializer.initialize_framework_views
|
92
|
+
# Reset the admin UI regions
|
93
|
+
initializer.admin.load_default_regions
|
92
94
|
extensions.each &:activate
|
93
95
|
end
|
94
96
|
alias :reactivate :activate_extensions
|
@@ -105,7 +107,7 @@ module Radiant
|
|
105
107
|
[]
|
106
108
|
end
|
107
109
|
end
|
108
|
-
|
110
|
+
|
109
111
|
def load_extension_roots
|
110
112
|
@load_extension_roots ||= unless configuration.extensions.empty?
|
111
113
|
select_extension_roots
|
@@ -113,10 +115,10 @@ module Radiant
|
|
113
115
|
[]
|
114
116
|
end
|
115
117
|
end
|
116
|
-
|
118
|
+
|
117
119
|
def select_extension_roots
|
118
120
|
all_roots = all_extension_roots.dup
|
119
|
-
|
121
|
+
|
120
122
|
roots = configuration.extensions.map do |ext_name|
|
121
123
|
if :all === ext_name
|
122
124
|
:all
|
@@ -135,7 +137,7 @@ module Radiant
|
|
135
137
|
end
|
136
138
|
roots
|
137
139
|
end
|
138
|
-
|
140
|
+
|
139
141
|
def all_extension_roots
|
140
142
|
@all_extension_roots ||= configuration.extension_paths.map do |path|
|
141
143
|
Dir["#{path}/*"].map {|f| File.expand_path(f) if File.directory?(f) }.compact.sort
|
data/lib/radiant/initializer.rb
CHANGED
@@ -21,7 +21,7 @@ module Radiant
|
|
21
21
|
|
22
22
|
def default_extension_paths
|
23
23
|
env = ENV["RAILS_ENV"] || RAILS_ENV
|
24
|
-
paths = [
|
24
|
+
paths = [RAILS_ROOT + '/vendor/extensions', RADIANT_ROOT + '/vendor/extensions'].uniq
|
25
25
|
# There's no other way it will work, config/environments/test.rb loads too late
|
26
26
|
# TODO: Should figure out how to include this extension path only for the tests that need it
|
27
27
|
paths.unshift(RADIANT_ROOT + "/test/fixtures/extensions") if env == "test"
|
data/lib/radiant/setup.rb
CHANGED
@@ -49,6 +49,8 @@ module Radiant
|
|
49
49
|
step { Radiant::Config['admin.subtitle'] = 'Publishing for Small Teams' }
|
50
50
|
step { Radiant::Config['defaults.page.parts' ] = 'body, extended' }
|
51
51
|
step { Radiant::Config['defaults.page.status' ] = 'draft' }
|
52
|
+
step { Radiant::Config['defaults.page.filter' ] = nil }
|
53
|
+
step { Radiant::Config['session_timeout'] = 2.weeks }
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
data/lib/tasks/framework.rake
CHANGED
@@ -28,39 +28,41 @@ unless File.directory? "#{RAILS_ROOT}/app"
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
desc "Lock to latest Edge Radiant or a specific revision with REVISION=X (ex: REVISION=
|
31
|
+
desc "Lock to latest Edge Radiant or a specific revision with REVISION=X (ex: REVISION=245484e), a tag with TAG=Y (ex: TAG=0.6.6), or a branch with BRANCH=Z (ex: BRANCH=mental)"
|
32
32
|
task :edge do
|
33
33
|
$verbose = false
|
34
|
-
|
34
|
+
system "git --version" rescue nil
|
35
35
|
unless !$?.nil? && $?.success?
|
36
|
-
$stderr.puts "ERROR: Must have
|
36
|
+
$stderr.puts "ERROR: Must have git available in the PATH to lock this application to Edge Radiant"
|
37
37
|
exit 1
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
mkdir_p "vendor/radiant"
|
42
|
-
|
43
|
-
svn_root = "http://svn.radiantcms.org/radiant/"
|
40
|
+
radiant_git = "git://github.com/radiant/radiant.git"
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
42
|
+
if File.exist?("vendor/radiant/.git/HEAD")
|
43
|
+
case
|
44
|
+
when ENV['TAG']
|
45
|
+
system "cd vendor/radiant; git pull origin master; git checkout -b #{ENV['TAG']}"
|
46
|
+
when ENV['BRANCH']
|
47
|
+
system "cd vendor/radiant; git pull origin master; git checkout --track -b #{ENV['BRANCH']} origin/#{ENV['BRANCH']}"
|
48
|
+
when ENV['REVISION']
|
49
|
+
system "cd vendor/radiant; git pull origin master; git checkout -b REV_#{ENV['REVISION']} #{ENV['REVISION']}"
|
50
|
+
else
|
51
|
+
system "cd vendor/radiant; git pull origin master"
|
52
|
+
end
|
52
53
|
else
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
case
|
55
|
+
when ENV['TAG']
|
56
|
+
system "git clone #{radiant_git} vendor/radiant"
|
57
|
+
system "cd vendor/radiant; git checkout -b #{ENV['TAG']}"
|
58
|
+
when ENV['BRANCH']
|
59
|
+
system "git clone #{radiant_git} vendor/radiant"
|
60
|
+
system "cd vendor/radiant; git checkout --track -b #{ENV['BRANCH']} origin/#{ENV['BRANCH']}"
|
61
|
+
when ENV['REVISION']
|
62
|
+
system "git clone #{radiant_git} vendor/radiant"
|
63
|
+
system "cd vendor/radiant; git checkout -b REV_#{ENV['REVISION']} #{ENV['REVISION']}"
|
58
64
|
end
|
59
|
-
|
60
|
-
touch "vendor/radiant/REVISION_#{ENV['REVISION']}"
|
61
65
|
end
|
62
|
-
|
63
|
-
system "svn export #{radiant_svn}/radiant vendor/radiant" + (ENV['REVISION'] ? " -r #{ENV['REVISION']}" : "") + " --force"
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
@@ -97,27 +99,35 @@ unless File.directory? "#{RAILS_ROOT}/app"
|
|
97
99
|
task :javascripts do
|
98
100
|
FileUtils.mkdir_p("#{RAILS_ROOT}/public/javascripts/admin/")
|
99
101
|
copy_javascripts = proc do |project_dir, scripts|
|
100
|
-
scripts.reject!{|s| File.basename(s) == 'application.js'} if File.exists?(project_dir + 'application.js')
|
101
|
-
FileUtils.cp(scripts, project_dir)
|
102
|
+
scripts.reject!{|s| File.basename(s) == 'application.js'} if File.exists?(project_dir + 'application.js')
|
103
|
+
FileUtils.cp(scripts, project_dir)
|
102
104
|
end
|
103
|
-
copy_javascripts[RAILS_ROOT + '/public/javascripts/', Dir["#{File.dirname(__FILE__)}/../../public/javascripts/*.js"]]
|
105
|
+
copy_javascripts[RAILS_ROOT + '/public/javascripts/', Dir["#{File.dirname(__FILE__)}/../../public/javascripts/*.js"]]
|
104
106
|
copy_javascripts[RAILS_ROOT + '/public/javascripts/admin/', Dir["#{File.dirname(__FILE__)}/../../public/javascripts/admin/*.js"]]
|
105
107
|
end
|
106
108
|
|
107
109
|
desc "Update config/boot.rb from your current radiant install"
|
108
110
|
task :configs do
|
111
|
+
require 'erb'
|
109
112
|
FileUtils.cp("#{File.dirname(__FILE__)}/../generators/instance/templates/instance_boot.rb", RAILS_ROOT + '/config/boot.rb')
|
110
113
|
instance_env = "#{RAILS_ROOT}/config/environment.rb"
|
114
|
+
tmp_env = "#{RAILS_ROOT}/config/environment.tmp"
|
115
|
+
File.open(tmp_env, 'w') do |f|
|
116
|
+
f.write ERB.new(File.read(instance_env)).result(lambda do
|
117
|
+
app_name = File.basename(File.expand_path(RAILS_ROOT))
|
118
|
+
end)
|
119
|
+
end
|
111
120
|
gen_env = "#{File.dirname(__FILE__)}/../generators/instance/templates/instance_environment.rb"
|
112
121
|
backup_env = "#{RAILS_ROOT}/config/environment.bak"
|
113
|
-
unless FileUtils.compare_file(instance_env,
|
122
|
+
unless FileUtils.compare_file(instance_env, tmp_env)
|
114
123
|
FileUtils.cp(instance_env, backup_env)
|
115
|
-
FileUtils.cp(
|
124
|
+
FileUtils.cp(tmp_env, instance_env)
|
116
125
|
puts "** WARNING **
|
117
|
-
config/environment.rb
|
126
|
+
config/environment.rb was changed in Radiant 0.6.5. Your original has been
|
118
127
|
backed up to config/environment.bak and replaced with the packaged version.
|
119
128
|
Please copy your customizations to the new file."
|
120
129
|
end
|
130
|
+
FileUtils.rm(tmp_env)
|
121
131
|
end
|
122
132
|
|
123
133
|
desc "Update admin images from your current radiant install"
|
data/public/500.html
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
"http://www.w3.org/TR/html4/loose.dtd">
|
3
3
|
<html>
|
4
4
|
<body>
|
5
|
-
<h1>Application error
|
5
|
+
<h1>Application error</h1>
|
6
6
|
<p>Change this error message for exceptions thrown outside of an action (like in Dispatcher setups or broken Ruby code) in public/500.html</p>
|
7
7
|
</body>
|
8
8
|
</html>
|
@@ -55,16 +55,18 @@ document.observe('dom:loaded', function() {
|
|
55
55
|
});
|
56
56
|
});
|
57
57
|
|
58
|
-
when('
|
59
|
-
if($
|
60
|
-
$('
|
61
|
-
|
62
|
-
select.observe('change', function(){
|
63
|
-
if($F(this) == '100')
|
58
|
+
when('publication-date', function(pub_date){
|
59
|
+
if($('page_status_id')) {
|
60
|
+
if($F('page_status_id') == '100')
|
64
61
|
$('publication-date').show().select('select').invoke('enable');
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
|
63
|
+
$('page_status_id').observe('change', function(){
|
64
|
+
if($F(this) == '100')
|
65
|
+
$('publication-date').show().select('select').invoke('enable');
|
66
|
+
else
|
67
|
+
$('publication-date').hide().select('select').invoke('disable');
|
68
|
+
})
|
69
|
+
}
|
68
70
|
});
|
69
71
|
|
70
72
|
when('notice', function(notice) {
|
data/script/extension
ADDED
@@ -6,7 +6,7 @@ describe Admin::UserController do
|
|
6
6
|
|
7
7
|
integrate_views
|
8
8
|
|
9
|
-
it "should inherit from the
|
9
|
+
it "should inherit from the abstract model controller" do
|
10
10
|
Admin::UserController.ancestors.should include(Admin::AbstractModelController)
|
11
11
|
end
|
12
12
|
|
@@ -28,11 +28,25 @@ describe Admin::WelcomeController do
|
|
28
28
|
flash[:error].should_not be_nil
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
describe "remember me" do
|
32
|
+
|
33
|
+
before do
|
34
|
+
Radiant::Config.stub!(:[]).with('session_timeout').and_return(2.weeks)
|
35
|
+
@user = users(:admin)
|
36
|
+
controller.stub!(:current_user).and_return(@user)
|
37
|
+
end
|
38
|
+
|
39
|
+
after do
|
40
|
+
post :login, :user => {:login => "admin", :password => "password"}, :remember_me => 1
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should remember user" do
|
44
|
+
@user.should_receive(:remember_me)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should set cookie" do
|
48
|
+
controller.should_receive(:set_session_cookie)
|
49
|
+
end
|
36
50
|
end
|
37
51
|
|
38
52
|
describe "with a logged-in user" do
|
@@ -40,6 +54,18 @@ describe Admin::WelcomeController do
|
|
40
54
|
login_as :admin
|
41
55
|
end
|
42
56
|
|
57
|
+
it "should clear the current user and redirect on logout" do
|
58
|
+
controller.should_receive(:current_user=).with(nil)
|
59
|
+
get :logout
|
60
|
+
response.should be_redirect
|
61
|
+
response.should redirect_to(login_url)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should forget user on logout" do
|
65
|
+
controller.send(:current_user).should_receive(:forget_me)
|
66
|
+
get :logout
|
67
|
+
end
|
68
|
+
|
43
69
|
it "should not show /login again" do
|
44
70
|
get :login
|
45
71
|
response.should redirect_to(welcome_url)
|
@@ -91,7 +91,7 @@ end
|
|
91
91
|
describe SiteController, "when custom 404 pages are defined" do
|
92
92
|
scenario :file_not_found
|
93
93
|
|
94
|
-
it "should use the top-most 404 page by default" do
|
94
|
+
it "should use the top-most published 404 page by default" do
|
95
95
|
get :show_page, :url => "/foo"
|
96
96
|
response.should be_missing
|
97
97
|
assigns[:page].should == pages(:file_not_found)
|
@@ -101,9 +101,22 @@ describe SiteController, "when custom 404 pages are defined" do
|
|
101
101
|
assigns[:page].should == pages(:file_not_found)
|
102
102
|
end
|
103
103
|
|
104
|
-
it "should use
|
104
|
+
it "should use the first published custom 404 page defined under a parent page" do
|
105
105
|
get :show_page, :url => "/gallery/draft"
|
106
106
|
response.should be_missing
|
107
107
|
assigns[:page].should == pages(:no_picture)
|
108
108
|
end
|
109
|
+
|
110
|
+
it "should not find hidden draft pages in live mode" do
|
111
|
+
get :show_page, :url => "/drafts/missing"
|
112
|
+
response.should be_missing
|
113
|
+
assigns[:page].should_not == pages(:lonely_draft_file_not_found)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should find hidden draft pages in dev mode" do
|
117
|
+
request.host = 'dev.mysite.com'
|
118
|
+
get :show_page, :url => "/drafts/missing"
|
119
|
+
response.should be_missing
|
120
|
+
assigns[:page].should == pages(:lonely_draft_file_not_found)
|
121
|
+
end
|
109
122
|
end
|
@@ -7,56 +7,21 @@ class StubController < ActionController::Base
|
|
7
7
|
|
8
8
|
def method_missing(method, *args, &block)
|
9
9
|
if (args.size == 0) and not block_given?
|
10
|
-
render :text => 'just a test'
|
10
|
+
render :text => 'just a test' unless @performed_render || @performed_redirect
|
11
11
|
else
|
12
12
|
super
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
class NoLoginRequiredController < StubController
|
21
|
-
no_login_required
|
22
|
-
end
|
23
|
-
|
24
|
-
class NoLoginRequiredChildController < NoLoginRequiredController
|
25
|
-
end
|
26
|
-
|
27
|
-
class LoginRequiredGrandChildController < NoLoginRequiredChildController
|
28
|
-
login_required
|
29
|
-
end
|
30
|
-
|
31
|
-
class LoginRequiredGreatGrandChildController < LoginRequiredGrandChildController
|
32
|
-
end
|
33
|
-
|
34
|
-
describe StubController do
|
35
|
-
it "should add self to controllers_where_no_login_required" do
|
36
|
-
StubController.controllers_where_no_login_required.should include(NoLoginRequiredController)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should inherit no_login_required" do
|
40
|
-
StubController.controllers_where_no_login_required.should include(NoLoginRequiredChildController)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should override parent with login_required" do
|
44
|
-
StubController.controllers_where_no_login_required.should_not include(LoginRequiredGrandChildController)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should inherit login_required" do
|
48
|
-
StubController.controllers_where_no_login_required.should_not include(LoginRequiredGreatGrandChildController)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe NoLoginRequiredController, :type => :controller do
|
17
|
+
describe NoLoginRequiredController = StubController.subclass('NoLoginRequiredController') { no_login_required }, :type => :controller do
|
53
18
|
it "should not require authentication" do
|
54
19
|
get :index
|
55
20
|
response.should be_success
|
56
21
|
end
|
57
22
|
end
|
58
23
|
|
59
|
-
describe LoginRequiredController, :type => :controller do
|
24
|
+
describe LoginRequiredController = StubController.subclass('LoginRequiredController') { }, :type => :controller do
|
60
25
|
scenario :users
|
61
26
|
|
62
27
|
it "should authenticate with user in session" do
|
@@ -71,16 +36,99 @@ describe LoginRequiredController, :type => :controller do
|
|
71
36
|
end
|
72
37
|
|
73
38
|
it "should store location" do
|
39
|
+
session[:return_to] = nil
|
74
40
|
get 'protected_action'
|
75
|
-
session[:return_to].should match(
|
41
|
+
session[:return_to].should match(%r{protected_action})
|
76
42
|
end
|
77
43
|
end
|
78
44
|
|
79
|
-
|
80
|
-
|
45
|
+
describe StubController, :type => :controller do
|
46
|
+
it "should add self to controllers_where_no_login_required" do
|
47
|
+
StubController.controllers_where_no_login_required.should include(NoLoginRequiredController)
|
48
|
+
end
|
49
|
+
|
50
|
+
describe ".authenticate" do
|
51
|
+
it "should attempt to login from cookie" do
|
52
|
+
controller.should_receive(:login_from_cookie)
|
53
|
+
get :action
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe ".login_from_cookie" do
|
58
|
+
|
59
|
+
before do
|
60
|
+
Radiant::Config.stub!(:[]).with('session_timeout').and_return(2.weeks)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not login user if no cookie found" do
|
64
|
+
controller.should_not_receive(:current_user=)
|
65
|
+
get :index
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "with session_token" do
|
69
|
+
scenario :users
|
70
|
+
|
71
|
+
before do
|
72
|
+
@user = users(:admin)
|
73
|
+
User.should_receive(:find_by_session_token).and_return(@user)
|
74
|
+
@cookies = { :session_token => 12345 }
|
75
|
+
controller.stub!(:cookies).and_return(@cookies)
|
76
|
+
end
|
77
|
+
|
78
|
+
after do
|
79
|
+
controller.send :login_from_cookie
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should log in user" do
|
83
|
+
controller.should_receive(:current_user=).with(@user).and_return {
|
84
|
+
# can't mock current_user before current_user= is
|
85
|
+
# called, else the method doesn't run
|
86
|
+
controller.stub!(:current_user).and_return(@user)
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should remember user" do
|
91
|
+
@user.should_receive(:remember_me)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should update cookie" do
|
95
|
+
@cookies.should_receive(:[]=) do |name,content|
|
96
|
+
name.should eql(:session_token)
|
97
|
+
content[:value].should eql(@user.session_token)
|
98
|
+
content[:expires].should be_close(2.weeks.from_now.utc, 1.minute) # sometimes specs are slow
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe NoLoginRequiredChildController = NoLoginRequiredController.subclass('NoLoginRequiredChildController') { }, :type => :controller do
|
107
|
+
it "should inherit no_login_required" do
|
108
|
+
StubController.controllers_where_no_login_required.should include(NoLoginRequiredChildController)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe LoginRequiredGrandChildController = NoLoginRequiredChildController.subclass('LoginRequiredGrandChildController') {
|
113
|
+
login_required
|
114
|
+
}, :type => :controller do
|
115
|
+
it "should override parent with login_required" do
|
116
|
+
StubController.controllers_where_no_login_required.should_not include(LoginRequiredGrandChildController)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe LoginRequiredGreatGrandChildController = LoginRequiredGrandChildController.subclass('LoginRequiredGreatGrandChildController') { }, :type => :controller do
|
121
|
+
it "should inherit login_required" do
|
122
|
+
StubController.controllers_where_no_login_required.should_not include(LoginRequiredGreatGrandChildController)
|
123
|
+
end
|
81
124
|
end
|
82
125
|
|
83
|
-
describe OnlyAllowAccessToWhenController
|
126
|
+
describe LoginRequiredController.subclass('OnlyAllowAccessToWhenController') {
|
127
|
+
only_allow_access_to :edit, :new,
|
128
|
+
:when => [:admin, :developer],
|
129
|
+
:denied_url => { :action => :test },
|
130
|
+
:denied_message => 'Fun.'
|
131
|
+
}, :type => :controller do
|
84
132
|
scenario :users
|
85
133
|
|
86
134
|
it "should only allow access when user in roles" do
|
@@ -103,11 +151,12 @@ describe OnlyAllowAccessToWhenController, :type => :controller do
|
|
103
151
|
end
|
104
152
|
end
|
105
153
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
154
|
+
describe LoginRequiredController.subclass('OnlyAllowAccessToWhenDefaultsController') {
|
155
|
+
only_allow_access_to :edit,
|
156
|
+
:when => :admin,
|
157
|
+
:denied_url => { :action => :test },
|
158
|
+
:denied_message => 'Fun.'
|
159
|
+
}, :type => :controller do
|
111
160
|
scenario :users
|
112
161
|
|
113
162
|
it "should not allow access when user not in default roles" do
|
@@ -118,30 +167,27 @@ describe OnlyAllowAccessToWhenDefaultsController, :type => :controller do
|
|
118
167
|
end
|
119
168
|
end
|
120
169
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
only_allow_access_to :edit, :if => :condition?, :denied_url => { :action => :test }, :denied_message => 'Fun.'
|
129
|
-
end
|
130
|
-
|
131
|
-
describe OnlyAllowAccessToIfController, :type => :controller do
|
170
|
+
describe LoginRequiredController.subclass('OnlyAllowAccessToIfController') {
|
171
|
+
attr_writer :condition
|
172
|
+
define_method(:condition?, proc { @condition ||= false })
|
173
|
+
only_allow_access_to :edit, :if => :condition?,
|
174
|
+
:denied_url => { :action => :test },
|
175
|
+
:denied_message => 'Fun.'
|
176
|
+
}, :type => :controller do
|
132
177
|
scenario :users
|
133
|
-
|
178
|
+
|
134
179
|
it "should allow access if condition is true" do
|
135
180
|
controller.condition = true
|
136
181
|
login_as :existing
|
137
182
|
get :edit
|
138
183
|
response.should be_success
|
139
184
|
end
|
140
|
-
|
185
|
+
|
141
186
|
it "should not allow access if condition is false" do
|
142
187
|
controller.condition = false
|
143
188
|
login_as :existing
|
144
189
|
get :edit
|
145
190
|
response.should redirect_to(:action => :test)
|
146
191
|
end
|
192
|
+
|
147
193
|
end
|