This repository has been archived by the owner on Jul 15, 2021. It is now read-only.
forked from orientation/orientation
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add specs and refactor ArticleDecorator#authors
- Loading branch information
Showing
2 changed files
with
57 additions
and
7 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 |
---|---|---|
@@ -1,4 +1,56 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe ArticleDecorator do | ||
describe "#authors" do | ||
let(:author) { create(:user) } | ||
let(:expected_author_with_created_at) do | ||
"#{subject.author.link_tag} #{subject.created_at_tag}" | ||
end | ||
subject { described_class.new(article) } | ||
|
||
context "without an editor" do | ||
let(:article) { create(:article, created_at: Time.at(0), author: author) } | ||
|
||
it "displays a link to the author and the created_at time" do | ||
expect(subject.authors).to eq(expected_author_with_created_at) | ||
end | ||
end | ||
|
||
context "with an editor who is also the author" do | ||
let(:article) do | ||
create( | ||
:article, | ||
created_at: Time.at(0), | ||
updated_at: Time.at(1), | ||
author: author, | ||
editor: author | ||
) | ||
end | ||
|
||
it "displays a link to the author, created_at time and the updated at time" do | ||
expect(subject.authors).to eq( | ||
"#{expected_author_with_created_at} and updated on #{subject.updated_at_tag}" | ||
) | ||
end | ||
end | ||
|
||
context "with an editor who is not the author" do | ||
let(:editor) { create(:user) } | ||
let(:article) do | ||
create( | ||
:article, | ||
created_at: Time.at(0), | ||
updated_at: Time.at(1), | ||
author: author, | ||
editor: editor | ||
) | ||
end | ||
|
||
it "displays a link to the author, created_at time and the editor with updated at time" do | ||
expect(subject.authors).to eq( | ||
"#{expected_author_with_created_at} and updated by #{subject.editor_email_tag} on #{subject.updated_at_tag}" | ||
) | ||
end | ||
end | ||
end | ||
end |