Null user should be used only for display purposes

This commit is contained in:
Marcin Kulik 2015-04-04 17:11:56 +00:00
parent dbc18f9ce6
commit 3ced30b4f0
4 changed files with 3 additions and 51 deletions

View File

@ -3,7 +3,9 @@ class AsciicastDecorator < ApplicationDecorator
THUMBNAIL_WIDTH = 20
THUMBNAIL_HEIGHT = 10
decorates_association :user
def user
@user ||= UserDecorator.new(model.user || User.null)
end
def os
if user_agent.present?

View File

@ -54,10 +54,6 @@ class Asciicast < ActiveRecord::Base
collection
end
def user
super || self.user = User.null
end
def stdout
return @stdout if @stdout
@stdout = Stdout::Buffered.new(get_stdout)

View File

@ -240,32 +240,6 @@ describe AsciicastDecorator do
end
end
describe '#author_link' do
subject { decorator.author_link }
let(:asciicast) { double('asciicast', user: user) }
let(:user) { double('user', link: 'link') }
before do
allow(user).to receive(:decorate) { user }
end
it { should eq('link') }
end
describe '#author_img_link' do
subject { decorator.author_img_link }
let(:asciicast) { double('asciicast', user: user) }
let(:user) { double('user', img_link: 'img-link') }
before do
allow(user).to receive(:decorate) { user }
end
it { should eq('img-link') }
end
describe '#formatted_duration' do
subject { decorator.formatted_duration }

View File

@ -54,26 +54,6 @@ describe Asciicast do
let(:asciicast) { described_class.new }
describe '#user' do
subject { asciicast.user }
context "when it has user assigned" do
let(:user) { User.new }
before do
asciicast.user = user
end
it { should be(user) }
end
context "when it doesn't have user assigned" do
it 'is a null user' do
expect(asciicast.user.temporary_username).to eq('anonymous')
end
end
end
describe '#stdout' do
context 'for single-file, JSON asciicast' do
let(:asciicast) { create(:asciicast) }