Fix the condition for displaying edit/delete links

openid
Marcin Kulik 11 years ago
parent 5c6f0e80d6
commit 2dbc811caf

@ -57,4 +57,12 @@ class Asciicast < ActiveRecord::Base
terminal.release if terminal terminal.release if terminal
end end
def managable_by?(user)
if user
user == self.user
else
false
end
end
end end

@ -33,7 +33,7 @@
= " #{@asciicast.views_count}" = " #{@asciicast.views_count}"
.col-md-4 .col-md-4
- if @asciicast.user == current_user - if @asciicast.managable_by?(current_user)
.dropdown.actions-dropdown.pull-right .dropdown.actions-dropdown.pull-right
button.btn.btn-default.dropdown-toggle[type="button" data-toggle="dropdown"] button.btn.btn-default.dropdown-toggle[type="button" data-toggle="dropdown"]
span.glyphicon.glyphicon-cog span.glyphicon.glyphicon-cog

@ -82,4 +82,35 @@ describe Asciicast do
end end
end end
describe '#managable_by?' do
subject { asciicast.managable_by?(user) }
let(:asciicast) { Asciicast.new }
let(:owner) { nil }
before do
asciicast.user = owner
end
context "when user is nil" do
let(:user) { nil }
it { should be(false) }
end
context "when user is owner of the asciicast" do
let(:user) { User.new }
let(:owner) { user }
it { should be(true) }
end
context "when user isn't owner of the asciicast" do
let(:user) { User.new }
let(:owner) { User.new }
it { should be(false) }
end
end
end end

Loading…
Cancel
Save