We were very inconsistent regarding these rules. Personally I prefer no empty lines around blocks, clases, etc... as recommended by the Ruby style guide [1], and they're the default values in rubocop, so those are the settings I'm applying. The exception is the `private` access modifier, since we were leaving empty lines around it most of the time. That's the default rubocop rule as well. Personally I don't have a strong preference about this one. [1] https://rubystyle.guide/#empty-lines-around-bodies
76 lines
1.9 KiB
Ruby
76 lines
1.9 KiB
Ruby
require "rails_helper"
|
|
|
|
describe Topic do
|
|
let(:topic) { build(:topic) }
|
|
|
|
describe "Concerns" do
|
|
it_behaves_like "notifiable"
|
|
end
|
|
|
|
it "is valid" do
|
|
expect(topic).to be_valid
|
|
end
|
|
|
|
it "is not valid without an author" do
|
|
topic.author = nil
|
|
expect(topic).not_to be_valid
|
|
end
|
|
|
|
it "is not valid without a title" do
|
|
topic.title = nil
|
|
expect(topic).not_to be_valid
|
|
end
|
|
|
|
it "is not valid without a description" do
|
|
topic.description = nil
|
|
expect(topic).not_to be_valid
|
|
end
|
|
|
|
context "order" do
|
|
it "orders by newest" do
|
|
proposal = create(:proposal)
|
|
community = proposal.community
|
|
topic1 = create(:topic, community: community)
|
|
topic2 = create(:topic, community: community)
|
|
topic3 = create(:topic, community: community)
|
|
|
|
results = community.topics.sort_by_newest
|
|
|
|
expect(results).to eq [topic3, topic2, topic1]
|
|
end
|
|
|
|
it "orders by oldest" do
|
|
proposal = create(:proposal)
|
|
community = proposal.community
|
|
topic1 = create(:topic, community: community)
|
|
topic2 = create(:topic, community: community)
|
|
topic3 = create(:topic, community: community)
|
|
|
|
results = community.topics.sort_by_oldest
|
|
|
|
expect(results.first).to eq(topic1)
|
|
expect(results.second).to eq(topic2)
|
|
expect(results.third).to eq(topic3)
|
|
end
|
|
|
|
it "orders by most_commented" do
|
|
proposal = create(:proposal)
|
|
community = proposal.community
|
|
topic1 = create(:topic, community: community)
|
|
create(:comment, commentable: topic1)
|
|
create(:comment, commentable: topic1)
|
|
topic2 = create(:topic, community: community)
|
|
create(:comment, commentable: topic2)
|
|
topic3 = create(:topic, community: community)
|
|
|
|
results = community.topics.sort_by_most_commented
|
|
|
|
expect(results).to eq [topic1, topic2, topic3]
|
|
end
|
|
end
|
|
|
|
describe "notifications" do
|
|
it_behaves_like "notifiable"
|
|
end
|
|
end
|