adds author_of? helper method
This commit is contained in:
@@ -35,4 +35,9 @@ module ApplicationHelper
|
|||||||
}
|
}
|
||||||
Redcarpet::Markdown.new(renderer, extensions).render(text).html_safe
|
Redcarpet::Markdown.new(renderer, extensions).render(text).html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def author_of?(authorable, user)
|
||||||
|
return false if authorable.blank? || user.blank?
|
||||||
|
authorable.author_id == user.id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
27
spec/helpers/application_helper_spec.rb
Normal file
27
spec/helpers/application_helper_spec.rb
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe ApplicationHelper do
|
||||||
|
|
||||||
|
describe "#author_of?" do
|
||||||
|
it "should be true if user is the author" do
|
||||||
|
user = create(:user)
|
||||||
|
proposal = create(:proposal, author: user)
|
||||||
|
expect(author_of?(proposal, user)).to eq true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be false if user is not the author" do
|
||||||
|
user = create(:user)
|
||||||
|
proposal = create(:proposal)
|
||||||
|
expect(author_of?(proposal, user)).to eq false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be false if user or authorable is nil" do
|
||||||
|
user = create(:user)
|
||||||
|
proposal = create(:proposal)
|
||||||
|
|
||||||
|
expect(author_of?(nil, user)).to eq false
|
||||||
|
expect(author_of?(proposal, nil)).to eq false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user