Created
November 5, 2017 17:30
-
-
Save domagude/a83f84760a04d7a4d4337082fb4fd73a to your computer and use it in GitHub Desktop.
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
require 'rails_helper' | |
require './app/services/posts_for_branch_service.rb' | |
describe PostsForBranchService do | |
context '#call' do | |
let(:not_included_posts) { create_list(:post, 2) } | |
let(:category) { create(:category, branch: 'hobby', name: 'arts') } | |
let(:post) do | |
create(:post, | |
title: 'a very fun post', | |
category_id: category.id) | |
end | |
it 'returns posts filtered by a branch' do | |
not_included_posts | |
category | |
included_posts = create_list(:post, 2, category_id: category.id) | |
expect(PostsForBranchService.new({branch: 'hobby'}).call).to( | |
match_array included_posts | |
) | |
end | |
it 'returns posts filtered by a branch and a search input' do | |
not_included_posts | |
category | |
included_post = [] << post | |
expect(PostsForBranchService.new({branch: 'hobby', search: 'fun'}).call).to( | |
eq included_post | |
) | |
end | |
it 'returns posts filtered by a category name' do | |
not_included_posts | |
category | |
included_post = [] << post | |
expect(PostsForBranchService.new({branch: 'hobby', category: 'arts'}).call).to( | |
eq included_post | |
) | |
end | |
it 'returns posts filtered by a category name and a search input' do | |
not_included_posts | |
category | |
included_post = [] << post | |
expect(PostsForBranchService.new({name: 'arts', | |
search: 'fun', | |
branch: 'hobby'}).call).to eq included_post | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment