diff --git a/app/controllers/api/v1/accounts/articles_controller.rb b/app/controllers/api/v1/accounts/articles_controller.rb index d650b19d9..50c960206 100644 --- a/app/controllers/api/v1/accounts/articles_controller.rb +++ b/app/controllers/api/v1/accounts/articles_controller.rb @@ -5,9 +5,10 @@ class Api::V1::Accounts::ArticlesController < Api::V1::Accounts::BaseController before_action :set_current_page, only: [:index] def index - @articles_count = @portal.articles.count - @articles = @portal.articles - @articles = @articles.search(list_params) if list_params.present? + @portal_articles = @portal.articles + @all_articles = @portal_articles.search(list_params) + @articles_count = @all_articles.count + @articles = @all_articles.page(@current_page) end def create diff --git a/app/controllers/api/v1/accounts/categories_controller.rb b/app/controllers/api/v1/accounts/categories_controller.rb index bc18b61b8..e28e601d5 100644 --- a/app/controllers/api/v1/accounts/categories_controller.rb +++ b/app/controllers/api/v1/accounts/categories_controller.rb @@ -5,6 +5,7 @@ class Api::V1::Accounts::CategoriesController < Api::V1::Accounts::BaseControlle before_action :set_current_page, only: [:index] def index + @current_locale = params[:locale] @categories = @portal.categories.search(params) end diff --git a/app/controllers/api/v1/accounts/portals_controller.rb b/app/controllers/api/v1/accounts/portals_controller.rb index 6ac000b58..62a98a872 100644 --- a/app/controllers/api/v1/accounts/portals_controller.rb +++ b/app/controllers/api/v1/accounts/portals_controller.rb @@ -14,7 +14,10 @@ class Api::V1::Accounts::PortalsController < Api::V1::Accounts::BaseController @portal.members << agents end - def show; end + def show + @all_articles = @portal.articles + @articles = @all_articles.search(locale: params[:locale]) + end def create @portal = Current.account.portals.build(portal_params) diff --git a/app/javascript/dashboard/api/helpCenter/categories.js b/app/javascript/dashboard/api/helpCenter/categories.js index b6eae3f32..01658497e 100644 --- a/app/javascript/dashboard/api/helpCenter/categories.js +++ b/app/javascript/dashboard/api/helpCenter/categories.js @@ -7,8 +7,8 @@ class CategoriesAPI extends PortalsAPI { super('categories', { accountScoped: true }); } - get({ portalSlug }) { - return axios.get(`${this.url}/${portalSlug}/categories`); + get({ portalSlug, locale }) { + return axios.get(`${this.url}/${portalSlug}/categories?locale=${locale}`); } create({ portalSlug, categoryObj }) { diff --git a/app/javascript/dashboard/api/helpCenter/portals.js b/app/javascript/dashboard/api/helpCenter/portals.js index 520453540..28220b0b5 100644 --- a/app/javascript/dashboard/api/helpCenter/portals.js +++ b/app/javascript/dashboard/api/helpCenter/portals.js @@ -6,6 +6,10 @@ class PortalsAPI extends ApiClient { super('portals', { accountScoped: true }); } + getPortal({ portalSlug, locale }) { + return axios.get(`${this.url}/${portalSlug}?locale=${locale}`); + } + updatePortal({ portalSlug, portalObj }) { return axios.patch(`${this.url}/${portalSlug}`, portalObj); } diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/HelpCenterLayout.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/components/HelpCenterLayout.vue index 562d6bd07..bda19b764 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/components/HelpCenterLayout.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/components/HelpCenterLayout.vue @@ -16,7 +16,7 @@ :accessible-menu-items="accessibleMenuItems" :additional-secondary-menu-items="additionalSecondaryMenuItems" @open-popover="openPortalPopover" - @open-modal="onClickOpenAddCatogoryModal" + @open-modal="onClickOpenAddCategoryModal" />
@@ -134,14 +134,14 @@ export default { }, accessibleMenuItems() { if (!this.selectedPortal) return []; + const { - meta: { - all_articles_count: allArticlesCount, - mine_articles_count: mineArticlesCount, - draft_articles_count: draftArticlesCount, - archived_articles_count: archivedArticlesCount, - } = {}, - } = this.selectedPortal; + allArticlesCount, + mineArticlesCount, + draftArticlesCount, + archivedArticlesCount, + } = this.meta; + return [ { icon: 'book', @@ -216,6 +216,13 @@ export default { return this.selectedPortal ? this.selectedPortal.name : ''; }, }, + + watch: { + selectedPortal() { + this.fetchPortalsAndItsCategories(); + }, + }, + mounted() { window.addEventListener('resize', this.handleResize); this.handleResize(); @@ -251,12 +258,15 @@ export default { toggleSidebar() { this.isSidebarOpen = !this.isSidebarOpen; }, - fetchPortalsAndItsCategories() { - this.$store.dispatch('portals/index').then(() => { - this.$store.dispatch('categories/index', { - portalSlug: this.selectedPortalSlug, - }); - }); + async fetchPortalsAndItsCategories() { + await this.$store.dispatch('portals/index'); + + const selectedPortalParam = { + portalSlug: this.selectedPortalSlug, + locale: this.selectedLocaleInPortal, + }; + this.$store.dispatch('portals/show', selectedPortalParam); + this.$store.dispatch('categories/index', selectedPortalParam); this.$store.dispatch('agents/get'); }, toggleKeyShortcutModal() { @@ -277,7 +287,7 @@ export default { closePortalPopover() { this.showPortalPopover = false; }, - onClickOpenAddCatogoryModal() { + onClickOpenAddCategoryModal() { this.showAddCategoryModal = true; }, onClickCloseAddCategoryModal() { diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalSwitch.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalSwitch.vue index 91b8a0467..4404a6c67 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalSwitch.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalSwitch.vue @@ -112,16 +112,8 @@ export default { this.selectedLocale = this.locale || this.portal?.meta?.default_locale; }, methods: { - fetchPortalsAndItsCategories() { - this.$store.dispatch('portals/index').then(() => { - this.$store.dispatch('categories/index', { - portalSlug: this.portal.slug, - }); - }); - }, onClick(event, code, portal) { event.preventDefault(); - this.fetchPortalsAndItsCategories(); this.$router.push({ name: 'list_all_locale_articles', params: { diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/ListAllArticles.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/ListAllArticles.vue index 34c9d7217..cacbd2195 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/ListAllArticles.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/articles/ListAllArticles.vue @@ -104,9 +104,6 @@ export default { } return null; }, - articleCount() { - return this.articles ? this.articles.length : 0; - }, headerTitleInCategoryView() { return this.categories && this.categories.length ? this.selectedCategory.name diff --git a/app/javascript/dashboard/store/modules/helpCenterCategories/actions.js b/app/javascript/dashboard/store/modules/helpCenterCategories/actions.js index ebea5d444..2d212ded3 100644 --- a/app/javascript/dashboard/store/modules/helpCenterCategories/actions.js +++ b/app/javascript/dashboard/store/modules/helpCenterCategories/actions.js @@ -2,13 +2,13 @@ import categoriesAPI from 'dashboard/api/helpCenter/categories.js'; import { throwErrorMessage } from 'dashboard/store/utils/api'; import types from '../../mutation-types'; export const actions = { - index: async ({ commit }, { portalSlug }) => { + index: async ({ commit }, { portalSlug, locale }) => { try { commit(types.SET_UI_FLAG, { isFetching: true }); if (portalSlug) { const { data: { payload }, - } = await categoriesAPI.get({ portalSlug }); + } = await categoriesAPI.get({ portalSlug, locale }); commit(types.CLEAR_CATEGORIES); const categoryIds = payload.map(category => category.id); commit(types.ADD_MANY_CATEGORIES, payload); diff --git a/app/javascript/dashboard/store/modules/helpCenterPortals/actions.js b/app/javascript/dashboard/store/modules/helpCenterPortals/actions.js index 2be7dc03f..bfae85d27 100644 --- a/app/javascript/dashboard/store/modules/helpCenterPortals/actions.js +++ b/app/javascript/dashboard/store/modules/helpCenterPortals/actions.js @@ -7,14 +7,12 @@ export const actions = { try { commit(types.SET_UI_FLAG, { isFetching: true }); const { - data: { payload, meta }, + data: { payload }, } = await portalAPIs.get(); commit(types.CLEAR_PORTALS); const portalSlugs = payload.map(portal => portal.slug); commit(types.ADD_MANY_PORTALS_ENTRY, payload); commit(types.ADD_MANY_PORTALS_IDS, portalSlugs); - - commit(types.SET_PORTALS_META, meta); } catch (error) { throwErrorMessage(error); } finally { @@ -22,6 +20,21 @@ export const actions = { } }, + show: async ({ commit }, { portalSlug, locale }) => { + commit(types.SET_UI_FLAG, { isFetchingItem: true }); + try { + const response = await portalAPIs.getPortal({ portalSlug, locale }); + const { + data: { meta }, + } = response; + commit(types.SET_PORTALS_META, meta); + } catch (error) { + // Ignore error + } finally { + commit(types.SET_UI_FLAG, { isFetchingItem: false }); + } + }, + create: async ({ commit }, params) => { commit(types.SET_UI_FLAG, { isCreating: true }); try { diff --git a/app/javascript/dashboard/store/modules/helpCenterPortals/getters.js b/app/javascript/dashboard/store/modules/helpCenterPortals/getters.js index c3cc790aa..b52f6b4ad 100644 --- a/app/javascript/dashboard/store/modules/helpCenterPortals/getters.js +++ b/app/javascript/dashboard/store/modules/helpCenterPortals/getters.js @@ -20,7 +20,5 @@ export const getters = { return portals; }, count: state => state.portals.allIds.length || 0, - getMeta: state => { - return state.meta; - }, + getMeta: state => state.meta, }; diff --git a/app/javascript/dashboard/store/modules/helpCenterPortals/index.js b/app/javascript/dashboard/store/modules/helpCenterPortals/index.js index fecb17d4d..346eb9e33 100755 --- a/app/javascript/dashboard/store/modules/helpCenterPortals/index.js +++ b/app/javascript/dashboard/store/modules/helpCenterPortals/index.js @@ -10,8 +10,10 @@ export const defaultPortalFlags = { const state = { meta: { - count: 0, - currentPage: 1, + allArticlesCount: 0, + mineArticlesCount: 0, + draftArticlesCount: 0, + archivedArticlesCount: 0, }, portals: { diff --git a/app/javascript/dashboard/store/modules/helpCenterPortals/mutations.js b/app/javascript/dashboard/store/modules/helpCenterPortals/mutations.js index 421b0dc7e..dcce09854 100644 --- a/app/javascript/dashboard/store/modules/helpCenterPortals/mutations.js +++ b/app/javascript/dashboard/store/modules/helpCenterPortals/mutations.js @@ -44,9 +44,16 @@ export const mutations = { }, [types.SET_PORTALS_META]: ($state, data) => { - const { portals_count: count, current_page: currentPage } = data; - Vue.set($state.meta, 'count', count); - Vue.set($state.meta, 'currentPage', currentPage); + const { + all_articles_count: allArticlesCount, + mine_articles_count: mineArticlesCount, + draft_articles_count: draftArticlesCount, + archived_articles_count: archivedArticlesCount, + } = data; + Vue.set($state.meta, 'allArticlesCount', allArticlesCount); + Vue.set($state.meta, 'archivedArticlesCount', archivedArticlesCount); + Vue.set($state.meta, 'mineArticlesCount', mineArticlesCount); + Vue.set($state.meta, 'draftArticlesCount', draftArticlesCount); }, [types.ADD_PORTAL_ID]($state, portalSlug) { diff --git a/app/javascript/dashboard/store/modules/helpCenterPortals/specs/actions.spec.js b/app/javascript/dashboard/store/modules/helpCenterPortals/specs/actions.spec.js index aeda57df0..6fdd054b3 100644 --- a/app/javascript/dashboard/store/modules/helpCenterPortals/specs/actions.spec.js +++ b/app/javascript/dashboard/store/modules/helpCenterPortals/specs/actions.spec.js @@ -22,7 +22,6 @@ describe('#actions', () => { [types.CLEAR_PORTALS], [types.ADD_MANY_PORTALS_ENTRY, apiResponse.payload], [types.ADD_MANY_PORTALS_IDS, ['domain', 'campaign']], - [types.SET_PORTALS_META, { current_page: 1, portals_count: 1 }], [types.SET_UI_FLAG, { isFetching: false }], ]); }); @@ -66,6 +65,36 @@ describe('#actions', () => { }); }); + describe('#show', () => { + it('sends correct actions if API is success', async () => { + axios.get.mockResolvedValue({ + data: { meta: { all_articles_count: 1 } }, + }); + await actions.show( + { commit }, + { + portalSlug: 'handbook', + locale: 'en', + } + ); + expect(commit.mock.calls).toEqual([ + [types.SET_UI_FLAG, { isFetchingItem: true }], + [types.SET_PORTALS_META, { all_articles_count: 1 }], + [types.SET_UI_FLAG, { isFetchingItem: false }], + ]); + }); + it('sends correct actions if API is error', async () => { + axios.post.mockRejectedValue({ message: 'Incorrect header' }); + await expect( + actions.create({ commit, dispatch, state: { portals: {} } }, {}) + ).rejects.toThrow(Error); + expect(commit.mock.calls).toEqual([ + [types.SET_UI_FLAG, { isCreating: true }], + [types.SET_UI_FLAG, { isCreating: false }], + ]); + }); + }); + describe('#update', () => { it('sends correct actions if API is success', async () => { axios.patch.mockResolvedValue({ data: apiResponse.payload[1] }); diff --git a/app/javascript/dashboard/store/modules/helpCenterPortals/specs/mutations.spec.js b/app/javascript/dashboard/store/modules/helpCenterPortals/specs/mutations.spec.js index d20cacd1b..2e58c1de7 100644 --- a/app/javascript/dashboard/store/modules/helpCenterPortals/specs/mutations.spec.js +++ b/app/javascript/dashboard/store/modules/helpCenterPortals/specs/mutations.spec.js @@ -107,12 +107,20 @@ describe('#mutations', () => { describe('#SET_PORTALS_META', () => { it('add meta to state', () => { mutations[types.SET_PORTALS_META](state, { - portals_count: 10, - current_page: 1, - }); - expect(state.meta).toEqual({ count: 10, currentPage: 1, + all_articles_count: 10, + archived_articles_count: 10, + draft_articles_count: 10, + mine_articles_count: 10, + }); + expect(state.meta).toEqual({ + count: 0, + currentPage: 1, + allArticlesCount: 10, + archivedArticlesCount: 10, + draftArticlesCount: 10, + mineArticlesCount: 10, }); }); }); diff --git a/app/models/article.rb b/app/models/article.rb index ac6506d01..351053380 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -83,11 +83,7 @@ class Article < ApplicationRecord ).search_by_category_locale(params[:locale]).search_by_author(params[:author_id]).search_by_status(params[:status]) records = records.text_search(params[:query]) if params[:query].present? - records.page(current_page(params)) - end - - def self.current_page(params) - params[:page] || 1 + records end def associate_root_article(associated_article_id) diff --git a/app/views/api/v1/accounts/articles/_article.json.jbuilder b/app/views/api/v1/accounts/articles/_article.json.jbuilder index 4a0d8a505..19b759161 100644 --- a/app/views/api/v1/accounts/articles/_article.json.jbuilder +++ b/app/views/api/v1/accounts/articles/_article.json.jbuilder @@ -13,12 +13,6 @@ json.category do json.locale article.category.locale end -if article.portal.present? - json.portal do - json.partial! 'api/v1/accounts/portals/portal', formats: [:json], portal: article.portal - end -end - json.views article.views if article.author.present? diff --git a/app/views/api/v1/accounts/articles/_associated_article.json.jbuilder b/app/views/api/v1/accounts/articles/_associated_article.json.jbuilder index 74101ed33..342018857 100644 --- a/app/views/api/v1/accounts/articles/_associated_article.json.jbuilder +++ b/app/views/api/v1/accounts/articles/_associated_article.json.jbuilder @@ -8,7 +8,7 @@ json.account_id article.account_id if article.portal.present? json.portal do - json.partial! 'api/v1/accounts/portals/portal', formats: [:json], portal: article.portal + json.partial! 'api/v1/accounts/portals/portal', formats: [:json], portal: article.portal, articles: [] end end diff --git a/app/views/api/v1/accounts/articles/index.json.jbuilder b/app/views/api/v1/accounts/articles/index.json.jbuilder index bcefd6d06..afc8b14d9 100644 --- a/app/views/api/v1/accounts/articles/index.json.jbuilder +++ b/app/views/api/v1/accounts/articles/index.json.jbuilder @@ -3,10 +3,11 @@ json.payload do end json.meta do - json.current_page @current_page - json.articles_count @articles_count + json.all_articles_count @portal_articles.size json.archived_articles_count @articles.archived.size + json.articles_count @articles_count + json.current_page @current_page + json.draft_articles_count @all_articles.draft.size + json.mine_articles_count @all_articles.search_by_author(current_user.id).size if current_user.present? json.published_count @articles.published.size - json.draft_articles_count @articles.draft.size - json.mine_articles_count @articles.search_by_author(current_user.id).size if current_user.present? end diff --git a/app/views/api/v1/accounts/categories/_category.json.jbuilder b/app/views/api/v1/accounts/categories/_category.json.jbuilder index 35105c813..825b9c2d7 100644 --- a/app/views/api/v1/accounts/categories/_category.json.jbuilder +++ b/app/views/api/v1/accounts/categories/_category.json.jbuilder @@ -27,5 +27,5 @@ if category.root_category.present? end json.meta do - json.articles_count category.articles.size + json.articles_count category.articles.search(locale: @current_locale).size end diff --git a/app/views/api/v1/accounts/portals/_portal.json.jbuilder b/app/views/api/v1/accounts/portals/_portal.json.jbuilder index 46c7a2fb0..b17c844d9 100644 --- a/app/views/api/v1/accounts/portals/_portal.json.jbuilder +++ b/app/views/api/v1/accounts/portals/_portal.json.jbuilder @@ -28,11 +28,11 @@ json.portal_members do end json.meta do - json.all_articles_count portal.articles.size - json.archived_articles_count portal.articles.archived.size - json.published_count portal.articles.published.size - json.draft_articles_count portal.articles.draft.size - json.mine_articles_count portal.articles.search_by_author(current_user.id).size if current_user.present? - json.categories_count portal.categories.size + json.all_articles_count articles.try(:size) + json.archived_articles_count articles.try(:archived).try(:size) + json.published_count articles.try(:published).try(:size) + json.draft_articles_count articles.try(:draft).try(:size) + json.mine_articles_count articles.search_by_author(current_user.id).try(:size) if current_user.present? && articles.any? + json.categories_count portal.categories.try(:size) json.default_locale portal.default_locale end diff --git a/app/views/api/v1/accounts/portals/add_members.json.jbuilder b/app/views/api/v1/accounts/portals/add_members.json.jbuilder index f4bc72924..40641fa79 100644 --- a/app/views/api/v1/accounts/portals/add_members.json.jbuilder +++ b/app/views/api/v1/accounts/portals/add_members.json.jbuilder @@ -1 +1 @@ -json.partial! 'portal', portal: @portal +json.partial! 'portal', portal: @portal, articles: [] diff --git a/app/views/api/v1/accounts/portals/create.json.jbuilder b/app/views/api/v1/accounts/portals/create.json.jbuilder index f4bc72924..40641fa79 100644 --- a/app/views/api/v1/accounts/portals/create.json.jbuilder +++ b/app/views/api/v1/accounts/portals/create.json.jbuilder @@ -1 +1 @@ -json.partial! 'portal', portal: @portal +json.partial! 'portal', portal: @portal, articles: [] diff --git a/app/views/api/v1/accounts/portals/index.json.jbuilder b/app/views/api/v1/accounts/portals/index.json.jbuilder index 2fb93d918..d602b660b 100644 --- a/app/views/api/v1/accounts/portals/index.json.jbuilder +++ b/app/views/api/v1/accounts/portals/index.json.jbuilder @@ -1,5 +1,7 @@ json.payload do - json.array! @portals, partial: 'portal', as: :portal + json.array! @portals.each do |portal| + json.partial! 'portal', formats: [:json], portal: portal, articles: [] + end end json.meta do diff --git a/app/views/api/v1/accounts/portals/show.json.jbuilder b/app/views/api/v1/accounts/portals/show.json.jbuilder index f4bc72924..6350b5a73 100644 --- a/app/views/api/v1/accounts/portals/show.json.jbuilder +++ b/app/views/api/v1/accounts/portals/show.json.jbuilder @@ -1 +1 @@ -json.partial! 'portal', portal: @portal +json.partial! 'portal', portal: @portal, articles: @articles diff --git a/app/views/api/v1/accounts/portals/update.json.jbuilder b/app/views/api/v1/accounts/portals/update.json.jbuilder index f4bc72924..40641fa79 100644 --- a/app/views/api/v1/accounts/portals/update.json.jbuilder +++ b/app/views/api/v1/accounts/portals/update.json.jbuilder @@ -1 +1 @@ -json.partial! 'portal', portal: @portal +json.partial! 'portal', portal: @portal, articles: [] diff --git a/spec/controllers/api/v1/accounts/articles_controller_spec.rb b/spec/controllers/api/v1/accounts/articles_controller_spec.rb index 2090533bd..1de808a20 100644 --- a/spec/controllers/api/v1/accounts/articles_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/articles_controller_spec.rb @@ -194,7 +194,8 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do expect(response).to have_http_status(:success) json_response = JSON.parse(response.body) expect(json_response['payload'].count).to be 1 - expect(json_response['meta']['articles_count']).to be 2 + expect(json_response['meta']['all_articles_count']).to be 2 + expect(json_response['meta']['articles_count']).to be 1 expect(json_response['meta']['mine_articles_count']).to be 1 end end diff --git a/spec/controllers/api/v1/accounts/portals_controller_spec.rb b/spec/controllers/api/v1/accounts/portals_controller_spec.rb index 71a4b755d..8333d52e5 100644 --- a/spec/controllers/api/v1/accounts/portals_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/portals_controller_spec.rb @@ -50,6 +50,25 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do expect(response).to have_http_status(:success) json_response = JSON.parse(response.body) expect(json_response['name']).to eq portal.name + expect(json_response['meta']['all_articles_count']).to eq 0 + end + + it 'returns portal articles metadata' do + portal.update(config: { allowed_locales: %w[en es], default_locale: 'en' }) + en_cat = create(:category, locale: :en, portal_id: portal.id, slug: 'en-cat') + es_cat = create(:category, locale: :es, portal_id: portal.id, slug: 'es-cat') + create(:article, category_id: en_cat.id, portal_id: portal.id, author_id: agent.id) + create(:article, category_id: en_cat.id, portal_id: portal.id, author_id: admin.id) + create(:article, category_id: es_cat.id, portal_id: portal.id, author_id: agent.id) + + get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}?locale=en", + headers: agent.create_new_auth_token + + expect(response).to have_http_status(:success) + json_response = JSON.parse(response.body) + expect(json_response['name']).to eq portal.name + expect(json_response['meta']['all_articles_count']).to eq 2 + expect(json_response['meta']['mine_articles_count']).to eq 1 end end end diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 2e0f957dc..dac5a3d52 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -126,20 +126,5 @@ RSpec.describe Article, type: :model do expect(article.slug).to include('the-awesome-article-1') end end - - context 'with pagination' do - it 'returns paginated articles' do - build_list(:article, 30) do |record, i| - record.category_id = category_2.id - record.title = "title #{i}" - record.portal_id = portal_2.id - record.author_id = user.id - record.save! - end - params = { category_slug: 'category_2' } - records = portal_2.articles.search(params) - expect(records.count).to eq(25) - end - end end end