radiant-vhost-extension 2.1.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/.gitmodules +3 -0
- data/README +64 -0
- data/Rakefile +125 -0
- data/VERSION +1 -0
- data/app/controllers/admin/sites_controller.rb +16 -0
- data/app/models/site.rb +26 -0
- data/app/models/site_association_observer.rb +8 -0
- data/app/views/admin/sites/_form.html.haml +19 -0
- data/app/views/admin/sites/edit.html.haml +5 -0
- data/app/views/admin/sites/index.html.haml +24 -0
- data/app/views/admin/sites/new.html.haml +5 -0
- data/app/views/admin/sites/remove.html.haml +19 -0
- data/app/views/admin/users/_edit_sites.html.haml +4 -0
- data/app/views/admin/users/_site_admin_roles.html.haml +5 -0
- data/app/views/admin/users/_sites_td.html.haml +2 -0
- data/app/views/admin/users/_sites_th.html.haml +2 -0
- data/config/routes.rb +5 -0
- data/db/migrate/001_create_sites.rb +11 -0
- data/db/migrate/002_add_sites_users.rb +18 -0
- data/db/migrate/003_replace_snippet_name_unique_index.rb +10 -0
- data/db/migrate/004_add_site_admin_to_users.rb +9 -0
- data/db/templates/empty.yml +7 -0
- data/db/templates/simple-blog.yml +213 -0
- data/lib/bootstrap_with_site_id.rb +50 -0
- data/lib/radiant-vhost-extension.rb +0 -0
- data/lib/site_scope.rb +65 -0
- data/lib/tasks/add_site_columns.rb +44 -0
- data/lib/tasks/vhost_extension_tasks.rake +115 -0
- data/lib/vhost/admin_users_controller_extensions.rb +22 -0
- data/lib/vhost/admin_users_helper_extensions.rb +17 -0
- data/lib/vhost/application_controller_extensions.rb +36 -0
- data/lib/vhost/application_helper_extensions.rb +15 -0
- data/lib/vhost/controller_access_extensions.rb +16 -0
- data/lib/vhost/pages_controller_extensions.rb +11 -0
- data/lib/vhost/radiant_cache_extensions.rb +53 -0
- data/lib/vhost/site_scoped_model_extensions.rb +46 -0
- data/lib/vhost_default_config.yml +22 -0
- data/spec/controllers/admin/pages_controller_spec.rb +173 -0
- data/spec/controllers/admin/sites_controller_spec.rb +33 -0
- data/spec/controllers/site_controller_spec.rb +33 -0
- data/spec/datasets/site_home_pages_dataset.rb +76 -0
- data/spec/datasets/site_pages_dataset.rb +31 -0
- data/spec/datasets/site_users_dataset.rb +50 -0
- data/spec/datasets/sites_dataset.rb +10 -0
- data/spec/datasets/sites_site_users_and_site_pages_dataset.rb +8 -0
- data/spec/datasets/sites_site_users_dataset.rb +13 -0
- data/spec/fixtures/page_parts.yml +11 -0
- data/spec/fixtures/pages.yml +19 -0
- data/spec/fixtures/sites.yml +7 -0
- data/spec/fixtures/sites_users.yml +6 -0
- data/spec/fixtures/users.yml +35 -0
- data/spec/models/page_spec.rb +22 -0
- data/spec/models/site_spec.rb +19 -0
- data/spec/models/user_spec.rb +16 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +42 -0
- data/test/fixtures/page_parts.yml +11 -0
- data/test/fixtures/pages.yml +19 -0
- data/test/fixtures/sites.yml +7 -0
- data/test/fixtures/sites_users.yml +6 -0
- data/test/fixtures/users.yml +35 -0
- data/test/functional/admin/pages_controller_test.rb +142 -0
- data/test/functional/admin/site_controller_test.rb +53 -0
- data/test/functional/vhost_extension_test.rb +37 -0
- data/test/helpers/page_part_test_helper.rb +49 -0
- data/test/test_helper.rb +17 -0
- data/test/unit/site_test.rb +26 -0
- data/vhost_extension.rb +154 -0
- metadata +167 -0
@@ -0,0 +1,173 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Admin::PagesController do
|
4
|
+
dataset :sites_site_users_and_site_pages
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
VhostExtension.HOST = sites(:site_a).hostname # Pretend we're connected to site_a so the SiteScope works right
|
8
|
+
rescue_action_in_public! # ActionController::TestCase no longer considers this request a local request
|
9
|
+
|
10
|
+
# don't bork results with stale cache items
|
11
|
+
Radiant::Cache.clear
|
12
|
+
login_as :usera
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "creating pages" do
|
16
|
+
|
17
|
+
it "should be associated with the site corresponding to the current hostname" do
|
18
|
+
# Need to call get :new or else the :before_filter in the ApplicationController
|
19
|
+
# that sets up the SiteScope doesn't run.
|
20
|
+
slug = "should-be-associated-with-site"
|
21
|
+
post :create, :page => page_params(:slug => slug)
|
22
|
+
Page.find_by_slug(slug).site.id.should == site_id(:site_a)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "permissions" do
|
28
|
+
|
29
|
+
# @todo it "should allow <various> actions for users that belong to multiple sites"
|
30
|
+
# (or something like that. probably just hook into the block below.)
|
31
|
+
|
32
|
+
[:admina, :developera, :usera].each do |user|
|
33
|
+
{
|
34
|
+
:post => :create,
|
35
|
+
:put => :update,
|
36
|
+
:delete => :destroy
|
37
|
+
}.each do |method, action|
|
38
|
+
it "should allow the #{action} action to a page belonging to a site #{user.to_s.humanize} has access to" do
|
39
|
+
login_as user
|
40
|
+
send method, action, :id => page_id(:page_a)
|
41
|
+
response.should redirect_to('admin/pages')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
[:developera, :usera].each do |user|
|
47
|
+
{
|
48
|
+
:post => :create,
|
49
|
+
:put => :update,
|
50
|
+
:delete => :destroy
|
51
|
+
}.each do |method, action|
|
52
|
+
it "should show a missing page (404) for the #{action} action on a page NOT belonging to a site #{user.to_s.humanize} has access to" do
|
53
|
+
login_as user
|
54
|
+
send method, action, :id => page_id(:page_b)
|
55
|
+
response.should be_missing
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
=begin
|
64
|
+
|
65
|
+
describe "permissions" do
|
66
|
+
|
67
|
+
[:admin, :developer, :non_admin, :existing].each do |user|
|
68
|
+
{
|
69
|
+
:post => :create,
|
70
|
+
:put => :update,
|
71
|
+
:delete => :destroy
|
72
|
+
}.each do |method, action|
|
73
|
+
it "should require login to access the #{action} action" do
|
74
|
+
logout
|
75
|
+
send method, action, :id => Page.first.id
|
76
|
+
response.should redirect_to('/admin/login')
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should allow access to #{user.to_s.humanize}s for the #{action} action" do
|
80
|
+
login_as user
|
81
|
+
send method, action, :id => Page.first.id
|
82
|
+
response.should redirect_to('/admin/pages')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
[:index, :show, :new, :edit, :remove].each do |action|
|
88
|
+
before :each do
|
89
|
+
@parameters = lambda do
|
90
|
+
case action
|
91
|
+
when :index
|
92
|
+
{}
|
93
|
+
when :new
|
94
|
+
{:page_id => page_id(:home)}
|
95
|
+
else
|
96
|
+
{:id => Page.first.id}
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should require login to access the #{action} action" do
|
102
|
+
logout
|
103
|
+
lambda { send(:get, action, @parameters.call) }.should require_login
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should allow access to admins for the #{action} action" do
|
107
|
+
lambda {
|
108
|
+
send(:get, action, @parameters.call)
|
109
|
+
}.should restrict_access(:allow => [users(:admin)],
|
110
|
+
:url => '/admin/pages')
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should allow access to developers for the #{action} action" do
|
114
|
+
lambda {
|
115
|
+
send(:get, action, @parameters.call)
|
116
|
+
}.should restrict_access(:allow => [users(:developer)],
|
117
|
+
:url => '/admin/pages')
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should allow non-developers and non-admins for the #{action} action" do
|
121
|
+
lambda {
|
122
|
+
send(:get, action, @parameters.call)
|
123
|
+
}.should restrict_access(:allow => [users(:non_admin), users(:existing)],
|
124
|
+
:url => '/admin/pages')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
describe "prompting page removal" do
|
131
|
+
integrate_views
|
132
|
+
|
133
|
+
# TODO: This should be in a view or integration spec
|
134
|
+
it "should render the expanded descendants of the page being removed" do
|
135
|
+
get :remove, :id => page_id(:parent), :format => 'html' # shouldn't need this!
|
136
|
+
rendered_pages = [:parent, :child, :grandchild, :great_grandchild, :child_2, :child_3].map {|p| pages(p) }
|
137
|
+
rendered_pages.each do |page|
|
138
|
+
response.should have_tag("tr#page-#{page.id}")
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should initialize meta and buttons_partials in new action" do
|
144
|
+
get :new, :page_id => page_id(:home)
|
145
|
+
response.should be_success
|
146
|
+
assigns(:meta).should be_kind_of(Array)
|
147
|
+
assigns(:buttons_partials).should be_kind_of(Array)
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should initialize meta and buttons_partials in edit action" do
|
151
|
+
get :edit, :id => page_id(:home)
|
152
|
+
response.should be_success
|
153
|
+
assigns(:meta).should be_kind_of(Array)
|
154
|
+
assigns(:buttons_partials).should be_kind_of(Array)
|
155
|
+
end
|
156
|
+
|
157
|
+
protected
|
158
|
+
|
159
|
+
def assert_rendered_nodes_where(&block)
|
160
|
+
wanted, unwanted = Page.find(:all).partition(&block)
|
161
|
+
wanted.each do |page|
|
162
|
+
response.should have_tag("tr#page-#{page.id}")
|
163
|
+
end
|
164
|
+
unwanted.each do |page|
|
165
|
+
response.should_not have_tag("tr#page-#{page.id}")
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def write_cookie(name, value)
|
170
|
+
request.cookies[name] = CGI::Cookie.new(name, value)
|
171
|
+
end
|
172
|
+
=end
|
173
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Admin::SitesController do
|
4
|
+
dataset :sites_site_users_and_site_pages
|
5
|
+
|
6
|
+
{ :get => [:index, :new, :edit, :remove],
|
7
|
+
:post => [:create],
|
8
|
+
:put => [:update],
|
9
|
+
:delete => [:destroy] }.each do |method, actions|
|
10
|
+
actions.each do |action|
|
11
|
+
it "should require login to access the #{action} action" do
|
12
|
+
logout
|
13
|
+
lambda { send(method, action, :id => site_id(:site_a)).should require_login }
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should allow you to access to #{action} action if you are a site_admin" do
|
17
|
+
lambda {
|
18
|
+
send(method, action, :id => site_id(:site_a))
|
19
|
+
}.should restrict_access(:allow => users(:admina),
|
20
|
+
:url => '/admin/page')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should deny you access to #{action} action if you are not a site_admin" do
|
24
|
+
lambda {
|
25
|
+
send(method, action, :id => site_id(:site_a))
|
26
|
+
}.should restrict_access(:deny => [users(:developera), users(:developerb), users(:usera), users(:userb)],
|
27
|
+
:url => '/admin/page')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe SiteController do
|
4
|
+
dataset :sites_site_users_and_site_pages, :site_home_pages
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
logout
|
8
|
+
VhostExtension.HOST = sites(:site_a).hostname # Pretend we're connected to site_a so the SiteScope works right
|
9
|
+
rescue_action_in_public! # ActionController::TestCase no longer considers this request a local request
|
10
|
+
|
11
|
+
# don't bork results with stale cache items
|
12
|
+
Radiant::Cache.clear
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should find and render the home page for the #{VhostExtension.HOST} site" do
|
16
|
+
get :show_page, :url => ''
|
17
|
+
response.should be_success
|
18
|
+
response.body.should == 'Hello A'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should find and render a child page for the #{VhostExtension.HOST} site" do
|
22
|
+
get :show_page, :url => 'page-a/'
|
23
|
+
response.should be_success
|
24
|
+
response.body.should == 'PageA Body'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should NOT find and render a child page for a site other than the #{VhostExtension.HOST} site" do
|
28
|
+
get :show_page, :url => 'page-b/'
|
29
|
+
response.should be_missing
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
class SiteHomePagesDataset < Dataset::Base
|
2
|
+
uses :sites
|
3
|
+
|
4
|
+
def load
|
5
|
+
create_page "Home A", :site_id => site_id(:site_a),
|
6
|
+
:slug => "/", :parent_id => nil,
|
7
|
+
:description => "The homepage A",
|
8
|
+
:keywords => "Home, Page" do
|
9
|
+
create_page_part "body", :content => "Hello A"
|
10
|
+
create_page_part "sidebar", :content => "<r:title /> sidebar."
|
11
|
+
create_page_part "extended", :content => "Just a test."
|
12
|
+
create_page_part "titles", :content => "<r:title /> <r:page:title />"
|
13
|
+
end
|
14
|
+
create_page "Home B", :site_id => site_id(:site_b),
|
15
|
+
:slug => "/", :parent_id => nil,
|
16
|
+
:description => "The homepage B",
|
17
|
+
:keywords => "Home, Page" do
|
18
|
+
create_page_part "body", :content => "Hello B"
|
19
|
+
create_page_part "sidebar", :content => "<r:title /> sidebar."
|
20
|
+
create_page_part "extended", :content => "Just a test."
|
21
|
+
create_page_part "titles", :content => "<r:title /> <r:page:title />"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
helpers do
|
26
|
+
def create_page(name, attributes={})
|
27
|
+
attributes = page_params(attributes.reverse_merge(:title => name))
|
28
|
+
body = attributes.delete(:body) || name
|
29
|
+
symbol = name.symbolize
|
30
|
+
create_record :page, symbol, attributes
|
31
|
+
if block_given?
|
32
|
+
old_page_id = @current_page_id
|
33
|
+
@current_page_id = page_id(symbol)
|
34
|
+
yield
|
35
|
+
@current_page_id = old_page_id
|
36
|
+
end
|
37
|
+
if pages(symbol).parts.empty?
|
38
|
+
create_page_part "#{name}_body".symbolize, :name => "body", :content => body + ' body.', :page_id => page_id(symbol)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
def page_params(attributes={})
|
42
|
+
title = attributes[:title] || unique_page_title
|
43
|
+
attributes = {
|
44
|
+
:title => title,
|
45
|
+
:breadcrumb => title,
|
46
|
+
:slug => attributes[:slug] || title.symbolize.to_s.gsub("_", "-"),
|
47
|
+
:class_name => nil,
|
48
|
+
:status_id => Status[:published].id,
|
49
|
+
:published_at => Time.now.to_s(:db)
|
50
|
+
}.update(attributes)
|
51
|
+
attributes[:parent_id] = @current_page_id unless attributes.has_key?(:parent_id)
|
52
|
+
attributes
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_page_part(name, attributes={})
|
56
|
+
attributes = page_part_params(attributes.reverse_merge(:name => name))
|
57
|
+
# Need to include the page_id here so we're creating new records for all sub-parts
|
58
|
+
create_record :page_part, name.symbolize.to_s+@current_page_id.to_s, attributes
|
59
|
+
end
|
60
|
+
def page_part_params(attributes={})
|
61
|
+
name = attributes[:name] || "unnamed"
|
62
|
+
attributes = {
|
63
|
+
:name => name,
|
64
|
+
:content => name,
|
65
|
+
:page_id => @current_page_id
|
66
|
+
}.update(attributes)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
@@unique_page_title_call_count = 0
|
71
|
+
def unique_page_title
|
72
|
+
@@unique_page_title_call_count += 1
|
73
|
+
"Page #{@@unique_page_title_call_count}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class VirtualPage < Page
|
2
|
+
def virtual?
|
3
|
+
true
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class SitePagesDataset < Dataset::Base
|
8
|
+
uses :site_home_pages, :sites
|
9
|
+
|
10
|
+
def load
|
11
|
+
create_page "Page A", :parent_id => page_id(:home_a), :site_id => site_id(:site_a) do
|
12
|
+
create_page_part "body", :content => "PageA Body", :id => 1
|
13
|
+
end
|
14
|
+
|
15
|
+
create_page "Page B", :parent_id => page_id(:home_b), :site_id => site_id(:site_b) do
|
16
|
+
create_page_part "body", :content => "PageB Body", :id => 2
|
17
|
+
end
|
18
|
+
|
19
|
+
create_page "Parent", :parent_id => page_id(:home_a), :site_id => site_id(:site_a) do
|
20
|
+
create_page "Child", :site_id => site_id(:site_a) do
|
21
|
+
create_page "Grandchild", :site_id => site_id(:site_a) do
|
22
|
+
create_page "Great Grandchild", :site_id => site_id(:site_a)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
create_page "Child 2", :site_id => site_id(:site_a)
|
26
|
+
create_page "Child 3", :site_id => site_id(:site_a)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class SiteUsersDataset < Dataset::Base
|
2
|
+
uses :users
|
3
|
+
|
4
|
+
def load
|
5
|
+
create_user "UserA"
|
6
|
+
create_user "UserB"
|
7
|
+
create_user "AdminA", :admin => true, :site_admin => true
|
8
|
+
create_user "AdminB", :admin => true
|
9
|
+
create_user "DeveloperA", :designer => true
|
10
|
+
create_user "DeveloperB", :designer => true
|
11
|
+
end
|
12
|
+
|
13
|
+
helpers do
|
14
|
+
def create_user(name, attributes={})
|
15
|
+
create_model :user, name.symbolize, user_attributes(attributes.update(:name => name))
|
16
|
+
end
|
17
|
+
def user_attributes(attributes={})
|
18
|
+
name = attributes[:name] || "John Doe"
|
19
|
+
symbol = name.symbolize
|
20
|
+
attributes = {
|
21
|
+
:name => name,
|
22
|
+
:email => "test@example.com",
|
23
|
+
:login => symbol.to_s,
|
24
|
+
:password => "password"
|
25
|
+
}.merge(attributes)
|
26
|
+
attributes[:password_confirmation] = attributes[:password]
|
27
|
+
attributes
|
28
|
+
end
|
29
|
+
def user_params(attributes={})
|
30
|
+
password = attributes[:password] || "password"
|
31
|
+
user_attributes(attributes).update(:password => password, :password_confirmation => password)
|
32
|
+
end
|
33
|
+
|
34
|
+
def login_as(user)
|
35
|
+
login_user = user.is_a?(User) ? user : users(user)
|
36
|
+
# Set the Vhost HOST to the first hostname in the sites list for the user.
|
37
|
+
# It works for these tests although it may be problematic as we add more
|
38
|
+
# rigorous tests that include multi-site users.
|
39
|
+
VhostExtension.HOST = login_user.sites[0].hostname
|
40
|
+
flunk "Can't login as non-existing user #{user.to_s}." unless login_user
|
41
|
+
request.session['user'] = login_user # Added this because it was in the old PagesController tests
|
42
|
+
request.session['user_id'] = login_user.id
|
43
|
+
login_user
|
44
|
+
end
|
45
|
+
|
46
|
+
def logout
|
47
|
+
request.session['user_id'] = nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class SitesSiteUsersAndSitePagesDataset < Dataset::Base
|
2
|
+
uses :site_pages, :sites_site_users
|
3
|
+
|
4
|
+
def load
|
5
|
+
Page.update_all "created_by_id = #{user_id(:usera)}, updated_by_id = #{user_id(:usera)}", "id = '#{page_id(:page_a)}'"
|
6
|
+
Page.update_all "created_by_id = #{user_id(:userb)}, updated_by_id = #{user_id(:userb)}", "id = '#{page_id(:page_b)}'"
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class SitesSiteUsersDataset < Dataset::Base
|
2
|
+
uses :site_users, :sites
|
3
|
+
|
4
|
+
def load
|
5
|
+
sites(:site_a).users << users(:usera)
|
6
|
+
sites(:site_b).users << users(:userb)
|
7
|
+
sites(:site_a).users << users(:developera)
|
8
|
+
sites(:site_b).users << users(:developerb)
|
9
|
+
sites(:site_a).users << users(:admina)
|
10
|
+
sites(:site_b).users << users(:adminb)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
2
|
+
ruby_body:
|
3
|
+
id: 1
|
4
|
+
name: body
|
5
|
+
content: This is the body portion of the Ruby home page.
|
6
|
+
page_id: 1
|
7
|
+
rails_body:
|
8
|
+
id: 2
|
9
|
+
name: body
|
10
|
+
content: This is the Rails home page.
|
11
|
+
page_id: 2
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
2
|
+
homepage:
|
3
|
+
id: 1
|
4
|
+
title: Ruby Home Page
|
5
|
+
breadcrumb: Home
|
6
|
+
slug: /
|
7
|
+
status_id: 100
|
8
|
+
parent_id:
|
9
|
+
published_at: 2006-01-30 08:41:07
|
10
|
+
site_id: 1
|
11
|
+
documentation:
|
12
|
+
id: 2
|
13
|
+
title: Rails Home Page
|
14
|
+
breadcrumb: Home
|
15
|
+
slug: /
|
16
|
+
status_id: 100
|
17
|
+
parent_id:
|
18
|
+
published_at: 2006-01-30 08:41:07
|
19
|
+
site_id: 2
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
2
|
+
existing:
|
3
|
+
id: 1
|
4
|
+
name: Existing User
|
5
|
+
login: existing
|
6
|
+
salt: 42ddb5b6479872565981adc78e86ddc50fa21637
|
7
|
+
password: 4c5f9d5a0d4cd65d61f6b1505890576d1272986c # password
|
8
|
+
email: existing.user@gmail.com
|
9
|
+
another:
|
10
|
+
id: 2
|
11
|
+
name: Another User
|
12
|
+
login: another
|
13
|
+
salt: 42ddb5b6479872565981adc78e86ddc50fa21637
|
14
|
+
password: 4c5f9d5a0d4cd65d61f6b1505890576d1272986c # password
|
15
|
+
admin:
|
16
|
+
id: 3
|
17
|
+
name: Admin User
|
18
|
+
login: admin
|
19
|
+
salt: 42ddb5b6479872565981adc78e86ddc50fa21637
|
20
|
+
password: 4c5f9d5a0d4cd65d61f6b1505890576d1272986c # password
|
21
|
+
admin: true
|
22
|
+
developer:
|
23
|
+
id: 4
|
24
|
+
name: Developer User
|
25
|
+
login: developer
|
26
|
+
salt: 42ddb5b6479872565981adc78e86ddc50fa21637
|
27
|
+
password: 4c5f9d5a0d4cd65d61f6b1505890576d1272986c # password
|
28
|
+
developer: true
|
29
|
+
non_admin:
|
30
|
+
id: 5
|
31
|
+
name: Non-Admin User
|
32
|
+
login: non-admin
|
33
|
+
salt: 42ddb5b6479872565981adc78e86ddc50fa21637
|
34
|
+
password: 4c5f9d5a0d4cd65d61f6b1505890576d1272986c # password
|
35
|
+
admin: false
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Page, "site scope" do
|
4
|
+
dataset :site_pages, :sites, :site_users
|
5
|
+
test_helper :validations
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
@page = @model = Page.new(page_params)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should validate uniqueness of' do
|
12
|
+
@page.parent = pages(:parent)
|
13
|
+
# Need to manually set the site_id since we're not going through the controller stack
|
14
|
+
@page.site_id = site_id(:site_a)
|
15
|
+
@page.valid?
|
16
|
+
@page.save
|
17
|
+
puts "ERRORS: "+@page.errors.length.to_s
|
18
|
+
assert_invalid :slug, 'slug already in use for child of parent', 'child', 'child-2', 'child-3'
|
19
|
+
assert_valid :slug, 'child-4'
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Site do
|
4
|
+
dataset :site_users
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@site = Site.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be valid" do
|
11
|
+
@site.should be_valid
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should allow users to be associated" do
|
15
|
+
user = users(:usera)
|
16
|
+
@site.users << user
|
17
|
+
@site.users.should have(1).items
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe User do
|
4
|
+
dataset :sites_site_users
|
5
|
+
test_helper :validations
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
@model = @user = User.new(user_params)
|
9
|
+
@user.confirm_password = false
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should have at least one associated site' do
|
13
|
+
users(:usera).should have_at_least(1).sites
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
unless defined? RADIANT_ROOT
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
case
|
4
|
+
when ENV["RADIANT_ENV_FILE"]
|
5
|
+
require ENV["RADIANT_ENV_FILE"]
|
6
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
7
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
|
8
|
+
else
|
9
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
require "#{RADIANT_ROOT}/spec/spec_helper"
|
13
|
+
|
14
|
+
if File.directory?(File.dirname(__FILE__) + "/scenarios")
|
15
|
+
Scenario.load_paths.unshift File.dirname(__FILE__) + "/scenarios"
|
16
|
+
end
|
17
|
+
if File.directory?(File.dirname(__FILE__) + "/matchers")
|
18
|
+
Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
|
19
|
+
end
|
20
|
+
|
21
|
+
Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
|
22
|
+
|
23
|
+
# Needs to be test.host so the SiteScope works right
|
24
|
+
VhostExtension.HOST = "test.host"
|
25
|
+
|
26
|
+
Spec::Runner.configure do |config|
|
27
|
+
# config.use_transactional_fixtures = true
|
28
|
+
# config.use_instantiated_fixtures = false
|
29
|
+
# config.fixture_path = RAILS_ROOT + '/spec/fixtures'
|
30
|
+
|
31
|
+
# You can declare fixtures for each behaviour like this:
|
32
|
+
# describe "...." do
|
33
|
+
# fixtures :table_a, :table_b
|
34
|
+
#
|
35
|
+
# Alternatively, if you prefer to declare them only once, you can
|
36
|
+
# do so here, like so ...
|
37
|
+
#
|
38
|
+
# config.global_fixtures = :page_parts, :pages, :sites_users, :sites, :users
|
39
|
+
#
|
40
|
+
# If you declare global fixtures, be aware that they will be declared
|
41
|
+
# for all of your examples, even those that don't use them.
|
42
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
2
|
+
ruby_body:
|
3
|
+
id: 1
|
4
|
+
name: body
|
5
|
+
content: This is the body portion of the Ruby home page.
|
6
|
+
page_id: 1
|
7
|
+
rails_body:
|
8
|
+
id: 2
|
9
|
+
name: body
|
10
|
+
content: This is the Rails home page.
|
11
|
+
page_id: 2
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
2
|
+
homepage:
|
3
|
+
id: 1
|
4
|
+
title: Ruby Home Page
|
5
|
+
breadcrumb: Home
|
6
|
+
slug: /
|
7
|
+
status_id: 100
|
8
|
+
parent_id:
|
9
|
+
published_at: 2006-01-30 08:41:07
|
10
|
+
site_id: 1
|
11
|
+
documentation:
|
12
|
+
id: 2
|
13
|
+
title: Rails Home Page
|
14
|
+
breadcrumb: Home
|
15
|
+
slug: /
|
16
|
+
status_id: 100
|
17
|
+
parent_id:
|
18
|
+
published_at: 2006-01-30 08:41:07
|
19
|
+
site_id: 2
|