forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add InstancePresenter to expose site details * Clean up about controller, use instance presenter
- Loading branch information
1 parent
6820a0b
commit f131fdc
Showing
8 changed files
with
175 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
class InstancePresenter | ||
delegate( | ||
:closed_registrations_message, | ||
:contact_email, | ||
:open_registrations, | ||
:site_description, | ||
:site_extended_description, | ||
to: Setting | ||
) | ||
|
||
def contact_account | ||
Account.find_local(Setting.site_contact_username) | ||
end | ||
|
||
def user_count | ||
Rails.cache.fetch('user_count') { User.count } | ||
end | ||
|
||
def status_count | ||
Rails.cache.fetch('local_status_count') { Status.local.count } | ||
end | ||
|
||
def domain_count | ||
Rails.cache.fetch('distinct_domain_count') { Account.distinct.count(:domain) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
= simple_form_for(new_user, url: user_registration_path) do |f| | ||
= f.simple_fields_for :account do |account_fields| | ||
= account_fields.input :username, | ||
autofocus: true, | ||
placeholder: t('simple_form.labels.defaults.username'), | ||
required: true, | ||
input_html: { 'aria-label' => t('simple_form.labels.defaults.username') } | ||
|
||
= f.input :email, | ||
placeholder: t('simple_form.labels.defaults.email'), | ||
required: true, | ||
input_html: { 'aria-label' => t('simple_form.labels.defaults.email') } | ||
= f.input :password, | ||
autocomplete: "off", | ||
placeholder: t('simple_form.labels.defaults.password'), | ||
required: true, | ||
input_html: { 'aria-label' => t('simple_form.labels.defaults.password') } | ||
= f.input :password_confirmation, | ||
autocomplete: "off", | ||
placeholder: t('simple_form.labels.defaults.confirm_password'), | ||
required: true, | ||
input_html: { 'aria-label' => t('simple_form.labels.defaults.confirm_password') } | ||
|
||
.actions | ||
= f.button :button, t('about.get_started'), type: :submit | ||
|
||
.info | ||
= link_to t('auth.login'), new_user_session_path, class: 'webapp-btn' | ||
· | ||
= link_to t('about.about_this'), about_more_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
require 'rails_helper' | ||
|
||
describe InstancePresenter do | ||
let(:instance_presenter) { InstancePresenter.new } | ||
|
||
it "delegates site_description to Setting" do | ||
Setting.site_description = "Site desc" | ||
|
||
expect(instance_presenter.site_description).to eq "Site desc" | ||
end | ||
|
||
it "delegates site_extended_description to Setting" do | ||
Setting.site_extended_description = "Extended desc" | ||
|
||
expect(instance_presenter.site_extended_description).to eq "Extended desc" | ||
end | ||
|
||
it "delegates open_registrations to Setting" do | ||
Setting.open_registrations = false | ||
|
||
expect(instance_presenter.open_registrations).to eq false | ||
end | ||
|
||
it "delegates closed_registrations_message to Setting" do | ||
Setting.closed_registrations_message = "Closed message" | ||
|
||
expect(instance_presenter.closed_registrations_message).to eq "Closed message" | ||
end | ||
|
||
it "delegates contact_email to Setting" do | ||
Setting.contact_email = "admin@example.com" | ||
|
||
expect(instance_presenter.contact_email).to eq "admin@example.com" | ||
end | ||
|
||
describe "contact_account" do | ||
it "returns the account for the site contact username" do | ||
Setting.site_contact_username = "aaa" | ||
account = Fabricate(:account, username: "aaa") | ||
|
||
expect(instance_presenter.contact_account).to eq(account) | ||
end | ||
end | ||
|
||
describe "user_count" do | ||
it "returns the number of site users" do | ||
cache = double | ||
allow(Rails).to receive(:cache).and_return(cache) | ||
allow(cache).to receive(:fetch).with("user_count").and_return(123) | ||
|
||
expect(instance_presenter.user_count).to eq(123) | ||
end | ||
end | ||
|
||
describe "status_count" do | ||
it "returns the number of local statuses" do | ||
cache = double | ||
allow(Rails).to receive(:cache).and_return(cache) | ||
allow(cache).to receive(:fetch).with("local_status_count").and_return(234) | ||
|
||
expect(instance_presenter.status_count).to eq(234) | ||
end | ||
end | ||
|
||
describe "domain_count" do | ||
it "returns the number of known domains" do | ||
cache = double | ||
allow(Rails).to receive(:cache).and_return(cache) | ||
allow(cache).to receive(:fetch).with("distinct_domain_count").and_return(345) | ||
|
||
expect(instance_presenter.domain_count).to eq(345) | ||
end | ||
end | ||
end |