Skip to content

Instantly share code, notes, and snippets.

@domagude
Created November 5, 2017 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domagude/a83f84760a04d7a4d4337082fb4fd73a to your computer and use it in GitHub Desktop.
Save domagude/a83f84760a04d7a4d4337082fb4fd73a to your computer and use it in GitHub Desktop.
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