Skip to content

Commit

Permalink
Merge pull request #2105 from tf/root-permalink-dirs
Browse files Browse the repository at this point in the history
Create default permalink directory for new sites
  • Loading branch information
tf authored May 13, 2024
2 parents a64bcd7 + 8890a07 commit d2aba71
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
4 changes: 4 additions & 0 deletions admins/pageflow/sites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ module Pageflow
controller do
helper Pageflow::Admin::FormHelper

before_create do |site|
site.build_default_permalink_directory
end

def index
redirect_to admin_account_path(parent, tab: 'sites')
end
Expand Down
1 change: 1 addition & 0 deletions app/models/pageflow/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Account < ApplicationRecord
def build_default_site(*args)
super.tap do |site|
site.account = self
site.build_default_permalink_directory
end
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/pageflow/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def cname_domain
cname.split('.').pop(2).join('.')
end

def build_default_permalink_directory
permalink_directories.build(path: '')
end

def first_paged_entry_template
entry_templates.find_or_initialize_by(entry_type_name: 'paged')
end
Expand Down
7 changes: 4 additions & 3 deletions spec/controllers/admin/accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def self.name
describe '#create' do
render_views

it 'creates nested default_site' do
it 'creates nested default_site with root permalink directory' do
sign_in(create(:user, :admin), scope: :user)
post(:create,
params: {
Expand All @@ -233,9 +233,10 @@ def self.name
}
}
})
site = Pageflow::Site.last

expect(Pageflow::Site.last.imprint_link_url)
.to eq('http://example.com/new')
expect(site.imprint_link_url).to eq('http://example.com/new')
expect(site.permalink_directories.map(&:path)).to eq([''])
end

it 'creates no paged entry template' do
Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/admin/sites_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,22 @@ def self.name
expect(site.feeds_enabled?).to eq(true)
end

it 'creates root permalink directory' do
account = create(:account)

sign_in(create(:user, :admin), scope: :user)
post(:create,
params: {
account_id: account,
site: {
name: 'second',
}
})

site = account.sites.last
expect(site.permalink_directories.map(&:path)).to eq([''])
end

it 'does not allow managers to create sites ' do
account = create(:account)

Expand Down
9 changes: 9 additions & 0 deletions spec/models/pageflow/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ module Pageflow
expect(site.account).to eq(account)
end

it 'creates root permalink directory' do
account = build(:account)

site = account.build_default_site

expect(site.permalink_directories.size).to eq(1)
expect(site.permalink_directories.first.path).to eq('')
end

it 'destroys default site when account is destroyed' do
account = create(:account)

Expand Down

0 comments on commit d2aba71

Please sign in to comment.