jakewendt-simply_pages 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +65 -0
- data/generators/simply_pages/USAGE +0 -0
- data/generators/simply_pages/simply_pages_generator.rb +120 -0
- data/generators/simply_pages/templates/autotest_simply_pages.rb +2 -0
- data/generators/simply_pages/templates/controllers/locales_controller.rb +16 -0
- data/generators/simply_pages/templates/controllers/pages_controller.rb +160 -0
- data/generators/simply_pages/templates/functional/locales_controller_test.rb +58 -0
- data/generators/simply_pages/templates/functional/pages_controller_test.rb +237 -0
- data/generators/simply_pages/templates/images/drag.gif +0 -0
- data/generators/simply_pages/templates/javascripts/pages.js +48 -0
- data/generators/simply_pages/templates/migrations/create_pages.rb +26 -0
- data/generators/simply_pages/templates/models/page.rb +107 -0
- data/generators/simply_pages/templates/models/page_sweeper.rb +74 -0
- data/generators/simply_pages/templates/simply_pages.rake +5 -0
- data/generators/simply_pages/templates/stylesheets/page.css +17 -0
- data/generators/simply_pages/templates/stylesheets/pages.css +22 -0
- data/generators/simply_pages/templates/unit/page_test.rb +149 -0
- data/generators/simply_pages/templates/unit/redcloth_extension_test.rb +64 -0
- data/generators/simply_pages/templates/views/pages/_child.html.erb +20 -0
- data/generators/simply_pages/templates/views/pages/_form.html.erb +44 -0
- data/generators/simply_pages/templates/views/pages/_page.html.erb +34 -0
- data/generators/simply_pages/templates/views/pages/all.html.erb +39 -0
- data/generators/simply_pages/templates/views/pages/edit.html.erb +10 -0
- data/generators/simply_pages/templates/views/pages/index.html.erb +29 -0
- data/generators/simply_pages/templates/views/pages/new.html.erb +10 -0
- data/generators/simply_pages/templates/views/pages/show.html.erb +31 -0
- data/generators/simply_pages/templates/views/pages/translate.js.erb +42 -0
- metadata +93 -0
data/README.rdoc
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
= SimplyPages
|
2
|
+
|
3
|
+
This WAS both a plugin engine and a basic rails app.
|
4
|
+
|
5
|
+
It is now being converted in a simple generator to copy the code into the app.
|
6
|
+
|
7
|
+
Still working on it, so it may be a bit bumpy.
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
== ToDo
|
12
|
+
|
13
|
+
|
14
|
+
== Required Gem Sources
|
15
|
+
|
16
|
+
gem sources -a http://rubygems.org
|
17
|
+
gem sources -a http://gems.github.com
|
18
|
+
|
19
|
+
== Required Gems
|
20
|
+
|
21
|
+
* {jakewendt-assert_this_and_that}[http://github.com/jakewendt/assert_this_and_that]
|
22
|
+
* {jakewendt-ruby_extension}[http://github.com/jakewendt/ruby_extension] - modifications, updates and patches for ruby.
|
23
|
+
* rails ~> 2
|
24
|
+
* jrails
|
25
|
+
* chronic
|
26
|
+
* ruby-hmac
|
27
|
+
* ssl_requirement
|
28
|
+
* ryanb-acts-as-list
|
29
|
+
* RedCloth # NOT 4.2.6
|
30
|
+
* thoughtbot-factory_girl
|
31
|
+
* {jakewendt-simply_helpful}[http://github.com/jakewendt/simply_helpful]
|
32
|
+
* {jakewendt-simply_authorized}[http://github.com/jakewendt/simply_authorized]
|
33
|
+
* {jakewendt-calnet_authenticated}[http://github.com/jakewendt/calnet_authenticated]
|
34
|
+
|
35
|
+
== Installation (as a plugin/engine)
|
36
|
+
|
37
|
+
# config.gem 'jakewendt-simply_pages',
|
38
|
+
# :source => 'http://rubygems.org'
|
39
|
+
|
40
|
+
script/generate simply_pages
|
41
|
+
|
42
|
+
# User.find_create_and_update_by_uid('859908').deputize
|
43
|
+
|
44
|
+
== Testing (as an app)
|
45
|
+
|
46
|
+
rake db:migrate
|
47
|
+
rake db:fixtures:load
|
48
|
+
rake test
|
49
|
+
script/server
|
50
|
+
|
51
|
+
== Gemified with Jeweler
|
52
|
+
|
53
|
+
vi Rakefile
|
54
|
+
rake version:write
|
55
|
+
|
56
|
+
rake version:bump:patch
|
57
|
+
rake version:bump:minor
|
58
|
+
rake version:bump:major
|
59
|
+
|
60
|
+
rake gemspec
|
61
|
+
|
62
|
+
rake install
|
63
|
+
rake release
|
64
|
+
|
65
|
+
Copyright (c) 2010 [Jake Wendt], released under the MIT license
|
File without changes
|
@@ -0,0 +1,120 @@
|
|
1
|
+
class SimplyPagesGenerator < Rails::Generator::Base
|
2
|
+
|
3
|
+
def manifest
|
4
|
+
# See Rails::Generator::Commands::Create
|
5
|
+
# rails-2.3.10/lib/rails_generator/commands.rb
|
6
|
+
# for code methods for record (Manifest)
|
7
|
+
record do |m|
|
8
|
+
|
9
|
+
# Will add this multiple times with multiple calls.
|
10
|
+
# TODO Would like to only do it conditionally.
|
11
|
+
# TODO Also, would prefer a bit more control as have other routes.
|
12
|
+
|
13
|
+
# map.resources :pages, :collection => {
|
14
|
+
# :all => :get,
|
15
|
+
# :translate => :get,
|
16
|
+
# :order => :post }
|
17
|
+
# map.resources :locales, :only => :show
|
18
|
+
|
19
|
+
m.route_resources :pages
|
20
|
+
|
21
|
+
# m.directory('config/autotest')
|
22
|
+
# m.file('autotest_simply_pages.rb', 'config/autotest/simply_pages.rb')
|
23
|
+
# m.directory('lib/tasks')
|
24
|
+
# m.file('simply_pages.rake', 'lib/tasks/simply_pages.rake')
|
25
|
+
|
26
|
+
# File.open('Rakefile','a'){|f|
|
27
|
+
# f.puts <<-EOF
|
28
|
+
## From `script/generate simply_pages` ...
|
29
|
+
#require 'simply_pages/test_tasks'
|
30
|
+
# EOF
|
31
|
+
# }
|
32
|
+
#
|
33
|
+
# File.open('.autotest','a'){|f|
|
34
|
+
# f.puts <<-EOF
|
35
|
+
## From `script/generate simply_pages` ...
|
36
|
+
#require 'simply_pages/autotest'
|
37
|
+
# EOF
|
38
|
+
# }
|
39
|
+
|
40
|
+
dot = File.dirname(__FILE__)
|
41
|
+
|
42
|
+
%w( create_pages ).each do |migration|
|
43
|
+
m.migration_template "migrations/#{migration}.rb",
|
44
|
+
'db/migrate', :migration_file_name => migration
|
45
|
+
end
|
46
|
+
|
47
|
+
m.directory('public/javascripts')
|
48
|
+
Dir["#{dot}/templates/javascripts/*js"].each{|file|
|
49
|
+
f = file.split('/').slice(-2,2).join('/')
|
50
|
+
m.file(f, "public/javascripts/#{File.basename(file)}")
|
51
|
+
}
|
52
|
+
m.directory('public/stylesheets')
|
53
|
+
Dir["#{dot}/templates/stylesheets/*css"].each{|file|
|
54
|
+
f = file.split('/').slice(-2,2).join('/')
|
55
|
+
m.file(f, "public/stylesheets/#{File.basename(file)}")
|
56
|
+
}
|
57
|
+
|
58
|
+
m.directory('app/models')
|
59
|
+
Dir["#{dot}/templates/models/*rb"].each{|file|
|
60
|
+
f = file.split('/').slice(-2,2).join('/')
|
61
|
+
m.file(f, "app/models/#{File.basename(file)}")
|
62
|
+
}
|
63
|
+
|
64
|
+
m.directory('app/controllers ')
|
65
|
+
Dir["#{dot}/templates/controllers/*rb"].each{|file|
|
66
|
+
f = file.split('/').slice(-2,2).join('/')
|
67
|
+
m.file(f, "app/controllers/#{File.basename(file)}")
|
68
|
+
}
|
69
|
+
|
70
|
+
m.directory('app/views/pages')
|
71
|
+
Dir["#{dot}/templates/views/pages/*rb"].each{|file|
|
72
|
+
f = file.split('/').slice(-3,3).join('/') # has an extra directory in path
|
73
|
+
m.file(f, "app/views/pages/#{File.basename(file)}")
|
74
|
+
}
|
75
|
+
|
76
|
+
m.directory('test/functional')
|
77
|
+
Dir["#{dot}/templates/functional/*rb"].each{|file|
|
78
|
+
f = file.split('/').slice(-2,2).join('/')
|
79
|
+
m.file(f, "test/functional/#{File.basename(file)}")
|
80
|
+
}
|
81
|
+
|
82
|
+
m.directory('test/unit')
|
83
|
+
Dir["#{dot}/templates/unit/*rb"].each{|file|
|
84
|
+
f = file.split('/').slice(-2,2).join('/')
|
85
|
+
m.file(f, "test/unit/#{File.basename(file)}")
|
86
|
+
}
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
module Rails::Generator::Commands
|
93
|
+
class Create
|
94
|
+
def migration_template(relative_source,
|
95
|
+
relative_destination, template_options = {})
|
96
|
+
migration_directory relative_destination
|
97
|
+
migration_file_name = template_options[
|
98
|
+
:migration_file_name] || file_name
|
99
|
+
if migration_exists?(migration_file_name)
|
100
|
+
puts "Another migration is already named #{migration_file_name}: #{existing_migrations(migration_file_name).first}: Skipping"
|
101
|
+
else
|
102
|
+
template(relative_source, "#{relative_destination}/#{next_migration_string}_#{migration_file_name}.rb", template_options)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end # Create
|
106
|
+
class Base
|
107
|
+
protected
|
108
|
+
# the loop through migrations happens so fast
|
109
|
+
# that they all have the same timestamp which
|
110
|
+
# won't work when you actually try to migrate.
|
111
|
+
# All the timestamps MUST be unique.
|
112
|
+
def next_migration_string(padding = 3)
|
113
|
+
@s = (!@s.nil?)? @s.to_i + 1 : if ActiveRecord::Base.timestamped_migrations
|
114
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
115
|
+
else
|
116
|
+
"%.#{padding}d" % next_migration_number
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end # Base
|
120
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class LocalesController < ApplicationController
|
2
|
+
|
3
|
+
skip_before_filter :login_required
|
4
|
+
# removed method
|
5
|
+
# skip_before_filter :build_menu_js
|
6
|
+
|
7
|
+
def show
|
8
|
+
session[:locale] = params[:id]
|
9
|
+
respond_to do |format|
|
10
|
+
format.html { redirect_to_referer_or_default(root_path) }
|
11
|
+
# format.js {}
|
12
|
+
format.js { render :text => "locale = '#{session[:locale]}'" }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
class PagesController < ApplicationController
|
2
|
+
|
3
|
+
before_filter :login_required
|
4
|
+
|
5
|
+
# calnet_authenticated
|
6
|
+
skip_before_filter :login_required,
|
7
|
+
:only => [:show, :translate]
|
8
|
+
|
9
|
+
# removed method
|
10
|
+
# skip_before_filter :build_menu_js,
|
11
|
+
# :only => [:translate]
|
12
|
+
|
13
|
+
# simply_authorized
|
14
|
+
before_filter :may_maintain_pages_required,
|
15
|
+
:except => [:show, :translate]
|
16
|
+
|
17
|
+
before_filter :id_required, :only => [ :edit, :update, :destroy ]
|
18
|
+
before_filter :page_required, :only => :show
|
19
|
+
# removed method
|
20
|
+
# before_filter :build_submenu_js, :except => [:index, :order, :translate]
|
21
|
+
|
22
|
+
# caches partials from layout as well, which is too much
|
23
|
+
# caching still buggy
|
24
|
+
# if do cache layout, contains user links
|
25
|
+
# if don't cache layout, submenu goes missing
|
26
|
+
|
27
|
+
# caches_action saves to memory
|
28
|
+
# caches_page generates an actual file in public/
|
29
|
+
# it would probably require modifications to the
|
30
|
+
# page_sweeper's expire calls
|
31
|
+
|
32
|
+
# This will also cache the flash output so don't cache layout
|
33
|
+
caches_action :show, :layout => false
|
34
|
+
|
35
|
+
# caches_page :show #, :layout => false
|
36
|
+
cache_sweeper :page_sweeper, :only => [:create, :update, :order, :destroy]
|
37
|
+
|
38
|
+
ssl_allowed :show, :translate
|
39
|
+
|
40
|
+
def order
|
41
|
+
# params[:pages].reverse.each { |id| Page.find(id).move_to_top }
|
42
|
+
# this doesn't even check for parents or anything
|
43
|
+
# making it faster, but potentially error prone.
|
44
|
+
|
45
|
+
if params[:pages] && params[:pages].is_a?(Array)
|
46
|
+
params[:pages].each_with_index { |id,index|
|
47
|
+
Page.find(id).update_attribute(:position, index+1 ) }
|
48
|
+
else
|
49
|
+
flash[:error] = "No page order given!"
|
50
|
+
end
|
51
|
+
redirect_to pages_path(:parent_id=>params[:parent_id])
|
52
|
+
end
|
53
|
+
|
54
|
+
def translate
|
55
|
+
respond_to do |format|
|
56
|
+
format.js {}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def show
|
61
|
+
end
|
62
|
+
|
63
|
+
def all
|
64
|
+
@page_title = "All CCLS Pages"
|
65
|
+
@pages = Page.all
|
66
|
+
end
|
67
|
+
|
68
|
+
def index
|
69
|
+
@page_title = "CCLS Pages"
|
70
|
+
params[:parent_id] = nil if params[:parent_id].blank?
|
71
|
+
@pages = Page.all(:conditions => { :parent_id => params[:parent_id] })
|
72
|
+
end
|
73
|
+
|
74
|
+
def new
|
75
|
+
@page_title = "Create New CCLS Page"
|
76
|
+
@page = Page.new(:parent_id => params[:parent_id])
|
77
|
+
end
|
78
|
+
|
79
|
+
def edit
|
80
|
+
@page_title = "Edit CCLS Page #{@page.title(session[:locale])}"
|
81
|
+
end
|
82
|
+
|
83
|
+
def create
|
84
|
+
@page = Page.new(params[:page])
|
85
|
+
@page.save!
|
86
|
+
flash[:notice] = 'Page was successfully created.'
|
87
|
+
redirect_to(@page)
|
88
|
+
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
|
89
|
+
flash.now[:error] = "There was a problem creating the page"
|
90
|
+
render :action => "new"
|
91
|
+
end
|
92
|
+
|
93
|
+
def update
|
94
|
+
@page.update_attributes!(params[:page])
|
95
|
+
flash[:notice] = 'Page was successfully updated.'
|
96
|
+
redirect_to(@page)
|
97
|
+
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
|
98
|
+
flash.now[:error] = "There was a problem updating the page."
|
99
|
+
render :action => "edit"
|
100
|
+
end
|
101
|
+
|
102
|
+
def destroy
|
103
|
+
@page.destroy
|
104
|
+
redirect_to(pages_path)
|
105
|
+
end
|
106
|
+
|
107
|
+
protected
|
108
|
+
|
109
|
+
def id_required
|
110
|
+
if !params[:id].blank? and Page.exists?(params[:id])
|
111
|
+
@page = Page.find(params[:id])
|
112
|
+
else
|
113
|
+
access_denied("Valid page id required!", pages_path)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# Put this in a separate before_filter so that
|
118
|
+
# another before_filter can access @page
|
119
|
+
def page_required
|
120
|
+
if params[:path]
|
121
|
+
@page = Page.by_path("/#{params[:path].join('/')}")
|
122
|
+
raise ActiveRecord::RecordNotFound if @page.nil?
|
123
|
+
else
|
124
|
+
@page = Page.find(params[:id])
|
125
|
+
end
|
126
|
+
@page_title = @page.title(session[:locale])
|
127
|
+
if @page.is_home? && class_exists?('HomePagePic')
|
128
|
+
@hpp = HomePagePic.random_active()
|
129
|
+
end
|
130
|
+
rescue ActiveRecord::RecordNotFound
|
131
|
+
flash_message = "Page not found with "
|
132
|
+
flash_message << (( params[:id].blank? ) ? "path '/#{params[:path].join('/')}'" : "ID #{params[:id]}")
|
133
|
+
flash.now[:error] = flash_message
|
134
|
+
end
|
135
|
+
|
136
|
+
# def build_submenu_js
|
137
|
+
# if @page && !@page.root.children.empty?
|
138
|
+
# js = "" <<
|
139
|
+
# "if ( typeof(translatables) == 'undefined' ){\n" <<
|
140
|
+
# " var translatables = [];\n" <<
|
141
|
+
# "}\n"
|
142
|
+
# js << "tmp={tag:'#current_root',locales:{}};\n"
|
143
|
+
# %w( en es ).each do |locale|
|
144
|
+
# js << "tmp.locales['#{locale}']='#{@page.root.menu(locale)}'\n"
|
145
|
+
# end
|
146
|
+
# js << "translatables.push(tmp);\n"
|
147
|
+
# @page.root.children.each do |child|
|
148
|
+
# js << "tmp={tag:'#menu_#{dom_id(child)}',locales:{}};\n"
|
149
|
+
# %w( en es ).each do |locale|
|
150
|
+
# js << "tmp.locales['#{locale}']='#{child.menu(locale)}'\n"
|
151
|
+
# end
|
152
|
+
# js << "translatables.push(tmp);\n"
|
153
|
+
# end
|
154
|
+
# @template.content_for :head do
|
155
|
+
# @template.javascript_tag js
|
156
|
+
# end
|
157
|
+
# end
|
158
|
+
# end
|
159
|
+
|
160
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LocalesControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
test "should set locale to en" do
|
6
|
+
assert_nil session[:locale]
|
7
|
+
get :show, :id => 'en'
|
8
|
+
assert_equal 'en', session[:locale]
|
9
|
+
assert_response :redirect
|
10
|
+
end
|
11
|
+
|
12
|
+
test "should change locale to es" do
|
13
|
+
assert_nil session[:locale]
|
14
|
+
session[:locale] = 'en'
|
15
|
+
assert_equal 'en', session[:locale]
|
16
|
+
get :show, :id => 'es'
|
17
|
+
assert_equal 'es', session[:locale]
|
18
|
+
assert_response :redirect
|
19
|
+
end
|
20
|
+
|
21
|
+
test "should change locale to en" do
|
22
|
+
assert_nil session[:locale]
|
23
|
+
session[:locale] = 'es'
|
24
|
+
assert_equal 'es', session[:locale]
|
25
|
+
get :show, :id => 'en'
|
26
|
+
assert_equal 'en', session[:locale]
|
27
|
+
assert_response :redirect
|
28
|
+
end
|
29
|
+
|
30
|
+
test "should set locale to en via js" do
|
31
|
+
@request.accept = "text/javascript"
|
32
|
+
assert_nil session[:locale]
|
33
|
+
get :show, :id => 'en'
|
34
|
+
assert_equal 'en', session[:locale]
|
35
|
+
assert_response :success
|
36
|
+
end
|
37
|
+
|
38
|
+
test "should change locale to es via js" do
|
39
|
+
@request.accept = "text/javascript"
|
40
|
+
assert_nil session[:locale]
|
41
|
+
session[:locale] = 'en'
|
42
|
+
assert_equal 'en', session[:locale]
|
43
|
+
get :show, :id => 'es'
|
44
|
+
assert_equal 'es', session[:locale]
|
45
|
+
assert_response :success
|
46
|
+
end
|
47
|
+
|
48
|
+
test "should change locale to en via js" do
|
49
|
+
@request.accept = "text/javascript"
|
50
|
+
assert_nil session[:locale]
|
51
|
+
session[:locale] = 'es'
|
52
|
+
assert_equal 'es', session[:locale]
|
53
|
+
get :show, :id => 'en'
|
54
|
+
assert_equal 'en', session[:locale]
|
55
|
+
assert_response :success
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,237 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PagesControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
ASSERT_ACCESS_OPTIONS = {
|
6
|
+
:model => 'Page',
|
7
|
+
:actions => [:new,:create,:edit,:update,:destroy,:index],
|
8
|
+
:method_for_create => :factory_create,
|
9
|
+
:attributes_for_create => :factory_attributes
|
10
|
+
}
|
11
|
+
|
12
|
+
def factory_create(options={})
|
13
|
+
Factory(:page,options)
|
14
|
+
end
|
15
|
+
def factory_attributes(options={})
|
16
|
+
Factory.attributes_for(:page,options)
|
17
|
+
end
|
18
|
+
|
19
|
+
with_options :actions => [:show] do |show|
|
20
|
+
show.assert_access_with_http
|
21
|
+
show.assert_access_with_https
|
22
|
+
show.assert_access_with_login({
|
23
|
+
:logins => [:superuser,:administrator,:editor],
|
24
|
+
:skip_show_failure => true })
|
25
|
+
show.assert_access_with_login({
|
26
|
+
:logins => [:interviewer,:reader,:active_user],
|
27
|
+
:skip_show_failure => true })
|
28
|
+
show.assert_access_without_login
|
29
|
+
end
|
30
|
+
|
31
|
+
assert_no_access_with_login({
|
32
|
+
:logins => [:interviewer,:reader,:active_user] })
|
33
|
+
assert_no_access_without_login
|
34
|
+
assert_no_access_with_http
|
35
|
+
|
36
|
+
%w( superuser administrator editor ).each do |cu|
|
37
|
+
#
|
38
|
+
# index/new/create/edit/update/destroy
|
39
|
+
# should only be visible to admins for editing
|
40
|
+
#
|
41
|
+
|
42
|
+
test "should get all with pages with #{cu} login" do
|
43
|
+
login_as send(cu)
|
44
|
+
get :all
|
45
|
+
assert_template 'all'
|
46
|
+
assert_response :success
|
47
|
+
assert_equal Page.count, assigns(:pages).length
|
48
|
+
end
|
49
|
+
|
50
|
+
test "should get index with pages with #{cu} login" do
|
51
|
+
3.times{ factory_create }
|
52
|
+
login_as send(cu)
|
53
|
+
get :index
|
54
|
+
assert_template 'index'
|
55
|
+
assert_response :success
|
56
|
+
assert_not_nil assigns(:pages)
|
57
|
+
assigns(:pages).each { |page| assert_nil page.parent }
|
58
|
+
# this isn't always true, depending the apps fixtures/pages.yml
|
59
|
+
# assert Page.count != assigns(:pages).length
|
60
|
+
end
|
61
|
+
|
62
|
+
test "should get index with blank parent with #{cu} login" do
|
63
|
+
3.times{ factory_create }
|
64
|
+
login_as send(cu)
|
65
|
+
get :index, :parent_id => ''
|
66
|
+
assert_template 'index'
|
67
|
+
assert_response :success
|
68
|
+
assert_not_nil assigns(:pages)
|
69
|
+
assigns(:pages).each { |page| assert_nil page.parent }
|
70
|
+
end
|
71
|
+
|
72
|
+
test "should get index with subpages with #{cu} login" do
|
73
|
+
parent = factory_create
|
74
|
+
3.times{ factory_create(:parent_id => parent.id) }
|
75
|
+
login_as send(cu)
|
76
|
+
get :index, :parent_id => parent.id
|
77
|
+
assert_template 'index'
|
78
|
+
assert_response :success
|
79
|
+
assert_not_nil assigns(:pages)
|
80
|
+
assigns(:pages).each do |page|
|
81
|
+
assert_equal page.parent_id, parent.id
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
test "should create page with parent with #{cu} login" do
|
86
|
+
parent = factory_create
|
87
|
+
login_as send(cu)
|
88
|
+
assert_difference('Page.count') do
|
89
|
+
post :create, :page => factory_attributes(
|
90
|
+
:parent_id => parent.id)
|
91
|
+
end
|
92
|
+
assert_equal parent, assigns(:page).parent
|
93
|
+
assert_redirected_to page_path(assigns(:page))
|
94
|
+
end
|
95
|
+
|
96
|
+
# I don't think that this is pertinant anymore
|
97
|
+
test "should get index with both help and non-help pages with #{cu} login" do
|
98
|
+
# test css menus
|
99
|
+
login_as send(cu)
|
100
|
+
nonhelp_page = factory_create(:path => "/hello" )
|
101
|
+
help_page = factory_create(:path => "/help/test" )
|
102
|
+
get :index
|
103
|
+
assert_response :success
|
104
|
+
assert_template 'index'
|
105
|
+
end
|
106
|
+
|
107
|
+
# action: order
|
108
|
+
|
109
|
+
test "should order pages with #{cu} login" do
|
110
|
+
login_as send(cu)
|
111
|
+
# pages = 3.times.collect{|i| factory_create }
|
112
|
+
# 3.times.collect doesn't work on
|
113
|
+
#> ruby --version
|
114
|
+
#ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]
|
115
|
+
pages = []
|
116
|
+
3.times{ pages.push(factory_create) }
|
117
|
+
before_page_ids = Page.all.collect(&:id)
|
118
|
+
post :order, :pages => before_page_ids.reverse
|
119
|
+
after_page_ids = Page.all.collect(&:id)
|
120
|
+
assert_equal after_page_ids, before_page_ids.reverse
|
121
|
+
assert_redirected_to pages_path
|
122
|
+
end
|
123
|
+
|
124
|
+
test "should NOT order pages without pages with #{cu} login" do
|
125
|
+
login_as send(cu)
|
126
|
+
post :order
|
127
|
+
assert_not_nil flash[:error]
|
128
|
+
assert_redirected_to pages_path
|
129
|
+
end
|
130
|
+
|
131
|
+
test "should order sub pages with #{cu} login" do
|
132
|
+
login_as send(cu)
|
133
|
+
parent = factory_create
|
134
|
+
pages = []
|
135
|
+
3.times{ pages.push(factory_create(:parent_id => parent.id)) }
|
136
|
+
assert_equal [1,2,3], pages.collect(&:position)
|
137
|
+
before_page_ids = parent.reload.children.collect(&:id)
|
138
|
+
post :order,:parent_id => parent.id, :pages => before_page_ids.reverse
|
139
|
+
after_page_ids = parent.reload.children.collect(&:id)
|
140
|
+
assert_equal after_page_ids, before_page_ids.reverse
|
141
|
+
assert_redirected_to pages_path(:parent_id => parent.id)
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
%w( interviewer reader active_user ).each do |cu|
|
147
|
+
|
148
|
+
test "should NOT order pages with #{cu} login" do
|
149
|
+
login_as send(cu)
|
150
|
+
pages = []
|
151
|
+
3.times{ pages.push(factory_create) }
|
152
|
+
before_page_ids = Page.all.collect(&:id)
|
153
|
+
post :order, :pages => before_page_ids.reverse
|
154
|
+
assert_not_nil flash[:error]
|
155
|
+
assert_redirected_to root_path
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
test "should NOT order pages without login" do
|
161
|
+
pages = []
|
162
|
+
3.times{ pages.push(factory_create) }
|
163
|
+
before_page_ids = Page.all.collect(&:id)
|
164
|
+
post :order, :pages => before_page_ids.reverse
|
165
|
+
assert_redirected_to_login
|
166
|
+
end
|
167
|
+
|
168
|
+
#
|
169
|
+
# /pages/:id should be visible to anyone ?
|
170
|
+
#
|
171
|
+
# as the pages controller uses the gateway filter, not being logged in currently
|
172
|
+
# requires the addition of the line ...
|
173
|
+
# CASClient::Frameworks::Rails::GatewayFilter.stubs(:filter).returns(false)
|
174
|
+
#
|
175
|
+
|
176
|
+
test "should NOT show page with invalid id" do
|
177
|
+
get :show, :id => 0
|
178
|
+
assert_not_nil flash[:error]
|
179
|
+
assert_template 'show'
|
180
|
+
assert_response :success
|
181
|
+
end
|
182
|
+
|
183
|
+
test "should NOT show page without matching path" do
|
184
|
+
get :show, :path => "/i/do/not/exist".split('/').delete_if{|x|x.blank?}
|
185
|
+
assert_not_nil flash[:error]
|
186
|
+
assert_template 'show'
|
187
|
+
assert_response :success
|
188
|
+
end
|
189
|
+
|
190
|
+
test "should show page by path" do
|
191
|
+
page = factory_create
|
192
|
+
get :show, :path => page.path.split('/').delete_if{|x|x.blank?}
|
193
|
+
assert_equal assigns(:page), page
|
194
|
+
assert_template 'show'
|
195
|
+
assert_response :success
|
196
|
+
assert_select 'title', page.title
|
197
|
+
end
|
198
|
+
|
199
|
+
test "should show page by path with slashes" do
|
200
|
+
page = factory_create(:path => "/help/blogs")
|
201
|
+
get :show, :path => page.path.split('/').delete_if{|x|x.blank?}
|
202
|
+
assert_equal assigns(:page), page
|
203
|
+
assert_template 'show'
|
204
|
+
assert_response :success
|
205
|
+
assert_select 'title', page.title
|
206
|
+
end
|
207
|
+
|
208
|
+
test "should show HOME page without HPP" do
|
209
|
+
page = Page.by_path('/')
|
210
|
+
get :show, :id => page.id
|
211
|
+
assert_nil assigns(:hpp)
|
212
|
+
assert_template 'show'
|
213
|
+
assert_response :success
|
214
|
+
assert_select 'title', page.title
|
215
|
+
end
|
216
|
+
|
217
|
+
test "should get translate via js without login" do
|
218
|
+
@request.accept = "text/javascript"
|
219
|
+
get :translate
|
220
|
+
assert_response :success
|
221
|
+
assert_match /jQuery/, @response.body
|
222
|
+
end
|
223
|
+
|
224
|
+
test "should get each page in fixtures in each locale" do
|
225
|
+
puts
|
226
|
+
Page.all.each do |page|
|
227
|
+
[ nil,'en','es' ].each do |locale|
|
228
|
+
puts "- Showing page id #{page.id} with locale #{locale}"
|
229
|
+
session[:locale] = locale
|
230
|
+
get :show, :id => page.id
|
231
|
+
assert_response :success
|
232
|
+
assert_template 'show'
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|