From 6d6a429af8fe4bd92ed497f401676353fdc603e0 Mon Sep 17 00:00:00 2001 From: Eugen Date: Fri, 7 Apr 2017 05:56:56 +0200 Subject: Rewrite Atom generation from stream entries to use Ox instead of Nokogiri (#1124) * Rewrite Atom generation from stream entries to use Ox instead of Nokogiri::Builder StreamEntry is now limited to only statuses, which allows some optimization. Removed extra queries on AccountsController#show. AtomSerializer instead of AtomBuilderHelper used in AccountsController#show, StreamEntriesController#show, StreamEntryRenderer and PubSubHubbub::DistributionWorker PubSubHubbub::DistributionWorker moves n+1 DomainBlock query to PubSubHubbub::DeliveryWorker instead. All Salmon slaps that aren't based on StreamEntry still use AtomBuilderHelper and Nokogiri * All Salmon slaps now use Ox instead of Nokogiri. No touch from status on account --- app/views/accounts/show.atom.ruby | 27 --------------------------- app/views/stream_entries/show.atom.ruby | 9 --------- 2 files changed, 36 deletions(-) delete mode 100644 app/views/accounts/show.atom.ruby delete mode 100644 app/views/stream_entries/show.atom.ruby (limited to 'app/views') diff --git a/app/views/accounts/show.atom.ruby b/app/views/accounts/show.atom.ruby deleted file mode 100644 index e15021178..000000000 --- a/app/views/accounts/show.atom.ruby +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -Nokogiri::XML::Builder.new do |xml| - feed(xml) do - simple_id xml, account_url(@account, format: 'atom') - title xml, @account.display_name - subtitle xml, @account.note - updated_at xml, stream_updated_at - logo xml, full_asset_url(@account.avatar.url(:original)) - - author(xml) do - include_author xml, @account - end - - link_alternate xml, TagManager.instance.url_for(@account) - link_self xml, account_url(@account, format: 'atom') - link_next xml, account_url(@account, format: 'atom', max_id: @entries.last.id) if @entries.size == 20 - link_hub xml, api_push_url - link_salmon xml, api_salmon_url(@account.id) - - @entries.each do |stream_entry| - entry(xml, false) do - include_entry xml, stream_entry - end - end - end -end.to_xml diff --git a/app/views/stream_entries/show.atom.ruby b/app/views/stream_entries/show.atom.ruby deleted file mode 100644 index a298f3269..000000000 --- a/app/views/stream_entries/show.atom.ruby +++ /dev/null @@ -1,9 +0,0 @@ -Nokogiri::XML::Builder.new do |xml| - entry(xml, true) do - author(xml) do - include_author xml, @stream_entry.account - end - - include_entry xml, @stream_entry - end -end.to_xml -- cgit From 1c351709bc45611c2ed48fb8539c2b27ab51b6fe Mon Sep 17 00:00:00 2001 From: Eugen Date: Fri, 7 Apr 2017 11:09:14 +0200 Subject: Force UTF8 encoding on generated XML (#1140) --- Procfile | 2 +- app/lib/atom_serializer.rb | 2 +- app/views/layouts/application.html.haml | 6 ++++-- config/puma.rb | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) (limited to 'app/views') diff --git a/Procfile b/Procfile index 6cdd89518..646e26059 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ web: bundle exec puma -C config/puma.rb -worker: bundle exec sidekiq -q default -q mailers -q push +worker: bundle exec sidekiq -q default -q push -q pull -q mailers diff --git a/app/lib/atom_serializer.rb b/app/lib/atom_serializer.rb index 21f485c2d..4e01c3d43 100644 --- a/app/lib/atom_serializer.rb +++ b/app/lib/atom_serializer.rb @@ -7,7 +7,7 @@ class AtomSerializer def render(element) document = Ox::Document.new(version: '1.0') document << element - "#{Ox.dump(element)}" + ('' + Ox.dump(element)).force_encoding('UTF-8') end end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 7eae6982b..abab14a28 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -11,8 +11,10 @@ %meta{:name => "theme-color", :content => "#282c37"}/ %meta{:name => "apple-mobile-web-app-capable", :content => "yes"}/ - %title - = "#{yield(:page_title)} - " if content_for?(:page_title) + %title< + - if content_for?(:page_title) + = yield(:page_title) + = ' - ' = Setting.site_title = stylesheet_link_tag 'application', media: 'all' diff --git a/config/puma.rb b/config/puma.rb index 550129bdc..191f00cca 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -9,7 +9,7 @@ preload_app! on_worker_boot do if ENV['HEROKU'] # Spawn the workers from Puma, to only use one dyno - @sidekiq_pid ||= spawn('bundle exec sidekiq -q default -q mailers -q push') + @sidekiq_pid ||= spawn('bundle exec sidekiq -q default -q push -q pull -q mailers ') end ActiveRecord::Base.establish_connection if defined?(ActiveRecord) -- cgit From e3a3422a65901c71ec3ff4a2729309c441660d63 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 7 Apr 2017 12:40:26 +0200 Subject: Allow setting of default language through config Setting of locale in controller extracted to Localized concern, the doorkeeper authorized applications controller moved under custom namespace with inclusion of Localized, which resolves the "it sometimes appears in a different random language" bug --- .env.production.sample | 3 +++ app/controllers/application_controller.rb | 9 ++------- app/controllers/concerns/localized.rb | 19 ++++++++++++++++++ app/controllers/oauth/authorizations_controller.rb | 9 ++------- .../oauth/authorized_applications_controller.rb | 16 +++++++++++++++ .../authorized_applications/index.html.haml | 23 ---------------------- .../oauth/authorized_applications/index.html.haml | 23 ++++++++++++++++++++++ config/routes.rb | 2 +- 8 files changed, 66 insertions(+), 38 deletions(-) create mode 100644 app/controllers/concerns/localized.rb create mode 100644 app/controllers/oauth/authorized_applications_controller.rb delete mode 100644 app/views/doorkeeper/authorized_applications/index.html.haml create mode 100644 app/views/oauth/authorized_applications/index.html.haml (limited to 'app/views') diff --git a/.env.production.sample b/.env.production.sample index a7f9eb4bf..a0e963ca6 100644 --- a/.env.production.sample +++ b/.env.production.sample @@ -25,6 +25,9 @@ OTP_SECRET= # Only allow registrations with the following e-mail domains # EMAIL_DOMAIN_WHITELIST=example1.com|example2.de|etc +# Optionally change default language +# DEFAULT_LOCALE=de + # E-mail configuration SMTP_SERVER=smtp.mailgun.org SMTP_PORT=587 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c06142fd4..f00f9c1e3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class ApplicationController < ActionController::Base + include Localized + # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception @@ -14,7 +16,6 @@ class ApplicationController < ActionController::Base rescue_from ActionController::InvalidAuthenticityToken, with: :unprocessable_entity before_action :store_current_location, except: :raise_not_found, unless: :devise_controller? - before_action :set_locale before_action :set_user_activity before_action :check_suspension, if: :user_signed_in? @@ -28,12 +29,6 @@ class ApplicationController < ActionController::Base store_location_for(:user, request.url) end - def set_locale - I18n.locale = current_user.try(:locale) || I18n.default_locale - rescue I18n::InvalidLocale - I18n.locale = I18n.default_locale - end - def require_admin! redirect_to root_path unless current_user&.admin? end diff --git a/app/controllers/concerns/localized.rb b/app/controllers/concerns/localized.rb new file mode 100644 index 000000000..b6f868090 --- /dev/null +++ b/app/controllers/concerns/localized.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Localized + extend ActiveSupport::Concern + + included do + before_action :set_locale + end + + def set_locale + I18n.locale = current_user.try(:locale) || default_locale + rescue I18n::InvalidLocale + I18n.locale = default_locale + end + + def default_locale + ENV.fetch('DEFAULT_LOCALE') { I18n.default_locale } + end +end diff --git a/app/controllers/oauth/authorizations_controller.rb b/app/controllers/oauth/authorizations_controller.rb index 7c25266d8..cdbfde0fb 100644 --- a/app/controllers/oauth/authorizations_controller.rb +++ b/app/controllers/oauth/authorizations_controller.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true class Oauth::AuthorizationsController < Doorkeeper::AuthorizationsController + include Localized + skip_before_action :authenticate_resource_owner! - before_action :set_locale before_action :store_current_location before_action :authenticate_resource_owner! @@ -12,10 +13,4 @@ class Oauth::AuthorizationsController < Doorkeeper::AuthorizationsController def store_current_location store_location_for(:user, request.url) end - - def set_locale - I18n.locale = current_user.try(:locale) || I18n.default_locale - rescue I18n::InvalidLocale - I18n.locale = I18n.default_locale - end end diff --git a/app/controllers/oauth/authorized_applications_controller.rb b/app/controllers/oauth/authorized_applications_controller.rb new file mode 100644 index 000000000..09dd5d3c4 --- /dev/null +++ b/app/controllers/oauth/authorized_applications_controller.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class Oauth::AuthorizedApplicationsController < Doorkeeper::AuthorizedApplicationsController + include Localized + + skip_before_action :authenticate_resource_owner! + + before_action :store_current_location + before_action :authenticate_resource_owner! + + private + + def store_current_location + store_location_for(:user, request.url) + end +end diff --git a/app/views/doorkeeper/authorized_applications/index.html.haml b/app/views/doorkeeper/authorized_applications/index.html.haml deleted file mode 100644 index d4719881c..000000000 --- a/app/views/doorkeeper/authorized_applications/index.html.haml +++ /dev/null @@ -1,23 +0,0 @@ -- content_for :page_title do - = t('doorkeeper.authorized_applications.index.title') - -%table.table - %thead - %tr - %th= t('doorkeeper.authorized_applications.index.application') - %th= t('doorkeeper.authorized_applications.index.scopes') - %th= t('doorkeeper.authorized_applications.index.created_at') - %th - %tbody - - @applications.each do |application| - %tr - %td - - if application.website.blank? - = application.name - - else - = link_to application.name, application.website - %th= application.scopes.map { |scope| t(scope, scope: [:doorkeeper, :scopes]) }.join('
').html_safe - %td= l application.created_at - %td - - unless application.superapp? - = table_link_to 'times', t('doorkeeper.authorized_applications.buttons.revoke'), oauth_authorized_application_path(application), method: :delete, data: { confirm: t('doorkeeper.authorized_applications.confirmations.revoke') } diff --git a/app/views/oauth/authorized_applications/index.html.haml b/app/views/oauth/authorized_applications/index.html.haml new file mode 100644 index 000000000..d4719881c --- /dev/null +++ b/app/views/oauth/authorized_applications/index.html.haml @@ -0,0 +1,23 @@ +- content_for :page_title do + = t('doorkeeper.authorized_applications.index.title') + +%table.table + %thead + %tr + %th= t('doorkeeper.authorized_applications.index.application') + %th= t('doorkeeper.authorized_applications.index.scopes') + %th= t('doorkeeper.authorized_applications.index.created_at') + %th + %tbody + - @applications.each do |application| + %tr + %td + - if application.website.blank? + = application.name + - else + = link_to application.name, application.website + %th= application.scopes.map { |scope| t(scope, scope: [:doorkeeper, :scopes]) }.join('
').html_safe + %td= l application.created_at + %td + - unless application.superapp? + = table_link_to 'times', t('doorkeeper.authorized_applications.buttons.revoke'), oauth_authorized_application_path(application), method: :delete, data: { confirm: t('doorkeeper.authorized_applications.confirmations.revoke') } diff --git a/config/routes.rb b/config/routes.rb index ca77191f7..315ad5da5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,7 +11,7 @@ Rails.application.routes.draw do end use_doorkeeper do - controllers authorizations: 'oauth/authorizations' + controllers authorizations: 'oauth/authorizations', authorized_applications: 'oauth/authorized_applications' end get '.well-known/host-meta', to: 'xrd#host_meta', as: :host_meta -- cgit From 786e6f94b986dbf98eae9d79bc75e147fcefc8ec Mon Sep 17 00:00:00 2001 From: Jantso Porali Date: Fri, 7 Apr 2017 12:58:12 +0200 Subject: Update Finnish translations, add sample Minio config (#954) --- .env.production.sample | 10 ++++++++++ app/views/user_mailer/confirmation_instructions.fi.html.erb | 5 +++++ app/views/user_mailer/confirmation_instructions.fi.text.erb | 5 +++++ app/views/user_mailer/password_change.fi.html.erb | 3 +++ app/views/user_mailer/password_change.fi.text.erb | 3 +++ .../user_mailer/reset_password_instructions.fi.html.erb | 8 ++++++++ .../user_mailer/reset_password_instructions.fi.text.erb | 8 ++++++++ config/locales/fi.yml | 12 ++++++------ docs/Using-Mastodon/FAQ.md | 3 ++- 9 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 app/views/user_mailer/confirmation_instructions.fi.html.erb create mode 100644 app/views/user_mailer/confirmation_instructions.fi.text.erb create mode 100644 app/views/user_mailer/password_change.fi.html.erb create mode 100644 app/views/user_mailer/password_change.fi.text.erb create mode 100644 app/views/user_mailer/reset_password_instructions.fi.html.erb create mode 100644 app/views/user_mailer/reset_password_instructions.fi.text.erb (limited to 'app/views') diff --git a/.env.production.sample b/.env.production.sample index a7f9eb4bf..a4eabc384 100644 --- a/.env.production.sample +++ b/.env.production.sample @@ -44,6 +44,16 @@ SMTP_FROM_ADDRESS=notifications@example.com # S3_PROTOCOL=http # S3_HOSTNAME=192.168.1.123:9000 +# S3 (Minio Config (optional) Please check Minio instance for details) +# S3_ENABLED=true +# S3_BUCKET= +# AWS_ACCESS_KEY_ID= +# AWS_SECRET_ACCESS_KEY= +# S3_REGION= +# S3_PROTOCOL=https +# S3_HOSTNAME= +# S3_ENDPOINT= + # Optional alias for S3 if you want to use Cloudfront or Cloudflare in front # S3_CLOUDFRONT_HOST= diff --git a/app/views/user_mailer/confirmation_instructions.fi.html.erb b/app/views/user_mailer/confirmation_instructions.fi.html.erb new file mode 100644 index 000000000..8b72722da --- /dev/null +++ b/app/views/user_mailer/confirmation_instructions.fi.html.erb @@ -0,0 +1,5 @@ +

Tervetuloa <%= @resource.email %>!

+ +

Voit vahvistaa Mastodon tilisi klikkaamalla alla olevaa linkkiä:

+ +

<%= link_to 'Varmista tilini', confirmation_url(@resource, confirmation_token: @token) %>

diff --git a/app/views/user_mailer/confirmation_instructions.fi.text.erb b/app/views/user_mailer/confirmation_instructions.fi.text.erb new file mode 100644 index 000000000..796913abb --- /dev/null +++ b/app/views/user_mailer/confirmation_instructions.fi.text.erb @@ -0,0 +1,5 @@ +Tervetuloa <%= @resource.email %>! + +Voit vahvistaa Mastodon tilisi klikkaamalla alla olevaa linkkiä: + +<%= confirmation_url(@resource, confirmation_token: @token) %> diff --git a/app/views/user_mailer/password_change.fi.html.erb b/app/views/user_mailer/password_change.fi.html.erb new file mode 100644 index 000000000..c56b96593 --- /dev/null +++ b/app/views/user_mailer/password_change.fi.html.erb @@ -0,0 +1,3 @@ +

Hei <%= @resource.email %>!

+ +

Lähetämme tämän viestin ilmoittaaksemme että salasanasi on vaihdettu.

diff --git a/app/views/user_mailer/password_change.fi.text.erb b/app/views/user_mailer/password_change.fi.text.erb new file mode 100644 index 000000000..d90c3fdeb --- /dev/null +++ b/app/views/user_mailer/password_change.fi.text.erb @@ -0,0 +1,3 @@ +Hei <%= @resource.email %>! + +Lähetämme tämän viestin ilmoittaaksemme että salasanasi on vaihdettu. diff --git a/app/views/user_mailer/reset_password_instructions.fi.html.erb b/app/views/user_mailer/reset_password_instructions.fi.html.erb new file mode 100644 index 000000000..53be0b62b --- /dev/null +++ b/app/views/user_mailer/reset_password_instructions.fi.html.erb @@ -0,0 +1,8 @@ +

Hei <%= @resource.email %>!

+ +

Joku on pyytänyt salasanvaihto Mastodonissa. Voit tehdä sen allaolevassa linkissä.

+ +

<%= link_to 'Vaihda salasanani', edit_password_url(@resource, reset_password_token: @token) %>

+ +

Jos et pyytänyt vaihtoa, poista tämä viesti.

+

Salasanaasi ei vaihdeta ennen kuin menet ylläolevaan linkkiin ja luot uuden.

diff --git a/app/views/user_mailer/reset_password_instructions.fi.text.erb b/app/views/user_mailer/reset_password_instructions.fi.text.erb new file mode 100644 index 000000000..c826d5fc8 --- /dev/null +++ b/app/views/user_mailer/reset_password_instructions.fi.text.erb @@ -0,0 +1,8 @@ +Hei <%= @resource.email %>! + +Joku on pyytänyt salasanvaihto Mastodonissa. Voit tehdä sen allaolevassa linkissä. + +<%= edit_password_url(@resource, reset_password_token: @token) %> + +Jos et pyytänyt vaihtoa, poista tämä viesti. +Salasanaasi ei vaihdeta ennen kuin menet ylläolevaan linkkiin ja luot uuden. diff --git a/config/locales/fi.yml b/config/locales/fi.yml index cdb2b9886..947d3f646 100644 --- a/config/locales/fi.yml +++ b/config/locales/fi.yml @@ -16,18 +16,18 @@ fi: chronology: Aikajana on kronologisessa järjestyksessä ethics: 'Eettinen suunnittelu: ei mainoksia, no seurantaa' gifv: GIFV settejä ja lyhyitä videoita - privacy: Julkaisu kohtainen yksityisyys aseuts + privacy: Julkaisu kohtainen yksityisyys asetus public: Julkiset aikajanat features_headline: Mikä erottaa Mastodonin muista get_started: Aloita käyttö links: Linkit - other_instances: muuhun palvelimeen + other_instances: Muut palvelimet source_code: Lähdekoodi status_count_after: statusta status_count_before: Ovat luoneet terms: Ehdot - user_count_after: käyttäjää - user_count_before: Koti käyttäjälle + user_count_after: käyttäjälle + user_count_before: Koti accounts: follow: Seuraa followers: Seuraajat @@ -130,8 +130,8 @@ fi: authorized_apps: Valtuutetut ohjelmat back: Takaisin Mastodoniin edit_profile: Muokkaa profiilia - export: Datan vienti - import: Datan tuonti + export: Vie dataa + import: Tuo dataa preferences: Ominaisuudet settings: Asetukset two_factor_auth: Kaksivaiheinen tunnistus diff --git a/docs/Using-Mastodon/FAQ.md b/docs/Using-Mastodon/FAQ.md index daedcbdd8..3b03a8ee4 100644 --- a/docs/Using-Mastodon/FAQ.md +++ b/docs/Using-Mastodon/FAQ.md @@ -36,8 +36,9 @@ While Mastodon is compatible with GNU social in terms of server to server commun Because Mastodon has been created from a blank slate, it is much simpler to have the API mirror internal structures as closely as possible, rather than build an emulation layer. Secondly, the GNU social client API is actually a half-way implementation of the legacy Twitter API - that's the reason why it works with some older Twitter client apps. However, many of those apps are not maintained anymore, the GNU social API does not actually keep up with the real Twitter API and never fully implemented all its features; at the same time, the Twitter API was never meant for a federated service and so obscures some of the functionality. + #### How is Mastodon funded? Development of Mastodon and hosting of mastodon.social is funded through my [Patreon (also BTC/PayPal donations)](https://www.patreon.com/user?u=619786). Beyond that, I am not interested in VC funding, monetizing, advertising, or anything of that sort. I could offer setup/maintenance services on demand. -The software is free and open source and communities should host their own servers if they can, that way the costs are more or less distributed. Obviously it'd be hard for me to pay the bills if literally everyone decided to use the mastodon.social instance only. \ No newline at end of file +The software is free and open source and communities should host their own servers if they can, that way the costs are more or less distributed. Obviously it'd be hard for me to pay the bills if literally everyone decided to use the mastodon.social instance only. -- cgit From d4c94fa004117fdb7226b1b846a12d12dc0542d9 Mon Sep 17 00:00:00 2001 From: Joël Quenneville Date: Fri, 7 Apr 2017 14:18:30 -0400 Subject: DRY up reblog vs original status check Checking reblog vs original status was happening in multiple places across the app. For views, this logic was encapsulated in a helper method named `proper_status` but in the other layers of the app, the logic was duplicated. Because the logic is used at all layers of the app, we extracted it into a `Status#proper` method on the model and changed all uses of the logic to use this method. There is now a single source of truth for this condition. We added test coverage to untested methods that got refactored. --- app/helpers/stream_entries_helper.rb | 4 -- app/lib/atom_serializer.rb | 2 +- app/models/account.rb | 4 +- app/models/status.rb | 6 ++- app/views/stream_entries/_status.html.haml | 2 +- spec/models/account_spec.rb | 68 +++++++++++++++++++++++++++++- spec/models/status_spec.rb | 11 +++++ 7 files changed, 86 insertions(+), 11 deletions(-) (limited to 'app/views') diff --git a/app/helpers/stream_entries_helper.rb b/app/helpers/stream_entries_helper.rb index a26e912a3..38e63ed8d 100644 --- a/app/helpers/stream_entries_helper.rb +++ b/app/helpers/stream_entries_helper.rb @@ -34,10 +34,6 @@ module StreamEntriesHelper user_signed_in? && @favourited.key?(status.id) ? 'favourited' : '' end - def proper_status(status) - status.reblog? ? status.reblog : status - end - def rtl?(text) return false if text.empty? diff --git a/app/lib/atom_serializer.rb b/app/lib/atom_serializer.rb index be1cced8b..b9dcee6b3 100644 --- a/app/lib/atom_serializer.rb +++ b/app/lib/atom_serializer.rb @@ -328,7 +328,7 @@ class AtomSerializer def serialize_status_attributes(entry, status) append_element(entry, 'summary', status.spoiler_text) unless status.spoiler_text.blank? - append_element(entry, 'content', Formatter.instance.format(status.reblog? ? status.reblog : status).to_str, type: 'html') + append_element(entry, 'content', Formatter.instance.format(status.proper).to_str, type: 'html') status.mentions.each do |mentioned| append_element(entry, 'link', nil, rel: :mentioned, 'ostatus:object-type': TagManager::TYPES[:person], href: TagManager.instance.uri_for(mentioned.account)) diff --git a/app/models/account.rb b/app/models/account.rb index 6968607a2..cbba8b5b6 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -125,11 +125,11 @@ class Account < ApplicationRecord end def favourited?(status) - (status.reblog? ? status.reblog : status).favourites.where(account: self).count.positive? + status.proper.favourites.where(account: self).count.positive? end def reblogged?(status) - (status.reblog? ? status.reblog : status).reblogs.where(account: self).count.positive? + status.proper.reblogs.where(account: self).count.positive? end def keypair diff --git a/app/models/status.rb b/app/models/status.rb index 6948ad77c..7e3dd3e28 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -62,8 +62,12 @@ class Status < ApplicationRecord reply? ? :comment : :note end + def proper + reblog? ? reblog : self + end + def content - reblog? ? reblog.text : text + proper.text end def target diff --git a/app/views/stream_entries/_status.html.haml b/app/views/stream_entries/_status.html.haml index cdd0dde3b..434c5c8da 100644 --- a/app/views/stream_entries/_status.html.haml +++ b/app/views/stream_entries/_status.html.haml @@ -16,7 +16,7 @@ %strong= display_name(status.account) = t('stream_entries.reblogged') - = render partial: centered ? 'stream_entries/detailed_status' : 'stream_entries/simple_status', locals: { status: proper_status(status) } + = render partial: centered ? 'stream_entries/detailed_status' : 'stream_entries/simple_status', locals: { status: status.proper } - if include_threads = render partial: 'stream_entries/status', collection: @descendants, as: :status, locals: { is_successor: true } diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index d7f59adb8..93a45459d 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -99,11 +99,75 @@ RSpec.describe Account, type: :model do end describe '#favourited?' do - pending + let(:original_status) do + author = Fabricate(:account, username: 'original') + Fabricate(:status, account: author) + end + + context 'when the status is a reblog of another status' do + let(:original_reblog) do + author = Fabricate(:account, username: 'original_reblogger') + Fabricate(:status, reblog: original_status, account: author) + end + + it 'is is true when this account has favourited it' do + Fabricate(:favourite, status: original_reblog, account: subject) + + expect(subject.favourited?(original_status)).to eq true + end + + it 'is false when this account has not favourited it' do + expect(subject.favourited?(original_status)).to eq false + end + end + + context 'when the status is an original status' do + it 'is is true when this account has favourited it' do + Fabricate(:favourite, status: original_status, account: subject) + + expect(subject.favourited?(original_status)).to eq true + end + + it 'is false when this account has not favourited it' do + expect(subject.favourited?(original_status)).to eq false + end + end end describe '#reblogged?' do - pending + let(:original_status) do + author = Fabricate(:account, username: 'original') + Fabricate(:status, account: author) + end + + context 'when the status is a reblog of another status'do + let(:original_reblog) do + author = Fabricate(:account, username: 'original_reblogger') + Fabricate(:status, reblog: original_status, account: author) + end + + it 'is true when this account has reblogged it' do + Fabricate(:status, reblog: original_reblog, account: subject) + + expect(subject.reblogged?(original_reblog)).to eq true + end + + it 'is false when this account has not reblogged it' do + expect(subject.reblogged?(original_reblog)).to eq false + end + end + + context 'when the status is an original status' do + it 'is true when this account has reblogged it' do + Fabricate(:status, reblog: original_status, account: subject) + + expect(subject.reblogged?(original_status)).to eq true + end + + it 'is false when this account has not reblogged it' do + expect(subject.reblogged?(original_status)).to eq false + end + end end describe '.find_local' do diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb index b9d079521..db244ebe7 100644 --- a/spec/models/status_spec.rb +++ b/spec/models/status_spec.rb @@ -97,4 +97,15 @@ RSpec.describe Status, type: :model do describe '#favourites_count' do pending end + + describe '#proper' do + it 'is itself for original statuses' do + expect(subject.proper).to eq subject + end + + it 'is the source status for reblogs' do + subject.reblog = other + expect(subject.proper).to eq other + end + end end -- cgit